def test_broadcast_arrays(): # Currently arrayfire is missing support for int64 x2 = numpy.array([[1,2,3]], dtype=numpy.float32) y2 = numpy.array([[1],[2],[3]], dtype=numpy.float32) x1 = afnumpy.array(x2) y1 = afnumpy.array(y2) iassert(afnumpy.broadcast_arrays(x1, y1), numpy.broadcast_arrays(x2, y2)) x1 = afnumpy.array([2]) y1 = afnumpy.array(2) x2 = numpy.array([2]) y2 = numpy.array(2) iassert(afnumpy.broadcast_arrays(x1, y1), numpy.broadcast_arrays(x2, y2))
def test_broadcast_arrays(): # Currently arrayfire is missing support for int64 x2 = numpy.array([[1, 2, 3]], dtype=numpy.float32) y2 = numpy.array([[1], [2], [3]], dtype=numpy.float32) x1 = afnumpy.array(x2) y1 = afnumpy.array(y2) iassert(afnumpy.broadcast_arrays(x1, y1), numpy.broadcast_arrays(x2, y2)) x1 = afnumpy.array([2]) y1 = afnumpy.array(2) x2 = numpy.array([2]) y2 = numpy.array(2) iassert(afnumpy.broadcast_arrays(x1, y1), numpy.broadcast_arrays(x2, y2))
def wrapper(*args, **kws): if all(isinstance(A, afnumpy.ndarray) for A in args): args = afnumpy.broadcast_arrays(*args) ret = func(*args, **kws) if len(ret.shape) == 0: return ret[()] return ret
def wrapper(*args, **kws): if all(isinstance(A, afnumpy.ndarray) for A in args): bcast_args = afnumpy.broadcast_arrays(*args) if(bcast_args[0].shape is not args[0].shape): raise ValueError("non-broadcastable output operand with" " shape %s doesn't match the broadcast" " shape %s" % (args[0].shape, bcast_args[0].shape)) args = bcast_args ret = func(*args, **kws) if len(ret.shape) == 0: return ret[()] return ret
def wrapper(*args, **kws): if all(isinstance(A, afnumpy.ndarray) for A in args): bcast_args = afnumpy.broadcast_arrays(*args) if (bcast_args[0].shape is not args[0].shape): raise ValueError("non-broadcastable output operand with" " shape %s doesn't match the broadcast" " shape %s" % (args[0].shape, bcast_args[0].shape)) args = bcast_args ret = func(*args, **kws) if len(ret.shape) == 0: return ret[()] return ret
def meshgrid(*xi, **kwargs): ndim = len(xi) copy_ = kwargs.pop('copy', True) sparse = kwargs.pop('sparse', False) indexing = kwargs.pop('indexing', 'xy') if kwargs: raise TypeError("meshgrid() got an unexpected keyword argument '%s'" % (list(kwargs)[0], )) if indexing not in ['xy', 'ij']: raise ValueError("Valid values for `indexing` are 'xy' and 'ij'.") s0 = (1, ) * ndim output = [ afnumpy.asanyarray(x).reshape(s0[:i] + (-1, ) + s0[i + 1::]) for i, x in enumerate(xi) ] shape = [x.size for x in output] if indexing == 'xy' and ndim > 1: # switch first and second axis output[0].shape = (1, -1) + (1, ) * (ndim - 2) output[1].shape = (-1, 1) + (1, ) * (ndim - 2) shape[0], shape[1] = shape[1], shape[0] if sparse: if copy_: return [x.copy() for x in output] else: return output else: # Return the full N-D matrix (not only the 1-D vector) if copy_: # Numpy uses dtype=int but Arrayfire does not support int64 in all functions mult_fact = afnumpy.ones(shape, dtype=numpy.int32) return [x * mult_fact for x in output] else: return afnumpy.broadcast_arrays(*output)
def meshgrid(*xi, **kwargs): ndim = len(xi) copy_ = kwargs.pop('copy', True) sparse = kwargs.pop('sparse', False) indexing = kwargs.pop('indexing', 'xy') if kwargs: raise TypeError("meshgrid() got an unexpected keyword argument '%s'" % (list(kwargs)[0],)) if indexing not in ['xy', 'ij']: raise ValueError( "Valid values for `indexing` are 'xy' and 'ij'.") s0 = (1,) * ndim output = [afnumpy.asanyarray(x).reshape(s0[:i] + (-1,) + s0[i + 1::]) for i, x in enumerate(xi)] shape = [x.size for x in output] if indexing == 'xy' and ndim > 1: # switch first and second axis output[0].shape = (1, -1) + (1,)*(ndim - 2) output[1].shape = (-1, 1) + (1,)*(ndim - 2) shape[0], shape[1] = shape[1], shape[0] if sparse: if copy_: return [x.copy() for x in output] else: return output else: # Return the full N-D matrix (not only the 1-D vector) if copy_: # Numpy uses dtype=int but Arrayfire does not support int64 in all functions mult_fact = afnumpy.ones(shape, dtype=numpy.int32) return [x * mult_fact for x in output] else: return afnumpy.broadcast_arrays(*output)