Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
----------
lhs, rhs : ElementWise or scalar
The objects to broadcast together.
Returns
-------
lhs, rhs : ElementWise
The broadcasted operands.
Raises
-------
ValueError
Raised when the operands cannot be broadcasted together.
"""
if not isinstance(lhs, ElementWise):
lhs = ElementWise([lhs])
if not isinstance(rhs, ElementWise):
rhs = ElementWise([rhs])
if len(lhs) == len(rhs):
return lhs, rhs
if len(lhs) == 1:
return ElementWise([lhs._elements[0]] * len(rhs)), rhs
if len(rhs) == 1:
return lhs, ElementWise([rhs._elements[0]] * len(lhs))
raise bad_broadcast(lhs, rhs)
The objects to broadcast together.
Returns
-------
lhs, rhs : ElementWise
The broadcasted operands.
Raises
-------
ValueError
Raised when the operands cannot be broadcasted together.
"""
if not isinstance(lhs, ElementWise):
lhs = ElementWise([lhs])
if not isinstance(rhs, ElementWise):
rhs = ElementWise([rhs])
if len(lhs) == len(rhs):
return lhs, rhs
if len(lhs) == 1:
return ElementWise([lhs._elements[0]] * len(rhs)), rhs
if len(rhs) == 1:
return lhs, ElementWise([rhs._elements[0]] * len(lhs))
raise bad_broadcast(lhs, rhs)
def op(self, other):
if (not isinstance(self, ElementWise) and
not isinstance(other, ElementWise)):
return operator(self, other)
return ElementWise(list(map(operator, *broadcast(self, other))))
op.__doc__ = doc
def op(self):
if not isinstance(self, ElementWise):
return operator(self)
return ElementWise(list(map(operator, self)))
ValueError
Raised when the operands cannot be broadcasted together.
"""
if not isinstance(lhs, ElementWise):
lhs = ElementWise([lhs])
if not isinstance(rhs, ElementWise):
rhs = ElementWise([rhs])
if len(lhs) == len(rhs):
return lhs, rhs
if len(lhs) == 1:
return ElementWise([lhs._elements[0]] * len(rhs)), rhs
if len(rhs) == 1:
return lhs, ElementWise([rhs._elements[0]] * len(lhs))
raise bad_broadcast(lhs, rhs)
def op(self, other):
return ElementWise(list(map(operator, *broadcast(other, self))))
def __getitem__(self, ix):
elements = self._elements
try:
return elements[ix]
except TypeError:
pass
if isinstance(ix[0], bool):
if len(self) != len(ix):
raise bad_broadcast(self, ix)
return ElementWise(list(compress(elements, ix)))
return ElementWise([elements[i] for i in ix])