Skip to content

Commit

Permalink
Fix buffersize and __repr__
Browse files Browse the repository at this point in the history
  • Loading branch information
Bchass committed Jun 27, 2024
1 parent d96f531 commit 3003d5c
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions tinynumpy/tinynumpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,13 @@ def _assign_from_object(array, obj, order):
def _assign_from_object_r(element, indices):
if isinstance(element, list):
for i, e in enumerate(element):
_assign_from_object_r(e, indices + [i])
new_indices = indices + [i]
_assign_from_object_r(e, new_indices)
else:
if order == 'F':
indices = indices[:-1]
indices = indices[::1]

Check warning on line 160 in tinynumpy/tinynumpy.py

View check run for this annotation

Codecov / codecov/patch

tinynumpy/tinynumpy.py#L160

Added line #L160 was not covered by tests
array[tuple(indices)] = element

_assign_from_object_r(obj, [])
return array

Expand Down Expand Up @@ -621,10 +623,17 @@ def __init__(self, shape, dtype='float64', buffer=None, offset=0,
assert len(strides) == len(shape)
self._strides = strides

# Define our buffer class
buffersize = self._strides[0] * self._shape[0] // self._itemsize
buffersize += self._offset
BufferClass = _convert_dtype(dtype, 'ctypes') * buffersize
# If order is F we need to loop
if order == 'F':
total_elements = 1
for dim in shape:
total_elements += dim
buffersize = total_elements
BufferClass = _convert_dtype(dtype, 'ctypes') * buffersize
else:
buffersize = self._strides[0] * self._shape[0] // self._itemsize
buffersize += self._offset
BufferClass = _convert_dtype(dtype, 'ctypes') * buffersize
# Create buffer
if buffer is None:
self._data = BufferClass()
Expand Down

0 comments on commit 3003d5c

Please sign in to comment.