Java Code Examples for cern.colt.matrix.DoubleMatrix2D#assign()
The following examples show how to use
cern.colt.matrix.DoubleMatrix2D#assign() .
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: TestMatrix2D.java From database with GNU General Public License v2.0 | 6 votes |
/** */ public static void doubleTest14(int r1, int c, int r2) { double[] values = {0, 1, 2, 3}; DoubleMatrix2D a = DoubleFactory2D.dense.ascending(r1,c); DoubleMatrix2D b = Transform.mult(DoubleFactory2D.dense.ascending(c,r2), -1); //System.out.println(a); //System.out.println(b); //System.out.println(Basic.product(a,b)); a.assign(0); b.assign(0); cern.colt.Timer timer = new cern.colt.Timer().start(); LinearAlgebra.mult(a,b); timer.stop().display(); }
Example 2
Source File: TestMatrix2D.java From database with GNU General Public License v2.0 | 6 votes |
/** */ public static void doubleTest() { int rows = 4; int columns = 5; // make a 4*5 matrix DoubleMatrix2D master = new DenseDoubleMatrix2D(rows,columns); System.out.println(master); master.assign(1); // set all cells to 1 System.out.println("\n"+master); master.viewPart(2,1,2,3).assign(2); // set [2,1] .. [3,3] to 2 System.out.println("\n"+master); DoubleMatrix2D copyPart = master.viewPart(2,1,2,3).copy(); copyPart.assign(3); // modify an independent copy copyPart.set(0,0,4); System.out.println("\n"+copyPart); // has changed System.out.println("\n"+master); // master has not changed DoubleMatrix2D view1 = master.viewPart(0,3,4,2); // [0,3] .. [3,4] DoubleMatrix2D view2 = view1.viewPart(0,0,4,1); // a view from a view System.out.println("\n"+view1); System.out.println("\n"+view2); }
Example 3
Source File: TestMatrix2D.java From database with GNU General Public License v2.0 | 6 votes |
/** */ public static void doubleTest7() { int rows = 4; int columns = 5; // make a 4*5 matrix DoubleMatrix2D master = Factory2D.ascending(rows,columns); //master.assign(1); // set all cells to 1 System.out.println("\n"+master); //master.viewPart(2,0,2,3).assign(2); // set [2,1] .. [3,3] to 2 //System.out.println("\n"+master); int[] rowIndexes = {0,1,3,0}; int[] columnIndexes = {0,2}; DoubleMatrix2D view1 = master.viewSelection(rowIndexes,columnIndexes); System.out.println("view1="+view1); DoubleMatrix2D view2 = view1.viewPart(0,0,2,2); System.out.println("view2="+view2); view2.assign(-1); System.out.println("master replaced"+master); System.out.println("flip1 replaced"+view1); System.out.println("flip2 replaced"+view2); }
Example 4
Source File: BenchmarkMatrix.java From database with GNU General Public License v2.0 | 6 votes |
/** * 2D assign with getQuick,setQuick */ protected static Double2DProcedure funLUSolve() { return new Double2DProcedure() { cern.colt.matrix.linalg.LUDecompositionQuick lu; public String toString() { return "LU.solve(A) [Mflops/sec]"; } public void setParameters(DoubleMatrix2D A, DoubleMatrix2D B) { lu = null; if (!cern.colt.matrix.linalg.Property.ZERO.isDiagonallyDominantByRow(A) || !cern.colt.matrix.linalg.Property.ZERO.isDiagonallyDominantByColumn(A)) { cern.colt.matrix.linalg.Property.ZERO.generateNonSingular(A); } super.setParameters(A,B); lu = new cern.colt.matrix.linalg.LUDecompositionQuick(0); lu.decompose(A); } public void init() { B.assign(D); } public void apply(cern.colt.Timer timer) { lu.solve(B); } public double operations() { // Mflops double n = A.columns(); double nx = B.columns(); return (2.0 * nx*(n*n + n) / 1.0E6); } }; }
Example 5
Source File: TestMatrix2D.java From jAudioGIT with GNU Lesser General Public License v2.1 | 5 votes |
/** */ public static void doubleTest10() { int rows = 6; int columns = 7; // make a 4*5 matrix //DoubleMatrix2D master = new DenseDoubleMatrix2D(rows,columns); DoubleMatrix2D master = Factory2D.ascending(rows,columns); //Basic.ascending(master); //master.assign(1); // set all cells to 1 Transform.mult(master,Math.sin(0.3)); System.out.println("\n"+master); //master.viewPart(2,0,2,3).assign(2); // set [2,1] .. [3,3] to 2 //System.out.println("\n"+master); int[] rowIndexes = {0,1,2,3}; int[] columnIndexes = {0,1,2,3}; int[] rowIndexes2 = {3,0,3}; int[] columnIndexes2 = {3,0,3}; DoubleMatrix2D view1 = master.viewPart(1,1,4,5).viewSelection(rowIndexes,columnIndexes); System.out.println("\nview1="+view1); DoubleMatrix2D view9 = view1.viewStrides(2,2).viewStrides(2,1); System.out.println("\nview9="+view9); view1 = view1.viewSelection(rowIndexes2,columnIndexes2); System.out.println("\nview1="+view1); DoubleMatrix2D view2 = view1.viewPart(1,1,2,2); System.out.println("\nview2="+view2); DoubleMatrix2D view3 = view2.viewRowFlip(); System.out.println("\nview3="+view3); view3.assign(Factory2D.ascending(view3.rows(),view3.columns())); //Basic.ascending(view3); System.out.println("\nview3="+view3); //view2.assign(-1); System.out.println("\nmaster replaced"+master); System.out.println("\nview1 replaced"+view1); System.out.println("\nview2 replaced"+view2); System.out.println("\nview3 replaced"+view3); }
Example 6
Source File: TestMatrix2D.java From jAudioGIT with GNU Lesser General Public License v2.1 | 5 votes |
/** */ public static void doubleTest4() { int rows = 4; int columns = 5; // make a 4*5 matrix DoubleMatrix2D master = new DenseDoubleMatrix2D(rows,columns); System.out.println(master); master.assign(1); // set all cells to 1 DoubleMatrix2D view = master.viewPart(2,0,2,3).assign(2); System.out.println("\n"+master); System.out.println("\n"+view); Transform.mult(view,3); System.out.println("\n"+master); System.out.println("\n"+view); /* DoubleMatrix2D copyPart = master.copyPart(2,1,2,3); copyPart.assign(3); // modify an independent copy copyPart.set(0,0,4); System.out.println("\n"+copyPart); // has changed System.out.println("\n"+master); // master has not changed DoubleMatrix2D view1 = master.viewPart(0,3,4,2); // [0,3] .. [3,4] DoubleMatrix2D view2 = view1.viewPart(0,0,4,1); // a view from a view System.out.println("\n"+view1); System.out.println("\n"+view2); */ }
Example 7
Source File: TestMatrix2D.java From database with GNU General Public License v2.0 | 5 votes |
/** */ public static void doubleTest10() { int rows = 6; int columns = 7; // make a 4*5 matrix //DoubleMatrix2D master = new DenseDoubleMatrix2D(rows,columns); DoubleMatrix2D master = Factory2D.ascending(rows,columns); //Basic.ascending(master); //master.assign(1); // set all cells to 1 Transform.mult(master,Math.sin(0.3)); System.out.println("\n"+master); //master.viewPart(2,0,2,3).assign(2); // set [2,1] .. [3,3] to 2 //System.out.println("\n"+master); int[] rowIndexes = {0,1,2,3}; int[] columnIndexes = {0,1,2,3}; int[] rowIndexes2 = {3,0,3}; int[] columnIndexes2 = {3,0,3}; DoubleMatrix2D view1 = master.viewPart(1,1,4,5).viewSelection(rowIndexes,columnIndexes); System.out.println("\nview1="+view1); DoubleMatrix2D view9 = view1.viewStrides(2,2).viewStrides(2,1); System.out.println("\nview9="+view9); view1 = view1.viewSelection(rowIndexes2,columnIndexes2); System.out.println("\nview1="+view1); DoubleMatrix2D view2 = view1.viewPart(1,1,2,2); System.out.println("\nview2="+view2); DoubleMatrix2D view3 = view2.viewRowFlip(); System.out.println("\nview3="+view3); view3.assign(Factory2D.ascending(view3.rows(),view3.columns())); //Basic.ascending(view3); System.out.println("\nview3="+view3); //view2.assign(-1); System.out.println("\nmaster replaced"+master); System.out.println("\nview1 replaced"+view1); System.out.println("\nview2 replaced"+view2); System.out.println("\nview3 replaced"+view3); }
Example 8
Source File: SeqBlas.java From jAudioGIT with GNU Lesser General Public License v2.1 | 4 votes |
public void assign(DoubleMatrix2D A, DoubleMatrix2D B, cern.colt.function.DoubleDoubleFunction function) { A.assign(B,function); }
Example 9
Source File: TestMatrix2D.java From jAudioGIT with GNU Lesser General Public License v2.1 | 4 votes |
/** */ public static void testLU() { double[][] vals = { {-0.074683, 0.321248,-0.014656, 0.286586,0}, {-0.344852, -0.16278 , 0.173711, 0.00064 ,0}, {-0.181924, -0.092926, 0.184153, 0.177966,1}, {-0.166829, -0.10321 , 0.582301, 0.142583,0}, { 0 , -0.112952,-0.04932 ,-0.700157,0}, { 0 , 0 ,0 ,0 ,0} }; DoubleMatrix2D H = new DenseDoubleMatrix2D( vals ); // see values below... System.out.println("\nHplus="+H.viewDice().zMult(H,null)); DoubleMatrix2D Hplus = Algebra.DEFAULT.inverse(H.viewDice().zMult( H,null )).zMult(H.viewDice(),null); Hplus.assign(cern.jet.math.Functions.round(1.0E-10)); System.out.println("\nHplus="+Hplus); /* DoubleMatrix2D HtH = new DenseDoubleMatrix2D( 5, 5 ); DoubleMatrix2D Hplus = new DenseDoubleMatrix2D( 5, 6 ); LUDecompositionQuick LUD = new LUDecompositionQuick(); //H.zMult( H, HtH, 1, 0, true, false ); //DoubleMatrix2D res = Algebra.DEFAULT.inverse(HtH).zMult(H,null,1,0,false,true); LUD.decompose( HtH ); // first fill Hplus with the transpose of H... for (int i = 0; i < 6; i++ ) { for ( int j = 0; j < 5; j++ ) { Hplus.set( j, i, H.get( i, j ) ); } } LUD.solve( Hplus ); DoubleMatrix2D perm = Algebra.DEFAULT.permute(Hplus, null,LUD.getPivot()); DoubleMatrix2D inv = Algebra.DEFAULT.inverse(HtH);//.zMult(H,null,1,0,false,true); */ // in matlab... // Hplus = inv(H' * H) * H' //System.out.println("\nLU="+LUD); //System.out.println("\nHplus="+Hplus); //System.out.println("\nperm="+perm); //System.out.println("\ninv="+inv); //System.out.println("\nres="+res); }
Example 10
Source File: BenchmarkMatrix2D.java From database with GNU General Public License v2.0 | 4 votes |
/** * Runs a bench on matrices holding double elements. */ public static void doubleBenchmarkMult(int runs, int rows, int columns, String kind, boolean print, int initialCapacity, double minLoadFactor, double maxLoadFactor) { System.out.println("benchmarking double matrix"); // certain loops need to be constructed so that the jitter can't optimize them away and we get fantastic numbers. // this involves primarly read-loops cern.colt.Timer timer1 = new cern.colt.Timer(); cern.colt.Timer timer2 = new cern.colt.Timer(); long size = (((long)rows)*columns)*runs; DoubleMatrix2D matrix = null; if (kind.equals("sparse")) matrix = new SparseDoubleMatrix2D(rows,columns,initialCapacity,minLoadFactor,maxLoadFactor); else if (kind.equals("dense")) matrix = new DenseDoubleMatrix2D(rows,columns); //else if (kind.equals("denseArray")) matrix = new DoubleArrayMatrix2D(rows,columns); else throw new RuntimeException("unknown kind"); System.out.println("\nNow multiplying..."); matrix.assign(1); //if (kind.equals("sparse")) ((SparseDoubleMatrix2D)matrix).elements.hashCollisions = 0; for (int i=0; i<runs; i++) { timer1.start(); cern.colt.matrix.doublealgo.Transform.mult(matrix, 3); timer1.stop(); } timer1.display(); System.out.println(size / timer1.seconds() +" elements / sec"); if (print) { System.out.println(matrix); } /* if (kind.equals("sparse")) { int hashCollisions = ((SparseDoubleMatrix2D)matrix).elements.hashCollisions; System.out.println("hashCollisions="+hashCollisions); System.out.println("--> "+ ((double)hashCollisions / (rows*columns)) +" hashCollisions/element on average."); } */ System.out.println("\nNow multiplying2..."); matrix.assign(1); //if (kind.equals("sparse")) ((SparseDoubleMatrix2D)matrix).elements.hashCollisions = 0; for (int i=0; i<runs; i++) { timer2.start(); cern.colt.matrix.doublealgo.Transform.mult(matrix,3); timer2.stop(); } timer2.display(); System.out.println(size / timer2.seconds() +" elements / sec"); if (print) { System.out.println(matrix); } /* if (kind.equals("sparse")) { int hashCollisions = ((SparseDoubleMatrix2D)matrix).elements.hashCollisions; System.out.println("hashCollisions="+hashCollisions); System.out.println("--> "+ ((double)hashCollisions / (rows*columns)) +" hashCollisions/element on average."); } */ System.out.println("bye bye."); }
Example 11
Source File: Transform.java From jAudioGIT with GNU Lesser General Public License v2.1 | 2 votes |
/** * <tt>A = A + s <=> A[row,col] = A[row,col] + s</tt>. * @param A the matrix to modify. * @param s the scalar; can have any value. * @return <tt>A</tt> (for convenience only). */ public static DoubleMatrix2D plus(DoubleMatrix2D A, double s) { return A.assign(F.plus(s)); }
Example 12
Source File: Transform.java From database with GNU General Public License v2.0 | 2 votes |
/** * <tt>A = A<sup>B</sup> <=> A[row,col] = Math.pow(A[row,col], B[row,col])</tt>. * @param A the matrix to modify. * @param B the matrix to stay unaffected. * @return <tt>A</tt> (for convenience only). */ public static DoubleMatrix2D pow(DoubleMatrix2D A, DoubleMatrix2D B) { return A.assign(B,F.pow); }
Example 13
Source File: Transform.java From jAudioGIT with GNU Lesser General Public License v2.1 | 2 votes |
/** * <tt>A[row,col] = Math.abs(A[row,col])</tt>. * @param A the matrix to modify. * @return <tt>A</tt> (for convenience only). */ public static DoubleMatrix2D abs(DoubleMatrix2D A) { return A.assign(F.abs); }
Example 14
Source File: Transform.java From jAudioGIT with GNU Lesser General Public License v2.1 | 2 votes |
/** * <tt>A[row,col] = A[row,col] < s ? 1 : 0</tt>. * @param A the matrix to modify. * @param s the scalar; can have any value. * @return <tt>A</tt> (for convenience only). */ public static DoubleMatrix2D less(DoubleMatrix2D A, double s) { return A.assign(F.less(s)); }
Example 15
Source File: Transform.java From jAudioGIT with GNU Lesser General Public License v2.1 | 2 votes |
/** * <tt>A = A - B*s <=> A[row,col] = A[row,col] - B[row,col]*s</tt>. * @param A the matrix to modify. * @param B the matrix to stay unaffected. * @param s the scalar; can have any value. * @return <tt>A</tt> (for convenience only). */ public static DoubleMatrix2D minusMult(DoubleMatrix2D A, DoubleMatrix2D B, double s) { return A.assign(B,F.minusMult(s)); }
Example 16
Source File: Transform.java From database with GNU General Public License v2.0 | 2 votes |
/** * <tt>A = A - B <=> A[row,col] = A[row,col] - B[row,col]</tt>. * @param A the matrix to modify. * @param B the matrix to stay unaffected. * @return <tt>A</tt> (for convenience only). */ public static DoubleMatrix2D minus(DoubleMatrix2D A, DoubleMatrix2D B) { return A.assign(B,F.minus); }
Example 17
Source File: Transform.java From jAudioGIT with GNU Lesser General Public License v2.1 | 2 votes |
/** * <tt>A = A / B <=> A[row,col] = A[row,col] / B[row,col]</tt>. * @param A the matrix to modify. * @param B the matrix to stay unaffected. * @return <tt>A</tt> (for convenience only). */ public static DoubleMatrix2D div(DoubleMatrix2D A, DoubleMatrix2D B) { return A.assign(B,F.div); }
Example 18
Source File: Transform.java From database with GNU General Public License v2.0 | 2 votes |
/** * <tt>A[row,col] = A[row,col] > B[row,col] ? 1 : 0</tt>. * @param A the matrix to modify. * @param B the matrix to stay unaffected. * @return <tt>A</tt> (for convenience only). */ public static DoubleMatrix2D greater(DoubleMatrix2D A, DoubleMatrix2D B) { return A.assign(B,F.greater); }
Example 19
Source File: Transform.java From database with GNU General Public License v2.0 | 2 votes |
/** * <tt>A[row,col] = A[row,col] > s ? 1 : 0</tt>. * @param A the matrix to modify. * @param s the scalar; can have any value. * @return <tt>A</tt> (for convenience only). */ public static DoubleMatrix2D greater(DoubleMatrix2D A, double s) { return A.assign(F.greater(s)); }
Example 20
Source File: Transform.java From jAudioGIT with GNU Lesser General Public License v2.1 | 2 votes |
/** * <tt>A[row,col] = A[row,col] > B[row,col] ? 1 : 0</tt>. * @param A the matrix to modify. * @param B the matrix to stay unaffected. * @return <tt>A</tt> (for convenience only). */ public static DoubleMatrix2D greater(DoubleMatrix2D A, DoubleMatrix2D B) { return A.assign(B,F.greater); }