Skip to content

ulab array corruption with slices #4753

Closed
@kevinjwalters

Description

@kevinjwalters

I noticed this on CircuitPython 6.2.0 on a CLUE (nRF52840):

Adafruit CircuitPython 6.2.0 on 2021-04-05; Adafruit CLUE nRF52840 Express with nRF52840
>>> import ulab
>>> import ulab.numerical
>>> import ulab.filter
>>> data = ulab.ones(10000)
>>> fir_taps = ulab.array([0.15, 0.2, 0.3, 0.2, 0.15])
>>> filtered_data = ulab.filter.convolve(data, fir_taps)[6:-6]
>>> ulab.numerical.sum(filtered_data)
9992.0
>>> len(filtered_data)
9992
>>> a = []  ### append to an array to write and use up free memory
>>> for idx in range(1_000_000):
...     a.append("AYMABTU")
...
...
...
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
MemoryError: memory allocation failed, allocating 131072 bytes
>>> del a
>>> ulab.numerical.sum(filtered_data)  ### no longer 9992.0 !!
9882.01
>>> ulab.numerical.sum(data)  ### although this one is ok
10000.0
>>> filtered_data[0:10]
array([2.98023e-08, 0.0, 1.19209e-07, 0.0, -6.61744e-24, 0.0, -2.64698e-23, 0.0, 1.70141e+38, 0.0], dtype=float32)

I'd guess it's related to premature GC of the ndarray returned by ulab.filter.convolve(). That would be inappropriate as the slice is a view onto that data as I understand it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugnordiculabRelated to the ulab module

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions