예제 #1
0
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"
예제 #2
0
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"
예제 #3
0
def array(value, dtype = None):
  if dtype is not None:
    expected_elt_type = _get_type(dtype)
    print "Got dtype argument to array: %s, ignoring for now" % expected_elt_type

  if isinstance(value.type, ArrayT):
    return value 
  else:
    assert isinstance(value.type, TupleT), "Don't know how to make array from %s : %s" % (value, value.type)
    elt_types = value.type.elt_types
    assert all(isinstance(t, ScalarT) for t in elt_types), \
      "Can only make array from tuple of scalars, not %s : %s" % (value, value.type)
    elt_t = combine_type_list(value.type.elt_types)
    array_elts = _get_tuple_elts(value, cast_type = elt_t)
    array_t = make_array_type(elt_t, 1)
    return Array(elts = array_elts, type = array_t)
예제 #4
0
def array(value, dtype=None):
    if dtype is not None:
        expected_elt_type = _get_type(dtype)
        print "Got dtype argument to array: %s, ignoring for now" % expected_elt_type

    if isinstance(value.type, ArrayT):
        return value
    else:
        assert isinstance(
            value.type,
            TupleT), "Don't know how to make array from %s : %s" % (value,
                                                                    value.type)
        elt_types = value.type.elt_types
        assert all(isinstance(t, ScalarT) for t in elt_types), \
          "Can only make array from tuple of scalars, not %s : %s" % (value, value.type)
        elt_t = combine_type_list(value.type.elt_types)
        array_elts = _get_tuple_elts(value, cast_type=elt_t)
        array_t = make_array_type(elt_t, 1)
        return Array(elts=array_elts, type=array_t)