示例#1
0
def ext_arr_to_matrix(arr: ext_arr(), mat: template(), as_vector: template()):
    for I in grouped(mat):
        for p in static(range(mat.n)):
            for q in static(range(mat.m)):
                if static(as_vector):
                    mat[I][p] = arr[I, p]
                else:
                    mat[I][p, q] = arr[I, p, q]
示例#2
0
def matrix_to_ext_arr(mat: template(), arr: ndarray_type.ndarray(),
                      as_vector: template()):
    for I in grouped(mat):
        for p in static(range(mat.n)):
            for q in static(range(mat.m)):
                if static(as_vector):
                    arr[I, p] = mat[I][p]
                else:
                    arr[I, p, q] = mat[I][p, q]
示例#3
0
def ndarray_matrix_to_ext_arr(ndarray: any_arr(), arr: ext_arr(),
                              as_vector: template()):
    for I in grouped(ndarray):
        for p in static(range(ndarray[I].n)):
            for q in static(range(ndarray[I].m)):
                if static(as_vector):
                    arr[I, p] = ndarray[I][p]
                else:
                    arr[I, p, q] = ndarray[I][p, q]
示例#4
0
def ndarray_matrix_to_ext_arr(ndarray: ndarray_type.ndarray(),
                              arr: ndarray_type.ndarray(),
                              layout_is_aos: template(),
                              as_vector: template()):
    for I in grouped(ndarray):
        for p in static(range(ndarray[I].n)):
            for q in static(range(ndarray[I].m)):
                if static(as_vector):
                    if static(layout_is_aos):
                        arr[I, p] = ndarray[I][p]
                    else:
                        arr[p, I] = ndarray[I][p]
                else:
                    if static(layout_is_aos):
                        arr[I, p, q] = ndarray[I][p, q]
                    else:
                        arr[p, q, I] = ndarray[I][p, q]
示例#5
0
 def build_static_for(ctx, node, is_grouped):
     if is_grouped:
         assert len(node.iter.args[0].args) == 1
         ndrange_arg = build_stmt(ctx, node.iter.args[0].args[0])
         if not isinstance(ndrange_arg, ndrange):
             raise TaichiSyntaxError(
                 "Only 'ti.ndrange' is allowed in 'ti.static(ti.grouped(...))'."
             )
         targets = ASTTransformer.get_for_loop_targets(node)
         if len(targets) != 1:
             raise TaichiSyntaxError(
                 f"Group for should have 1 loop target, found {len(targets)}"
             )
         target = targets[0]
         for value in impl.grouped(ndrange_arg):
             with ctx.variable_scope_guard():
                 ctx.create_variable(target, value)
                 build_stmts(ctx, node.body)
                 status = ctx.loop_status()
                 if status == LoopStatus.Break:
                     break
                 elif status == LoopStatus.Continue:
                     ctx.set_loop_status(LoopStatus.Normal)
     else:
         build_stmt(ctx, node.iter)
         targets = ASTTransformer.get_for_loop_targets(node)
         for target_values in node.iter.ptr:
             if not isinstance(
                     target_values,
                     collections.abc.Sequence) or len(targets) == 1:
                 target_values = [target_values]
             with ctx.variable_scope_guard():
                 for target, target_value in zip(targets, target_values):
                     ctx.create_variable(target, target_value)
                 build_stmts(ctx, node.body)
                 status = ctx.loop_status()
                 if status == LoopStatus.Break:
                     break
                 elif status == LoopStatus.Continue:
                     ctx.set_loop_status(LoopStatus.Normal)
     return None
示例#6
0
def fill_tensor(tensor: template(), val: template()):
    for I in grouped(tensor):
        tensor[I] = val
示例#7
0
def ext_arr_to_ndarray(arr: ndarray_type.ndarray(),
                       ndarray: ndarray_type.ndarray()):
    for I in grouped(ndarray):
        ndarray[I] = arr[I]
示例#8
0
def ndarray_to_ndarray(ndarray: any_arr(), other: any_arr()):
    for I in grouped(ndarray):
        ndarray[I] = other[I]
