Shall we separate Matrix class and Vector class? #4318
lin-hitonami
started this conversation in
Ideas
Replies: 1 comment 1 reply
-
One more supporting argument for separating these two classes: #2683. I vote for way 2 as it is clean and mimics the behavior of numpy. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Currently,
ti.Matrix
andti.Vector
are the same class.ti.Vector
is only a constructor that constructs ati.Matrix
with shape (n, 1).However, it introduces a problem that some methods which are only meaningful for vectors appear in the API of
ti.Matrix
, likex()
, which returns the first value of the vector. Also, vectors can also access APIs likedeterminant()
which are only meaningful for square matrices.Therefore, I think maybe we should separate Matrix class and Vector class. I've come up with two ways to separate them.
Matrix
andVector
inherit the same classMatrixBase
.MatrixBase
stores a two-dimensional array. We define operators that apply both to vectors and matrices in this class.Matrix
is the class for general two-dimensional matrices. We define constructors of special matrices and functions only apply to matrices in this class.Vector
is the class for row vectors and column vectors, and they are stored as matrices with shapes (1, n) and (n, 1). We define constructors of special vectors and functions only apply to vectors in this class.Pros: The changes do not affect users' code.
Cons: The vectors are stored as matrices, and we have to take care of both row vectors and column vectors.
Vector
class andMatrix
classMatrix
stores a two-dimensional array, andVector
stores a one-dimensional array.Define the operators between
Matrix
andVector
in one of the classes.When doing operations like multiplication between a matrix and a vector, the vector is treated as row vector when it is on the left side of the matrix, or column vector otherwise.
Pros: Vectors are really one-dimensional, and we do not need to deal with two types of vectors.
Cons: We need to define the operators between
Matrix
andVector
. Also, the behaviors of some functions may be different from the current Taichi, we might break some of users' code.Beta Was this translation helpful? Give feedback.
All reactions