I feel like $matrix->value should give an array of arrays, but instead it seems to give an array of references to arrays.
The reason for this is that Perl flattens arrays or arrays into one big array, so that ((1,2),(3,4))
becomes (1,2,3,4)
. So the usual way to represent a matrix is as an array of references of arrays.
You can dereference an array using the @
operator, so
$M = Matrix([1,2],[3,4]); @r = @{($M->value)[0]}; # produces (1,2), the first row
Or you could use
$r = Vector(($M->value)[0]);to get the first row as a Vector object.
Of course, there is an easier way to do that, using
$r = Vector($M->row(1));Note that
$M->row(1)
is a Matrix with one row.
There is also a $M->column(j)
method to obtain a column (as a matrix of one-element rows), and $M->extract(i,j)
method to obtain the (i,j)-th entry of the matrix.
These may make your algorithm easier to handle.