DistributedRowMatrix implements VectorIterable, Configurable { @Override public Vector timesSquared(Vector v) { try { Configuration initialConf = getConf() == null ? new Configuration() : getConf(); Path outputVectorTmpPath = new Path(outputTmpBasePath, new Path(Long.toString(System.nanoTime()))); Configuration conf = TimesSquaredJob.createTimesSquaredJobConf(initialConf, v, rowPath, outputVectorTmpPath); JobClient.runJob(new JobConf(conf)); Vector result = TimesSquaredJob.retrieveTimesSquaredOutputVector(conf); if (!keepTempFiles) { FileSystem fs = outputVectorTmpPath.getFileSystem(conf); fs.delete(outputVectorTmpPath, true); } return result; } catch (IOException ioe) { throw new IllegalStateException(ioe); } } DistributedRowMatrix(Path inputPath,
                              Path outputTmpPath,
                              int numRows,
                              int numCols);  DistributedRowMatrix(Path inputPath,
                              Path outputTmpPath,
                              int numRows,
                              int numCols,
                              boolean keepTempFiles); @Override Configuration getConf(); @Override void setConf(Configuration conf); Path getRowPath(); Path getOutputTempPath(); void setOutputTempPathString(String outPathString); @Override Iterator<MatrixSlice> iterateAll(); @Override int numSlices(); @Override int numRows(); @Override int numCols(); DistributedRowMatrix times(DistributedRowMatrix other); DistributedRowMatrix transpose(); @Override Vector times(Vector v); @Override Vector timesSquared(Vector v); @Override Iterator<MatrixSlice> iterator(); static final String KEEP_TEMP_FILES; }
@Test public void testMatrixTimesSquaredVector() throws Exception { Vector v = new RandomAccessSparseVector(50); v.assign(1.0); Matrix m = SolverTest.randomSequentialAccessSparseMatrix(100, 90, 50, 20, 1.0); DistributedRowMatrix dm = randomDistributedMatrix(100, 90, 50, 20, 1.0, false); Vector expected = m.timesSquared(v); Vector actual = dm.timesSquared(v); assertEquals(0.0, expected.getDistanceSquared(actual), 1.0e-9); }