|
Mac unit tests 2012-12-21_00-30-00
|
|
Link testing.
Using Firefox |
| 0 PASS: linkhome ==> Numerical analysis in Javascript in page |
| 1 PASS: linkworkshop ==> IN in page |
| 2 PASS: linkdoc ==> vectors and matrices in page |
| 3 PASS: linklib ==> var numeric in page |
| 4 PASS: linklibmin ==> var numeric= in page |
| Link testing complete. PASS: 5 FAIL: 0 Total: 5
Fetching http://numericjs.com/staging/documentation.html
In-browser unit tests.
Using Chrome |
| 0 PASS: numeric.seedrandom.seedrandom('1'); Math.random = numeric.seedrandom.random; Math.random(); ==> 0.2694 |
| 1 PASS: A = [[1,2,3],[4,5,6]]; ==> [[1,2,3],[4,5,6]] |
| 2 PASS: x = [7,8,9] ==> [7,8,9] |
| 3 PASS: numeric.dot(A,x); ==> [50,122] |
| 4 PASS: x = [7,8,9]; y = [10,1,2]; numeric['+'](x,y) ==> [17,9,11] |
| 5 PASS: numeric['>'](x,y) ==> [false,true,true] |
| 6 PASS: numeric.add([7,8,9],[10,1,2]) ==> [17,9,11] |
| 7 PASS: numeric.add([1,2],[3,4],[5,6],[7,8]) ==> [16,20] |
| 8 PASS: A = [[1,2,3],[4,5,6],[7,1,9]] ==> [[1,2,3],[4,5,6],[7,1,9]] |
| 9 PASS: Ainv = numeric.inv(A); ==> [[-0.9286,0.3571,0.07143],[-0.1429,0.2857,-0.1429],[0.7381,-0.3095,0.07143]] |
| 10 PASS: numeric.precision = 10; x = 3.141592653589793 ==> 3.141592654 |
| 11 PASS: numeric.precision = 4; x ==> 3.142 |
| 12 PASS: numeric.identity(100) ==> ...LargeArray... |
| 13 PASS: numeric.largeArray = 2; A = numeric.identity(4) ==> ...LargeArray... |
| 14 PASS: numeric.largeArray = 50; A ==> [[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]] |
| 15 PASS: numeric.exp([1,2]); ==> [2.718,7.389] |
| 16 PASS: numeric.exp([[1,2],[3,4]]) ==> [[2.718,7.389],[20.09,54.6]] |
| 17 PASS: numeric.abs([-2,3]) ==> [2,3] |
| 18 PASS: numeric.acos([0.1,0.2]) ==> [1.471,1.369] |
| 19 PASS: numeric.asin([0.1,0.2]) ==> [0.1002,0.2014] |
| 20 PASS: numeric.atan([1,2]) ==> [0.7854,1.107] |
| 21 PASS: numeric.atan2([1,2],[3,4]) ==> [0.3218,0.4636] |
| 22 PASS: numeric.ceil([-2.2,3.3]) ==> [-2,4] |
| 23 PASS: numeric.floor([-2.2,3.3]) ==> [-3,3] |
| 24 PASS: numeric.log([1,2]) ==> [0,0.6931] |
| 25 PASS: numeric.pow([2,3],[0.25,7.1]) ==> [1.189,2441] |
| 26 PASS: numeric.round([-2.2,3.3]) ==> [-2,3] |
| 27 PASS: numeric.sin([1,2]) ==> [0.8415,0.9093] |
| 28 PASS: numeric.sqrt([1,2]) ==> [1,1.414] |
| 29 PASS: numeric.tan([1,2]) ==> [1.557,-2.185] |
| 30 PASS: numeric.dim([1,2]) ==> [2] |
| 31 PASS: numeric.dim([[1,2,3],[4,5,6]]) ==> [2,3] |
| 32 PASS: numeric.same([1,2],[1,2]) ==> true |
| 33 PASS: numeric.same([1,2],[1,2,3]) ==> false |
| 34 PASS: numeric.same([1,2],[[1],[2]]) ==> false |
| 35 PASS: numeric.same([[1,2],[3,4]],[[1,2],[3,4]]) ==> true |
| 36 PASS: numeric.same([[1,2],[3,4]],[[1,2],[3,5]]) ==> false |
| 37 PASS: numeric.same([[1,2],[2,4]],[[1,2],[3,4]]) ==> false |
| 38 PASS: numeric.rep([3],5) ==> [5,5,5] |
| 39 PASS: numeric.rep([2,3],0) ==> [[0,0,0],[0,0,0]] |
| 40 PASS: sum = numeric.mapreduce('accum += xi','0'); sum([1,2,3]) ==> 6 |
| 41 PASS: sum([[1,2,3],[4,5,6]]) ==> 21 |
| 42 PASS: numeric.any([false,true]) ==> true |
| 43 PASS: numeric.any([[0,0,3.14],[0,false,0]]) ==> true |
| 44 PASS: numeric.any([0,0,false]) ==> false |
| 45 PASS: numeric.all([false,true]) ==> false |
| 46 PASS: numeric.all([[1,4,3.14],["no",true,-1]]) ==> true |
| 47 PASS: numeric.all([0,0,false]) ==> false |
| 48 PASS: numeric.diag([1,2,3]) ==> [[1,0,0],[0,2,0],[0,0,3]] |
| 49 PASS: numeric.identity(3) ==> [[1,0,0],[0,1,0],[0,0,1]] |
| 50 PASS: numeric.linspace(1,5); ==> [1,2,3,4,5] |
| 51 PASS: numeric.linspace(1,3,5); ==> [1,1.5,2,2.5,3] |
| 52 PASS: numeric.blockMatrix([[[[1,2],[3,4]],[[5,6],[7,8]]], [[[11,12],[13,14]],[[15,16],[17,18]]]]) ==> [[1,2,5,6],[3,4,7,8],[11,12,15,16],[13,14,17,18]] |
| 53 PASS: numeric.addVV([1,2],[3,4]) ==> [4,6] |
| 54 PASS: numeric.addVS([1,2],3) ==> [4,5] |
| 55 PASS: numeric.add(1,[2,3]) ==> [3,4] |
| 56 PASS: numeric.add([1,2,3],[4,5,6]) ==> [5,7,9] |
| 57 PASS: numeric.sub([1,2],[3,4]) ==> [-2,-2] |
| 58 PASS: numeric.mul([1,2],[3,4]) ==> [3,8] |
| 59 PASS: numeric.div([1,2],[3,4]) ==> [0.3333,0.5] |
| 60 PASS: v = [1,2,3,4]; numeric.addeq(v,3); v ==> [4,5,6,7] |
| 61 PASS: numeric.subeq([1,2,3],[5,3,1]) ==> [-4,-1,2] |
| 62 PASS: numeric.neg([1,-2,3]) ==> [-1,2,-3] |
| 63 PASS: numeric.isFinite([10,NaN,Infinity]) ==> [true,false,false] |
| 64 PASS: numeric.isNaN([10,NaN,Infinity]) ==> [false,true,false] |
| 65 PASS: n = 41; A = numeric.random([n,n]); numeric.norm2(numeric.sub(numeric.dotMMsmall(numeric.inv(A),A),numeric.identity(n)))<1e-12 ==> true |
| 66 PASS: n = 42; A = numeric.random([n,n]); numeric.norm2(numeric.sub(numeric.dotMMsmall(numeric.inv(A),A),numeric.identity(n)))<1e-12 ==> true |
| 67 PASS: n = 43; A = numeric.random([n,n]); numeric.norm2(numeric.sub(numeric.dotMMsmall(numeric.inv(A),A),numeric.identity(n)))<1e-12 ==> true |
| 68 PASS: n = 44; A = numeric.random([n,n]); numeric.norm2(numeric.sub(numeric.dotMMbig(numeric.inv(A),A),numeric.identity(n)))<1e-12 ==> true |
| 69 PASS: n = 45; A = numeric.random([n,n]); numeric.norm2(numeric.sub(numeric.dotMMbig(numeric.inv(A),A),numeric.identity(n)))<1e-12 ==> true |
| 70 PASS: n = 46; A = numeric.random([n,n]); numeric.norm2(numeric.sub(numeric.dotMMbig(numeric.inv(A),A),numeric.identity(n)))<1e-12 ==> true |
| 71 PASS: numeric.dotVV([1,2],[3,4]) ==> 11 |
| 72 PASS: numeric.dotVM([1,2],[[3,4],[5,6]]) ==> [13,16] |
| 73 PASS: numeric.dotMV([[1,2],[3,4]],[5,6]) ==> [17,39] |
| 74 PASS: numeric.dotMMbig([[1,2],[3,4]],[[5,6],[7,8]]) ==> [[19,22],[43,50]] |
| 75 PASS: numeric.dotMMsmall([[1,2],[3,4]],[[5,6],[7,8]]) ==> [[19,22],[43,50]] |
| 76 PASS: numeric.dot([1,2,3,4,5,6,7,8,9],[1,2,3,4,5,6,7,8,9]) ==> 285 |
| 77 PASS: numeric.dot([1,2,3],[4,5,6]) ==> 32 |
| 78 PASS: numeric.dot([[1,2,3],[4,5,6]],[7,8,9]) ==> [50,122] |
| 79 PASS: numeric.solve([[1,2],[3,4]],[17,39]) ==> [5,6] |
| 80 PASS: LU = numeric.LU([[1,2],[3,4]]) ==> {LU:[[3,4],[0.3333,0.6667]],P:[1,1]} |
| 81 PASS: numeric.LUsolve(LU,[17,39]) ==> [5,6] |
| 82 PASS: ns = [5,6,10,16,25,40,41]; for(j=0;j "numeric.solveStressTestOK" |
| 83 PASS: numeric.det([[1,2],[3,4]]); ==> -2 |
| 84 PASS: numeric.det([[6,8,4,2,8,5],[3,5,2,4,9,2],[7,6,8,3,4,5],[5,5,2,8,1,6],[3,2,2,4,2,2],[8,3,2,2,4,1]]); ==> -1404 |
| 85 PASS: numeric.inv([[1,2],[3,4]]) ==> [[-2,1],[1.5,-0.5]] |
| 86 PASS: numeric.transpose([[1,2,3],[4,5,6]]) ==> [[1,4],[2,5],[3,6]] |
| 87 PASS: numeric.transpose([[1,2,3,4,5,6,7,8,9,10,11,12]]) ==> [[1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12]] |
| 88 PASS: numeric.norm2([1,2]) ==> 2.236 |
| 89 PASS: numeric.tensor([1,2],[3,4,5]) ==> [[3,4,5],[6,8,10]] |
| 90 PASS: numeric.parseDate(['1/13/2013','2001-5-9, 9:31']); ==> [1.358e12,9.894e11] |
| 91 PASS: numeric.parseFloat(['12','0.1']) ==> [12,0.1] |
| 92 PASS: numeric.parseCSV('a,b,c\n1,2.3,.3\n4e6,-5.3e-8,6.28e+4') ==> [["a","b","c"],[1,2.3,0.3],[4e6,-5.3e-8,62800]] |
| 93 PASS: numeric.toCSV([[1.23456789123,2],[3,4]]) ==> "1.23456789123,23,4" |
| 94 PASS: numeric.getURL('tools/helloworld.txt').responseText ==> "Hello,world!" |
| 95 PASS: z = new numeric.T(3,4); ==> {x:3,y:4} |
| 96 PASS: z.add(5) ==> {x:8,y:4} |
| 97 PASS: w = new numeric.T(2,8); ==> {x:2,y:8} |
| 98 PASS: z.add(w) ==> {x:5,y:12} |
| 99 PASS: z.mul(w) ==> {x:-26,y:32} |
| 100 PASS: z.div(w) ==> {x:0.5588,y:-0.2353} |
| 101 PASS: z.sub(w) ==> {x:1,y:-4} |
| 102 PASS: z = new numeric.T([1,2],[3,4]); ==> {x:[1,2],y:[3,4]} |
| 103 PASS: z.abs() ==> {x:[3.162,4.472],y:} |
| 104 PASS: z.conj() ==> {x:[1,2],y:[-3,-4]} |
| 105 PASS: z.norm2() ==> 5.477 |
| 106 PASS: z.exp() ==> {x:[-2.691,-4.83],y:[0.3836,-5.592]} |
| 107 PASS: z.cos() ==> {x:[-1.528,-2.459],y:[0.1658,-2.745]} |
| 108 PASS: z.sin() ==> {x:[0.2178,-2.847],y:[1.163,2.371]} |
| 109 PASS: z.log() ==> {x:[1.151,1.498],y:[1.249,1.107]} |
| 110 PASS: A = new numeric.T([[1,2],[3,4]],[[0,1],[2,-1]]); ==> {x:[[1,2],[3,4]],y:[[0,1],[2,-1]]} |
| 111 PASS: A.inv(); ==> {x:[[0.125,0.125],[0.25,0]],y:[[0.5,-0.25],[-0.375,0.125]]} |
| 112 PASS: A.inv().dot(A) ==> {x:[[1,0],[0,1]],y:[[0,-2.776e-17],[0,0]]} |
| 113 PASS: A.get([1,1]) ==> {x:4,y:-1} |
| 114 PASS: A.transpose() ==> {x:[[1,3],[2,4]],y:[[0,2],[1,-1]]} |
| 115 PASS: A.transjugate() ==> {x:[[1,3],[2,4]],y:[[0,-2],[-1,1]]} |
| 116 PASS: numeric.T.rep([2,2],new numeric.T(2,3)); ==> {x:[[2,2],[2,2]],y:[[3,3],[3,3]]} |
| 117 PASS: A = [[1,2,5],[3,5,-1],[7,-3,5]]; ==> [[1,2,5],[3,5,-1],[7,-3,5]] |
| 118 PASS: B = numeric.eig(A); ==> {lambda:{x:[-4.284,9.027,6.257],y:},E:{x:[[0.7131,-0.5543,0.4019],[-0.2987,-0.2131,0.9139],[-0.6342,-0.8046,0.057]],y:}} |
| 119 PASS: C = B.E.dot(numeric.T.diag(B.lambda)).dot(B.E.inv()); ==> {x:[[1,2,5],[3,5,-1],[7,-3,5]],y:} |
| 120 PASS: A=[[ 22, 10, 2, 3, 7], [ 14, 7, 10, 0, 8], [ -1, 13, -1,-11, 3], [ -3, -2, 13, -2, 4], [ 9, 8, 1, -2, 4], [ 9, 1, -7, 5, -1], [ 2, -6, 6, 5, 1], [ 4, 5, 0, -2, 2]]; numeric.svd(A); ==> {U:[[-0.7071,-0.1581,0.1768,0.2494,0.4625],[-0.5303,-0.1581,-0.3536,0.1556,-0.4984],[-0.1768,0.7906,-0.1768,-0.1546,0.3967],[-1.506e-17,-0.1581,-0.7071,-0.3277,0.1],[-0.3536,0.1581,1.954e-15,-0.07265,-0.2084],[-0.1768,-0.1581,0.5303,-0.5726,-0.05555],[-7.109e-18,-0.4743,-0.1768,-0.3142,0.4959],[-0.1768,0.1581,1.915e-15,-0.592,-0.2791]],S:[35.33,20,19.6,0,0],V:[[-0.8006,-0.3162,0.2887,-0.4191,0],[-0.4804,0.6325,7.768e-15,0.4405,0.4185],[-0.1601,-0.3162,-0.866,-0.052,0.3488],[4.684e-17,-0.6325,0.2887,0.6761,0.2442],[-0.3203,3.594e-15,-0.2887,0.413,-0.8022]]} |
| 121 PASS: n = 31; A = numeric.random([n,n]); B = numeric.eig(A); !(B.E.dot(numeric.T.diag(B.lambda).dot(B.E.inv())).sub(A).norm2()>1e-12) ==> true |
| 122 PASS: n = 32; A = numeric.random([n,n]); B = numeric.eig(A); !(B.E.dot(numeric.T.diag(B.lambda).dot(B.E.inv())).sub(A).norm2()>1e-12) ==> true |
| 123 PASS: n = 33; A = numeric.random([n,n]); B = numeric.eig(A); !(B.E.dot(numeric.T.diag(B.lambda).dot(B.E.inv())).sub(A).norm2()>1e-12) ==> true |
| 124 PASS: n = 34; A = numeric.random([n,n]); B = numeric.eig(A); !(B.E.dot(numeric.T.diag(B.lambda).dot(B.E.inv())).sub(A).norm2()>1e-12) ==> true |
| 125 PASS: n = 35; A = numeric.random([n,n]); B = numeric.eig(A); !(B.E.dot(numeric.T.diag(B.lambda).dot(B.E.inv())).sub(A).norm2()>1e-12) ==> true |
| 126 PASS: m = 17; n = 12; A = numeric.random([m,n]); B = numeric.svd(A); U = new numeric.T(B.U); V = new numeric.T(B.V); !(U.dot(numeric.T.diag(B.S)).dot(V.transpose()).sub(A).norm2()>1e-12) ==> true |
| 127 PASS: m = 21; n = 19; A = numeric.random([m,n]); B = numeric.svd(A); U = new numeric.T(B.U); V = new numeric.T(B.V); !(U.dot(numeric.T.diag(B.S)).dot(V.transpose()).sub(A).norm2()>1e-12) ==> true |
| 128 PASS: m = 33; n = 33; A = numeric.random([m,n]); B = numeric.svd(A); U = new numeric.T(B.U); V = new numeric.T(B.V); !(U.dot(numeric.T.diag(B.S)).dot(V.transpose()).sub(A).norm2()>1e-12) ==> true |
| 129 PASS: m = 59; n = 42; A = numeric.random([m,n]); B = numeric.svd(A); U = new numeric.T(B.U); V = new numeric.T(B.V); !(U.dot(numeric.T.diag(B.S)).dot(V.transpose()).sub(A).norm2()>1e-12) ==> true |
| 130 PASS: numeric.eig([[1, 0, 0], [0, 0.7181, -0.6960], [0, 0.6960, 0.7181]]) // This was a bug found by bdmartin ==> {lambda:{x:[1,0.7181,0.7181],y:[0,0.696,-0.696]},E:{x:[[1,0,0],[0,0,0.7071],[0,-0.7071,0]],y:[[0,0,0],[0,-0.7071,0],[0,0,0.7071]]}} |
| 131 PASS: A = [[1,2,0], [0,3,0], [2,0,5]]; SA = numeric.ccsSparse(A); ==> [[0,2,4,5],[0,2,0,1,2],[1,2,2,3,5]] |
| 132 PASS: A = numeric.ccsSparse([[ 3, 5, 8,10, 8], [ 7,10, 3, 5, 3], [ 6, 3, 5, 1, 8], [ 2, 6, 7, 1, 2], [ 1, 2, 9, 3, 9]]); ==> [[0,5,10,15,20,25],[0,1,2,3,4,0,1,2,3,4,0,1,2,3,4,0,1,2,3,4,0,1,2,3,4],[3,7,6,2,1,5,10,3,6,2,8,3,5,7,9,10,5,1,1,3,8,3,8,2,9]] |
| 133 PASS: numeric.ccsFull(A); ==> [[3,5,8,10,8],[7,10,3,5,3],[6,3,5,1,8],[2,6,7,1,2],[1,2,9,3,9]] |
| 134 PASS: numeric.ccsDot(numeric.ccsSparse([[1,2,3],[4,5,6]]),numeric.ccsSparse([[7,8],[9,10],[11,12]])) ==> [[0,2,4],[0,1,0,1],[58,139,64,154]] |
| 135 PASS: M = [[0,1,3,6],[0,0,1,0,1,2],[3,-1,2,3,-2,4]]; b = [9,3,2]; x = numeric.ccsTSolve(M,b); ==> [3.167,2,0.5] |
| 136 PASS: numeric.ccsDot(M,[[0,3],[0,1,2],x]) ==> [[0,3],[0,1,2],[9,3,2]] |
| 137 PASS: A = [[0,5,10,15,20,25], [0,1,2,3,4,0,1,2,3,4,0,1,2,3,4,0,1,2,3,4,0,1,2,3,4], [3,7,6,2,1,5,10,3,6,2,8,3,5,7,9,10,5,1,1,3,8,3,8,2,9]]; LUP = numeric.ccsLUP(A); ==> {L:[[0,5,9,12,14,15],[0,2,4,1,3,1,3,4,2,2,4,3,3,4,4],[1,0.1429,0.2857,0.8571,0.4286,1,-0.1282,-0.5641,-0.1026,1,0.8517,0.7965,1,-0.67,1]],U:[[0,1,3,6,10,15],[0,0,1,0,1,2,0,1,2,3,0,1,2,3,4],[7,10,-5.571,3,2.429,8.821,5,-3.286,1.949,5.884,3,5.429,9.128,0.1395,-3.476]],P:[1,2,4,0,3],Pinv:[3,0,1,4,2]} |
| 138 PASS: numeric.ccsFull(numeric.ccsDot(LUP.L,LUP.U)) ==> [[7,10,3,5,3],[6,3,5,1,8],[1,2,9,3,9],[3,5,8,10,8],[2,6,7,1,2]] |
| 139 PASS: x = numeric.ccsLUPSolve(LUP,[96,63,82,51,89]) ==> [3,1,4,1,5] |
| 140 PASS: X = numeric.trunc(numeric.ccsFull(numeric.ccsLUPSolve(LUP,A)),1e-15); // Solve LUX = PA ==> [[1,0,0,0,0],[0,1,0,0,0],[0,0,1,0,0],[0,0,0,1,0],[0,0,0,0,1]] |
| 141 PASS: numeric.ccsLUP(A,0.4).P; ==> [0,2,1,3,4] |
| 142 PASS: result = "Sparse LUP Stress Test OK"; for(k=0;k<1000;++k) { A = numeric.ccsSparse(numeric.random([10,10])); LUP = numeric.ccsLUP(A); foo = numeric.ccsFull(numeric.ccsDot(LUP.L,LUP.U)); PA = numeric.ccsFull(numeric.ccsGetBlock(A,LUP.P)); res = numeric.norminf(numeric.sub(foo,PA)); if(!isFinite(res) || res>1e-6) { result = { code: "Failed during 1000 sparse LUP", k:k,A:A,LUP:LUP,res:res }; break; }; }; result; ==> "SparseLUPStressTestOK" |
| 143 PASS: A = numeric.ccsSparse([[1,2,0],[0,3,0],[0,0,5]]); B = numeric.ccsSparse([[2,9,0],[0,4,0],[-2,0,0]]); numeric.ccsadd(A,B); ==> [[0,2,4,5],[0,2,0,1,2],[3,-2,11,7,5]] |
| 144 PASS: X = [[0,0,1,1,2,2],[0,1,1,2,2,3],[1,2,3,4,5,6]]; SX = numeric.ccsScatter(X); ==> [[0,1,3,5,6],[0,0,1,1,2,2],[1,2,3,4,5,6]] |
| 145 PASS: numeric.ccsGather(SX) ==> [[0,0,1,1,2,2],[0,1,1,2,2,3],[1,2,3,4,5,6]] |
| 146 PASS: lu = numeric.cLU([[0,0,1,1,1,2,2],[0,1,0,1,2,1,2],[2,-1,-1,2,-1,-1,2]]) ==> {U:[[0,0,1,1,2],[0,1,1,2,2],[2,-1,1.5,-1,1.333]],L:[[0,1,1,2,2],[0,0,1,1,2],[1,-0.5,1,-0.6667,1]]} |
| 147 PASS: numeric.cLUsolve(lu,[5,-8,13]) ==> [3,1,7] |
| 148 PASS: g = numeric.cgrid(5) ==> [[-1,-1,-1,-1,-1],[-1,0,1,2,-1],[-1,3,4,5,-1],[-1,6,7,8,-1],[-1,-1,-1,-1,-1]] |
| 149 PASS: coordL = numeric.cdelsq(g) ==> [[0,0,0,1,1,1,1,2,2,2,3,3,3,3,4,4,4,4,4,5,5,5,5,6,6,6,7,7,7,7,8,8,8],[1,3,0,0,2,4,1,1,5,2,0,4,6,3,1,3,5,7,4,2,4,8,5,3,7,6,4,6,8,7,5,7,8],[-1,-1,4,-1,-1,-1,4,-1,-1,4,-1,-1,-1,4,-1,-1,-1,-1,4,-1,-1,-1,4,-1,-1,4,-1,-1,-1,4,-1,-1,4]] |
| 150 PASS: L = numeric.sscatter(coordL); // Just to see what it looks like ==> [[4,-1,,-1],[-1,4,-1,,-1],[,-1,4,,,-1],[-1,,,4,-1,,-1],[,-1,,-1,4,-1,,-1],[,,-1,,-1,4,,,-1],[,,,-1,,,4,-1],[,,,,-1,,-1,4,-1],[,,,,,-1,,-1,4]] |
| 151 PASS: lu = numeric.cLU(coordL); x = numeric.cLUsolve(lu,[1,1,1,1,1,1,1,1,1]); ==> [0.6875,0.875,0.6875,0.875,1.125,0.875,0.6875,0.875,0.6875] |
| 152 PASS: numeric.cdotMV(coordL,x) ==> [1,1,1,1,1,1,1,1,1] |
| 153 PASS: G = numeric.rep([5,5],0); for(i=0;i<5;i++) for(j=0;j<5;j++) if(g[i][j]>=0) G[i][j] = x[g[i][j]]; G ==> [[0,0,0,0,0],[0,0.6875,0.875,0.6875,0],[0,0.875,1.125,0.875,0],[0,0.6875,0.875,0.6875,0],[0,0,0,0,0]] |
| 154 PASS: workshop.html('<img src="'+numeric.imageURL(numeric.mul([G,G,G],200))+'" width=100 />'); ==> |
| 155 PASS: numeric.cgrid(6,'L') ==> [[-1,-1,-1,-1,-1,-1],[-1,0,1,-1,-1,-1],[-1,2,3,-1,-1,-1],[-1,4,5,6,7,-1],[-1,8,9,10,11,-1],[-1,-1,-1,-1,-1,-1]] |
| 156 PASS: numeric.cgrid(5,function(i,j) { return i!==2 || j!==2; }) ==> [[-1,-1,-1,-1,-1],[-1,0,1,2,-1],[-1,3,-1,4,-1],[-1,5,6,7,-1],[-1,-1,-1,-1,-1]] |
| 157 PASS: numeric.spline([1,2,3,4,5],[1,2,1,3,2]).at(numeric.linspace(1,5,10)) ==> [1,1.731,2.039,1.604,1.019,1.294,2.364,3.085,2.82,2] |
| 158 PASS: numeric.spline([1,2,3,4,5],[1,2,1,3,2],0,0).at(numeric.linspace(1,5,10)) ==> [1,1.435,1.98,1.669,1.034,1.316,2.442,3.017,2.482,2] |
| 159 PASS: numeric.spline([1,2,3,4],[0.8415,0.04718,-0.8887,0.8415],'periodic').at(numeric.linspace(1,4,10)) ==> [0.8415,0.9024,0.5788,0.04718,-0.5106,-0.8919,-0.8887,-0.3918,0.3131,0.8415] |
| 160 PASS: numeric.spline([1,2,3],[[0,1],[1,0],[0,1]]).at(1.78) ==> [0.9327,0.06728] |
| 161 PASS: xs = [0,1,2,3]; numeric.spline(xs,numeric.sin(xs)).diff().at(1.5) ==> 0.07302 |
| 162 PASS: xs = numeric.linspace(0,30,31); ys = numeric.sin(xs); s = numeric.spline(xs,ys).roots(); ==> [0,3.142,6.284,9.425,12.57,15.71,18.85,21.99,25.13,28.27] |
| 163 PASS: z = (new numeric.T([1,2,3,4,5],[6,7,8,9,10])).fft() ==> {x:[15,-5.941,-3.312,-1.688,0.941],y:[40,0.941,-1.688,-3.312,-5.941]} |
| 164 PASS: z.ifft() ==> {x:[1,2,3,4,5],y:[6,7,8,9,10]} |
| 165 PASS: numeric.solveQP([[1,0,0],[0,1,0],[0,0,1]],[0,5,0],[[-4,2,0],[-3,1,-2],[0,0,1]],[-8,2,0]); ==> {solution:[0.4762,1.048,2.095],value:[-2.381],unconstrained_solution:[0,5,0],iterations:[3,0],iact:[3,2,0],message:""} |
| 166 PASS: sqr = function(x) { return x*x; }; numeric.uncmin(function(x) { return sqr(10*(x[1]-x[0]*x[0])) + sqr(1-x[0]); },[-1.2,1]).solution ==> [1,1] |
| 167 PASS: f = function(x) { return sqr(-13+x[0]+((5-x[1])*x[1]-2)*x[1])+sqr(-29+x[0]+((x[1]+1)*x[1]-14)*x[1]); }; x0 = numeric.uncmin(f,[0.5,-2]).solution ==> [11.41,-0.8968] |
| 168 PASS: f = function(x) { return sqr(1e4*x[0]*x[1]-1)+sqr(Math.exp(-x[0])+Math.exp(-x[1])-1.0001); }; x0 = numeric.uncmin(f,[0,1]).solution ==> [1.098e-5,9.106] |
| 169 PASS: f = function(x) { return sqr(x[0]-1e6)+sqr(x[1]-2e-6)+sqr(x[0]*x[1]-2)}; x0 = numeric.uncmin(f,[0,1]).solution ==> [1e6,2e-6] |
| 170 PASS: f = function(x) { return sqr(1.5-x[0]*(1-x[1]))+sqr(2.25-x[0]*(1-x[1]*x[1]))+sqr(2.625-x[0]*(1-x[1]*x[1]*x[1])); }; x0 = numeric.uncmin(f,[1,1]).solution ==> [3,0.5] |
| 171 PASS: f = function(x) { var ret = 0,i; for(i=1;i<=10;i++) ret+=sqr(2+2*i-Math.exp(i*x[0])-Math.exp(i*x[1])); return ret; }; x0 = numeric.uncmin(f,[0.3,0.4]).solution ==> [0.2578,0.2578] |
| 172 PASS: y = [0.14,0.18,0.22,0.25,0.29,0.32,0.35,0.39,0.37,0.58,0.73,0.96,1.34,2.10,4.39]; f = function(x) { var ret = 0,i; for(i=1;i<=15;i++) ret+=sqr(y[i-1]-(x[0]+i/((16-i)*x[1]+Math.min(i,16-i)*x[2]))); return ret; }; x0 = numeric.uncmin(f,[1,1,1]).solution ==> [0.08241,1.133,2.344] |
| 173 PASS: y = [0.0009,0.0044,0.0175,0.0540,0.1295,0.2420,0.3521,0.3989,0.3521,0.2420,0.1295,0.0540,0.0175,0.0044,0.0009]; f = function(x) { var ret = 0,i; for(i=1;i<=15;i++) ret+=sqr(x[0]*Math.exp(-x[1]*sqr((8-i)/2-x[2])/2)-y[i-1]); return ret; }; x0 = numeric.div(numeric.round(numeric.mul(numeric.uncmin(f,[1,1,1]).solution,1000)),1000) ==> [0.399,1,0] |
| 174 PASS: f = function(x) { return sqr(x[0]+10*x[1])+5*sqr(x[2]-x[3])+sqr(sqr(x[1]-2*x[2]))+10*sqr(x[0]-x[3]); }; x0 = numeric.div(numeric.round(numeric.mul(numeric.uncmin(f,[3,-1,0,1]).solution,1e5)),1e5) ==> [0,0,0,0] |
| 175 PASS: f = function(x) { return (sqr(10*(x[1]-x[0]*x[0]))+sqr(1-x[0])+ 90*sqr(x[3]-x[2]*x[2])+sqr(1-x[2])+ 10*sqr(x[1]+x[3]-2)+0.1*sqr(x[1]-x[3])); }; x0 = numeric.uncmin(f,[-3,-1,-3,-1]).solution ==> [1,1,1,1] |
| 176 PASS: y = [0.1957,0.1947,0.1735,0.1600,0.0844,0.0627,0.0456,0.0342,0.0323,0.0235,0.0246]; u = [4,2,1,0.5,0.25,0.167,0.125,0.1,0.0833,0.0714,0.0625]; f = function(x) { var ret=0, i; for(i=0;i<11;++i) ret += sqr(y[i]-x[0]*(u[i]*u[i]+u[i]*x[1])/(u[i]*u[i]+u[i]*x[2]+x[3])); return ret; }; x0 = numeric.uncmin(f,[0.25,0.39,0.415,0.39]).solution ==> [0.1928,0.1913,0.1231,0.1361] |
| 177 PASS: y = [0.844,0.908,0.932,0.936,0.925,0.908,0.881,0.850,0.818,0.784,0.751,0.718, 0.685,0.658,0.628,0.603,0.580,0.558,0.538,0.522,0.506,0.490,0.478,0.467, 0.457,0.448,0.438,0.431,0.424,0.420,0.414,0.411,0.406]; f = function(x) { var ret=0, i; for(i=0;i<33;++i) ret += sqr(y[i]-(x[0]+x[1]*Math.exp(-10*i*x[3])+x[2]*Math.exp(-10*i*x[4]))); return ret; }; x0 = numeric.uncmin(f,[0.5,1.5,-1,0.01,0.02]).solution ==> [0.3754,1.936,-1.465,0.01287,0.02212] |
| 178 PASS: f = function(x) { var ret=0, i,ti,yi,exp=Math.exp; for(i=1;i<=13;++i) { ti = 0.1*i; yi = exp(-ti)-5*exp(-10*ti)+3*exp(-4*ti); ret += sqr(x[2]*exp(-ti*x[0])-x[3]*exp(-ti*x[1])+x[5]*exp(-ti*x[4])-yi); } return ret; }; x0 = numeric.uncmin(f,[1,2,1,1,1,1],1e-14).solution; f(x0)<1e-20; ==> true |
| 179 PASS: z = []; cb = function(i,x,f,g,H) { z.push({i:i, x:x, f:f, g:g, H:H }); }; x0 = numeric.uncmin(function(x) { return Math.cos(2*x[0]); }, [1],1e-10, function(x) { return [-2*Math.sin(2*x[0])]; }, 100,cb); ==> {solution:[1.571],f:-1,gradient:[2.242e-11],invHessian:[[0.25]],iterations:6,message:"Newtonstepsmallerthantol"} |
| 180 PASS: z ==> [{i:0,x:[1],f:-0.4161,g:[-1.819],H:[[1]]},{i:2,x:[1.909],f:-0.7795,g:[1.253],H:[[0.296]]},{i:3,x:[1.538],f:-0.9979,g:[-0.1296],H:[[0.2683]]},{i:4,x:[1.573],f:-1,g:[9.392e-3],H:[[0.2502]]},{i:5,x:[1.571],f:-1,g:[-6.105e-6],H:[[0.25]]},{i:6,x:[1.571],f:-1,g:[2.242e-11],H:[[0.25]]}] |
| 181 PASS: x = numeric.solveLP([1,1], /* minimize [1,1]*x */ [[-1,0],[0,-1],[-1,-2]], /* matrix of inequalities */ [0,0,-3] /* right-hand-side of inequalities */ ); numeric.trunc(x.solution,1e-12); ==> [0,1.5] |
| 182 PASS: numeric.solveLP([1,1],[[1,0],[0,1],[-1,-1]],[-1,-1,-1]) ==> {solution:NaN,message:"Infeasible",iterations:5} |
| 183 PASS: numeric.solveLP([1,1],[[1,0],[0,1]],[0,0]).message; ==> "Unbounded" |
| 184 PASS: numeric.solveLP([1,2,3], /* minimize [1,2,3]*x */ [[-1,0,0],[0,-1,0],[0,0,-1]], /* matrix A of inequality constraint */ [0,0,0], /* RHS b of inequality constraint */ [[1,1,1]], /* matrix Aeq of equality constraint */ [3] /* vector beq of equality constraint */ ); ==> {solution:[3,1.685e-16,4.559e-19],message:"",iterations:12} |
| 185 PASS: n = 7; m = 3; for(k=0;k<10;++k) { A = numeric.random([n,n]); x = numeric.rep([m],1).concat(numeric.rep([n-m],0)); b = numeric.dot(A,x); J = numeric.diag(numeric.rep([n],-1)); B = numeric.blockMatrix([[A , J ], [numeric.neg(A) , J ], [numeric.rep([n,n],0), J ]]); c = b.concat(numeric.neg(b)).concat(numeric.rep([n],0)); d = numeric.rep([n],0).concat(numeric.rep([n],1)); y = numeric.solveLP(d,B,c).solution; y.length = n; foo = numeric.norm2(numeric.sub(x,y)); if(foo>1e-10) throw new Error("solveLP test fails: "+numeric.prettyPrint({A:A,x:x})); } "solveLP tests pass" ==> "solveLPtestspass" |
| 186 PASS: numeric.solveLP([1,2,3], /* minimize [1,2,3]*x */ [[1, 0, 0], [0, 1, 0], [0, 0, 1],[-1,0,0],[0,-1,0],[0,0,-1]], /* matrix A of inequality constraint */ [1,1,1,0,0,0], /* RHS b of inequality constraint */ [[1,1,1]], /* matrix Aeq of equality constraint */ [3] /* vector beq of equality constraint */ ); ==> {solution:NaN,message:"Infeasible",iterations:10} |
| 187 PASS: sol = numeric.dopri(0,1,1,function(t,y) { return y; }) ==> {x:[0,0.1,0.1522,0.361,0.5792,0.7843,0.9813,1],y:[1,1.105,1.164,1.435,1.785,2.191,2.668,2.718],f:[1,1.105,1.164,1.435,1.785,2.191,2.668,2.718],ymid:[1.051,1.134,1.293,1.6,1.977,2.418,2.693],iterations:8,events:,message:""} |
| 188 PASS: sol.at([0.3,0.7]) ==> [1.35,2.014] |
| 189 PASS: sol = numeric.dopri(0,10,[3,0],function (x,y) { return [y[1],-y[0]]; }); sol.at([0,0.5*Math.PI,Math.PI,1.5*Math.PI,2*Math.PI]) ==> [[3,0],[-9.534e-8,-3],[-3,2.768e-7],[3.63e-7,3],[3,-3.065e-7]] |
| 190 PASS: numeric.dopri(0,20,[2,0],function(t,y) { return [y[1], (1-y[0]*y[0])*y[1]-y[0]]; }).at([18,19,20]) ==> [[-1.208,0.9916],[0.4258,2.535],[2.008,-0.04251]] |
| 191 PASS: sol = numeric.dopri(0,2,1,function (x,y) { return y; },1e-8,100,function (x,y) { return y-1.3; }); ==> {x:[0,0.0181,0.09051,0.1822,0.2624],y:[1,1.018,1.095,1.2,1.3],f:[1,1.018,1.095,1.2,1.3],ymid:[1.009,1.056,1.146,1.249],iterations:5,events:true,message:""} |
| 192 PASS: sol = numeric.dopri(0,2,1, function(x,y) { return y; }, undefined,50, function(x,y) { return [y-1.5,Math.sin(y-1.5)]; }); ==> {x:[0,0.2,0.4055],y:[1,1.221,1.5],f:[1,1.221,1.5],ymid:[1.105,1.354],iterations:2,events:[true,true],message:""} |
| 193 PASS: D = numeric.identity(8); d = numeric.rep([8],0); A = [[1, 1, -1, 0, 0, 0, 0, 0, 0, 0],[-1, 1, 0, 1, 0, 0, 0, 0, 0, 0],[1, 1, 0, 0, -1, 0, 0, 0, 0, 0],[-1, 1, 0, 0, 0, 1, 0, 0, 0, 0],[1, 1, 0, 0, 0, 0, -1, 0, 0, 0],[-1, 1, 0, 0, 0, 0, 0, 1, 0, 0],[1, 1, 0, 0, 0, 0, 0, 0, -1, 0],[-1, 1, 0, 0, 0, 0, 0, 0, 0, 1]]; b = [1, 1, -1, 0, -1, 0, -1, 0, -1, 0]; numeric.solveQP(D,d,A,b,undefined,2) ==> {solution:[0.25,0,0.25,0,0.25,0,0.25,0],value:[0.125],unconstrained_solution:[0,0,0,0,0,0,0,0],iterations:[3,0],iact:[1,2,0,0,0,0,0,0,0,0],message:""} |
| 194 PASS: numeric.imageURL(numeric.rep([3],[[1,2],[3,4]])); ==> "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAIAAAD91JpzAAAAH0lEQVQIHQAIAPf/AAEBAQICAgABBwD4/wMDAwQEBAAAogAfhs2H3QAAAABJRU5ErkJggg==" |
| 195 PASS: numeric.gradient(function(x) { return Math.exp(Math.sin(x[0])*(x[1]+2)); },[1,2]); ==> [62.59,24.37] |
| 196 PASS: numeric.seedrandom.seedrandom(3); numeric.seedrandom.random() ==> 0.7569 |
| 197 PASS: numeric.seedrandom.random() ==> 0.6139 |
| 198 PASS: numeric.seedrandom.seedrandom(3); numeric.seedrandom.random() ==> 0.7569 |
| Chrome testing complete. PASS: 199 FAIL: 0 Total: 199
Fetching http://numericjs.com/staging/documentation.html
In-browser unit tests.
Using Firefox |
| 0 PASS: numeric.seedrandom.seedrandom('1'); Math.random = numeric.seedrandom.random; Math.random(); ==> 0.2694 |
| 1 PASS: A = [[1,2,3],[4,5,6]]; ==> [[1,2,3],[4,5,6]] |
| 2 PASS: x = [7,8,9] ==> [7,8,9] |
| 3 PASS: numeric.dot(A,x); ==> [50,122] |
| 4 PASS: x = [7,8,9]; y = [10,1,2]; numeric['+'](x,y) ==> [17,9,11] |
| 5 PASS: numeric['>'](x,y) ==> [false,true,true] |
| 6 PASS: numeric.add([7,8,9],[10,1,2]) ==> [17,9,11] |
| 7 PASS: numeric.add([1,2],[3,4],[5,6],[7,8]) ==> [16,20] |
| 8 PASS: A = [[1,2,3],[4,5,6],[7,1,9]] ==> [[1,2,3],[4,5,6],[7,1,9]] |
| 9 PASS: Ainv = numeric.inv(A); ==> [[-0.9286,0.3571,0.07143],[-0.1429,0.2857,-0.1429],[0.7381,-0.3095,0.07143]] |
| 10 PASS: numeric.precision = 10; x = 3.141592653589793 ==> 3.141592654 |
| 11 PASS: numeric.precision = 4; x ==> 3.142 |
| 12 PASS: numeric.identity(100) ==> ...LargeArray... |
| 13 PASS: numeric.largeArray = 2; A = numeric.identity(4) ==> ...LargeArray... |
| 14 PASS: numeric.largeArray = 50; A ==> [[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]] |
| 15 PASS: numeric.exp([1,2]); ==> [2.718,7.389] |
| 16 PASS: numeric.exp([[1,2],[3,4]]) ==> [[2.718,7.389],[20.09,54.6]] |
| 17 PASS: numeric.abs([-2,3]) ==> [2,3] |
| 18 PASS: numeric.acos([0.1,0.2]) ==> [1.471,1.369] |
| 19 PASS: numeric.asin([0.1,0.2]) ==> [0.1002,0.2014] |
| 20 PASS: numeric.atan([1,2]) ==> [0.7854,1.107] |
| 21 PASS: numeric.atan2([1,2],[3,4]) ==> [0.3218,0.4636] |
| 22 PASS: numeric.ceil([-2.2,3.3]) ==> [-2,4] |
| 23 PASS: numeric.floor([-2.2,3.3]) ==> [-3,3] |
| 24 PASS: numeric.log([1,2]) ==> [0,0.6931] |
| 25 PASS: numeric.pow([2,3],[0.25,7.1]) ==> [1.189,2441] |
| 26 PASS: numeric.round([-2.2,3.3]) ==> [-2,3] |
| 27 PASS: numeric.sin([1,2]) ==> [0.8415,0.9093] |
| 28 PASS: numeric.sqrt([1,2]) ==> [1,1.414] |
| 29 PASS: numeric.tan([1,2]) ==> [1.557,-2.185] |
| 30 PASS: numeric.dim([1,2]) ==> [2] |
| 31 PASS: numeric.dim([[1,2,3],[4,5,6]]) ==> [2,3] |
| 32 PASS: numeric.same([1,2],[1,2]) ==> true |
| 33 PASS: numeric.same([1,2],[1,2,3]) ==> false |
| 34 PASS: numeric.same([1,2],[[1],[2]]) ==> false |
| 35 PASS: numeric.same([[1,2],[3,4]],[[1,2],[3,4]]) ==> true |
| 36 PASS: numeric.same([[1,2],[3,4]],[[1,2],[3,5]]) ==> false |
| 37 PASS: numeric.same([[1,2],[2,4]],[[1,2],[3,4]]) ==> false |
| 38 PASS: numeric.rep([3],5) ==> [5,5,5] |
| 39 PASS: numeric.rep([2,3],0) ==> [[0,0,0],[0,0,0]] |
| 40 PASS: sum = numeric.mapreduce('accum += xi','0'); sum([1,2,3]) ==> 6 |
| 41 PASS: sum([[1,2,3],[4,5,6]]) ==> 21 |
| 42 PASS: numeric.any([false,true]) ==> true |
| 43 PASS: numeric.any([[0,0,3.14],[0,false,0]]) ==> true |
| 44 PASS: numeric.any([0,0,false]) ==> false |
| 45 PASS: numeric.all([false,true]) ==> false |
| 46 PASS: numeric.all([[1,4,3.14],["no",true,-1]]) ==> true |
| 47 PASS: numeric.all([0,0,false]) ==> false |
| 48 PASS: numeric.diag([1,2,3]) ==> [[1,0,0],[0,2,0],[0,0,3]] |
| 49 PASS: numeric.identity(3) ==> [[1,0,0],[0,1,0],[0,0,1]] |
| 50 PASS: numeric.linspace(1,5); ==> [1,2,3,4,5] |
| 51 PASS: numeric.linspace(1,3,5); ==> [1,1.5,2,2.5,3] |
| 52 PASS: numeric.blockMatrix([[[[1,2],[3,4]],[[5,6],[7,8]]], [[[11,12],[13,14]],[[15,16],[17,18]]]]) ==> [[1,2,5,6],[3,4,7,8],[11,12,15,16],[13,14,17,18]] |
| 53 PASS: numeric.addVV([1,2],[3,4]) ==> [4,6] |
| 54 PASS: numeric.addVS([1,2],3) ==> [4,5] |
| 55 PASS: numeric.add(1,[2,3]) ==> [3,4] |
| 56 PASS: numeric.add([1,2,3],[4,5,6]) ==> [5,7,9] |
| 57 PASS: numeric.sub([1,2],[3,4]) ==> [-2,-2] |
| 58 PASS: numeric.mul([1,2],[3,4]) ==> [3,8] |
| 59 PASS: numeric.div([1,2],[3,4]) ==> [0.3333,0.5] |
| 60 PASS: v = [1,2,3,4]; numeric.addeq(v,3); v ==> [4,5,6,7] |
| 61 PASS: numeric.subeq([1,2,3],[5,3,1]) ==> [-4,-1,2] |
| 62 PASS: numeric.neg([1,-2,3]) ==> [-1,2,-3] |
| 63 PASS: numeric.isFinite([10,NaN,Infinity]) ==> [true,false,false] |
| 64 PASS: numeric.isNaN([10,NaN,Infinity]) ==> [false,true,false] |
| 65 PASS: n = 41; A = numeric.random([n,n]); numeric.norm2(numeric.sub(numeric.dotMMsmall(numeric.inv(A),A),numeric.identity(n)))<1e-12 ==> true |
| 66 PASS: n = 42; A = numeric.random([n,n]); numeric.norm2(numeric.sub(numeric.dotMMsmall(numeric.inv(A),A),numeric.identity(n)))<1e-12 ==> true |
| 67 PASS: n = 43; A = numeric.random([n,n]); numeric.norm2(numeric.sub(numeric.dotMMsmall(numeric.inv(A),A),numeric.identity(n)))<1e-12 ==> true |
| 68 PASS: n = 44; A = numeric.random([n,n]); numeric.norm2(numeric.sub(numeric.dotMMbig(numeric.inv(A),A),numeric.identity(n)))<1e-12 ==> true |
| 69 PASS: n = 45; A = numeric.random([n,n]); numeric.norm2(numeric.sub(numeric.dotMMbig(numeric.inv(A),A),numeric.identity(n)))<1e-12 ==> true |
| 70 PASS: n = 46; A = numeric.random([n,n]); numeric.norm2(numeric.sub(numeric.dotMMbig(numeric.inv(A),A),numeric.identity(n)))<1e-12 ==> true |
| 71 PASS: numeric.dotVV([1,2],[3,4]) ==> 11 |
| 72 PASS: numeric.dotVM([1,2],[[3,4],[5,6]]) ==> [13,16] |
| 73 PASS: numeric.dotMV([[1,2],[3,4]],[5,6]) ==> [17,39] |
| 74 PASS: numeric.dotMMbig([[1,2],[3,4]],[[5,6],[7,8]]) ==> [[19,22],[43,50]] |
| 75 PASS: numeric.dotMMsmall([[1,2],[3,4]],[[5,6],[7,8]]) ==> [[19,22],[43,50]] |
| 76 PASS: numeric.dot([1,2,3,4,5,6,7,8,9],[1,2,3,4,5,6,7,8,9]) ==> 285 |
| 77 PASS: numeric.dot([1,2,3],[4,5,6]) ==> 32 |
| 78 PASS: numeric.dot([[1,2,3],[4,5,6]],[7,8,9]) ==> [50,122] |
| 79 PASS: numeric.solve([[1,2],[3,4]],[17,39]) ==> [5,6] |
| 80 PASS: LU = numeric.LU([[1,2],[3,4]]) ==> {LU:[[3,4],[0.3333,0.6667]],P:[1,1]} |
| 81 PASS: numeric.LUsolve(LU,[17,39]) ==> [5,6] |
| 82 PASS: ns = [5,6,10,16,25,40,41]; for(j=0;j "numeric.solveStressTestOK" |
| 83 PASS: numeric.det([[1,2],[3,4]]); ==> -2 |
| 84 PASS: numeric.det([[6,8,4,2,8,5],[3,5,2,4,9,2],[7,6,8,3,4,5],[5,5,2,8,1,6],[3,2,2,4,2,2],[8,3,2,2,4,1]]); ==> -1404 |
| 85 PASS: numeric.inv([[1,2],[3,4]]) ==> [[-2,1],[1.5,-0.5]] |
| 86 PASS: numeric.transpose([[1,2,3],[4,5,6]]) ==> [[1,4],[2,5],[3,6]] |
| 87 PASS: numeric.transpose([[1,2,3,4,5,6,7,8,9,10,11,12]]) ==> [[1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12]] |
| 88 PASS: numeric.norm2([1,2]) ==> 2.236 |
| 89 PASS: numeric.tensor([1,2],[3,4,5]) ==> [[3,4,5],[6,8,10]] |
| 90 PASS: numeric.parseDate(['1/13/2013','2001-5-9, 9:31']); ==> [1.358e12,9.894e11] |
| 91 PASS: numeric.parseFloat(['12','0.1']) ==> [12,0.1] |
| 92 PASS: numeric.parseCSV('a,b,c\n1,2.3,.3\n4e6,-5.3e-8,6.28e+4') ==> [["a","b","c"],[1,2.3,0.3],[4e6,-5.3e-8,62800]] |
| 93 PASS: numeric.toCSV([[1.23456789123,2],[3,4]]) ==> "1.23456789123,23,4" |
| 94 PASS: numeric.getURL('tools/helloworld.txt').responseText ==> "Hello,world!" |
| 95 PASS: z = new numeric.T(3,4); ==> {x:3,y:4} |
| 96 PASS: z.add(5) ==> {x:8,y:4} |
| 97 PASS: w = new numeric.T(2,8); ==> {x:2,y:8} |
| 98 PASS: z.add(w) ==> {x:5,y:12} |
| 99 PASS: z.mul(w) ==> {x:-26,y:32} |
| 100 PASS: z.div(w) ==> {x:0.5588,y:-0.2353} |
| 101 PASS: z.sub(w) ==> {x:1,y:-4} |
| 102 PASS: z = new numeric.T([1,2],[3,4]); ==> {x:[1,2],y:[3,4]} |
| 103 PASS: z.abs() ==> {x:[3.162,4.472],y:} |
| 104 PASS: z.conj() ==> {x:[1,2],y:[-3,-4]} |
| 105 PASS: z.norm2() ==> 5.477 |
| 106 PASS: z.exp() ==> {x:[-2.691,-4.83],y:[0.3836,-5.592]} |
| 107 PASS: z.cos() ==> {x:[-1.528,-2.459],y:[0.1658,-2.745]} |
| 108 PASS: z.sin() ==> {x:[0.2178,-2.847],y:[1.163,2.371]} |
| 109 PASS: z.log() ==> {x:[1.151,1.498],y:[1.249,1.107]} |
| 110 PASS: A = new numeric.T([[1,2],[3,4]],[[0,1],[2,-1]]); ==> {x:[[1,2],[3,4]],y:[[0,1],[2,-1]]} |
| 111 PASS: A.inv(); ==> {x:[[0.125,0.125],[0.25,0]],y:[[0.5,-0.25],[-0.375,0.125]]} |
| 112 PASS: A.inv().dot(A) ==> {x:[[1,0],[0,1]],y:[[0,-2.776e-17],[0,0]]} |
| 113 PASS: A.get([1,1]) ==> {x:4,y:-1} |
| 114 PASS: A.transpose() ==> {x:[[1,3],[2,4]],y:[[0,2],[1,-1]]} |
| 115 PASS: A.transjugate() ==> {x:[[1,3],[2,4]],y:[[0,-2],[-1,1]]} |
| 116 PASS: numeric.T.rep([2,2],new numeric.T(2,3)); ==> {x:[[2,2],[2,2]],y:[[3,3],[3,3]]} |
| 117 PASS: A = [[1,2,5],[3,5,-1],[7,-3,5]]; ==> [[1,2,5],[3,5,-1],[7,-3,5]] |
| 118 PASS: B = numeric.eig(A); ==> {lambda:{x:[-4.284,9.027,6.257],y:},E:{x:[[0.7131,-0.5543,0.4019],[-0.2987,-0.2131,0.9139],[-0.6342,-0.8046,0.057]],y:}} |
| 119 PASS: C = B.E.dot(numeric.T.diag(B.lambda)).dot(B.E.inv()); ==> {x:[[1,2,5],[3,5,-1],[7,-3,5]],y:} |
| 120 PASS: A=[[ 22, 10, 2, 3, 7], [ 14, 7, 10, 0, 8], [ -1, 13, -1,-11, 3], [ -3, -2, 13, -2, 4], [ 9, 8, 1, -2, 4], [ 9, 1, -7, 5, -1], [ 2, -6, 6, 5, 1], [ 4, 5, 0, -2, 2]]; numeric.svd(A); ==> {U:[[-0.7071,-0.1581,0.1768,0.2494,0.4625],[-0.5303,-0.1581,-0.3536,0.1556,-0.4984],[-0.1768,0.7906,-0.1768,-0.1546,0.3967],[-1.506e-17,-0.1581,-0.7071,-0.3277,0.1],[-0.3536,0.1581,1.954e-15,-0.07265,-0.2084],[-0.1768,-0.1581,0.5303,-0.5726,-0.05555],[-7.109e-18,-0.4743,-0.1768,-0.3142,0.4959],[-0.1768,0.1581,1.915e-15,-0.592,-0.2791]],S:[35.33,20,19.6,0,0],V:[[-0.8006,-0.3162,0.2887,-0.4191,0],[-0.4804,0.6325,7.768e-15,0.4405,0.4185],[-0.1601,-0.3162,-0.866,-0.052,0.3488],[4.684e-17,-0.6325,0.2887,0.6761,0.2442],[-0.3203,3.594e-15,-0.2887,0.413,-0.8022]]} |
| 121 PASS: n = 31; A = numeric.random([n,n]); B = numeric.eig(A); !(B.E.dot(numeric.T.diag(B.lambda).dot(B.E.inv())).sub(A).norm2()>1e-12) ==> true |
| 122 PASS: n = 32; A = numeric.random([n,n]); B = numeric.eig(A); !(B.E.dot(numeric.T.diag(B.lambda).dot(B.E.inv())).sub(A).norm2()>1e-12) ==> true |
| 123 PASS: n = 33; A = numeric.random([n,n]); B = numeric.eig(A); !(B.E.dot(numeric.T.diag(B.lambda).dot(B.E.inv())).sub(A).norm2()>1e-12) ==> true |
| 124 PASS: n = 34; A = numeric.random([n,n]); B = numeric.eig(A); !(B.E.dot(numeric.T.diag(B.lambda).dot(B.E.inv())).sub(A).norm2()>1e-12) ==> true |
| 125 PASS: n = 35; A = numeric.random([n,n]); B = numeric.eig(A); !(B.E.dot(numeric.T.diag(B.lambda).dot(B.E.inv())).sub(A).norm2()>1e-12) ==> true |
| 126 PASS: m = 17; n = 12; A = numeric.random([m,n]); B = numeric.svd(A); U = new numeric.T(B.U); V = new numeric.T(B.V); !(U.dot(numeric.T.diag(B.S)).dot(V.transpose()).sub(A).norm2()>1e-12) ==> true |
| 127 PASS: m = 21; n = 19; A = numeric.random([m,n]); B = numeric.svd(A); U = new numeric.T(B.U); V = new numeric.T(B.V); !(U.dot(numeric.T.diag(B.S)).dot(V.transpose()).sub(A).norm2()>1e-12) ==> true |
| 128 PASS: m = 33; n = 33; A = numeric.random([m,n]); B = numeric.svd(A); U = new numeric.T(B.U); V = new numeric.T(B.V); !(U.dot(numeric.T.diag(B.S)).dot(V.transpose()).sub(A).norm2()>1e-12) ==> true |
| 129 PASS: m = 59; n = 42; A = numeric.random([m,n]); B = numeric.svd(A); U = new numeric.T(B.U); V = new numeric.T(B.V); !(U.dot(numeric.T.diag(B.S)).dot(V.transpose()).sub(A).norm2()>1e-12) ==> true |
| 130 PASS: numeric.eig([[1, 0, 0], [0, 0.7181, -0.6960], [0, 0.6960, 0.7181]]) // This was a bug found by bdmartin ==> {lambda:{x:[1,0.7181,0.7181],y:[0,0.696,-0.696]},E:{x:[[1,0,0],[0,0,0.7071],[0,-0.7071,0]],y:[[0,0,0],[0,-0.7071,0],[0,0,0.7071]]}} |
| 131 PASS: A = [[1,2,0], [0,3,0], [2,0,5]]; SA = numeric.ccsSparse(A); ==> [[0,2,4,5],[0,2,0,1,2],[1,2,2,3,5]] |
| 132 PASS: A = numeric.ccsSparse([[ 3, 5, 8,10, 8], [ 7,10, 3, 5, 3], [ 6, 3, 5, 1, 8], [ 2, 6, 7, 1, 2], [ 1, 2, 9, 3, 9]]); ==> [[0,5,10,15,20,25],[0,1,2,3,4,0,1,2,3,4,0,1,2,3,4,0,1,2,3,4,0,1,2,3,4],[3,7,6,2,1,5,10,3,6,2,8,3,5,7,9,10,5,1,1,3,8,3,8,2,9]] |
| 133 PASS: numeric.ccsFull(A); ==> [[3,5,8,10,8],[7,10,3,5,3],[6,3,5,1,8],[2,6,7,1,2],[1,2,9,3,9]] |
| 134 PASS: numeric.ccsDot(numeric.ccsSparse([[1,2,3],[4,5,6]]),numeric.ccsSparse([[7,8],[9,10],[11,12]])) ==> [[0,2,4],[0,1,0,1],[58,139,64,154]] |
| 135 PASS: M = [[0,1,3,6],[0,0,1,0,1,2],[3,-1,2,3,-2,4]]; b = [9,3,2]; x = numeric.ccsTSolve(M,b); ==> [3.167,2,0.5] |
| 136 PASS: numeric.ccsDot(M,[[0,3],[0,1,2],x]) ==> [[0,3],[0,1,2],[9,3,2]] |
| 137 PASS: A = [[0,5,10,15,20,25], [0,1,2,3,4,0,1,2,3,4,0,1,2,3,4,0,1,2,3,4,0,1,2,3,4], [3,7,6,2,1,5,10,3,6,2,8,3,5,7,9,10,5,1,1,3,8,3,8,2,9]]; LUP = numeric.ccsLUP(A); ==> {L:[[0,5,9,12,14,15],[0,2,4,1,3,1,3,4,2,2,4,3,3,4,4],[1,0.1429,0.2857,0.8571,0.4286,1,-0.1282,-0.5641,-0.1026,1,0.8517,0.7965,1,-0.67,1]],U:[[0,1,3,6,10,15],[0,0,1,0,1,2,0,1,2,3,0,1,2,3,4],[7,10,-5.571,3,2.429,8.821,5,-3.286,1.949,5.884,3,5.429,9.128,0.1395,-3.476]],P:[1,2,4,0,3],Pinv:[3,0,1,4,2]} |
| 138 PASS: numeric.ccsFull(numeric.ccsDot(LUP.L,LUP.U)) ==> [[7,10,3,5,3],[6,3,5,1,8],[1,2,9,3,9],[3,5,8,10,8],[2,6,7,1,2]] |
| 139 PASS: x = numeric.ccsLUPSolve(LUP,[96,63,82,51,89]) ==> [3,1,4,1,5] |
| 140 PASS: X = numeric.trunc(numeric.ccsFull(numeric.ccsLUPSolve(LUP,A)),1e-15); // Solve LUX = PA ==> [[1,0,0,0,0],[0,1,0,0,0],[0,0,1,0,0],[0,0,0,1,0],[0,0,0,0,1]] |
| 141 PASS: numeric.ccsLUP(A,0.4).P; ==> [0,2,1,3,4] |
| 142 PASS: result = "Sparse LUP Stress Test OK"; for(k=0;k<1000;++k) { A = numeric.ccsSparse(numeric.random([10,10])); LUP = numeric.ccsLUP(A); foo = numeric.ccsFull(numeric.ccsDot(LUP.L,LUP.U)); PA = numeric.ccsFull(numeric.ccsGetBlock(A,LUP.P)); res = numeric.norminf(numeric.sub(foo,PA)); if(!isFinite(res) || res>1e-6) { result = { code: "Failed during 1000 sparse LUP", k:k,A:A,LUP:LUP,res:res }; break; }; }; result; ==> "SparseLUPStressTestOK" |
| 143 PASS: A = numeric.ccsSparse([[1,2,0],[0,3,0],[0,0,5]]); B = numeric.ccsSparse([[2,9,0],[0,4,0],[-2,0,0]]); numeric.ccsadd(A,B); ==> [[0,2,4,5],[0,2,0,1,2],[3,-2,11,7,5]] |
| 144 PASS: X = [[0,0,1,1,2,2],[0,1,1,2,2,3],[1,2,3,4,5,6]]; SX = numeric.ccsScatter(X); ==> [[0,1,3,5,6],[0,0,1,1,2,2],[1,2,3,4,5,6]] |
| 145 PASS: numeric.ccsGather(SX) ==> [[0,0,1,1,2,2],[0,1,1,2,2,3],[1,2,3,4,5,6]] |
| 146 PASS: lu = numeric.cLU([[0,0,1,1,1,2,2],[0,1,0,1,2,1,2],[2,-1,-1,2,-1,-1,2]]) ==> {U:[[0,0,1,1,2],[0,1,1,2,2],[2,-1,1.5,-1,1.333]],L:[[0,1,1,2,2],[0,0,1,1,2],[1,-0.5,1,-0.6667,1]]} |
| 147 PASS: numeric.cLUsolve(lu,[5,-8,13]) ==> [3,1,7] |
| 148 PASS: g = numeric.cgrid(5) ==> [[-1,-1,-1,-1,-1],[-1,0,1,2,-1],[-1,3,4,5,-1],[-1,6,7,8,-1],[-1,-1,-1,-1,-1]] |
| 149 PASS: coordL = numeric.cdelsq(g) ==> [[0,0,0,1,1,1,1,2,2,2,3,3,3,3,4,4,4,4,4,5,5,5,5,6,6,6,7,7,7,7,8,8,8],[1,3,0,0,2,4,1,1,5,2,0,4,6,3,1,3,5,7,4,2,4,8,5,3,7,6,4,6,8,7,5,7,8],[-1,-1,4,-1,-1,-1,4,-1,-1,4,-1,-1,-1,4,-1,-1,-1,-1,4,-1,-1,-1,4,-1,-1,4,-1,-1,-1,4,-1,-1,4]] |
| 150 PASS: L = numeric.sscatter(coordL); // Just to see what it looks like ==> [[4,-1,,-1],[-1,4,-1,,-1],[,-1,4,,,-1],[-1,,,4,-1,,-1],[,-1,,-1,4,-1,,-1],[,,-1,,-1,4,,,-1],[,,,-1,,,4,-1],[,,,,-1,,-1,4,-1],[,,,,,-1,,-1,4]] |
| 151 PASS: lu = numeric.cLU(coordL); x = numeric.cLUsolve(lu,[1,1,1,1,1,1,1,1,1]); ==> [0.6875,0.875,0.6875,0.875,1.125,0.875,0.6875,0.875,0.6875] |
| 152 PASS: numeric.cdotMV(coordL,x) ==> [1,1,1,1,1,1,1,1,1] |
| 153 PASS: G = numeric.rep([5,5],0); for(i=0;i<5;i++) for(j=0;j<5;j++) if(g[i][j]>=0) G[i][j] = x[g[i][j]]; G ==> [[0,0,0,0,0],[0,0.6875,0.875,0.6875,0],[0,0.875,1.125,0.875,0],[0,0.6875,0.875,0.6875,0],[0,0,0,0,0]] |
| 154 PASS: workshop.html('<img src="'+numeric.imageURL(numeric.mul([G,G,G],200))+'" width=100 />'); ==> |
| 155 PASS: numeric.cgrid(6,'L') ==> [[-1,-1,-1,-1,-1,-1],[-1,0,1,-1,-1,-1],[-1,2,3,-1,-1,-1],[-1,4,5,6,7,-1],[-1,8,9,10,11,-1],[-1,-1,-1,-1,-1,-1]] |
| 156 PASS: numeric.cgrid(5,function(i,j) { return i!==2 || j!==2; }) ==> [[-1,-1,-1,-1,-1],[-1,0,1,2,-1],[-1,3,-1,4,-1],[-1,5,6,7,-1],[-1,-1,-1,-1,-1]] |
| 157 PASS: numeric.spline([1,2,3,4,5],[1,2,1,3,2]).at(numeric.linspace(1,5,10)) ==> [1,1.731,2.039,1.604,1.019,1.294,2.364,3.085,2.82,2] |
| 158 PASS: numeric.spline([1,2,3,4,5],[1,2,1,3,2],0,0).at(numeric.linspace(1,5,10)) ==> [1,1.435,1.98,1.669,1.034,1.316,2.442,3.017,2.482,2] |
| 159 PASS: numeric.spline([1,2,3,4],[0.8415,0.04718,-0.8887,0.8415],'periodic').at(numeric.linspace(1,4,10)) ==> [0.8415,0.9024,0.5788,0.04718,-0.5106,-0.8919,-0.8887,-0.3918,0.3131,0.8415] |
| 160 PASS: numeric.spline([1,2,3],[[0,1],[1,0],[0,1]]).at(1.78) ==> [0.9327,0.06728] |
| 161 PASS: xs = [0,1,2,3]; numeric.spline(xs,numeric.sin(xs)).diff().at(1.5) ==> 0.07302 |
| 162 PASS: xs = numeric.linspace(0,30,31); ys = numeric.sin(xs); s = numeric.spline(xs,ys).roots(); ==> [0,3.142,6.284,9.425,12.57,15.71,18.85,21.99,25.13,28.27] |
| 163 PASS: z = (new numeric.T([1,2,3,4,5],[6,7,8,9,10])).fft() ==> {x:[15,-5.941,-3.312,-1.688,0.941],y:[40,0.941,-1.688,-3.312,-5.941]} |
| 164 PASS: z.ifft() ==> {x:[1,2,3,4,5],y:[6,7,8,9,10]} |
| 165 PASS: numeric.solveQP([[1,0,0],[0,1,0],[0,0,1]],[0,5,0],[[-4,2,0],[-3,1,-2],[0,0,1]],[-8,2,0]); ==> {solution:[0.4762,1.048,2.095],value:[-2.381],unconstrained_solution:[0,5,0],iterations:[3,0],iact:[3,2,0],message:""} |
| 166 PASS: sqr = function(x) { return x*x; }; numeric.uncmin(function(x) { return sqr(10*(x[1]-x[0]*x[0])) + sqr(1-x[0]); },[-1.2,1]).solution ==> [1,1] |
| 167 PASS: f = function(x) { return sqr(-13+x[0]+((5-x[1])*x[1]-2)*x[1])+sqr(-29+x[0]+((x[1]+1)*x[1]-14)*x[1]); }; x0 = numeric.uncmin(f,[0.5,-2]).solution ==> [11.41,-0.8968] |
| 168 PASS: f = function(x) { return sqr(1e4*x[0]*x[1]-1)+sqr(Math.exp(-x[0])+Math.exp(-x[1])-1.0001); }; x0 = numeric.uncmin(f,[0,1]).solution ==> [1.098e-5,9.106] |
| 169 PASS: f = function(x) { return sqr(x[0]-1e6)+sqr(x[1]-2e-6)+sqr(x[0]*x[1]-2)}; x0 = numeric.uncmin(f,[0,1]).solution ==> [1e6,2e-6] |
| 170 PASS: f = function(x) { return sqr(1.5-x[0]*(1-x[1]))+sqr(2.25-x[0]*(1-x[1]*x[1]))+sqr(2.625-x[0]*(1-x[1]*x[1]*x[1])); }; x0 = numeric.uncmin(f,[1,1]).solution ==> [3,0.5] |
| 171 PASS: f = function(x) { var ret = 0,i; for(i=1;i<=10;i++) ret+=sqr(2+2*i-Math.exp(i*x[0])-Math.exp(i*x[1])); return ret; }; x0 = numeric.uncmin(f,[0.3,0.4]).solution ==> [0.2578,0.2578] |
| 172 PASS: y = [0.14,0.18,0.22,0.25,0.29,0.32,0.35,0.39,0.37,0.58,0.73,0.96,1.34,2.10,4.39]; f = function(x) { var ret = 0,i; for(i=1;i<=15;i++) ret+=sqr(y[i-1]-(x[0]+i/((16-i)*x[1]+Math.min(i,16-i)*x[2]))); return ret; }; x0 = numeric.uncmin(f,[1,1,1]).solution ==> [0.08241,1.133,2.344] |
| 173 PASS: y = [0.0009,0.0044,0.0175,0.0540,0.1295,0.2420,0.3521,0.3989,0.3521,0.2420,0.1295,0.0540,0.0175,0.0044,0.0009]; f = function(x) { var ret = 0,i; for(i=1;i<=15;i++) ret+=sqr(x[0]*Math.exp(-x[1]*sqr((8-i)/2-x[2])/2)-y[i-1]); return ret; }; x0 = numeric.div(numeric.round(numeric.mul(numeric.uncmin(f,[1,1,1]).solution,1000)),1000) ==> [0.399,1,0] |
| 174 PASS: f = function(x) { return sqr(x[0]+10*x[1])+5*sqr(x[2]-x[3])+sqr(sqr(x[1]-2*x[2]))+10*sqr(x[0]-x[3]); }; x0 = numeric.div(numeric.round(numeric.mul(numeric.uncmin(f,[3,-1,0,1]).solution,1e5)),1e5) ==> [0,0,0,0] |
| 175 PASS: f = function(x) { return (sqr(10*(x[1]-x[0]*x[0]))+sqr(1-x[0])+ 90*sqr(x[3]-x[2]*x[2])+sqr(1-x[2])+ 10*sqr(x[1]+x[3]-2)+0.1*sqr(x[1]-x[3])); }; x0 = numeric.uncmin(f,[-3,-1,-3,-1]).solution ==> [1,1,1,1] |
| 176 PASS: y = [0.1957,0.1947,0.1735,0.1600,0.0844,0.0627,0.0456,0.0342,0.0323,0.0235,0.0246]; u = [4,2,1,0.5,0.25,0.167,0.125,0.1,0.0833,0.0714,0.0625]; f = function(x) { var ret=0, i; for(i=0;i<11;++i) ret += sqr(y[i]-x[0]*(u[i]*u[i]+u[i]*x[1])/(u[i]*u[i]+u[i]*x[2]+x[3])); return ret; }; x0 = numeric.uncmin(f,[0.25,0.39,0.415,0.39]).solution ==> [0.1928,0.1913,0.1231,0.1361] |
| 177 PASS: y = [0.844,0.908,0.932,0.936,0.925,0.908,0.881,0.850,0.818,0.784,0.751,0.718, 0.685,0.658,0.628,0.603,0.580,0.558,0.538,0.522,0.506,0.490,0.478,0.467, 0.457,0.448,0.438,0.431,0.424,0.420,0.414,0.411,0.406]; f = function(x) { var ret=0, i; for(i=0;i<33;++i) ret += sqr(y[i]-(x[0]+x[1]*Math.exp(-10*i*x[3])+x[2]*Math.exp(-10*i*x[4]))); return ret; }; x0 = numeric.uncmin(f,[0.5,1.5,-1,0.01,0.02]).solution ==> [0.3754,1.936,-1.465,0.01287,0.02212] |
| 178 PASS: f = function(x) { var ret=0, i,ti,yi,exp=Math.exp; for(i=1;i<=13;++i) { ti = 0.1*i; yi = exp(-ti)-5*exp(-10*ti)+3*exp(-4*ti); ret += sqr(x[2]*exp(-ti*x[0])-x[3]*exp(-ti*x[1])+x[5]*exp(-ti*x[4])-yi); } return ret; }; x0 = numeric.uncmin(f,[1,2,1,1,1,1],1e-14).solution; f(x0)<1e-20; ==> true |
| 179 PASS: z = []; cb = function(i,x,f,g,H) { z.push({i:i, x:x, f:f, g:g, H:H }); }; x0 = numeric.uncmin(function(x) { return Math.cos(2*x[0]); }, [1],1e-10, function(x) { return [-2*Math.sin(2*x[0])]; }, 100,cb); ==> {solution:[1.571],f:-1,gradient:[2.242e-11],invHessian:[[0.25]],iterations:6,message:"Newtonstepsmallerthantol"} |
| 180 PASS: z ==> [{i:0,x:[1],f:-0.4161,g:[-1.819],H:[[1]]},{i:2,x:[1.909],f:-0.7795,g:[1.253],H:[[0.296]]},{i:3,x:[1.538],f:-0.9979,g:[-0.1296],H:[[0.2683]]},{i:4,x:[1.573],f:-1,g:[9.392e-3],H:[[0.2502]]},{i:5,x:[1.571],f:-1,g:[-6.105e-6],H:[[0.25]]},{i:6,x:[1.571],f:-1,g:[2.242e-11],H:[[0.25]]}] |
| 181 PASS: x = numeric.solveLP([1,1], /* minimize [1,1]*x */ [[-1,0],[0,-1],[-1,-2]], /* matrix of inequalities */ [0,0,-3] /* right-hand-side of inequalities */ ); numeric.trunc(x.solution,1e-12); ==> [0,1.5] |
| 182 PASS: numeric.solveLP([1,1],[[1,0],[0,1],[-1,-1]],[-1,-1,-1]) ==> {solution:NaN,message:"Infeasible",iterations:5} |
| 183 PASS: numeric.solveLP([1,1],[[1,0],[0,1]],[0,0]).message; ==> "Unbounded" |
| 184 PASS: numeric.solveLP([1,2,3], /* minimize [1,2,3]*x */ [[-1,0,0],[0,-1,0],[0,0,-1]], /* matrix A of inequality constraint */ [0,0,0], /* RHS b of inequality constraint */ [[1,1,1]], /* matrix Aeq of equality constraint */ [3] /* vector beq of equality constraint */ ); ==> {solution:[3,1.685e-16,4.559e-19],message:"",iterations:12} |
| 185 PASS: n = 7; m = 3; for(k=0;k<10;++k) { A = numeric.random([n,n]); x = numeric.rep([m],1).concat(numeric.rep([n-m],0)); b = numeric.dot(A,x); J = numeric.diag(numeric.rep([n],-1)); B = numeric.blockMatrix([[A , J ], [numeric.neg(A) , J ], [numeric.rep([n,n],0), J ]]); c = b.concat(numeric.neg(b)).concat(numeric.rep([n],0)); d = numeric.rep([n],0).concat(numeric.rep([n],1)); y = numeric.solveLP(d,B,c).solution; y.length = n; foo = numeric.norm2(numeric.sub(x,y)); if(foo>1e-10) throw new Error("solveLP test fails: "+numeric.prettyPrint({A:A,x:x})); } "solveLP tests pass" ==> "solveLPtestspass" |
| 186 PASS: numeric.solveLP([1,2,3], /* minimize [1,2,3]*x */ [[1, 0, 0], [0, 1, 0], [0, 0, 1],[-1,0,0],[0,-1,0],[0,0,-1]], /* matrix A of inequality constraint */ [1,1,1,0,0,0], /* RHS b of inequality constraint */ [[1,1,1]], /* matrix Aeq of equality constraint */ [3] /* vector beq of equality constraint */ ); ==> {solution:NaN,message:"Infeasible",iterations:10} |
| 187 PASS: sol = numeric.dopri(0,1,1,function(t,y) { return y; }) ==> {x:[0,0.1,0.1522,0.361,0.5792,0.7843,0.9813,1],y:[1,1.105,1.164,1.435,1.785,2.191,2.668,2.718],f:[1,1.105,1.164,1.435,1.785,2.191,2.668,2.718],ymid:[1.051,1.134,1.293,1.6,1.977,2.418,2.693],iterations:8,events:,message:""} |
| 188 PASS: sol.at([0.3,0.7]) ==> [1.35,2.014] |
| 189 PASS: sol = numeric.dopri(0,10,[3,0],function (x,y) { return [y[1],-y[0]]; }); sol.at([0,0.5*Math.PI,Math.PI,1.5*Math.PI,2*Math.PI]) ==> [[3,0],[-9.534e-8,-3],[-3,2.768e-7],[3.63e-7,3],[3,-3.065e-7]] |
| 190 PASS: numeric.dopri(0,20,[2,0],function(t,y) { return [y[1], (1-y[0]*y[0])*y[1]-y[0]]; }).at([18,19,20]) ==> [[-1.208,0.9916],[0.4258,2.535],[2.008,-0.04251]] |
| 191 PASS: sol = numeric.dopri(0,2,1,function (x,y) { return y; },1e-8,100,function (x,y) { return y-1.3; }); ==> {x:[0,0.0181,0.09051,0.1822,0.2624],y:[1,1.018,1.095,1.2,1.3],f:[1,1.018,1.095,1.2,1.3],ymid:[1.009,1.056,1.146,1.249],iterations:5,events:true,message:""} |
| 192 PASS: sol = numeric.dopri(0,2,1, function(x,y) { return y; }, undefined,50, function(x,y) { return [y-1.5,Math.sin(y-1.5)]; }); ==> {x:[0,0.2,0.4055],y:[1,1.221,1.5],f:[1,1.221,1.5],ymid:[1.105,1.354],iterations:2,events:[true,true],message:""} |
| 193 PASS: D = numeric.identity(8); d = numeric.rep([8],0); A = [[1, 1, -1, 0, 0, 0, 0, 0, 0, 0],[-1, 1, 0, 1, 0, 0, 0, 0, 0, 0],[1, 1, 0, 0, -1, 0, 0, 0, 0, 0],[-1, 1, 0, 0, 0, 1, 0, 0, 0, 0],[1, 1, 0, 0, 0, 0, -1, 0, 0, 0],[-1, 1, 0, 0, 0, 0, 0, 1, 0, 0],[1, 1, 0, 0, 0, 0, 0, 0, -1, 0],[-1, 1, 0, 0, 0, 0, 0, 0, 0, 1]]; b = [1, 1, -1, 0, -1, 0, -1, 0, -1, 0]; numeric.solveQP(D,d,A,b,undefined,2) ==> {solution:[0.25,0,0.25,0,0.25,0,0.25,0],value:[0.125],unconstrained_solution:[0,0,0,0,0,0,0,0],iterations:[3,0],iact:[1,2,0,0,0,0,0,0,0,0],message:""} |
| 194 PASS: numeric.imageURL(numeric.rep([3],[[1,2],[3,4]])); ==> "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAIAAAD91JpzAAAAH0lEQVQIHQAIAPf/AAEBAQICAgABBwD4/wMDAwQEBAAAogAfhs2H3QAAAABJRU5ErkJggg==" |
| 195 PASS: numeric.gradient(function(x) { return Math.exp(Math.sin(x[0])*(x[1]+2)); },[1,2]); ==> [62.59,24.37] |
| 196 PASS: numeric.seedrandom.seedrandom(3); numeric.seedrandom.random() ==> 0.7569 |
| 197 PASS: numeric.seedrandom.random() ==> 0.6139 |
| 198 PASS: numeric.seedrandom.seedrandom(3); numeric.seedrandom.random() ==> 0.7569 |
| Firefox testing complete. PASS: 199 FAIL: 0 Total: 199
|
|
Windows unit tests 2012-12-21_00-30-00
|
|
Fetching http://numericjs.com/staging/documentation.html
In-browser unit tests.
Using Ie |
| 0 PASS: numeric.seedrandom.seedrandom('1'); Math.random = numeric.seedrandom.random; Math.random(); ==> 0.2694 |
| 1 PASS: A = [[1,2,3],[4,5,6]]; ==> [[1,2,3],[4,5,6]] |
| 2 PASS: x = [7,8,9] ==> [7,8,9] |
| 3 PASS: numeric.dot(A,x); ==> [50,122] |
| 4 PASS: x = [7,8,9]; y = [10,1,2]; numeric['+'](x,y) ==> [17,9,11] |
| 5 PASS: numeric['>'](x,y) ==> [false,true,true] |
| 6 PASS: numeric.add([7,8,9],[10,1,2]) ==> [17,9,11] |
| 7 PASS: numeric.add([1,2],[3,4],[5,6],[7,8]) ==> [16,20] |
| 8 PASS: A = [[1,2,3],[4,5,6],[7,1,9]] ==> [[1,2,3],[4,5,6],[7,1,9]] |
| 9 PASS: Ainv = numeric.inv(A); ==> [[-0.9286,0.3571,0.07143],[-0.1429,0.2857,-0.1429],[0.7381,-0.3095,0.07143]] |
| 10 PASS: numeric.precision = 10; x = 3.141592653589793 ==> 3.141592654 |
| 11 PASS: numeric.precision = 4; x ==> 3.142 |
| 12 PASS: numeric.identity(100) ==> ...LargeArray... |
| 13 PASS: numeric.largeArray = 2; A = numeric.identity(4) ==> ...LargeArray... |
| 14 PASS: numeric.largeArray = 50; A ==> [[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]] |
| 15 PASS: numeric.exp([1,2]); ==> [2.718,7.389] |
| 16 PASS: numeric.exp([[1,2],[3,4]]) ==> [[2.718,7.389],[20.09,54.6]] |
| 17 PASS: numeric.abs([-2,3]) ==> [2,3] |
| 18 PASS: numeric.acos([0.1,0.2]) ==> [1.471,1.369] |
| 19 PASS: numeric.asin([0.1,0.2]) ==> [0.1002,0.2014] |
| 20 PASS: numeric.atan([1,2]) ==> [0.7854,1.107] |
| 21 PASS: numeric.atan2([1,2],[3,4]) ==> [0.3218,0.4636] |
| 22 PASS: numeric.ceil([-2.2,3.3]) ==> [-2,4] |
| 23 PASS: numeric.floor([-2.2,3.3]) ==> [-3,3] |
| 24 PASS: numeric.log([1,2]) ==> [0,0.6931] |
| 25 PASS: numeric.pow([2,3],[0.25,7.1]) ==> [1.189,2441] |
| 26 PASS: numeric.round([-2.2,3.3]) ==> [-2,3] |
| 27 PASS: numeric.sin([1,2]) ==> [0.8415,0.9093] |
| 28 PASS: numeric.sqrt([1,2]) ==> [1,1.414] |
| 29 PASS: numeric.tan([1,2]) ==> [1.557,-2.185] |
| 30 PASS: numeric.dim([1,2]) ==> [2] |
| 31 PASS: numeric.dim([[1,2,3],[4,5,6]]) ==> [2,3] |
| 32 PASS: numeric.same([1,2],[1,2]) ==> true |
| 33 PASS: numeric.same([1,2],[1,2,3]) ==> false |
| 34 PASS: numeric.same([1,2],[[1],[2]]) ==> false |
| 35 PASS: numeric.same([[1,2],[3,4]],[[1,2],[3,4]]) ==> true |
| 36 PASS: numeric.same([[1,2],[3,4]],[[1,2],[3,5]]) ==> false |
| 37 PASS: numeric.same([[1,2],[2,4]],[[1,2],[3,4]]) ==> false |
| 38 PASS: numeric.rep([3],5) ==> [5,5,5] |
| 39 PASS: numeric.rep([2,3],0) ==> [[0,0,0],[0,0,0]] |
| 40 PASS: sum = numeric.mapreduce('accum += xi','0'); sum([1,2,3]) ==> 6 |
| 41 PASS: sum([[1,2,3],[4,5,6]]) ==> 21 |
| 42 PASS: numeric.any([false,true]) ==> true |
| 43 PASS: numeric.any([[0,0,3.14],[0,false,0]]) ==> true |
| 44 PASS: numeric.any([0,0,false]) ==> false |
| 45 PASS: numeric.all([false,true]) ==> false |
| 46 PASS: numeric.all([[1,4,3.14],["no",true,-1]]) ==> true |
| 47 PASS: numeric.all([0,0,false]) ==> false |
| 48 PASS: numeric.diag([1,2,3]) ==> [[1,0,0],[0,2,0],[0,0,3]] |
| 49 PASS: numeric.identity(3) ==> [[1,0,0],[0,1,0],[0,0,1]] |
| 50 PASS: numeric.linspace(1,5); ==> [1,2,3,4,5] |
| 51 PASS: numeric.linspace(1,3,5); ==> [1,1.5,2,2.5,3] |
| 52 PASS: numeric.blockMatrix([[[[1,2],[3,4]],[[5,6],[7,8]]], [[[11,12],[13,14]],[[15,16],[17,18]]]]) ==> [[1,2,5,6],[3,4,7,8],[11,12,15,16],[13,14,17,18]] |
| 53 PASS: numeric.addVV([1,2],[3,4]) ==> [4,6] |
| 54 PASS: numeric.addVS([1,2],3) ==> [4,5] |
| 55 PASS: numeric.add(1,[2,3]) ==> [3,4] |
| 56 PASS: numeric.add([1,2,3],[4,5,6]) ==> [5,7,9] |
| 57 PASS: numeric.sub([1,2],[3,4]) ==> [-2,-2] |
| 58 PASS: numeric.mul([1,2],[3,4]) ==> [3,8] |
| 59 PASS: numeric.div([1,2],[3,4]) ==> [0.3333,0.5] |
| 60 PASS: v = [1,2,3,4]; numeric.addeq(v,3); v ==> [4,5,6,7] |
| 61 PASS: numeric.subeq([1,2,3],[5,3,1]) ==> [-4,-1,2] |
| 62 PASS: numeric.neg([1,-2,3]) ==> [-1,2,-3] |
| 63 PASS: numeric.isFinite([10,NaN,Infinity]) ==> [true,false,false] |
| 64 PASS: numeric.isNaN([10,NaN,Infinity]) ==> [false,true,false] |
| 65 PASS: n = 41; A = numeric.random([n,n]); numeric.norm2(numeric.sub(numeric.dotMMsmall(numeric.inv(A),A),numeric.identity(n)))<1e-12 ==> true |
| 66 PASS: n = 42; A = numeric.random([n,n]); numeric.norm2(numeric.sub(numeric.dotMMsmall(numeric.inv(A),A),numeric.identity(n)))<1e-12 ==> true |
| 67 PASS: n = 43; A = numeric.random([n,n]); numeric.norm2(numeric.sub(numeric.dotMMsmall(numeric.inv(A),A),numeric.identity(n)))<1e-12 ==> true |
| 68 PASS: n = 44; A = numeric.random([n,n]); numeric.norm2(numeric.sub(numeric.dotMMbig(numeric.inv(A),A),numeric.identity(n)))<1e-12 ==> true |
| 69 PASS: n = 45; A = numeric.random([n,n]); numeric.norm2(numeric.sub(numeric.dotMMbig(numeric.inv(A),A),numeric.identity(n)))<1e-12 ==> true |
| 70 PASS: n = 46; A = numeric.random([n,n]); numeric.norm2(numeric.sub(numeric.dotMMbig(numeric.inv(A),A),numeric.identity(n)))<1e-12 ==> true |
| 71 PASS: numeric.dotVV([1,2],[3,4]) ==> 11 |
| 72 PASS: numeric.dotVM([1,2],[[3,4],[5,6]]) ==> [13,16] |
| 73 PASS: numeric.dotMV([[1,2],[3,4]],[5,6]) ==> [17,39] |
| 74 PASS: numeric.dotMMbig([[1,2],[3,4]],[[5,6],[7,8]]) ==> [[19,22],[43,50]] |
| 75 PASS: numeric.dotMMsmall([[1,2],[3,4]],[[5,6],[7,8]]) ==> [[19,22],[43,50]] |
| 76 PASS: numeric.dot([1,2,3,4,5,6,7,8,9],[1,2,3,4,5,6,7,8,9]) ==> 285 |
| 77 PASS: numeric.dot([1,2,3],[4,5,6]) ==> 32 |
| 78 PASS: numeric.dot([[1,2,3],[4,5,6]],[7,8,9]) ==> [50,122] |
| 79 PASS: numeric.solve([[1,2],[3,4]],[17,39]) ==> [5,6] |
| 80 PASS: LU = numeric.LU([[1,2],[3,4]]) ==> {LU:[[3,4],[0.3333,0.6667]],P:[1,1]} |
| 81 PASS: numeric.LUsolve(LU,[17,39]) ==> [5,6] |
| 82 PASS: ns = [5,6,10,16,25,40,41]; for(j=0;j "numeric.solveStressTestOK" |
| 83 PASS: numeric.det([[1,2],[3,4]]); ==> -2 |
| 84 PASS: numeric.det([[6,8,4,2,8,5],[3,5,2,4,9,2],[7,6,8,3,4,5],[5,5,2,8,1,6],[3,2,2,4,2,2],[8,3,2,2,4,1]]); ==> -1404 |
| 85 PASS: numeric.inv([[1,2],[3,4]]) ==> [[-2,1],[1.5,-0.5]] |
| 86 PASS: numeric.transpose([[1,2,3],[4,5,6]]) ==> [[1,4],[2,5],[3,6]] |
| 87 PASS: numeric.transpose([[1,2,3,4,5,6,7,8,9,10,11,12]]) ==> [[1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12]] |
| 88 PASS: numeric.norm2([1,2]) ==> 2.236 |
| 89 PASS: numeric.tensor([1,2],[3,4,5]) ==> [[3,4,5],[6,8,10]] |
| 90 PASS: numeric.parseDate(['1/13/2013','2001-5-9, 9:31']); ==> [1.358e12,9.894e11] |
| 91 PASS: numeric.parseFloat(['12','0.1']) ==> [12,0.1] |
| 92 PASS: numeric.parseCSV('a,b,c\n1,2.3,.3\n4e6,-5.3e-8,6.28e+4') ==> [["a","b","c"],[1,2.3,0.3],[4e6,-5.3e-8,62800]] |
| 93 PASS: numeric.toCSV([[1.23456789123,2],[3,4]]) ==> "1.23456789123,23,4" |
| 94 PASS: numeric.getURL('tools/helloworld.txt').responseText ==> "Hello,world!" |
| 95 PASS: z = new numeric.T(3,4); ==> {x:3,y:4} |
| 96 PASS: z.add(5) ==> {x:8,y:4} |
| 97 PASS: w = new numeric.T(2,8); ==> {x:2,y:8} |
| 98 PASS: z.add(w) ==> {x:5,y:12} |
| 99 PASS: z.mul(w) ==> {x:-26,y:32} |
| 100 PASS: z.div(w) ==> {x:0.5588,y:-0.2353} |
| 101 PASS: z.sub(w) ==> {x:1,y:-4} |
| 102 PASS: z = new numeric.T([1,2],[3,4]); ==> {x:[1,2],y:[3,4]} |
| 103 PASS: z.abs() ==> {x:[3.162,4.472],y:} |
| 104 PASS: z.conj() ==> {x:[1,2],y:[-3,-4]} |
| 105 PASS: z.norm2() ==> 5.477 |
| 106 PASS: z.exp() ==> {x:[-2.691,-4.83],y:[0.3836,-5.592]} |
| 107 PASS: z.cos() ==> {x:[-1.528,-2.459],y:[0.1658,-2.745]} |
| 108 PASS: z.sin() ==> {x:[0.2178,-2.847],y:[1.163,2.371]} |
| 109 PASS: z.log() ==> {x:[1.151,1.498],y:[1.249,1.107]} |
| 110 PASS: A = new numeric.T([[1,2],[3,4]],[[0,1],[2,-1]]); ==> {x:[[1,2],[3,4]],y:[[0,1],[2,-1]]} |
| 111 PASS: A.inv(); ==> {x:[[0.125,0.125],[0.25,0]],y:[[0.5,-0.25],[-0.375,0.125]]} |
| 112 PASS: A.inv().dot(A) ==> {x:[[1,0],[0,1]],y:[[0,-2.776e-17],[0,0]]} |
| 113 PASS: A.get([1,1]) ==> {x:4,y:-1} |
| 114 PASS: A.transpose() ==> {x:[[1,3],[2,4]],y:[[0,2],[1,-1]]} |
| 115 PASS: A.transjugate() ==> {x:[[1,3],[2,4]],y:[[0,-2],[-1,1]]} |
| 116 PASS: numeric.T.rep([2,2],new numeric.T(2,3)); ==> {x:[[2,2],[2,2]],y:[[3,3],[3,3]]} |
| 117 PASS: A = [[1,2,5],[3,5,-1],[7,-3,5]]; ==> [[1,2,5],[3,5,-1],[7,-3,5]] |
| 118 PASS: B = numeric.eig(A); ==> {lambda:{x:[-4.284,9.027,6.257],y:},E:{x:[[0.7131,-0.5543,0.4019],[-0.2987,-0.2131,0.9139],[-0.6342,-0.8046,0.057]],y:}} |
| 119 PASS: C = B.E.dot(numeric.T.diag(B.lambda)).dot(B.E.inv()); ==> {x:[[1,2,5],[3,5,-1],[7,-3,5]],y:} |
| 120 PASS: A=[[ 22, 10, 2, 3, 7], [ 14, 7, 10, 0, 8], [ -1, 13, -1,-11, 3], [ -3, -2, 13, -2, 4], [ 9, 8, 1, -2, 4], [ 9, 1, -7, 5, -1], [ 2, -6, 6, 5, 1], [ 4, 5, 0, -2, 2]]; numeric.svd(A); ==> {U:[[-0.7071,-0.1581,0.1768,0.2494,0.4625],[-0.5303,-0.1581,-0.3536,0.1556,-0.4984],[-0.1768,0.7906,-0.1768,-0.1546,0.3967],[-1.506e-17,-0.1581,-0.7071,-0.3277,0.1],[-0.3536,0.1581,1.954e-15,-0.07265,-0.2084],[-0.1768,-0.1581,0.5303,-0.5726,-0.05555],[-7.109e-18,-0.4743,-0.1768,-0.3142,0.4959],[-0.1768,0.1581,1.915e-15,-0.592,-0.2791]],S:[35.33,20,19.6,0,0],V:[[-0.8006,-0.3162,0.2887,-0.4191,0],[-0.4804,0.6325,7.768e-15,0.4405,0.4185],[-0.1601,-0.3162,-0.866,-0.052,0.3488],[4.684e-17,-0.6325,0.2887,0.6761,0.2442],[-0.3203,3.594e-15,-0.2887,0.413,-0.8022]]} |
| 121 PASS: n = 31; A = numeric.random([n,n]); B = numeric.eig(A); !(B.E.dot(numeric.T.diag(B.lambda).dot(B.E.inv())).sub(A).norm2()>1e-12) ==> true |
| 122 PASS: n = 32; A = numeric.random([n,n]); B = numeric.eig(A); !(B.E.dot(numeric.T.diag(B.lambda).dot(B.E.inv())).sub(A).norm2()>1e-12) ==> true |
| 123 PASS: n = 33; A = numeric.random([n,n]); B = numeric.eig(A); !(B.E.dot(numeric.T.diag(B.lambda).dot(B.E.inv())).sub(A).norm2()>1e-12) ==> true |
| 124 PASS: n = 34; A = numeric.random([n,n]); B = numeric.eig(A); !(B.E.dot(numeric.T.diag(B.lambda).dot(B.E.inv())).sub(A).norm2()>1e-12) ==> true |
| 125 PASS: n = 35; A = numeric.random([n,n]); B = numeric.eig(A); !(B.E.dot(numeric.T.diag(B.lambda).dot(B.E.inv())).sub(A).norm2()>1e-12) ==> true |
| 126 PASS: m = 17; n = 12; A = numeric.random([m,n]); B = numeric.svd(A); U = new numeric.T(B.U); V = new numeric.T(B.V); !(U.dot(numeric.T.diag(B.S)).dot(V.transpose()).sub(A).norm2()>1e-12) ==> true |
| 127 PASS: m = 21; n = 19; A = numeric.random([m,n]); B = numeric.svd(A); U = new numeric.T(B.U); V = new numeric.T(B.V); !(U.dot(numeric.T.diag(B.S)).dot(V.transpose()).sub(A).norm2()>1e-12) ==> true |
| 128 PASS: m = 33; n = 33; A = numeric.random([m,n]); B = numeric.svd(A); U = new numeric.T(B.U); V = new numeric.T(B.V); !(U.dot(numeric.T.diag(B.S)).dot(V.transpose()).sub(A).norm2()>1e-12) ==> true |
| 129 PASS: m = 59; n = 42; A = numeric.random([m,n]); B = numeric.svd(A); U = new numeric.T(B.U); V = new numeric.T(B.V); !(U.dot(numeric.T.diag(B.S)).dot(V.transpose()).sub(A).norm2()>1e-12) ==> true |
| 130 PASS: numeric.eig([[1, 0, 0], [0, 0.7181, -0.6960], [0, 0.6960, 0.7181]]) // This was a bug found by bdmartin ==> {lambda:{x:[1,0.7181,0.7181],y:[0,0.696,-0.696]},E:{x:[[1,0,0],[0,0,0.7071],[0,-0.7071,0]],y:[[0,0,0],[0,-0.7071,0],[0,0,0.7071]]}} |
| 131 PASS: A = [[1,2,0], [0,3,0], [2,0,5]]; SA = numeric.ccsSparse(A); ==> [[0,2,4,5],[0,2,0,1,2],[1,2,2,3,5]] |
| 132 PASS: A = numeric.ccsSparse([[ 3, 5, 8,10, 8], [ 7,10, 3, 5, 3], [ 6, 3, 5, 1, 8], [ 2, 6, 7, 1, 2], [ 1, 2, 9, 3, 9]]); ==> [[0,5,10,15,20,25],[0,1,2,3,4,0,1,2,3,4,0,1,2,3,4,0,1,2,3,4,0,1,2,3,4],[3,7,6,2,1,5,10,3,6,2,8,3,5,7,9,10,5,1,1,3,8,3,8,2,9]] |
| 133 PASS: numeric.ccsFull(A); ==> [[3,5,8,10,8],[7,10,3,5,3],[6,3,5,1,8],[2,6,7,1,2],[1,2,9,3,9]] |
| 134 PASS: numeric.ccsDot(numeric.ccsSparse([[1,2,3],[4,5,6]]),numeric.ccsSparse([[7,8],[9,10],[11,12]])) ==> [[0,2,4],[0,1,0,1],[58,139,64,154]] |
| 135 PASS: M = [[0,1,3,6],[0,0,1,0,1,2],[3,-1,2,3,-2,4]]; b = [9,3,2]; x = numeric.ccsTSolve(M,b); ==> [3.167,2,0.5] |
| 136 PASS: numeric.ccsDot(M,[[0,3],[0,1,2],x]) ==> [[0,3],[0,1,2],[9,3,2]] |
| 137 PASS: A = [[0,5,10,15,20,25], [0,1,2,3,4,0,1,2,3,4,0,1,2,3,4,0,1,2,3,4,0,1,2,3,4], [3,7,6,2,1,5,10,3,6,2,8,3,5,7,9,10,5,1,1,3,8,3,8,2,9]]; LUP = numeric.ccsLUP(A); ==> {L:[[0,5,9,12,14,15],[0,2,4,1,3,1,3,4,2,2,4,3,3,4,4],[1,0.1429,0.2857,0.8571,0.4286,1,-0.1282,-0.5641,-0.1026,1,0.8517,0.7965,1,-0.67,1]],U:[[0,1,3,6,10,15],[0,0,1,0,1,2,0,1,2,3,0,1,2,3,4],[7,10,-5.571,3,2.429,8.821,5,-3.286,1.949,5.884,3,5.429,9.128,0.1395,-3.476]],P:[1,2,4,0,3],Pinv:[3,0,1,4,2]} |
| 138 PASS: numeric.ccsFull(numeric.ccsDot(LUP.L,LUP.U)) ==> [[7,10,3,5,3],[6,3,5,1,8],[1,2,9,3,9],[3,5,8,10,8],[2,6,7,1,2]] |
| 139 PASS: x = numeric.ccsLUPSolve(LUP,[96,63,82,51,89]) ==> [3,1,4,1,5] |
| 140 PASS: X = numeric.trunc(numeric.ccsFull(numeric.ccsLUPSolve(LUP,A)),1e-15); // Solve LUX = PA ==> [[1,0,0,0,0],[0,1,0,0,0],[0,0,1,0,0],[0,0,0,1,0],[0,0,0,0,1]] |
| 141 PASS: numeric.ccsLUP(A,0.4).P; ==> [0,2,1,3,4] |
| 142 PASS: result = "Sparse LUP Stress Test OK"; for(k=0;k<1000;++k) { A = numeric.ccsSparse(numeric.random([10,10])); LUP = numeric.ccsLUP(A); foo = numeric.ccsFull(numeric.ccsDot(LUP.L,LUP.U)); PA = numeric.ccsFull(numeric.ccsGetBlock(A,LUP.P)); res = numeric.norminf(numeric.sub(foo,PA)); if(!isFinite(res) || res>1e-6) { result = { code: "Failed during 1000 sparse LUP", k:k,A:A,LUP:LUP,res:res }; break; }; }; result; ==> "SparseLUPStressTestOK" |
| 143 PASS: A = numeric.ccsSparse([[1,2,0],[0,3,0],[0,0,5]]); B = numeric.ccsSparse([[2,9,0],[0,4,0],[-2,0,0]]); numeric.ccsadd(A,B); ==> [[0,2,4,5],[0,2,0,1,2],[3,-2,11,7,5]] |
| 144 PASS: X = [[0,0,1,1,2,2],[0,1,1,2,2,3],[1,2,3,4,5,6]]; SX = numeric.ccsScatter(X); ==> [[0,1,3,5,6],[0,0,1,1,2,2],[1,2,3,4,5,6]] |
| 145 PASS: numeric.ccsGather(SX) ==> [[0,0,1,1,2,2],[0,1,1,2,2,3],[1,2,3,4,5,6]] |
| 146 PASS: lu = numeric.cLU([[0,0,1,1,1,2,2],[0,1,0,1,2,1,2],[2,-1,-1,2,-1,-1,2]]) ==> {U:[[0,0,1,1,2],[0,1,1,2,2],[2,-1,1.5,-1,1.333]],L:[[0,1,1,2,2],[0,0,1,1,2],[1,-0.5,1,-0.6667,1]]} |
| 147 PASS: numeric.cLUsolve(lu,[5,-8,13]) ==> [3,1,7] |
| 148 PASS: g = numeric.cgrid(5) ==> [[-1,-1,-1,-1,-1],[-1,0,1,2,-1],[-1,3,4,5,-1],[-1,6,7,8,-1],[-1,-1,-1,-1,-1]] |
| 149 PASS: coordL = numeric.cdelsq(g) ==> [[0,0,0,1,1,1,1,2,2,2,3,3,3,3,4,4,4,4,4,5,5,5,5,6,6,6,7,7,7,7,8,8,8],[1,3,0,0,2,4,1,1,5,2,0,4,6,3,1,3,5,7,4,2,4,8,5,3,7,6,4,6,8,7,5,7,8],[-1,-1,4,-1,-1,-1,4,-1,-1,4,-1,-1,-1,4,-1,-1,-1,-1,4,-1,-1,-1,4,-1,-1,4,-1,-1,-1,4,-1,-1,4]] |
| 150 PASS: L = numeric.sscatter(coordL); // Just to see what it looks like ==> [[4,-1,,-1],[-1,4,-1,,-1],[,-1,4,,,-1],[-1,,,4,-1,,-1],[,-1,,-1,4,-1,,-1],[,,-1,,-1,4,,,-1],[,,,-1,,,4,-1],[,,,,-1,,-1,4,-1],[,,,,,-1,,-1,4]] |
| 151 PASS: lu = numeric.cLU(coordL); x = numeric.cLUsolve(lu,[1,1,1,1,1,1,1,1,1]); ==> [0.6875,0.875,0.6875,0.875,1.125,0.875,0.6875,0.875,0.6875] |
| 152 PASS: numeric.cdotMV(coordL,x) ==> [1,1,1,1,1,1,1,1,1] |
| 153 PASS: G = numeric.rep([5,5],0); for(i=0;i<5;i++) for(j=0;j<5;j++) if(g[i][j]>=0) G[i][j] = x[g[i][j]]; G ==> [[0,0,0,0,0],[0,0.6875,0.875,0.6875,0],[0,0.875,1.125,0.875,0],[0,0.6875,0.875,0.6875,0],[0,0,0,0,0]] |
| 154 PASS: workshop.html('<img src="'+numeric.imageURL(numeric.mul([G,G,G],200))+'" width=100 />'); ==> |
| 155 PASS: numeric.cgrid(6,'L') ==> [[-1,-1,-1,-1,-1,-1],[-1,0,1,-1,-1,-1],[-1,2,3,-1,-1,-1],[-1,4,5,6,7,-1],[-1,8,9,10,11,-1],[-1,-1,-1,-1,-1,-1]] |
| 156 PASS: numeric.cgrid(5,function(i,j) { return i!==2 || j!==2; }) ==> [[-1,-1,-1,-1,-1],[-1,0,1,2,-1],[-1,3,-1,4,-1],[-1,5,6,7,-1],[-1,-1,-1,-1,-1]] |
| 157 PASS: numeric.spline([1,2,3,4,5],[1,2,1,3,2]).at(numeric.linspace(1,5,10)) ==> [1,1.731,2.039,1.604,1.019,1.294,2.364,3.085,2.82,2] |
| 158 PASS: numeric.spline([1,2,3,4,5],[1,2,1,3,2],0,0).at(numeric.linspace(1,5,10)) ==> [1,1.435,1.98,1.669,1.034,1.316,2.442,3.017,2.482,2] |
| 159 PASS: numeric.spline([1,2,3,4],[0.8415,0.04718,-0.8887,0.8415],'periodic').at(numeric.linspace(1,4,10)) ==> [0.8415,0.9024,0.5788,0.04718,-0.5106,-0.8919,-0.8887,-0.3918,0.3131,0.8415] |
| 160 PASS: numeric.spline([1,2,3],[[0,1],[1,0],[0,1]]).at(1.78) ==> [0.9327,0.06728] |
| 161 PASS: xs = [0,1,2,3]; numeric.spline(xs,numeric.sin(xs)).diff().at(1.5) ==> 0.07302 |
| 162 PASS: xs = numeric.linspace(0,30,31); ys = numeric.sin(xs); s = numeric.spline(xs,ys).roots(); ==> [0,3.142,6.284,9.425,12.57,15.71,18.85,21.99,25.13,28.27] |
| 163 PASS: z = (new numeric.T([1,2,3,4,5],[6,7,8,9,10])).fft() ==> {x:[15,-5.941,-3.312,-1.688,0.941],y:[40,0.941,-1.688,-3.312,-5.941]} |
| 164 PASS: z.ifft() ==> {x:[1,2,3,4,5],y:[6,7,8,9,10]} |
| 165 PASS: numeric.solveQP([[1,0,0],[0,1,0],[0,0,1]],[0,5,0],[[-4,2,0],[-3,1,-2],[0,0,1]],[-8,2,0]); ==> {solution:[0.4762,1.048,2.095],value:[-2.381],unconstrained_solution:[0,5,0],iterations:[3,0],iact:[3,2,0],message:""} |
| 166 PASS: sqr = function(x) { return x*x; }; numeric.uncmin(function(x) { return sqr(10*(x[1]-x[0]*x[0])) + sqr(1-x[0]); },[-1.2,1]).solution ==> [1,1] |
| 167 PASS: f = function(x) { return sqr(-13+x[0]+((5-x[1])*x[1]-2)*x[1])+sqr(-29+x[0]+((x[1]+1)*x[1]-14)*x[1]); }; x0 = numeric.uncmin(f,[0.5,-2]).solution ==> [11.41,-0.8968] |
| 168 PASS: f = function(x) { return sqr(1e4*x[0]*x[1]-1)+sqr(Math.exp(-x[0])+Math.exp(-x[1])-1.0001); }; x0 = numeric.uncmin(f,[0,1]).solution ==> [1.098e-5,9.106] |
| 169 PASS: f = function(x) { return sqr(x[0]-1e6)+sqr(x[1]-2e-6)+sqr(x[0]*x[1]-2)}; x0 = numeric.uncmin(f,[0,1]).solution ==> [1e6,2e-6] |
| 170 PASS: f = function(x) { return sqr(1.5-x[0]*(1-x[1]))+sqr(2.25-x[0]*(1-x[1]*x[1]))+sqr(2.625-x[0]*(1-x[1]*x[1]*x[1])); }; x0 = numeric.uncmin(f,[1,1]).solution ==> [3,0.5] |
| 171 PASS: f = function(x) { var ret = 0,i; for(i=1;i<=10;i++) ret+=sqr(2+2*i-Math.exp(i*x[0])-Math.exp(i*x[1])); return ret; }; x0 = numeric.uncmin(f,[0.3,0.4]).solution ==> [0.2578,0.2578] |
| 172 PASS: y = [0.14,0.18,0.22,0.25,0.29,0.32,0.35,0.39,0.37,0.58,0.73,0.96,1.34,2.10,4.39]; f = function(x) { var ret = 0,i; for(i=1;i<=15;i++) ret+=sqr(y[i-1]-(x[0]+i/((16-i)*x[1]+Math.min(i,16-i)*x[2]))); return ret; }; x0 = numeric.uncmin(f,[1,1,1]).solution ==> [0.08241,1.133,2.344] |
| 173 PASS: y = [0.0009,0.0044,0.0175,0.0540,0.1295,0.2420,0.3521,0.3989,0.3521,0.2420,0.1295,0.0540,0.0175,0.0044,0.0009]; f = function(x) { var ret = 0,i; for(i=1;i<=15;i++) ret+=sqr(x[0]*Math.exp(-x[1]*sqr((8-i)/2-x[2])/2)-y[i-1]); return ret; }; x0 = numeric.div(numeric.round(numeric.mul(numeric.uncmin(f,[1,1,1]).solution,1000)),1000) ==> [0.399,1,0] |
| 174 PASS: f = function(x) { return sqr(x[0]+10*x[1])+5*sqr(x[2]-x[3])+sqr(sqr(x[1]-2*x[2]))+10*sqr(x[0]-x[3]); }; x0 = numeric.div(numeric.round(numeric.mul(numeric.uncmin(f,[3,-1,0,1]).solution,1e5)),1e5) ==> [0,0,0,0] |
| 175 PASS: f = function(x) { return (sqr(10*(x[1]-x[0]*x[0]))+sqr(1-x[0])+ 90*sqr(x[3]-x[2]*x[2])+sqr(1-x[2])+ 10*sqr(x[1]+x[3]-2)+0.1*sqr(x[1]-x[3])); }; x0 = numeric.uncmin(f,[-3,-1,-3,-1]).solution ==> [1,1,1,1] |
| 176 PASS: y = [0.1957,0.1947,0.1735,0.1600,0.0844,0.0627,0.0456,0.0342,0.0323,0.0235,0.0246]; u = [4,2,1,0.5,0.25,0.167,0.125,0.1,0.0833,0.0714,0.0625]; f = function(x) { var ret=0, i; for(i=0;i<11;++i) ret += sqr(y[i]-x[0]*(u[i]*u[i]+u[i]*x[1])/(u[i]*u[i]+u[i]*x[2]+x[3])); return ret; }; x0 = numeric.uncmin(f,[0.25,0.39,0.415,0.39]).solution ==> [0.1928,0.1913,0.1231,0.1361] |
| 177 PASS: y = [0.844,0.908,0.932,0.936,0.925,0.908,0.881,0.850,0.818,0.784,0.751,0.718, 0.685,0.658,0.628,0.603,0.580,0.558,0.538,0.522,0.506,0.490,0.478,0.467, 0.457,0.448,0.438,0.431,0.424,0.420,0.414,0.411,0.406]; f = function(x) { var ret=0, i; for(i=0;i<33;++i) ret += sqr(y[i]-(x[0]+x[1]*Math.exp(-10*i*x[3])+x[2]*Math.exp(-10*i*x[4]))); return ret; }; x0 = numeric.uncmin(f,[0.5,1.5,-1,0.01,0.02]).solution ==> [0.3754,1.936,-1.465,0.01287,0.02212] |
| 178 PASS: f = function(x) { var ret=0, i,ti,yi,exp=Math.exp; for(i=1;i<=13;++i) { ti = 0.1*i; yi = exp(-ti)-5*exp(-10*ti)+3*exp(-4*ti); ret += sqr(x[2]*exp(-ti*x[0])-x[3]*exp(-ti*x[1])+x[5]*exp(-ti*x[4])-yi); } return ret; }; x0 = numeric.uncmin(f,[1,2,1,1,1,1],1e-14).solution; f(x0)<1e-20; ==> true |
| 179 PASS: z = []; cb = function(i,x,f,g,H) { z.push({i:i, x:x, f:f, g:g, H:H }); }; x0 = numeric.uncmin(function(x) { return Math.cos(2*x[0]); }, [1],1e-10, function(x) { return [-2*Math.sin(2*x[0])]; }, 100,cb); ==> {solution:[1.571],f:-1,gradient:[2.242e-11],invHessian:[[0.25]],iterations:6,message:"Newtonstepsmallerthantol"} |
| 180 PASS: z ==> [{i:0,x:[1],f:-0.4161,g:[-1.819],H:[[1]]},{i:2,x:[1.909],f:-0.7795,g:[1.253],H:[[0.296]]},{i:3,x:[1.538],f:-0.9979,g:[-0.1296],H:[[0.2683]]},{i:4,x:[1.573],f:-1,g:[9.392e-3],H:[[0.2502]]},{i:5,x:[1.571],f:-1,g:[-6.105e-6],H:[[0.25]]},{i:6,x:[1.571],f:-1,g:[2.242e-11],H:[[0.25]]}] |
| 181 PASS: x = numeric.solveLP([1,1], /* minimize [1,1]*x */ [[-1,0],[0,-1],[-1,-2]], /* matrix of inequalities */ [0,0,-3] /* right-hand-side of inequalities */ ); numeric.trunc(x.solution,1e-12); ==> [0,1.5] |
| 182 PASS: numeric.solveLP([1,1],[[1,0],[0,1],[-1,-1]],[-1,-1,-1]) ==> {solution:NaN,message:"Infeasible",iterations:5} |
| 183 PASS: numeric.solveLP([1,1],[[1,0],[0,1]],[0,0]).message; ==> "Unbounded" |
| 184 PASS: numeric.solveLP([1,2,3], /* minimize [1,2,3]*x */ [[-1,0,0],[0,-1,0],[0,0,-1]], /* matrix A of inequality constraint */ [0,0,0], /* RHS b of inequality constraint */ [[1,1,1]], /* matrix Aeq of equality constraint */ [3] /* vector beq of equality constraint */ ); ==> {solution:[3,1.685e-16,4.559e-19],message:"",iterations:12} |
| 185 PASS: n = 7; m = 3; for(k=0;k<10;++k) { A = numeric.random([n,n]); x = numeric.rep([m],1).concat(numeric.rep([n-m],0)); b = numeric.dot(A,x); J = numeric.diag(numeric.rep([n],-1)); B = numeric.blockMatrix([[A , J ], [numeric.neg(A) , J ], [numeric.rep([n,n],0), J ]]); c = b.concat(numeric.neg(b)).concat(numeric.rep([n],0)); d = numeric.rep([n],0).concat(numeric.rep([n],1)); y = numeric.solveLP(d,B,c).solution; y.length = n; foo = numeric.norm2(numeric.sub(x,y)); if(foo>1e-10) throw new Error("solveLP test fails: "+numeric.prettyPrint({A:A,x:x})); } "solveLP tests pass" ==> "solveLPtestspass" |
| 186 PASS: numeric.solveLP([1,2,3], /* minimize [1,2,3]*x */ [[1, 0, 0], [0, 1, 0], [0, 0, 1],[-1,0,0],[0,-1,0],[0,0,-1]], /* matrix A of inequality constraint */ [1,1,1,0,0,0], /* RHS b of inequality constraint */ [[1,1,1]], /* matrix Aeq of equality constraint */ [3] /* vector beq of equality constraint */ ); ==> {solution:NaN,message:"Infeasible",iterations:10} |
| 187 PASS: sol = numeric.dopri(0,1,1,function(t,y) { return y; }) ==> {x:[0,0.1,0.1522,0.361,0.5792,0.7843,0.9813,1],y:[1,1.105,1.164,1.435,1.785,2.191,2.668,2.718],f:[1,1.105,1.164,1.435,1.785,2.191,2.668,2.718],ymid:[1.051,1.134,1.293,1.6,1.977,2.418,2.693],iterations:8,events:,message:""} |
| 188 PASS: sol.at([0.3,0.7]) ==> [1.35,2.014] |
| 189 PASS: sol = numeric.dopri(0,10,[3,0],function (x,y) { return [y[1],-y[0]]; }); sol.at([0,0.5*Math.PI,Math.PI,1.5*Math.PI,2*Math.PI]) ==> [[3,0],[-9.534e-8,-3],[-3,2.768e-7],[3.63e-7,3],[3,-3.065e-7]] |
| 190 PASS: numeric.dopri(0,20,[2,0],function(t,y) { return [y[1], (1-y[0]*y[0])*y[1]-y[0]]; }).at([18,19,20]) ==> [[-1.208,0.9916],[0.4258,2.535],[2.008,-0.04251]] |
| 191 PASS: sol = numeric.dopri(0,2,1,function (x,y) { return y; },1e-8,100,function (x,y) { return y-1.3; }); ==> {x:[0,0.0181,0.09051,0.1822,0.2624],y:[1,1.018,1.095,1.2,1.3],f:[1,1.018,1.095,1.2,1.3],ymid:[1.009,1.056,1.146,1.249],iterations:5,events:true,message:""} |
| 192 PASS: sol = numeric.dopri(0,2,1, function(x,y) { return y; }, undefined,50, function(x,y) { return [y-1.5,Math.sin(y-1.5)]; }); ==> {x:[0,0.2,0.4055],y:[1,1.221,1.5],f:[1,1.221,1.5],ymid:[1.105,1.354],iterations:2,events:[true,true],message:""} |
| 193 PASS: D = numeric.identity(8); d = numeric.rep([8],0); A = [[1, 1, -1, 0, 0, 0, 0, 0, 0, 0],[-1, 1, 0, 1, 0, 0, 0, 0, 0, 0],[1, 1, 0, 0, -1, 0, 0, 0, 0, 0],[-1, 1, 0, 0, 0, 1, 0, 0, 0, 0],[1, 1, 0, 0, 0, 0, -1, 0, 0, 0],[-1, 1, 0, 0, 0, 0, 0, 1, 0, 0],[1, 1, 0, 0, 0, 0, 0, 0, -1, 0],[-1, 1, 0, 0, 0, 0, 0, 0, 0, 1]]; b = [1, 1, -1, 0, -1, 0, -1, 0, -1, 0]; numeric.solveQP(D,d,A,b,undefined,2) ==> {solution:[0.25,0,0.25,0,0.25,0,0.25,0],value:[0.125],unconstrained_solution:[0,0,0,0,0,0,0,0],iterations:[3,0],iact:[1,2,0,0,0,0,0,0,0,0],message:""} |
| 194 PASS: numeric.imageURL(numeric.rep([3],[[1,2],[3,4]])); ==> "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAIAAAD91JpzAAAAH0lEQVQIHQAIAPf/AAEBAQICAgABBwD4/wMDAwQEBAAAogAfhs2H3QAAAABJRU5ErkJggg==" |
| 195 PASS: numeric.gradient(function(x) { return Math.exp(Math.sin(x[0])*(x[1]+2)); },[1,2]); ==> [62.59,24.37] |
| 196 PASS: numeric.seedrandom.seedrandom(3); numeric.seedrandom.random() ==> 0.7569 |
| 197 PASS: numeric.seedrandom.random() ==> 0.6139 |
| 198 PASS: numeric.seedrandom.seedrandom(3); numeric.seedrandom.random() ==> 0.7569 |
| Ie testing complete. PASS: 199 FAIL: 0 Total: 199
|