Java Code Examples for cern.colt.matrix.DoubleMatrix1D#toStringShort()
The following examples show how to use
cern.colt.matrix.DoubleMatrix1D#toStringShort() .
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: RCMDoubleMatrix2D.java From database with GNU General Public License v2.0 | 6 votes |
/** * Linear algebraic matrix-vector multiplication; <tt>z = A * y</tt>. * <tt>z[i] = alpha*Sum(A[i,j] * y[j]) + beta*z[i], i=0..A.rows()-1, j=0..y.size()-1</tt>. * Where <tt>A == this</tt>. * @param y the source vector. * @param z the vector where results are to be stored. * * @throws IllegalArgumentException if <tt>A.columns() != y.size() || A.rows() > z.size())</tt>. */ protected void zMult(final DoubleMatrix1D y, final DoubleMatrix1D z, cern.colt.list.IntArrayList nonZeroIndexes, DoubleMatrix1D[] allRows, final double alpha, final double beta) { if (columns != y.size() || rows > z.size()) throw new IllegalArgumentException("Incompatible args: "+toStringShort()+", "+y.toStringShort()+", "+z.toStringShort()); z.assign(cern.jet.math.Functions.mult(beta/alpha)); for (int i = indexes.length; --i >= 0; ) { if (indexes[i] != null) { for (int k = indexes[i].size(); --k >= 0; ) { int j = indexes[i].getQuick(k); double value = values[i].getQuick(k); z.setQuick(i,z.getQuick(i) + value * y.getQuick(j)); } } } z.assign(cern.jet.math.Functions.mult(alpha)); }
Example 2
Source File: SeqBlas.java From database with GNU General Public License v2.0 | 6 votes |
public void dsymv(boolean isUpperTriangular, double alpha, DoubleMatrix2D A, DoubleMatrix1D x, double beta, DoubleMatrix1D y) { if (isUpperTriangular) A = A.viewDice(); Property.DEFAULT.checkSquare(A); int size = A.rows(); if (size != x.size() || size!=y.size()) { throw new IllegalArgumentException(A.toStringShort() + ", " + x.toStringShort() + ", " + y.toStringShort()); } DoubleMatrix1D tmp = x.like(); for (int i = 0; i < size; i++) { double sum = 0; for (int j = 0; j <= i; j++) { sum += A.getQuick(i,j) * x.getQuick(j); } for (int j = i + 1; j < size; j++) { sum += A.getQuick(j,i) * x.getQuick(j); } tmp.setQuick(i, alpha * sum + beta * y.getQuick(i)); } y.assign(tmp); }
Example 3
Source File: RCMDoubleMatrix2D.java From jAudioGIT with GNU Lesser General Public License v2.1 | 6 votes |
/** * Linear algebraic matrix-vector multiplication; <tt>z = A * y</tt>. * <tt>z[i] = alpha*Sum(A[i,j] * y[j]) + beta*z[i], i=0..A.rows()-1, j=0..y.size()-1</tt>. * Where <tt>A == this</tt>. * @param y the source vector. * @param z the vector where results are to be stored. * * @throws IllegalArgumentException if <tt>A.columns() != y.size() || A.rows() > z.size())</tt>. */ protected void zMult(final DoubleMatrix1D y, final DoubleMatrix1D z, cern.colt.list.IntArrayList nonZeroIndexes, DoubleMatrix1D[] allRows, final double alpha, final double beta) { if (columns != y.size() || rows > z.size()) throw new IllegalArgumentException("Incompatible args: "+toStringShort()+", "+y.toStringShort()+", "+z.toStringShort()); z.assign(cern.jet.math.Functions.mult(beta/alpha)); for (int i = indexes.length; --i >= 0; ) { if (indexes[i] != null) { for (int k = indexes[i].size(); --k >= 0; ) { int j = indexes[i].getQuick(k); double value = values[i].getQuick(k); z.setQuick(i,z.getQuick(i) + value * y.getQuick(j)); } } } z.assign(cern.jet.math.Functions.mult(alpha)); }
Example 4
Source File: SeqBlas.java From jAudioGIT with GNU Lesser General Public License v2.1 | 6 votes |
public void dsymv(boolean isUpperTriangular, double alpha, DoubleMatrix2D A, DoubleMatrix1D x, double beta, DoubleMatrix1D y) { if (isUpperTriangular) A = A.viewDice(); Property.DEFAULT.checkSquare(A); int size = A.rows(); if (size != x.size() || size!=y.size()) { throw new IllegalArgumentException(A.toStringShort() + ", " + x.toStringShort() + ", " + y.toStringShort()); } DoubleMatrix1D tmp = x.like(); for (int i = 0; i < size; i++) { double sum = 0; for (int j = 0; j <= i; j++) { sum += A.getQuick(i,j) * x.getQuick(j); } for (int j = i + 1; j < size; j++) { sum += A.getQuick(j,i) * x.getQuick(j); } tmp.setQuick(i, alpha * sum + beta * y.getQuick(i)); } y.assign(tmp); }
Example 5
Source File: SeqBlas.java From database with GNU General Public License v2.0 | 5 votes |
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); }
Example 6
Source File: SeqBlas.java From jAudioGIT with GNU Lesser General Public License v2.1 | 5 votes |
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); }
Example 7
Source File: TridiagonalDoubleMatrix2D.java From database with GNU General Public License v2.0 | 4 votes |
public DoubleMatrix1D zMult(DoubleMatrix1D y, DoubleMatrix1D z, double alpha, double beta, final boolean transposeA) { int m = rows; int n = columns; if (transposeA) { m = columns; n = rows; } boolean ignore = (z==null); if (z==null) z = new DenseDoubleMatrix1D(m); if (!(this.isNoView && y instanceof DenseDoubleMatrix1D && z instanceof DenseDoubleMatrix1D)) { return super.zMult(y,z,alpha,beta,transposeA); } if (n != y.size() || m > z.size()) throw new IllegalArgumentException("Incompatible args: "+ ((transposeA ? viewDice() : this).toStringShort()) +", "+y.toStringShort()+", "+z.toStringShort()); if (!ignore) z.assign(cern.jet.math.Functions.mult(beta/alpha)); DenseDoubleMatrix1D zz = (DenseDoubleMatrix1D) z; final double[] zElements = zz.elements; final int zStride = zz.stride; final int zi = z.index(0); DenseDoubleMatrix1D yy = (DenseDoubleMatrix1D) y; final double[] yElements = yy.elements; final int yStride = yy.stride; final int yi = y.index(0); if (yElements==null || zElements==null) throw new InternalError(); forEachNonZero( new cern.colt.function.IntIntDoubleFunction() { public double apply(int i, int j, double value) { if (transposeA) { int tmp=i; i=j; j=tmp; } zElements[zi + zStride*i] += value * yElements[yi + yStride*j]; //z.setQuick(row,z.getQuick(row) + value * y.getQuick(column)); //System.out.println("["+i+","+j+"]-->"+value); return value; } } ); if (alpha!=1) z.assign(cern.jet.math.Functions.mult(alpha)); return z; }
Example 8
Source File: SparseDoubleMatrix2D.java From database with GNU General Public License v2.0 | 4 votes |
public DoubleMatrix1D zMult(DoubleMatrix1D y, DoubleMatrix1D z, double alpha, double beta, final boolean transposeA) { int m = rows; int n = columns; if (transposeA) { m = columns; n = rows; } boolean ignore = (z==null); if (z==null) z = new DenseDoubleMatrix1D(m); if (!(this.isNoView && y instanceof DenseDoubleMatrix1D && z instanceof DenseDoubleMatrix1D)) { return super.zMult(y,z,alpha,beta,transposeA); } if (n != y.size() || m > z.size()) throw new IllegalArgumentException("Incompatible args: "+ ((transposeA ? viewDice() : this).toStringShort()) +", "+y.toStringShort()+", "+z.toStringShort()); if (!ignore) z.assign(cern.jet.math.Functions.mult(beta/alpha)); DenseDoubleMatrix1D zz = (DenseDoubleMatrix1D) z; final double[] zElements = zz.elements; final int zStride = zz.stride; final int zi = z.index(0); DenseDoubleMatrix1D yy = (DenseDoubleMatrix1D) y; final double[] yElements = yy.elements; final int yStride = yy.stride; final int yi = y.index(0); if (yElements==null || zElements==null) throw new InternalError(); this.elements.forEachPair( new cern.colt.function.IntDoubleProcedure() { public boolean apply(int key, double value) { int i = key/columns; int j = key%columns; if (transposeA) { int tmp=i; i=j; j=tmp; } zElements[zi + zStride*i] += value * yElements[yi + yStride*j]; //System.out.println("["+i+","+j+"]-->"+value); return true; } } ); /* forEachNonZero( new cern.colt.function.IntIntDoubleFunction() { public double apply(int i, int j, double value) { if (transposeA) { int tmp=i; i=j; j=tmp; } zElements[zi + zStride*i] += value * yElements[yi + yStride*j]; //z.setQuick(row,z.getQuick(row) + value * y.getQuick(column)); //System.out.println("["+i+","+j+"]-->"+value); return value; } } ); */ if (alpha!=1) z.assign(cern.jet.math.Functions.mult(alpha)); return z; }
Example 9
Source File: DenseDoubleMatrix2D.java From database with GNU General Public License v2.0 | 4 votes |
public DoubleMatrix1D zMult(DoubleMatrix1D y, DoubleMatrix1D z, double alpha, double beta, boolean transposeA) { if (transposeA) return viewDice().zMult(y,z,alpha,beta,false); if (z==null) z = new DenseDoubleMatrix1D(this.rows); if (!(y instanceof DenseDoubleMatrix1D && z instanceof DenseDoubleMatrix1D)) return super.zMult(y,z,alpha,beta,transposeA); if (columns != y.size || rows > z.size) throw new IllegalArgumentException("Incompatible args: "+toStringShort()+", "+y.toStringShort()+", "+z.toStringShort()); DenseDoubleMatrix1D yy = (DenseDoubleMatrix1D) y; DenseDoubleMatrix1D zz = (DenseDoubleMatrix1D) z; final double[] AElems = this.elements; final double[] yElems = yy.elements; final double[] zElems = zz.elements; if (AElems==null || yElems==null || zElems==null) throw new InternalError(); int As = this.columnStride; int ys = yy.stride; int zs = zz.stride; int indexA = index(0,0); int indexY = yy.index(0); int indexZ = zz.index(0); int cols = columns; for (int row=rows; --row >= 0; ) { double sum = 0; /* // not loop unrolled for (int i=indexA, j=indexY, column=columns; --column >= 0; ) { sum += AElems[i] * yElems[j]; i += As; j += ys; } */ // loop unrolled int i = indexA - As; int j = indexY - ys; for (int k=cols%4; --k >= 0; ) { sum += AElems[i += As] * yElems[j += ys]; } for (int k=cols/4; --k >= 0; ) { sum += AElems[i += As] * yElems[j += ys] + AElems[i += As] * yElems[j += ys] + AElems[i += As] * yElems[j += ys] + AElems[i += As] * yElems[j += ys]; } zElems[indexZ] = alpha*sum + beta*zElems[indexZ]; indexA += this.rowStride; indexZ += zs; } return z; }
Example 10
Source File: TridiagonalDoubleMatrix2D.java From jAudioGIT with GNU Lesser General Public License v2.1 | 4 votes |
public DoubleMatrix1D zMult(DoubleMatrix1D y, DoubleMatrix1D z, double alpha, double beta, final boolean transposeA) { int m = rows; int n = columns; if (transposeA) { m = columns; n = rows; } boolean ignore = (z==null); if (z==null) z = new DenseDoubleMatrix1D(m); if (!(this.isNoView && y instanceof DenseDoubleMatrix1D && z instanceof DenseDoubleMatrix1D)) { return super.zMult(y,z,alpha,beta,transposeA); } if (n != y.size() || m > z.size()) throw new IllegalArgumentException("Incompatible args: "+ ((transposeA ? viewDice() : this).toStringShort()) +", "+y.toStringShort()+", "+z.toStringShort()); if (!ignore) z.assign(cern.jet.math.Functions.mult(beta/alpha)); DenseDoubleMatrix1D zz = (DenseDoubleMatrix1D) z; final double[] zElements = zz.elements; final int zStride = zz.stride; final int zi = z.index(0); DenseDoubleMatrix1D yy = (DenseDoubleMatrix1D) y; final double[] yElements = yy.elements; final int yStride = yy.stride; final int yi = y.index(0); if (yElements==null || zElements==null) throw new InternalError(); forEachNonZero( new cern.colt.function.IntIntDoubleFunction() { public double apply(int i, int j, double value) { if (transposeA) { int tmp=i; i=j; j=tmp; } zElements[zi + zStride*i] += value * yElements[yi + yStride*j]; //z.setQuick(row,z.getQuick(row) + value * y.getQuick(column)); //System.out.println("["+i+","+j+"]-->"+value); return value; } } ); if (alpha!=1) z.assign(cern.jet.math.Functions.mult(alpha)); return z; }
Example 11
Source File: SparseDoubleMatrix2D.java From jAudioGIT with GNU Lesser General Public License v2.1 | 4 votes |
public DoubleMatrix1D zMult(DoubleMatrix1D y, DoubleMatrix1D z, double alpha, double beta, final boolean transposeA) { int m = rows; int n = columns; if (transposeA) { m = columns; n = rows; } boolean ignore = (z==null); if (z==null) z = new DenseDoubleMatrix1D(m); if (!(this.isNoView && y instanceof DenseDoubleMatrix1D && z instanceof DenseDoubleMatrix1D)) { return super.zMult(y,z,alpha,beta,transposeA); } if (n != y.size() || m > z.size()) throw new IllegalArgumentException("Incompatible args: "+ ((transposeA ? viewDice() : this).toStringShort()) +", "+y.toStringShort()+", "+z.toStringShort()); if (!ignore) z.assign(cern.jet.math.Functions.mult(beta/alpha)); DenseDoubleMatrix1D zz = (DenseDoubleMatrix1D) z; final double[] zElements = zz.elements; final int zStride = zz.stride; final int zi = z.index(0); DenseDoubleMatrix1D yy = (DenseDoubleMatrix1D) y; final double[] yElements = yy.elements; final int yStride = yy.stride; final int yi = y.index(0); if (yElements==null || zElements==null) throw new InternalError(); this.elements.forEachPair( new cern.colt.function.IntDoubleProcedure() { public boolean apply(int key, double value) { int i = key/columns; int j = key%columns; if (transposeA) { int tmp=i; i=j; j=tmp; } zElements[zi + zStride*i] += value * yElements[yi + yStride*j]; //System.out.println("["+i+","+j+"]-->"+value); return true; } } ); /* forEachNonZero( new cern.colt.function.IntIntDoubleFunction() { public double apply(int i, int j, double value) { if (transposeA) { int tmp=i; i=j; j=tmp; } zElements[zi + zStride*i] += value * yElements[yi + yStride*j]; //z.setQuick(row,z.getQuick(row) + value * y.getQuick(column)); //System.out.println("["+i+","+j+"]-->"+value); return value; } } ); */ if (alpha!=1) z.assign(cern.jet.math.Functions.mult(alpha)); return z; }
Example 12
Source File: DenseDoubleMatrix2D.java From jAudioGIT with GNU Lesser General Public License v2.1 | 4 votes |
public DoubleMatrix1D zMult(DoubleMatrix1D y, DoubleMatrix1D z, double alpha, double beta, boolean transposeA) { if (transposeA) return viewDice().zMult(y,z,alpha,beta,false); if (z==null) z = new DenseDoubleMatrix1D(this.rows); if (!(y instanceof DenseDoubleMatrix1D && z instanceof DenseDoubleMatrix1D)) return super.zMult(y,z,alpha,beta,transposeA); if (columns != y.size || rows > z.size) throw new IllegalArgumentException("Incompatible args: "+toStringShort()+", "+y.toStringShort()+", "+z.toStringShort()); DenseDoubleMatrix1D yy = (DenseDoubleMatrix1D) y; DenseDoubleMatrix1D zz = (DenseDoubleMatrix1D) z; final double[] AElems = this.elements; final double[] yElems = yy.elements; final double[] zElems = zz.elements; if (AElems==null || yElems==null || zElems==null) throw new InternalError(); int As = this.columnStride; int ys = yy.stride; int zs = zz.stride; int indexA = index(0,0); int indexY = yy.index(0); int indexZ = zz.index(0); int cols = columns; for (int row=rows; --row >= 0; ) { double sum = 0; /* // not loop unrolled for (int i=indexA, j=indexY, column=columns; --column >= 0; ) { sum += AElems[i] * yElems[j]; i += As; j += ys; } */ // loop unrolled int i = indexA - As; int j = indexY - ys; for (int k=cols%4; --k >= 0; ) { sum += AElems[i += As] * yElems[j += ys]; } for (int k=cols/4; --k >= 0; ) { sum += AElems[i += As] * yElems[j += ys] + AElems[i += As] * yElems[j += ys] + AElems[i += As] * yElems[j += ys] + AElems[i += As] * yElems[j += ys]; } zElems[indexZ] = alpha*sum + beta*zElems[indexZ]; indexA += this.rowStride; indexZ += zs; } return z; }