Skip to content

Commit

Permalink
refactor _strides_for_shape
Browse files Browse the repository at this point in the history
  • Loading branch information
Bchass committed Jun 17, 2024
1 parent 4941343 commit b2ca693
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions tinynumpy/tinynumpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,16 @@ def _get_step(view):
return 0 # not contiguous

def _strides_for_shape(shape, itemsize, order='C'):
strides = []
stride_product = 1

if order == 'F':
shape_iter = shape
else:
shape_iter = reversed(shape)
for s in shape_iter:
strides.append(stride_product)
stride_product *= s
if order == 'C':
strides.reverse()
return tuple(i * itemsize for i in strides)
strides = [itemsize]
for dim in reversed(shape[1:]):
strides.insert(0, strides[0] * dim)
elif order == 'F':
strides = [itemsize]
for dim in shape[:-1]:
strides.append(strides[-1] * dim)
return tuple(strides)


def _size_for_shape(shape):
Expand Down

0 comments on commit b2ca693

Please sign in to comment.