Skip to content

Commit

Permalink
Format code
Browse files Browse the repository at this point in the history
  • Loading branch information
dream189free committed May 8, 2023
1 parent 9db8af2 commit bf56ef0
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 11 deletions.
2 changes: 1 addition & 1 deletion python/taichi/_kernels.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def tensor_to_tensor(tensor: template(), other: template()):
other_offset_new = static([0] * len(other_shape) if len(other_offset) == 0 else other_offset)

for I in grouped(ndrange(*tensor_shape)):
print('index ', I)
print("index ", I)
tensor[I + tensor_offset_new] = other[I + other_offset_new]


Expand Down
19 changes: 17 additions & 2 deletions tests/python/test_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ def test_scalr_field_from_numpy(dtype, shape):


@pytest.mark.parametrize("dtype", data_types)
@pytest.mark.parametrize("shape, offset", [((), ()), (8, 0), (8, 8), (8, -4), ((6, 12), (-4, -4)), ((6, 12), (-4, 4)), ((6, 12), (4, -4)), ((6, 12), (8, 8))])
@pytest.mark.parametrize(
"shape, offset",
[((), ()), (8, 0), (8, 8), (8, -4), ((6, 12), (-4, -4)), ((6, 12), (-4, 4)), ((6, 12), (4, -4)), ((6, 12), (8, 8))],
)
@test_utils.test(arch=get_host_arch_list())
def test_scalr_field_from_numpy_with_offset(dtype, shape, offset):
import numpy as np
Expand Down Expand Up @@ -273,7 +276,19 @@ def test_field_copy_from_with_mismatch_shape():


@test_utils.test()
@pytest.mark.parametrize("shape, x_offset, other_offset", [((), (), ()), (8, 4, 0), (8, 0, -4), (8, -4, -4), (8, 8, -4), ((6, 12), (0, 0), (-6, -6)), ((6, 12), (-6, -6), (0, 0)), ((6, 12), (-6, -6), (-6, -6))])
@pytest.mark.parametrize(
"shape, x_offset, other_offset",
[
((), (), ()),
(8, 4, 0),
(8, 0, -4),
(8, -4, -4),
(8, 8, -4),
((6, 12), (0, 0), (-6, -6)),
((6, 12), (-6, -6), (0, 0)),
((6, 12), (-6, -6), (-6, -6)),
],
)
@pytest.mark.parametrize("dtype", [ti.i32, ti.f32])
def test_field_copy_from_with_offset(shape, dtype, x_offset, other_offset):
x = ti.field(dtype=ti.f32, shape=shape, offset=x_offset)
Expand Down
6 changes: 3 additions & 3 deletions tests/python/test_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ def test_set_image_with_offset(fast_gui, offset, dtype, color):
n = 300
shape = (n, n)
if fast_gui is True or dtype is ti.f64:
img = ti.Vector.field(dtype=dtype, n = 3, shape=shape, offset=offset)
img = ti.Vector.field(dtype=dtype, n=3, shape=shape, offset=offset)
else:
img = ti.field(dtype=dtype, shape=shape, offset=offset)
img.fill(color);
img.fill(color)

gui = ti.GUI(name='test', res=shape, show_gui=False, fast_gui=fast_gui)
gui = ti.GUI(name="test", res=shape, show_gui=False, fast_gui=fast_gui)
gui.set_image(img)
gui.show()
8 changes: 6 additions & 2 deletions tests/python/test_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -1306,13 +1306,17 @@ def access_mat(i: ti.i32, j: ti.i32):


@pytest.mark.parametrize("dtype", [ti.i32, ti.f32, ti.i64, ti.f64])
@pytest.mark.parametrize("shape, offset", [((), ()), (8, 0), (8, 8), (8, -4), ((6, 12), (-4, -4)), ((6, 12), (-4, 4)), ((6, 12), (4, -4)), ((6, 12), (8, 8))])
@pytest.mark.parametrize(
"shape, offset",
[((), ()), (8, 0), (8, 8), (8, -4), ((6, 12), (-4, -4)), ((6, 12), (-4, 4)), ((6, 12), (4, -4)), ((6, 12), (8, 8))],
)
@test_utils.test(arch=get_host_arch_list())
def test_matrix_from_numpy_with_offset(dtype, shape, offset):
import numpy as np

m = 3
n = 4
x = ti.Matrix.field(dtype=dtype,m=m,n=n, shape=shape, offset=offset)
x = ti.Matrix.field(dtype=dtype, m=m, n=n, shape=shape, offset=offset)
# use the corresponding dtype for the numpy array.
numpy_dtypes = {
ti.i32: np.int32,
Expand Down
6 changes: 3 additions & 3 deletions tests/python/test_offset.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,14 @@ def test_offset_must_throw_matrix():

@test_utils.test(arch=get_host_arch_list())
def test_field_offset_print():
val = ti.field(dtype=ti.f32, shape=(3,3), offset=(-1, -1))
val = ti.field(dtype=ti.f32, shape=(3, 3), offset=(-1, -1))
val.fill(1.0)
print(val)


@test_utils.test(arch=get_host_arch_list())
def test_field_offset_to_numpy():
shape = (3,3)
val = ti.field(dtype=ti.f32, shape=shape, offset=(-1, -1))
shape = (3, 3)
val = ti.field(dtype=ti.f32, shape=shape, offset=(-1, -1))
val.fill(1.0)
assert np.allclose(val.to_numpy(), np.ones(shape, dtype=np.float32))

0 comments on commit bf56ef0

Please sign in to comment.