}
/**
*/
public static void doubleTest13() {
double[] values = {0, 1, 2, 3};
DoubleMatrix1D matrix = new DenseDoubleMatrix1D(values);
System.out.println(matrix);
// Sum( x[i]*x[i] )
System.out.println(matrix.viewSelection(
new cern.colt.function.DoubleProcedure() {
public final boolean apply(double a) { return a % 2 == 0; }
}
));
//--> 14
// Sum( x[i]*x[i] )
System.out.println(matrix.aggregate(F.plus,F.square));
//--> 14
// Sum( x[i]*x[i]*x[i] )
System.out.println(matrix.aggregate(F.plus,F.pow(3)));
//--> 36
// Sum( x[i] )
System.out.println(matrix.aggregate(F.plus,F.identity));
//--> 6
// Min( x[i] )
System.out.println(matrix.aggregate(F.min,F.identity));
//--> 0
// Max( Sqrt(x[i]) / 2 )
System.out.println(matrix.aggregate(F.max,F.chain(F.div(2),F.sqrt)));
//--> 0.8660254037844386
// Number of all cells with 0 <= value <= 2
System.out.println(matrix.aggregate(F.plus,F.between(0,2)));
//--> 3
// Number of all cells with 0.8 <= Log2(value) <= 1.2
System.out.println(matrix.aggregate(F.plus,F.chain(F.between(0.8,1.2),F.log2)));
//--> 1
// Product( x[i] )
System.out.println(matrix.aggregate(F.mult,F.identity));
//--> 0
// Product( x[i] ) of all x[i] > limit
final double limit = 1;
DoubleFunction f = new DoubleFunction() {
public final double apply(double a) { return a>limit ? a : 1; }
};
System.out.println(matrix.aggregate(F.mult,f));
//--> 6
// Sum( (x[i]+y[i])^2 )
DoubleMatrix1D otherMatrix1D = matrix.copy();
System.out.println(matrix.aggregate(otherMatrix1D, F.plus, F.chain(F.square,F.plus)));
// --> 56
matrix.assign(F.plus(1));