# Vectors have an inconsistent interpretation in matrix math Classic List Threaded 11 messages Open this post in threaded view
|

## Vectors have an inconsistent interpretation in matrix math

 Mathematically, we might expect 1-dimensional vectors to act like scalars and nx1-dimensional matrices to act like vectors. There are some important places where current implementations seem to violate these expectations:1-dimensional vectors are not scalars with respect to vectors:2 * #(1 2 3) asPMVector. "a PMVector(2 4 6)"#(2) asPMVector * #(1 2 3) asPMVector. "Error"1-dimensional vectors are not scalars with respect to matrices, and in fact have undefined behavior:2 * (PMMatrix rows: #((1 2) (3 4))). "a PMVector(2 4) a PMVector(6 8)"#(2) asPMVector * (PMMatrix rows: #((1 2) (3 4))). "a PMVector(2 4)"n-dimensional vectors are row vectors when right-multiplied by an nx1 matrix, but column vectors when left multiplied by a matrix 1xn, meaning they cannot be used as either a 1xn or an nx1 matrix in code that expects one or the other: the dimensions will be unpredictable.#(1 2) asPMVector * (PMMatrix rows: #((1) (2))). "a PMVector(5)"(PMMatrix rows: #((1 2))) * #(1 2) asPMVector. "a PMVector(5)"1x1 matrices are not scalars with respect to vectors:(PMMatrix rows: #((2))) * #(1 2) asPMVector. "Error"1xn * nx1 matrix multiplication produces a matrix, not a scalar, which behaves differently than a scalar, as per above:(PMMatrix rows: #((1 2))) * (PMMatrix rows: #((1) (2))) "a PMVector(5) <-- actually a 1x1 matrix"As long as one works only with scalars and vectors OR scalars and matrices, things seem fine. It seems like maybe either matrix-vector operations should throw errors, or vectors should behave consistently as an nx1 matrix during matrix math. It may also make sense to make the 1-dimensional vectors and matrices either just convert to scalar Numbers, or make them polymorphic with #= etc, but I'm not sure. -- You received this message because you are subscribed to the Google Groups "SciSmalltalk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. For more options, visit https://groups.google.com/d/optout.
Open this post in threaded view
|

## Re: Vectors have an inconsistent interpretation in matrix math

 One possible solution is to reduce a size-1 vector to a scalar, exactly like a Fraction with denominator 1 is reduced to Integer (for example 2/1 -> 2).But in this case, the scalar has to be polymorphic to a vector (understand the whole vector protocol...).For nx1 and 1xn matrices, this sounds more delicate: if we reduce it to a vector, we loose the layout (we have no distinction of column/row vectors so far). In Smallapack, I chosed to have only matrix for this reason.2017-05-18 20:56 GMT+02:00 Evan Donahue :Mathematically, we might expect 1-dimensional vectors to act like scalars and nx1-dimensional matrices to act like vectors. There are some important places where current implementations seem to violate these expectations:1-dimensional vectors are not scalars with respect to vectors:2 * #(1 2 3) asPMVector. "a PMVector(2 4 6)"#(2) asPMVector * #(1 2 3) asPMVector. "Error"1-dimensional vectors are not scalars with respect to matrices, and in fact have undefined behavior:2 * (PMMatrix rows: #((1 2) (3 4))). "a PMVector(2 4) a PMVector(6 8)"#(2) asPMVector * (PMMatrix rows: #((1 2) (3 4))). "a PMVector(2 4)"n-dimensional vectors are row vectors when right-multiplied by an nx1 matrix, but column vectors when left multiplied by a matrix 1xn, meaning they cannot be used as either a 1xn or an nx1 matrix in code that expects one or the other: the dimensions will be unpredictable.#(1 2) asPMVector * (PMMatrix rows: #((1) (2))). "a PMVector(5)"(PMMatrix rows: #((1 2))) * #(1 2) asPMVector. "a PMVector(5)"1x1 matrices are not scalars with respect to vectors:(PMMatrix rows: #((2))) * #(1 2) asPMVector. "Error"1xn * nx1 matrix multiplication produces a matrix, not a scalar, which behaves differently than a scalar, as per above:(PMMatrix rows: #((1 2))) * (PMMatrix rows: #((1) (2))) "a PMVector(5) <-- actually a 1x1 matrix"As long as one works only with scalars and vectors OR scalars and matrices, things seem fine. It seems like maybe either matrix-vector operations should throw errors, or vectors should behave consistently as an nx1 matrix during matrix math. It may also make sense to make the 1-dimensional vectors and matrices either just convert to scalar Numbers, or make them polymorphic with #= etc, but I'm not sure. -- You received this message because you are subscribed to the Google Groups "SciSmalltalk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "SciSmalltalk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. For more options, visit https://groups.google.com/d/optout.
Open this post in threaded view
|

## Re: Vectors have an inconsistent interpretation in matrix math

Open this post in threaded view
|

## Re: Vectors have an inconsistent interpretation in matrix math

Open this post in threaded view
|

## Re: Vectors have an inconsistent interpretation in matrix math

Open this post in threaded view
|

## Re: Vectors have an inconsistent interpretation in matrix math

Open this post in threaded view
|

## Re: Vectors have an inconsistent interpretation in matrix math

Open this post in threaded view
|

## Re: Vectors have an inconsistent interpretation in matrix math

Open this post in threaded view
|