本文整理了Java中org.apache.mahout.math.Matrix.viewColumn()
方法的一些代码示例,展示了Matrix.viewColumn()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Matrix.viewColumn()
方法的具体详情如下:
包路径:org.apache.mahout.math.Matrix
类名称:Matrix
方法名:viewColumn
[英]Return a reference to a column. Changes to the view will change the original matrix.
[中]返回对列的引用。对视图的更改将更改原始矩阵。
代码示例来源:origin: apache/mahout
@Override
public Vector viewRow(int row) {
return m.viewColumn(row);
}
代码示例来源:origin: apache/mahout
@Override
public Vector like(int cardinality) {
return matrix.like(cardinality, 1).viewColumn(0);
}
代码示例来源:origin: apache/mahout
@Override
public double getQuick(int index) {
Vector v = rowToColumn ? matrix.viewColumn(index) : matrix.viewRow(index);
return v == null ? 0.0 : v.getQuick(transposeOffset);
}
代码示例来源:origin: apache/mahout
@Override
public boolean isAddConstantTime() {
return (rowToColumn ? matrix.viewColumn(0) : matrix.viewRow(0)).isAddConstantTime();
}
}
代码示例来源:origin: apache/mahout
/**
* Return an empty vector of the same underlying class as the receiver
*
* @return a Vector
*/
@Override
public Vector like() {
return matrix.like(size(), 1).viewColumn(0);
}
代码示例来源:origin: apache/mahout
@Override
public double getLookupCost() {
return (rowToColumn ? matrix.viewColumn(0) : matrix.viewRow(0)).getLookupCost();
}
代码示例来源:origin: apache/mahout
@Override
public double getIteratorAdvanceCost() {
return (rowToColumn ? matrix.viewColumn(0) : matrix.viewRow(0)).getIteratorAdvanceCost();
}
代码示例来源:origin: apache/mahout
@Test(expected = IndexException.class)
public void testViewColumnIndexUnder() {
test.viewColumn(-1);
}
代码示例来源:origin: apache/mahout
@Test(expected = IndexException.class)
public void testViewColumnIndexOver() {
test.viewColumn(5);
}
代码示例来源:origin: apache/mahout
@Test(expected = IndexException.class)
public void testViewColumnIndexUnder() {
test.viewColumn(-1);
}
代码示例来源:origin: apache/mahout
@Test(expected = IndexException.class)
public void testViewColumnIndexOver() {
test.viewColumn(5);
}
代码示例来源:origin: apache/mahout
@Override
public Vector viewColumn(int column) {
if (column < 0 || column >= columnSize()) {
throw new IndexException(column, columnSize());
}
return matrix.viewColumn(column + offset[COL]).viewPart(offset[ROW], rowSize());
}
代码示例来源:origin: apache/mahout
@Override
public Matrix timesLeft(Matrix that) {
if (that.numCols() != diagonal.size()) {
throw new IllegalArgumentException(
"Incompatible number of rows in the left operand of matrix-matrix multiplication.");
}
Matrix m = that.like();
for (int col = 0; col < diagonal.size(); col++) {
m.assignColumn(col, that.viewColumn(col).times(diagonal.getQuick(col)));
}
return m;
}
代码示例来源:origin: apache/mahout
@Override
public void setQuick(int index, double value) {
Vector v = rowToColumn ? matrix.viewColumn(index) : matrix.viewRow(index);
if (v == null) {
v = newVector(numCols);
if (rowToColumn) {
matrix.assignColumn(index, v);
} else {
matrix.assignRow(index, v);
}
}
v.setQuick(transposeOffset, value);
}
代码示例来源:origin: apache/mahout
@Test
public void testViewColumn() {
Vector column = test.viewColumn(1);
assertEquals("row size", 3, column.getNumNondefaultElements());
}
代码示例来源:origin: apache/mahout
@Test
public void testIterate() {
Iterator<MatrixSlice> it = test.iterator();
MatrixSlice m;
while (it.hasNext() && (m = it.next()) != null) {
Vector v = m.vector();
Vector w = test instanceof SparseColumnMatrix ? test.viewColumn(m.index()) : test.viewRow(m.index());
assertEquals("iterator: " + v + ", randomAccess: " + w, v, w);
}
}
代码示例来源:origin: apache/mahout
@Test
public void testViewColumn() {
Vector column = test.viewColumn(1);
assertEquals("row size", 3, column.getNumNondefaultElements());
int i = 0;
for (double x : new double[]{3.3, 5.5, 7.7}) {
assertEquals(x, column.get(i++), 0);
}
}
代码示例来源:origin: apache/mahout
@Test
public void testAggregateCols() {
Vector v = test.aggregateColumns(new VectorFunction() {
@Override
public double apply(Vector v) {
return v.zSum();
}
});
for (int i = 0; i < test.numCols(); i++) {
assertEquals(test.viewColumn(i).zSum(), v.get(i), EPSILON);
}
}
代码示例来源:origin: apache/mahout
@Test
public void testViewDenseSparseReporting() {
Matrix m = new SparseMatrix(1000, 1000);
m.set(1, 1, 33.0);
Matrix mt = Matrices.transposedView(m);
assertTrue(mt.viewColumn(0).isDense() == m.viewRow(0).isDense());
assertTrue(mt.viewRow(0).isDense() == m.viewColumn(0).isDense());
m = new DenseMatrix(10,10);
m.set(1, 1, 33.0);
mt = Matrices.transposedView(m);
assertTrue(mt.viewColumn(0).isDense());
assertTrue(mt.viewRow(0).isDense());
}
代码示例来源:origin: apache/mahout
/**
* Test for the error reported in https://issues.apache.org/jira/browse/MAHOUT-1146
*/
@Test
public void testColumnView() {
Matrix matrix = new DenseMatrix(5, 3);
Vector column2 = matrix.viewColumn(2);
Matrix outerProduct = column2.cross(column2);
assertEquals(matrix.numRows(), outerProduct.numRows());
assertEquals(matrix.numRows(), outerProduct.numCols());
}
内容来源于网络,如有侵权,请联系作者删除!