Java Code Examples for cern.colt.matrix.DoubleMatrix2D#zMult()

The following examples show how to use cern.colt.matrix.DoubleMatrix2D#zMult() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BenchmarkMatrix.java    From database with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Linear algebrax matrix-matrix multiply.
 */
protected static Double2DProcedure funMatMultLarge() {
	return new Double2DProcedure() {
		public String toString() { return "xxxxxxx";	}
		public void setParameters(DoubleMatrix2D A, DoubleMatrix2D B) {
			// do not allocate mem for "D" --> safe some mem
			this.A = A;
			this.B = B;
			this.C = A.copy();
		}
		public void init() { C.assign(0); }
		public void apply(cern.colt.Timer timer) { A.zMult(B,C); }
		public double operations() { // Mflops
			double m = A.rows();
			double n = A.columns();
			double p = B.columns();
			return 2.0*m*n*p / 1.0E6; 
		}
	};
}
 
Example 2
Source File: TestMatrix2D.java    From database with GNU General Public License v2.0 6 votes vote down vote up
/**
 */
public static void doubleTest28() {
	double[] data={1,2,3,4,5,6};
	double[][] arrMatrix = 
	{ 
		{ 1, 2, 3, 4, 5, 6},
		{ 2, 3, 4, 5, 6, 7}
	};
	DoubleFactory2D f = DoubleFactory2D.dense;
	DoubleMatrix1D vector = new DenseDoubleMatrix1D(data);
	DoubleMatrix2D matrix = f.make(arrMatrix);
	DoubleMatrix1D res = vector.like(matrix.rows());
	
	matrix.zMult(vector,res);

	System.out.println(res);
}
 
Example 3
Source File: TestMatrix2D.java    From database with GNU General Public License v2.0 6 votes vote down vote up
/**
 */
public static void doubleTest28(DoubleFactory2D f) {
	double[] data={1,2,3,4,5,6};
	double[][] arrMatrix = 
	{ 
		{ 1, 2, 3, 4, 5, 6},
		{ 2, 3, 4, 5, 6, 7}
	};
	
	DoubleMatrix1D vector = new DenseDoubleMatrix1D(data);
	DoubleMatrix2D matrix = f.make(arrMatrix);
	DoubleMatrix1D res = vector.like(matrix.rows());
	
	matrix.zMult(vector,res);

	System.out.println(res);
}
 
Example 4
Source File: TestMatrix2D.java    From database with GNU General Public License v2.0 6 votes vote down vote up
/**
 */
public static void doubleTest29(DoubleFactory2D f) {
	double[][] data = 
	{ 
		{ 6, 5, 4 },
		{ 7, 6, 3 },
		{ 6, 5, 4 },
		{ 7, 6, 3 },
		{ 6, 5, 4 },
		{ 7, 6, 3 }
	};
	
	double[][] arrMatrix = 
	{ 
		{ 1, 2, 3, 4, 5, 6},
		{ 2, 3, 4, 5, 6, 7}
	};
	
	DoubleMatrix2D x = new DenseDoubleMatrix2D(data);
	DoubleMatrix2D matrix = f.make(arrMatrix);
	
	DoubleMatrix2D res = matrix.zMult(x,null);

	System.out.println(res);
}
 
Example 5
Source File: TestMatrix2D.java    From database with GNU General Public License v2.0 6 votes vote down vote up
/**
 */
public static void doubleTest34() {
	double[][] data = 
	{ 
		{ 3, 0, 0, 0 },
		{ 0, 4, 2, 0 },
		{ 0, 0, 0, 0 },
		{ 0, 0, 0, 0 },
	};
	
	DoubleMatrix2D A = new DenseDoubleMatrix2D(data);
	Property.DEFAULT.generateNonSingular(A);
	DoubleMatrix2D inv = Algebra.DEFAULT.inverse(A);


	System.out.println("\n\n\n"+A);
	System.out.println("\n"+inv);
	DoubleMatrix2D B = A.zMult(inv,null);
	System.out.println(B);
	if (!(B.equals(DoubleFactory2D.dense.identity(A.rows)))) {
		throw new InternalError();
	}
}
 
Example 6
Source File: TestMatrix2D.java    From jAudioGIT with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 */
public static void doubleTest34() {
	double[][] data = 
	{ 
		{ 3, 0, 0, 0 },
		{ 0, 4, 2, 0 },
		{ 0, 0, 0, 0 },
		{ 0, 0, 0, 0 },
	};
	
	DoubleMatrix2D A = new DenseDoubleMatrix2D(data);
	Property.DEFAULT.generateNonSingular(A);
	DoubleMatrix2D inv = Algebra.DEFAULT.inverse(A);


	System.out.println("\n\n\n"+A);
	System.out.println("\n"+inv);
	DoubleMatrix2D B = A.zMult(inv,null);
	System.out.println(B);
	if (!(B.equals(DoubleFactory2D.dense.identity(A.rows)))) {
		throw new InternalError();
	}
}
 
