Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[test] [std] Add matrix SSA violation regression test #1412

Merged
merged 1 commit into from
Jul 5, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions tests/python/test_linalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import numpy as np
from taichi import approx
import pytest
import math


@ti.all_archs
Expand Down Expand Up @@ -65,6 +66,25 @@ def init():
assert aNormalized[None][2] == approx(3.0 * invSqrt14)


@ti.all_archs
def test_matrix_ssa():
a = ti.Vector(2, ti.f32, ())
b = ti.Matrix(2, 2, ti.f32, ())

@ti.kernel
def func():
a[None] = a[None].normalized()
b[None] = b[None].transpose()

inv_sqrt2 = 1 / math.sqrt(2)

a[None] = [1, 1]
b[None] = [[1, 2], [3, 4]]
func()
assert a[None].value == ti.Vector([inv_sqrt2, inv_sqrt2])
assert b[None].value == ti.Matrix([[1, 3], [2, 4]])


@ti.all_archs
def test_cross():
a = ti.Vector(3, dt=ti.f32)
Expand Down Expand Up @@ -243,8 +263,6 @@ def test_mat_inverse():

@ti.all_archs
def test_matrix_factories():
import math

a = ti.Vector.var(3, dt=ti.i32, shape=3)
b = ti.Matrix.var(2, 2, dt=ti.f32, shape=2)
c = ti.Matrix.var(2, 3, dt=ti.f32, shape=2)
Expand Down