def empty(shape, dtype = float64): elt_t = _get_type(dtype) assert isinstance(elt_t, ScalarT), "Array element type %s must be scalar" % (elt_t,) shape = _get_shape(shape) rank = len(shape.type.elt_types) arr_t = make_array_type(elt_t, rank) return AllocArray(shape = shape, elt_type = elt_t, type = arr_t)
def empty(shape, dtype=float64): elt_t = _get_type(dtype) assert isinstance( elt_t, ScalarT), "Array element type %s must be scalar" % (elt_t, ) shape = _get_shape(shape) rank = len(shape.type.elt_types) arr_t = make_array_type(elt_t, rank) return AllocArray(shape=shape, elt_type=elt_t, type=arr_t)
def ones(shape, dtype = float64): shape = _get_shape(shape) elt_type = _get_type(dtype) one = Cast(one_i64, type = elt_type) ndims = len(shape.type.elt_types) if ndims == 0: return one else: t = make_array_type(elt_type, ndims) return ConstArray(shape = shape, value = one, type = t)
def zeros(shape, dtype = float64): shape = _get_shape(shape) elt_type = _get_type(dtype) zero = Cast(zero_i64, type = elt_type) ndims = len(shape.type.elt_types) if ndims == 0: return zero else: t = make_array_type(elt_type, ndims) return ConstArray(shape = shape, value = zero, type = t)
def ones(shape, dtype=float64): shape = _get_shape(shape) elt_type = _get_type(dtype) one = Cast(one_i64, type=elt_type) ndims = len(shape.type.elt_types) if ndims == 0: return one else: t = make_array_type(elt_type, ndims) return ConstArray(shape=shape, value=one, type=t)
def zeros(shape, dtype=float64): shape = _get_shape(shape) elt_type = _get_type(dtype) zero = Cast(zero_i64, type=elt_type) ndims = len(shape.type.elt_types) if ndims == 0: return zero else: t = make_array_type(elt_type, ndims) return ConstArray(shape=shape, value=zero, type=t)
def tile(A, reps): reps = _get_shape(reps) reps_dims = len(reps.type.elt_types) if reps_dims == 0: return A A_rank = A.type.rank if isinstance(A.type, ArrayT) else 0 if A_rank == 0: # array scalars, ugh! if isinstance(A.type, ArrayT): A = Index(A, make_tuple(()), type = A.elt_type) assert isinstance(A.type, ScalarT), "First argument to 'tile' must be array or scalar" array_t = make_array_type(A.type, reps_dims) return ConstArray(value = A, shape = reps, type = array_t) else: A_shape = Shape(A, type = repeat_tuple(Int64, A_rank)) A_shape_elts = _get_tuple_elts(A_shape) reps_elts = _get_tuple_elts(reps) result_shape_elts = [] assert False, "np.tile not yet implemented"
def tile(A, reps): reps = _get_shape(reps) reps_dims = len(reps.type.elt_types) if reps_dims == 0: return A A_rank = A.type.rank if isinstance(A.type, ArrayT) else 0 if A_rank == 0: # array scalars, ugh! if isinstance(A.type, ArrayT): A = Index(A, make_tuple(()), type=A.elt_type) assert isinstance( A.type, ScalarT), "First argument to 'tile' must be array or scalar" array_t = make_array_type(A.type, reps_dims) return ConstArray(value=A, shape=reps, type=array_t) else: A_shape = Shape(A, type=repeat_tuple(Int64, A_rank)) A_shape_elts = _get_tuple_elts(A_shape) reps_elts = _get_tuple_elts(reps) result_shape_elts = [] assert False, "np.tile not yet implemented"
def parfor(fn, bounds): fn = translate_function_value(fn) bounds = _get_shape(bounds) return ParFor(fn = fn, bounds = bounds)