示例#9
0
def ext_arr_to_tensor(arr: ext_arr(), tensor: template()):
    for I in grouped(tensor):
        tensor[I] = arr[I]
示例#10
0
def ndarray_to_ndarray(ndarray: ndarray_type.ndarray(),
                       other: ndarray_type.ndarray()):
    for I in grouped(ndarray):
        ndarray[I] = other[I]
示例#11
0
def tensor_to_ext_arr(tensor: template(), arr: ndarray_type.ndarray()):
    for I in grouped(tensor):
        arr[I] = tensor[I]
示例#12
0
def ext_arr_to_ndarray(arr: ext_arr(), ndarray: any_arr()):
    for I in grouped(ndarray):
        ndarray[I] = arr[I]
示例#13
0
def snode_deactivate(b: template()):
    for I in grouped(b):
        deactivate(b, I)
示例#14
0
def fill_ndarray(ndarray: ndarray_type.ndarray(), val: template()):
    for I in grouped(ndarray):
        ndarray[I] = val
示例#15
0
def clear_gradients(_vars: template()):
    for I in grouped(ScalarField(Expr(_vars[0]))):
        for s in static(_vars):
            ScalarField(Expr(s))[I] = 0
示例#16
0
def ndarray_to_ext_arr(ndarray: any_arr(), arr: ext_arr()):
    for I in grouped(ndarray):
        arr[I] = ndarray[I]
示例#17
0
def tensor_to_ext_arr(tensor: template(), arr: ext_arr()):
    for I in grouped(tensor):
        arr[I] = tensor[I]
示例#18
0
def fill_ndarray_matrix(ndarray: any_arr(), val: template()):
    for I in grouped(ndarray):
        ndarray[I].fill(val)
示例#19
0
def fill_ndarray(ndarray: any_arr(), val: template()):
    for I in grouped(ndarray):
        ndarray[I] = val
示例#20
0
def fill_matrix(mat: template(), vals: template()):
    for I in grouped(mat):
        for p in static(range(mat.n)):
            for q in static(range(mat.m)):
                mat[I][p, q] = vals[p][q]
示例#21
0
def tensor_to_image(tensor: template(), arr: ext_arr()):
    for I in grouped(tensor):
        t = ops.cast(tensor[I], f32)
        arr[I, 0] = t
        arr[I, 1] = t
        arr[I, 2] = t
示例#22
0
def snode_deactivate_dynamic(b: template()):
    for I in grouped(b.parent()):
        deactivate(b, I)
示例#23
0
def vector_to_image(mat: template(), arr: ndarray_type.ndarray()):
    for I in grouped(mat):
        for p in static(range(mat.n)):
            arr[I, p] = ops.cast(mat[I][p], f32)
            if static(mat.n <= 2):
                arr[I, 2] = 0
示例#24
0
def fill_ndarray_matrix(ndarray: ndarray_type.ndarray(), val: template()):
    for I in grouped(ndarray):
        ndarray[I].fill(val)
示例#25
0
def tensor_to_tensor(tensor: template(), other: template()):
    for I in grouped(tensor):
        tensor[I] = other[I]
示例#26
0
def ndarray_to_ext_arr(ndarray: ndarray_type.ndarray(),
                       arr: ndarray_type.ndarray()):
    for I in grouped(ndarray):
        arr[I] = ndarray[I]
示例#27
0
def ext_arr_to_tensor(arr: ndarray_type.ndarray(), tensor: template()):
    for I in grouped(tensor):
        tensor[I] = arr[I]
示例#28
0
def tensor_to_image(tensor: template(), arr: ndarray_type.ndarray()):
    for I in grouped(tensor):
        t = ops.cast(tensor[I], f32)
        arr[I, 0] = t
        arr[I, 1] = t
        arr[I, 2] = t
示例#29
0
文件: _funcs.py 项目: k-ye/taichi
def field_fill_taichi_scope(F: template(), val: template()):
    for I in grouped(F):
        F[I] = val