Java 类org.apache.commons.math3.linear.DefaultRealMatrixPreservingVisitor 实例源码

项目:incubator-hivemall    文件:MatrixUtils.java   
@Nonnull
public static double[] flatten(@Nonnull final RealMatrix[] grid) {
    Preconditions.checkArgument(grid.length >= 1, "The number of rows must be greather than 1");

    final int rows = grid.length;
    RealMatrix grid0 = grid[0];
    Preconditions.checkNotNull(grid0);
    int cellRows = grid0.getRowDimension();
    int cellCols = grid0.getColumnDimension();

    final DoubleArrayList list = new DoubleArrayList(rows * cellRows * cellCols);
    final RealMatrixPreservingVisitor visitor = new DefaultRealMatrixPreservingVisitor() {
        @Override
        public void visit(int row, int column, double value) {
            list.add(value);
        }
    };

    for (int row = 0; row < rows; row++) {
        RealMatrix cell = grid[row];
        cell.walkInRowOrder(visitor);
    }

    return list.toArray();
}
项目:renderScriptFFT    文件:MelMath.java   
public static RealMatrix doubleAllExceptDCandNyquist(RealMatrix v, final RealMatrix c, final double mn, final double n, final double fn2){
    final RealMatrix out = MatrixUtils.createRealMatrix(v.getRowDimension(), v.getColumnDimension());
       DefaultRealMatrixPreservingVisitor mv = new DefaultRealMatrixPreservingVisitor(){
        @Override
        public void visit(int row, int col, double vval) {
            final double cval =  c.getEntry(row, col);
            if (cval + mn > 0 & (cval + mn < n - fn2)){
                out.setEntry(row, col, vval*2.0);
            } else {
                out.setEntry(row, col, vval);
            }

        }
       };

       v.walkInOptimizedOrder(mv);
    return out; 
}
项目:incubator-hivemall    文件:MatrixUtils.java   
@Nonnull
public static double[] flatten(@Nonnull final RealMatrix[][] grid) {
    Preconditions.checkArgument(grid.length >= 1, "The number of rows must be greather than 1");
    Preconditions.checkArgument(grid[0].length >= 1,
        "The number of cols must be greather than 1");

    final int rows = grid.length;
    final int cols = grid[0].length;
    RealMatrix grid00 = grid[0][0];
    Preconditions.checkNotNull(grid00);
    int cellRows = grid00.getRowDimension();
    int cellCols = grid00.getColumnDimension();

    final DoubleArrayList list = new DoubleArrayList(rows * cols * cellRows * cellCols);
    final RealMatrixPreservingVisitor visitor = new DefaultRealMatrixPreservingVisitor() {
        @Override
        public void visit(int row, int column, double value) {
            list.add(value);
        }
    };

    for (int row = 0; row < rows; row++) {
        for (int col = 0; col < cols; col++) {
            RealMatrix cell = grid[row][col];
            cell.walkInRowOrder(visitor);
        }
    }

    return list.toArray();
}
项目:safe-java    文件:SparseAnnotationProvider.java   
@Override
public void forEachAttributeValue(int attributeIndex,
                                  IndexedDoubleConsumer consumer) {
    values.walkInOptimizedOrder(new DefaultRealMatrixPreservingVisitor() {
        @Override
        public void visit(int row,
                          int column,
                          double value) {
            consumer.accept(row, value);
        }
    }, 0, values.getRowDimension() - 1, attributeIndex, attributeIndex);

}
项目:buffer_bci    文件:MatrixTest.java   
public void testAbs() throws Exception {
    Matrix abs = c.abs();
    abs.walkInOptimizedOrder(new DefaultRealMatrixPreservingVisitor() {
        public void visit(int row, int column, double value) {
            assertTrue(value >= 0);
        }
    });
}
项目:renderScriptFFT    文件:MelMath.java   
public static RealMatrix frq2mel(RealMatrix frq){
    final RealMatrix mel = MatrixUtils.createRealMatrix(frq.getRowDimension(), frq.getColumnDimension());
       DefaultRealMatrixPreservingVisitor mv = new DefaultRealMatrixPreservingVisitor(){
        @Override
        public void visit(int row, int col, double curFrq) {
            final double aF = FastMath.abs(curFrq);
            mel.setEntry(row, col, FastMath.signum(curFrq)*Math.log(1.0+aF/700.0)*k);
        }
       };

       frq.walkInOptimizedOrder(mv);
    return mel; 
}
项目:renderScriptFFT    文件:MelMath.java   
public static RealMatrix mel2frq(RealMatrix mel){  
    final RealMatrix frq = MatrixUtils.createRealMatrix(mel.getRowDimension(), mel.getColumnDimension());
    DefaultRealMatrixPreservingVisitor mv = new DefaultRealMatrixPreservingVisitor(){
        @Override
        public void visit(int row, int col, double curMel) {
            final double aM = FastMath.abs(curMel);
            frq.setEntry(row, col, 700.0 * FastMath.signum(curMel) * (Math.exp( aM/k ) - 1.0));
        }
       };

       mel.walkInOptimizedOrder(mv);
    return frq; 
}