FastDistance implements ContinuousDistance { public FastDistanceVectorData prepareVectorData(Row row, int vectorIdx, int... keepIdxs) { return prepareVectorData(Tuple2.of(VectorUtil.getVector(row.getField(vectorIdx)), TableUtil.getRow(row, keepIdxs))); }  List<FastDistanceData> prepareMatrixData(Iterable<Row> rows, int vectorIdx, int... keepIdxs); FastDistanceVectorData prepareVectorData(Row row, int vectorIdx, int... keepIdxs); List<FastDistanceData> prepareMatrixData(Iterable<Tuple2<Vector, Row>> tuples); FastDistanceVectorData prepareVectorData(Tuple2<Vector, Row> tuple); DenseMatrix calc(FastDistanceData left, FastDistanceData right); DenseMatrix calc(FastDistanceData left, FastDistanceData right, DenseMatrix res); abstract void updateLabel(FastDistanceData data);  }
@Test public void testDenseVectorRowInput(){ Vector vec = DenseVector.rand(10); EuclideanDistance distance = new EuclideanDistance(); FastDistanceVectorData vectorData = distance.prepareVectorData(Row.of(vec, 0, "a"), 0, 1, 2); assertVectorInput(vectorData, vec, Row.of(0, "a")); }
@Test public void testDenseVectorTupleInput(){ Vector vec = DenseVector.rand(10); EuclideanDistance distance = new EuclideanDistance(); FastDistanceVectorData vectorData = distance.prepareVectorData(Tuple2.of(vec, Row.of(0, "a"))); assertVectorInput(vectorData, vec, Row.of(0, "a")); }
@Test public void testSparseVectorRowInput(){ Vector vec = new SparseVector(10, new int[]{1, 2}, new double[]{1.0, 1.0}); EuclideanDistance distance = new EuclideanDistance(); FastDistanceVectorData vectorData = distance.prepareVectorData(Row.of(vec, 0, "a"), 0, 1, 2); assertVectorInput(vectorData, vec, Row.of(0, "a")); }
@Test public void testSparseVectorTupleInput(){ Vector vec = new SparseVector(10, new int[]{1, 2}, new double[]{1.0, 1.0}); EuclideanDistance distance = new EuclideanDistance(); FastDistanceVectorData vectorData = distance.prepareVectorData(Tuple2.of(vec, Row.of(0, "a"))); assertVectorInput(vectorData, vec, Row.of(0, "a")); }