Skip to content

Commit

Permalink
check order is not None
Browse files Browse the repository at this point in the history
  • Loading branch information
Bchass committed Jun 7, 2024
1 parent 984b14a commit d1f6f3f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 2 additions & 2 deletions tinynumpy/tests/test_tinynumpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,17 @@ def test_strides_for_shape():
# check against numpy
assert actual_strides == numpy_strides, f"For shape {shape}, order {order}: Expected {actual_strides}, got {numpy_strides}"


def test_order_flags():
b = tnp.array([[1, 2, 3], [4, 5, 6]], order='F')
a = tnp.array([1,2,3], order='C')

if b.ndim > 1:
assert b.flags['F_CONTIGUOUS'] == True
assert b.flags['C_CONTIGUOUS'] == False
else:
assert b.flags['F_CONTIGUOUS'] == True
assert b.flags['C_CONTIGUOUS'] == True
with pytest.raises(ValueError):
b = tnp.array([[1, 2, 3], [4, 5, 6]], order='')


def test_repr():
Expand Down
4 changes: 3 additions & 1 deletion tinynumpy/tinynumpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def _strides_for_shape(shape, itemsize, order='C'):
for s in shape:
strides.append(stride_product)
stride_product *= s
return tuple([i * itemsize for i in (strides)])
return tuple([i * itemsize for i in strides])
elif order == 'C':
strides = []
stride_product = 1
Expand Down Expand Up @@ -599,6 +599,8 @@ def __init__(self, shape, dtype='float64', buffer=None, offset=0,
self.flags = {'F_CONTIGUOUS': True, 'C_CONTIGUOUS': False}
else:
self.flags = {'F_CONTIGUOUS': True, 'C_CONTIGUOUS': True}
elif order is not None:
raise ValueError("Invalid order specified. Please specify 'C' for C-order or 'F' for Fortran-order.")
else:
# Existing array
if isinstance(buffer, ndarray) and buffer.base is not None:
Expand Down

0 comments on commit d1f6f3f

Please sign in to comment.