Skip to content

[Code scan] block_avg crashes when no full block remains #143

Description

@njzjz

Source: Codex global repository scan of deepmodeling/dpti at commit b719828.
Project: DeepModeling Agent Code Scan

Problem
block_avg() assumes at least one full block survives after skip. If the input after skipping is empty, data_chunks[-1] raises IndexError; if it has fewer samples than block_size, the only partial block is dropped and NumPy later raises an axis error.

Code references

def block_avg(inp, skip = 0, block_size = 10) :

if (len(data_chunks[-1]) != block_size) :

data_chunks = np.array(data_chunks)

Reproduction
Run:

import numpy as np
from dpti.lib.utils import block_avg
block_avg(np.arange(5), block_size=10)

Expected result
The function should either handle the partial block intentionally or raise a clear validation error explaining that no complete block is available.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    Status
    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions