Skip to content

Commit

Permalink
Fix mat() for concatation of vectors and scalars in a column vector
Browse files Browse the repository at this point in the history
  • Loading branch information
lauerfab committed Dec 10, 2015
1 parent 52bb73c commit 2fb080e
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions lalolab/src/linalg.js
Original file line number Diff line number Diff line change
Expand Up @@ -2886,9 +2886,12 @@ function issymmetric ( A ) {
*/
function mat( elems, rowwise ) {
var k;
var onlyVectorsAndNumbers = true;
var elemtypes = new Array(elems.length);
for ( k=0; k < elems.length; k++) {
elemtypes[k] = type(elems[k]);
if ( elemtypes[k] != "number" && elemtypes[k] != "vector" && elemtypes[k] != "spvector")
onlyVectorsAndNumbers = false;
}


Expand Down Expand Up @@ -2918,6 +2921,7 @@ function mat( elems, rowwise ) {
var j;
if ( rowwise ) {
var res = new Array( ) ;

for ( k= 0; k<elems.length; k++) {
switch( elemtypes[k] ) {
case "matrix":
Expand All @@ -2926,10 +2930,20 @@ function mat( elems, rowwise ) {
n = elems[k].n;
break;

case "vector": // vector (auto transposed)
res.push (elems[k]) ;
m += 1;
n = elems[k].length;
case "vector":
if ( onlyVectorsAndNumbers ) {
// return a column by concatenating vectors and numbers
for ( var l=0; l < elems[k].length; l++)
res.push(elems[k][l]) ;
n = 1;
m += elems[k].length;
}
else {
// vector (auto transposed) as row in a matrix
res.push (elems[k]) ;
m += 1;
n = elems[k].length;
}
break;

case "number":
Expand Down

0 comments on commit 2fb080e

Please sign in to comment.