158159160161162163164165166167168
assertEquals (9.0, binary2.dotProduct (s1), 0.0001); assertEquals (9.0, s1.dotProduct (binary2), 0.0001); IndexedSparseVector dblVec = (IndexedSparseVector) s1.cloneMatrix (); dblVec.plusEqualsSparse (binary1); checkAnswer (dblVec, new double[] { 2, 3, 4, 5, 6 }); IndexedSparseVector dblVec2 = (IndexedSparseVector) s1.cloneMatrix (); dblVec2.plusEqualsSparse (binary2); checkAnswer (dblVec2, new double[] { 2, 2, 4, 4, 6 });
162163164165166167168169170171172
IndexedSparseVector dblVec = (IndexedSparseVector) s1.cloneMatrix (); dblVec.plusEqualsSparse (binary1); checkAnswer (dblVec, new double[] { 2, 3, 4, 5, 6 }); IndexedSparseVector dblVec2 = (IndexedSparseVector) s1.cloneMatrix (); dblVec2.plusEqualsSparse (binary2); checkAnswer (dblVec2, new double[] { 2, 2, 4, 4, 6 }); } public void testCloneMatrixZeroed () {
5253545556575859606162
} public void testPlusEquals () { SparseVector s = (SparseVector) s1.cloneMatrix (); s.plusEqualsSparse (s2, 2.0); checkAnswer (s, new double[] { 3, 5, 7, 6, 7 }); SparseVector s2p = new SparseVector (new int[] { 13 }, new double[] { 0.8 });
7475767778798081828384
new double[] { 0.2, 0.8, 1.2 }); s.plusEqualsSparse (s4, 1.0); checkAnswer (s, new double[] { 3, 5, 7.2, 6.8, 8.2 }); SparseVector s5 = new SparseVector (new int[] { 7 }, new double[] { 0.2 }); s5.plusEqualsSparse (s1); for (int i = 0; i < s5.numLocations(); i++) { assertEquals (7, s5.indexAtLocation (i)); assertEquals (3.2, s5.valueAtLocation (i), 0.0); }
8182838485868788899091
assertEquals (7, s5.indexAtLocation (i)); assertEquals (3.2, s5.valueAtLocation (i), 0.0); } SparseVector s6 = new SparseVector (new int[] { 7 }, new double[] { 0.2 }); s6.plusEqualsSparse (s1, 3.5); for (int i = 0; i < s6.numLocations(); i++) { assertEquals (7, s6.indexAtLocation (i)); assertEquals (10.7, s6.valueAtLocation (i), 0.0); } }
136137138139140141142143144145146
SparseVector svDense = new SparseVector (null, dbl3); double sdot = svDense.dotProduct (svDense); double ddot = d1.dotProduct (d1); assertEquals (sdot, ddot, 0.0001); svDense.plusEqualsSparse (s1); checkAnswer (svDense, new double[] { 2.0, 2.5, 3.0, 5.7, 3.5, 5.6, 0, 3, 0, 0, 0, 0, 0, 4, 0, 5, });
142143144145146147148149150151152
checkAnswer (svDense, new double[] { 2.0, 2.5, 3.0, 5.7, 3.5, 5.6, 0, 3, 0, 0, 0, 0, 0, 4, 0, 5, }); svDense.plusEqualsSparse (s1, 2.0); checkAnswer (svDense, new double[] { 2.0, 2.5, 3.0, 7.7, 3.5, 9.6, 0, 9, 0, 0, 0, 0, 0, 12, 0, 15, });
177178179180181182183184185186187
assertEquals (9.0, binary2.dotProduct (s1), 0.0001); assertEquals (9.0, s1.dotProduct (binary2), 0.0001); SparseVector dblVec = (SparseVector) s1.cloneMatrix (); dblVec.plusEqualsSparse (binary1); checkAnswer (dblVec, new double[] { 2, 3, 4, 5, 6 }); SparseVector dblVec2 = (SparseVector) s1.cloneMatrix (); dblVec2.plusEqualsSparse (binary2); checkAnswer (dblVec2, new double[] { 2, 2, 4, 4, 6 });
181182183184185186187188189190191
SparseVector dblVec = (SparseVector) s1.cloneMatrix (); dblVec.plusEqualsSparse (binary1); checkAnswer (dblVec, new double[] { 2, 3, 4, 5, 6 }); SparseVector dblVec2 = (SparseVector) s1.cloneMatrix (); dblVec2.plusEqualsSparse (binary2); checkAnswer (dblVec2, new double[] { 2, 2, 4, 4, 6 }); } public void testCloneMatrixZeroed () {