Example 7
Source File: TestMatrix2D.java    From jAudioGIT with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 */
public static void doubleTest29(DoubleFactory2D f) {
	double[][] data = 
	{ 
		{ 6, 5, 4 },
		{ 7, 6, 3 },
		{ 6, 5, 4 },
		{ 7, 6, 3 },
		{ 6, 5, 4 },
		{ 7, 6, 3 }
	};
	
	double[][] arrMatrix = 
	{ 
		{ 1, 2, 3, 4, 5, 6},
		{ 2, 3, 4, 5, 6, 7}
	};
	
	DoubleMatrix2D x = new DenseDoubleMatrix2D(data);
	DoubleMatrix2D matrix = f.make(arrMatrix);
	
	DoubleMatrix2D res = matrix.zMult(x,null);

	System.out.println(res);
}
 
Example 8
Source File: TestMatrix2D.java    From jAudioGIT with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 */
public static void doubleTest28() {
	double[] data={1,2,3,4,5,6};
	double[][] arrMatrix = 
	{ 
		{ 1, 2, 3, 4, 5, 6},
		{ 2, 3, 4, 5, 6, 7}
	};
	DoubleFactory2D f = DoubleFactory2D.dense;
	DoubleMatrix1D vector = new DenseDoubleMatrix1D(data);
	DoubleMatrix2D matrix = f.make(arrMatrix);
	DoubleMatrix1D res = vector.like(matrix.rows());
	
	matrix.zMult(vector,res);

	System.out.println(res);
}
 
Example 9
Source File: TestMatrix2D.java    From jAudioGIT with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 */
public static void doubleTest28(DoubleFactory2D f) {
	double[] data={1,2,3,4,5,6};
	double[][] arrMatrix = 
	{ 
		{ 1, 2, 3, 4, 5, 6},
		{ 2, 3, 4, 5, 6, 7}
	};
	
	DoubleMatrix1D vector = new DenseDoubleMatrix1D(data);
	DoubleMatrix2D matrix = f.make(arrMatrix);
	DoubleMatrix1D res = vector.like(matrix.rows());
	
	matrix.zMult(vector,res);

	System.out.println(res);
}
 
Example 10
Source File: TestMatrix2D.java    From database with GNU General Public License v2.0 5 votes vote down vote up
/**
 */
public static void doubleTest29(int size,DoubleFactory2D f) {
	
	DoubleMatrix2D x = new DenseDoubleMatrix2D(size,size).assign(0.5);
	DoubleMatrix2D matrix = f.sample(size,size,0.5,0.001);
	
	cern.colt.Timer timer = new cern.colt.Timer().start();
	DoubleMatrix2D res = matrix.zMult(x,null);
	timer.stop().display();
	
	//System.out.println(res);
}
 
Example 11
Source File: VarianceProportionStatistic.java    From beast-mcmc with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static Matrix getMatrixSqrt(Matrix M, Boolean invert) {
    DoubleMatrix2D S = new DenseDoubleMatrix2D(M.toComponents());
    RobustEigenDecomposition eigenDecomp = new RobustEigenDecomposition(S, 100);
    DoubleMatrix1D eigenValues = eigenDecomp.getRealEigenvalues();
    int dim = eigenValues.size();
    for (int i = 0; i < dim; i++) {
        double value = sqrt(eigenValues.get(i));
        if (invert) {
            value = 1 / value;
        }
        eigenValues.set(i, value);
    }

    DoubleMatrix2D eigenVectors = eigenDecomp.getV();
    for (int i = 0; i < dim; i++) {
        for (int j = 0; j < dim; j++) {
            eigenVectors.set(i, j, eigenVectors.get(i, j) * eigenValues.get(j));

        }
    }
    DoubleMatrix2D storageMatrix = new DenseDoubleMatrix2D(dim, dim);
    eigenVectors.zMult(eigenDecomp.getV(), storageMatrix, 1, 0, false, true);


    return new Matrix(storageMatrix.toArray());

}
 
Example 12
Source File: TestMatrix2D.java    From jAudioGIT with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 */
public static void doubleTest29(int size,DoubleFactory2D f) {
	
	DoubleMatrix2D x = new DenseDoubleMatrix2D(size,size).assign(0.5);
	DoubleMatrix2D matrix = f.sample(size,size,0.5,0.001);
	
	cern.colt.Timer timer = new cern.colt.Timer().start();
	DoubleMatrix2D res = matrix.zMult(x,null);
	timer.stop().display();
	
	//System.out.println(res);
}
 
