Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions lazyarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def check_shape(meth):
"""
@wraps(meth)
def wrapped_meth(self, val):
if isinstance(val, (larray, numpy.ndarray)):
if isinstance(val, (larray, numpy.ndarray)) and val.shape:
if val.shape != self._shape:
raise ValueError("shape mismatch: objects cannot be broadcast to a single shape")
return meth(self, val)
Expand Down Expand Up @@ -160,7 +160,7 @@ class larray(object):
- in parallelized code, different rows or columns may be evaluated
on different nodes or in different threads.
"""


def __init__(self, value, shape=None, dtype=None):
"""
Expand All @@ -186,19 +186,19 @@ def __init__(self, value, shape=None, dtype=None):
self.base_value = value.base_value
self.dtype = dtype or value.dtype
self.operations = value.operations # should deepcopy?

elif isinstance(value, collections.Sized): # False for numbers, generators, functions, iterators
if have_scipy and sparse.issparse(value): # For sparse matrices
self.dtype = dtype or value.dtype
elif not isinstance(value, numpy.ndarray):
self.dtype = dtype or value.dtype
elif not isinstance(value, numpy.ndarray):
value = numpy.array(value, dtype=dtype)
elif dtype is not None:
assert numpy.can_cast(value.dtype, dtype, casting='safe') # or could convert value to the provided dtype
if shape and value.shape != shape:
raise ValueError("Array has shape %s, value has shape %s" % (shape, value.shape))
self._shape = value.shape
self.base_value = value

else:
assert numpy.isreal(value) # also True for callables, generators, iterators
self._shape = shape
Expand Down