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

[Lang] Matrix lib: Stop changing dimension in transpose() #6528

Merged
merged 3 commits into from
Nov 7, 2022
Merged
Show file tree
Hide file tree
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
15 changes: 0 additions & 15 deletions python/taichi/_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,6 @@ def randn(dt=None):
return _randn(dt)


@pyfunc
def _matrix_transpose(mat):
"""Permute the first two axes of the matrix.

Args:
mat (:class:`~taichi.lang.matrix.Matrix`): Input matrix.

Returns:
Transpose of the input matrix.
"""
return matrix.Matrix([[mat(i, j) for i in range(mat.n)]
for j in range(mat.m)],
ndim=mat.ndim)


@pyfunc
def _matrix_cross3d(self, other):
return matrix.Matrix([
Expand Down
34 changes: 6 additions & 28 deletions python/taichi/lang/matrix_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,36 +123,14 @@ def determinant(x):
return None


def _vector_transpose(v):
shape = v.get_shape()
if isinstance(v, Vector):

@pyfunc
def _transpose():
return Matrix([[v[i] for i in static(range(shape[0]))]], ndim=1)

return _transpose()
if isinstance(v, Matrix):

@pyfunc
def _transpose():
return Vector([v[i, 0] for i in static(range(shape[0]))])

return _transpose()
return v


@preconditions(assert_tensor)
@func
def transpose(m):
shape = static(m.get_shape())
@pyfunc
def transpose(mat):
shape = static(mat.get_shape())
if static(len(shape) == 1):
return _vector_transpose(m)
result = _init_matrix((shape[1], shape[0]), dt=m.element_type())
for i in static(range(shape[0])):
for j in static(range(shape[1])):
result[j, i] = m[i, j]
return result
return Vector([mat[i] for i in static(range(shape[0]))])
return Matrix([[mat[i, j] for i in static(range(shape[0]))]
for j in static(range(shape[1]))])


@preconditions(arg_at(0, is_int_const),
Expand Down