Example 13
Source File: SeqBlas.java    From jAudioGIT with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void dgemv(boolean transposeA, double alpha, DoubleMatrix2D A, DoubleMatrix1D x, double beta, DoubleMatrix1D y) {
	A.zMult(x,y,alpha,beta,transposeA);
}
 
Example 14
Source File: SeqBlas.java    From jAudioGIT with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void dgemm(boolean transposeA, boolean transposeB, double alpha, DoubleMatrix2D A, DoubleMatrix2D B, double beta, DoubleMatrix2D C) {
	A.zMult(B,C,alpha,beta,transposeA,transposeB);
}
 
Example 15
Source File: SeqBlas.java    From database with GNU General Public License v2.0 4 votes vote down vote up
public void dgemv(boolean transposeA, double alpha, DoubleMatrix2D A, DoubleMatrix1D x, double beta, DoubleMatrix1D y) {
	A.zMult(x,y,alpha,beta,transposeA);
}
 
Example 16
Source File: SeqBlas.java    From database with GNU General Public License v2.0 4 votes vote down vote up
public void dgemm(boolean transposeA, boolean transposeB, double alpha, DoubleMatrix2D A, DoubleMatrix2D B, double beta, DoubleMatrix2D C) {
	A.zMult(B,C,alpha,beta,transposeA,transposeB);
}
 
Example 17
Source File: Algebra.java    From jAudioGIT with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Linear algebraic matrix-vector multiplication; <tt>z = A * y</tt>.
 * <tt>z[i] = Sum(A[i,j] * y[j]), i=0..A.rows()-1, j=0..y.size()-1</tt>.
 * @param A the source matrix.
 * @param y the source vector.
 * @return <tt>z</tt>; a new vector with <tt>z.size()==A.rows()</tt>.
 * 
 * @throws IllegalArgumentException if <tt>A.columns() != y.size()</tt>.
 */
public DoubleMatrix1D mult(DoubleMatrix2D A, DoubleMatrix1D y) {
	return A.zMult(y,null);
}
 
Example 18
Source File: Algebra.java    From jAudioGIT with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Linear algebraic matrix-matrix multiplication; <tt>C = A x B</tt>.
 * <tt>C[i,j] = Sum(A[i,k] * B[k,j]), k=0..n-1</tt>.
 * <br>
 * Matrix shapes: <tt>A(m x n), B(n x p), C(m x p)</tt>.
 *
 * @param A the first source matrix.
 * @param B the second source matrix.
 * @return <tt>C</tt>; a new matrix holding the results, with <tt>C.rows()=A.rows(), C.columns()==B.columns()</tt>.
 *
 * @throws IllegalArgumentException if <tt>B.rows() != A.columns()</tt>.
 */
public DoubleMatrix2D mult(DoubleMatrix2D A, DoubleMatrix2D B) {
	return A.zMult(B,null);
}
 
Example 19
Source File: Algebra.java    From database with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Linear algebraic matrix-matrix multiplication; <tt>C = A x B</tt>.
 * <tt>C[i,j] = Sum(A[i,k] * B[k,j]), k=0..n-1</tt>.
 * <br>
 * Matrix shapes: <tt>A(m x n), B(n x p), C(m x p)</tt>.
 *
 * @param A the first source matrix.
 * @param B the second source matrix.
 * @return <tt>C</tt>; a new matrix holding the results, with <tt>C.rows()=A.rows(), C.columns()==B.columns()</tt>.
 *
 * @throws IllegalArgumentException if <tt>B.rows() != A.columns()</tt>.
 */
public DoubleMatrix2D mult(DoubleMatrix2D A, DoubleMatrix2D B) {
	return A.zMult(B,null);
}
 
Example 20
Source File: Algebra.java    From database with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Linear algebraic matrix-vector multiplication; <tt>z = A * y</tt>.
 * <tt>z[i] = Sum(A[i,j] * y[j]), i=0..A.rows()-1, j=0..y.size()-1</tt>.
 * @param A the source matrix.
 * @param y the source vector.
 * @return <tt>z</tt>; a new vector with <tt>z.size()==A.rows()</tt>.
 * 
 * @throws IllegalArgumentException if <tt>A.columns() != y.size()</tt>.
 */
public DoubleMatrix1D mult(DoubleMatrix2D A, DoubleMatrix1D y) {
	return A.zMult(y,null);
}