use of cern.colt.matrix.DoubleMatrix1D in project tdq-studio-se by Talend.
the class CholeskyDecomposition method XXXsolveBuggy.
/**
*Solves <tt>A*X = B</tt>; returns <tt>X</tt>.
*@param B A Matrix with as many rows as <tt>A</tt> and any number of columns.
*@return <tt>X</tt> so that <tt>L*L'*X = B</tt>.
*@exception IllegalArgumentException if <tt>B.rows() != A.rows()</tt>.
*@exception IllegalArgumentException if <tt>!isSymmetricPositiveDefinite()</tt>.
*/
private DoubleMatrix2D XXXsolveBuggy(DoubleMatrix2D B) {
cern.jet.math.Functions F = cern.jet.math.Functions.functions;
if (B.rows() != n) {
throw new IllegalArgumentException("Matrix row dimensions must agree.");
}
if (!isSymmetricPositiveDefinite) {
throw new IllegalArgumentException("Matrix is not symmetric positive definite.");
}
// Copy right hand side.
DoubleMatrix2D X = B.copy();
int nx = B.columns();
// precompute and cache some views to avoid regenerating them time and again
DoubleMatrix1D[] Xrows = new DoubleMatrix1D[n];
for (int k = 0; k < n; k++) Xrows[k] = X.viewRow(k);
// Solve L*Y = B;
for (int k = 0; k < n; k++) {
for (int i = k + 1; i < n; i++) {
// X[i,j] -= X[k,j]*L[i,k]
Xrows[i].assign(Xrows[k], F.minusMult(L.getQuick(i, k)));
}
Xrows[k].assign(F.div(L.getQuick(k, k)));
}
// Solve L'*X = Y;
for (int k = n - 1; k >= 0; k--) {
Xrows[k].assign(F.div(L.getQuick(k, k)));
for (int i = 0; i < k; i++) {
// X[i,j] -= X[k,j]*L[k,i]
Xrows[i].assign(Xrows[k], F.minusMult(L.getQuick(k, i)));
}
}
return X;
}
use of cern.colt.matrix.DoubleMatrix1D in project tdq-studio-se by Talend.
the class SeqBlas method dtrmv.
public void dtrmv(boolean isUpperTriangular, boolean transposeA, boolean isUnitTriangular, DoubleMatrix2D A, DoubleMatrix1D x) {
if (transposeA) {
A = A.viewDice();
isUpperTriangular = !isUpperTriangular;
}
Property.DEFAULT.checkSquare(A);
int size = A.rows();
if (size != x.size()) {
throw new IllegalArgumentException(A.toStringShort() + ", " + x.toStringShort());
}
DoubleMatrix1D b = x.like();
DoubleMatrix1D y = x.like();
if (isUnitTriangular) {
y.assign(1);
} else {
for (int i = 0; i < size; i++) {
y.setQuick(i, A.getQuick(i, i));
}
}
for (int i = 0; i < size; i++) {
double sum = 0;
if (!isUpperTriangular) {
for (int j = 0; j < i; j++) {
sum += A.getQuick(i, j) * x.getQuick(j);
}
sum += y.getQuick(i) * x.getQuick(i);
} else {
sum += y.getQuick(i) * x.getQuick(i);
for (int j = i + 1; j < size; j++) {
sum += A.getQuick(i, j) * x.getQuick(j);
}
}
b.setQuick(i, sum);
}
x.assign(b);
}
use of cern.colt.matrix.DoubleMatrix1D in project tdq-studio-se by Talend.
the class DenseDoubleMatrix1D method assign.
/**
* Replaces all cell values of the receiver with the values of another matrix.
* Both matrices must have the same size.
* If both matrices share the same cells (as is the case if they are views derived from the same matrix) and intersect in an ambiguous way, then replaces <i>as if</i> using an intermediate auxiliary deep copy of <tt>other</tt>.
*
* @param source the source matrix to copy from (may be identical to the receiver).
* @return <tt>this</tt> (for convenience only).
* @throws IllegalArgumentException if <tt>size() != other.size()</tt>.
*/
public DoubleMatrix1D assign(DoubleMatrix1D source) {
// overriden for performance only
if (!(source instanceof DenseDoubleMatrix1D)) {
return super.assign(source);
}
DenseDoubleMatrix1D other = (DenseDoubleMatrix1D) source;
if (other == this)
return this;
checkSize(other);
if (isNoView && other.isNoView) {
// quickest
System.arraycopy(other.elements, 0, this.elements, 0, this.elements.length);
return this;
}
if (haveSharedCells(other)) {
DoubleMatrix1D c = other.copy();
if (!(c instanceof DenseDoubleMatrix1D)) {
// should not happen
return super.assign(source);
}
other = (DenseDoubleMatrix1D) c;
}
final double[] elems = this.elements;
final double[] otherElems = other.elements;
if (elements == null || otherElems == null)
throw new InternalError();
int s = this.stride;
int ys = other.stride;
int index = index(0);
int otherIndex = other.index(0);
for (int k = size; --k >= 0; ) {
elems[index] = otherElems[otherIndex];
index += s;
otherIndex += ys;
}
return this;
}
use of cern.colt.matrix.DoubleMatrix1D in project tdq-studio-se by Talend.
the class TestMatrix2D method doubleTest23.
/**
*/
public static void doubleTest23(int runs, int size, double nonZeroFraction, boolean dense) {
System.out.println("\n\n");
System.out.println("initializing...");
DoubleMatrix2D A, LU, I, Inv;
DoubleMatrix1D b, solved;
double mean = 5.0;
double stdDev = 3.0;
cern.jet.random.Normal random = new cern.jet.random.Normal(mean, stdDev, new cern.jet.random.engine.MersenneTwister());
System.out.println("sampling...");
double value = 2;
if (dense)
A = Factory2D.dense.sample(size, size, value, nonZeroFraction);
else
A = Factory2D.sparse.sample(size, size, value, nonZeroFraction);
b = A.like1D(size).assign(1);
// A.assign(random);
// A.assign(F.rint); // round
System.out.println("generating invertible matrix...");
Property.generateNonSingular(A);
// I = Factory2D.identity(size);
LU = A.like();
solved = b.like();
// Inv = Factory2D.make(size,size);
LUDecompositionQuick lu = new LUDecompositionQuick();
System.out.println("benchmarking assignment...");
cern.colt.Timer timer = new cern.colt.Timer().start();
LU.assign(A);
solved.assign(b);
timer.stop().display();
LU.assign(A);
lu.decompose(LU);
System.out.println("benchmarking LU...");
timer.reset().start();
for (int i = runs; --i >= 0; ) {
solved.assign(b);
// Inv.assign(I);
// lu.decompose(LU);
lu.solve(solved);
// lu.solve(Inv);
}
timer.stop().display();
// System.out.println("A="+A);
// System.out.println("LU="+LU);
// System.out.println("U="+lu.getU());
// System.out.println("L="+lu.getL());
System.out.println("done.");
}
use of cern.colt.matrix.DoubleMatrix1D in project tdq-studio-se by Talend.
the class TestMatrix2D method doubleTest36.
/**
* Title: Aero3D<p>
* Description: A Program to analyse aeroelestic evects in transonic wings<p>
* Copyright: Copyright (c) 1998<p>
* Company: PIERSOL Engineering Inc.<p>
* @author John R. Piersol
* @version
*/
public static void doubleTest36() {
double[] testSort = new double[5];
testSort[0] = 5;
testSort[1] = Double.NaN;
testSort[2] = 2;
testSort[3] = Double.NaN;
testSort[4] = 1;
DoubleMatrix1D doubleDense = new DenseDoubleMatrix1D(testSort);
System.out.println("orig = " + doubleDense);
doubleDense = doubleDense.viewSorted();
doubleDense.toArray(testSort);
System.out.println("sort = " + doubleDense);
System.out.println("done\n");
}
Aggregations