Skip to content

Commit

Permalink
Fix renewObject()
Browse files Browse the repository at this point in the history
  • Loading branch information
lauerfab committed Dec 11, 2015
1 parent 2fb080e commit 7ff3c47
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 8 deletions.
11 changes: 11 additions & 0 deletions lalolab/lalolabworker.js
Original file line number Diff line number Diff line change
Expand Up @@ -1501,6 +1501,17 @@ function renewObject( obj ) {
var newobj = new Class(typearray[1]);
for ( var p in obj )
newobj[p] = renewObject(obj[p]);


// deal with particular cases:
// Rebuild kernelFunc
if (typearray[1] == "SVM" || typearray[1] == "SVR" ) {
newobj["kernelFunc"] = kernelFunction(newobj["kernel"], newobj["kernelpar"], type(newobj["SV"]) == "spmatrix"?"spvector":"vector");
}
if (typearray[1] == "KernelRidgeRegression" ) {
newobj["kernelFunc"] = kernelFunction(newobj["kernel"], newobj["kernelpar"], type(newobj["X"]) == "spmatrix"?"spvector":"vector");
}

return newobj;
break;
}
Expand Down
31 changes: 27 additions & 4 deletions lalolab/src/lalolibbase.js
Original file line number Diff line number Diff line change
Expand Up @@ -1420,7 +1420,23 @@ function getObjectWithoutFunc( obj ) {
for (var p in obj ) {
switch( type(obj[p]) ) {
case "vector":
res[p] = {type: "vector", data: [].slice.call(obj[p])};
break;
case "matrix":
res[p] = obj[p];
res[p].val = [].slice.call(obj[p].val);
break;
case "spvector":
res[p] = obj[p];
res[p].val = [].slice.call(obj[p].val);
res[p].ind = [].slice.call(obj[p].ind);
break;
case "spmatrix":
res[p] = obj[p];
res[p].val = [].slice.call(obj[p].val);
res[p].cols = [].slice.call(obj[p].cols);
res[p].rows = [].slice.call(obj[p].rows);
break;
case "undefined":
res[p] = obj[p];
break;
Expand All @@ -1434,7 +1450,7 @@ function getObjectWithoutFunc( obj ) {
default:
res[p] = getObjectWithoutFunc( obj[p] );
break;
}
}
}
return res;
}
Expand All @@ -1448,14 +1464,21 @@ function renewObject( obj ) {
case "number":
case "boolean":
case "string":
case "vector":
case "undefined":
return obj;
break;
case "vector":
return new Float64Array(obj.data);
break;
case "matrix":
return new Matrix(obj.m, obj.n, obj.val, true);
return new Matrix(obj.m, obj.n, obj.val);
break;
case "spvector":
return new spVector(obj.length,obj.val,obj.ind);
break;
case "spmatrix":
return new spMatrix(obj.m, obj.n, obj.val, obj.cols, obj.rows);
break;

case "object":
// Object without type property and thus without Class
var newobj = {};
Expand Down
8 changes: 4 additions & 4 deletions lalolab/src/linalg.js
Original file line number Diff line number Diff line change
Expand Up @@ -2886,12 +2886,12 @@ function issymmetric ( A ) {
*/
function mat( elems, rowwise ) {
var k;
var onlyVectorsAndNumbers = true;
var concatWithNumbers = false;
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;
if ( elemtypes[k] == "number" )
concatWithNumbers = true;
}


Expand Down Expand Up @@ -2931,7 +2931,7 @@ function mat( elems, rowwise ) {
break;

case "vector":
if ( onlyVectorsAndNumbers ) {
if ( concatWithNumbers ) {
// return a column by concatenating vectors and numbers
for ( var l=0; l < elems[k].length; l++)
res.push(elems[k][l]) ;
Expand Down

0 comments on commit 7ff3c47

Please sign in to comment.