Example usage for org.apache.commons.math3.linear RealVectorChangingVisitor RealVectorChangingVisitor

List of usage examples for org.apache.commons.math3.linear RealVectorChangingVisitor RealVectorChangingVisitor

Introduction

In this page you can find the example usage for org.apache.commons.math3.linear RealVectorChangingVisitor RealVectorChangingVisitor.

Prototype

RealVectorChangingVisitor

Source Link

Usage

From source file:com.github.thorbenlindhauer.factor.CanonicalGaussianFactor.java

/**
 * mapping must have the size of the new vector; maps a vector to a new size by applying the mapping of the positions
 * and fills the remaining places with 0 values
 *//*from w  ww  .jav a2  s  .c  o m*/
protected static RealVector padVector(final RealVector vector, int newSize, final int[] mapping) {
    final RealVector newVector = new ArrayRealVector(newSize);

    newVector.walkInOptimizedOrder(new RealVectorChangingVisitor() {

        @Override
        public double visit(int index, double value) {
            if (mapping[index] >= 0) {
                return vector.getEntry(mapping[index]);
            } else {
                return 0;
            }
        }

        @Override
        public void start(int dimension, int start, int end) {
        }

        @Override
        public double end() {
            return 0;
        }
    });
    return newVector;
}