@Test public void testSparseIterableTupleInput(){ int len = 20; int size = 50; List<Vector> vectorList = initSparseData(len, size); List<Tuple2<Vector, Row>> rows = new ArrayList<>(); for(int i = 0; i < vectorList.size(); i++){ rows.add(Tuple2.of(vectorList.get(i), Row.of(i))); } EuclideanDistance distance = new EuclideanDistance(); List<FastDistanceData> list = distance.prepareMatrixData(rows); assertIterableSparseInput(list, len, vectorList); }
public List<FastDistanceData> prepareMatrixData(Iterable<Row> rows, int vectorIdx, int... keepIdxs) { Iterable<Tuple2<Vector, Row>> newItearble = Iterables.transform(rows, (row) -> { Vector vec = VectorUtil.getVector(row.getField(vectorIdx)); row = TableUtil.getRow(row, keepIdxs); return Tuple2.of(vec, row); }); return prepareMatrixData(newItearble); }
FastDistance implements ContinuousDistance { public List<FastDistanceData> prepareMatrixData(Iterable<Row> rows, int vectorIdx, int... keepIdxs) { Iterable<Tuple2<Vector, Row>> newItearble = Iterables.transform(rows, (row) -> { Vector vec = VectorUtil.getVector(row.getField(vectorIdx)); row = TableUtil.getRow(row, keepIdxs); return Tuple2.of(vec, row); }); return prepareMatrixData(newItearble); } }
FastDistance implements ContinuousDistance { public List<FastDistanceData> prepareMatrixData(Iterable<Row> rows, int vectorIdx, int... keepIdxs) { Iterable<Tuple2<Vector, Row>> newItearble = Iterables.transform(rows, (row) -> { Vector vec = VectorUtil.getVector(row.getField(vectorIdx)); row = TableUtil.getRow(row, keepIdxs); return Tuple2.of(vec, row); }); return prepareMatrixData(newItearble); }  }
FastDistance implements ContinuousDistance { public List<FastDistanceData> prepareMatrixData(Iterable<Row> rows, int vectorIdx, int... keepIdxs) { Iterable<Tuple2<Vector, Row>> newItearble = Iterables.transform(rows, (row) -> { Vector vec = VectorUtil.getVector(row.getField(vectorIdx)); row = TableUtil.getRow(row, keepIdxs); return Tuple2.of(vec, row); }); return prepareMatrixData(newItearble); }  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); }
FastDistance implements ContinuousDistance { public List<FastDistanceData> prepareMatrixData(Iterable<Row> rows, int vectorIdx, int... keepIdxs) { Iterable<Tuple2<Vector, Row>> newItearble = Iterables.transform(rows, (row) -> { Vector vec = VectorUtil.getVector(row.getField(vectorIdx)); row = TableUtil.getRow(row, keepIdxs); return Tuple2.of(vec, row); }); return prepareMatrixData(newItearble); }  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);  }