public void handleContextVector(String primaryKey, String secondaryKey, SparseDoubleVector v) { assertEquals("foxes.n.123", secondaryKey); assertEquals("foxes", primaryKey); assertEquals(0, v.get(0), .001); assertEquals(1.0, v.get(1), .001); assertEquals(4.0, v.get(2), .001); assertEquals(4.5, v.get(3), .001); assertEquals(0, v.get(4), .001); assertEquals(2, v.get(5), .001); }
/** * Create a {@code CompactSparseVector} from an array, saving only the non zero entries. * * @param array The double array to produce a sparse vector from. */ public CompactSparseVector(SparseDoubleVector v) { int length = v.length(); int[] nz = v.getNonZeroIndices(); double[] values = new double[nz.length]; for (int i = 0; i < nz.length; ++i) values[i] = v.get(nz[i]); vector = new SparseDoubleArray(nz, values, length); magnitude = -1; }
@Override public double get(int row, int col) { SparseDoubleVector vector = matrix.get(row); if (vector == null) { return NOT_FLAGGED; } else { return vector.get(col); } }