Clover icon

Coverage Report

  1. Project Clover database Thu Aug 13 2020 12:04:21 BST
  2. Package jalview.math

File Matrix.java

 

Coverage histogram

../../img/srcFileCovDistChart6.png
33% of files have more coverage

Code metrics

184
375
32
1
1,025
737
126
0.34
11.72
32
3.94

Classes

Class Line # Actions
Matrix 32 375 126
0.561759756.2%
 

Contributing tests

This file is covered by 32 tests. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
7    * Jalview is free software: you can redistribute it and/or
8    * modify it under the terms of the GNU General Public License
9    * as published by the Free Software Foundation, either version 3
10    * of the License, or (at your option) any later version.
11    *
12    * Jalview is distributed in the hope that it will be useful, but
13    * WITHOUT ANY WARRANTY; without even the implied warranty
14    * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15    * PURPOSE. See the GNU General Public License for more details.
16    *
17    * You should have received a copy of the GNU General Public License
18    * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19    * The Jalview Authors are detailed in the 'AUTHORS' file.
20    */
21    package jalview.math;
22   
23    import jalview.util.Format;
24    import jalview.util.MessageManager;
25   
26    import java.io.PrintStream;
27    import java.util.Arrays;
28   
29    /**
30    * A class to model rectangular matrices of double values and operations on them
31    */
 
32    public class Matrix implements MatrixI
33    {
34    /*
35    * maximum number of iterations for tqli
36    */
37    private static final int MAX_ITER = 45;
38    // fudge - add 15 iterations, just in case
39   
40    /*
41    * the number of rows
42    */
43    final protected int rows;
44   
45    /*
46    * the number of columns
47    */
48    final protected int cols;
49   
50    /*
51    * the cell values in row-major order
52    */
53    private double[][] value;
54   
55    protected double[] d; // Diagonal
56   
57    protected double[] e; // off diagonal
58   
59    /**
60    * Constructor given number of rows and columns
61    *
62    * @param colCount
63    * @param rowCount
64    */
 
65  22 toggle protected Matrix(int rowCount, int colCount)
66    {
67  22 rows = rowCount;
68  22 cols = colCount;
69    }
70   
71    /**
72    * Creates a new Matrix object containing a copy of the supplied array values.
73    * For example
74    *
75    * <pre>
76    * new Matrix(new double[][] {{2, 3, 4}, {5, 6, 7})
77    * constructs
78    * (2 3 4)
79    * (5 6 7)
80    * </pre>
81    *
82    * Note that ragged arrays (with not all rows, or columns, of the same
83    * length), are not supported by this class. They can be constructed, but
84    * results of operations on them are undefined and may throw exceptions.
85    *
86    * @param values
87    * the matrix values in row-major order
88    */
 
89  67 toggle public Matrix(double[][] values)
90    {
91  67 this.rows = values.length;
92  67 this.cols = this.rows == 0 ? 0 : values[0].length;
93   
94    /*
95    * make a copy of the values array, for immutability
96    */
97  67 this.value = new double[rows][];
98  67 int i = 0;
99  67 for (double[] row : values)
100    {
101  1251 if (row != null)
102    {
103  1251 value[i] = new double[row.length];
104  1251 System.arraycopy(row, 0, value[i], 0, row.length);
105    }
106  1251 i++;
107    }
108    }
109   
 
110  0 toggle @Override
111    public MatrixI transpose()
112    {
113  0 double[][] out = new double[cols][rows];
114   
115  0 for (int i = 0; i < cols; i++)
116    {
117  0 for (int j = 0; j < rows; j++)
118    {
119  0 out[i][j] = value[j][i];
120    }
121    }
122   
123  0 return new Matrix(out);
124    }
125   
126    /**
127    * DOCUMENT ME!
128    *
129    * @param ps
130    * DOCUMENT ME!
131    * @param format
132    */
 
133  0 toggle @Override
134    public void print(PrintStream ps, String format)
135    {
136  0 for (int i = 0; i < rows; i++)
137    {
138  0 for (int j = 0; j < cols; j++)
139    {
140  0 Format.print(ps, format, getValue(i, j));
141    }
142   
143  0 ps.println();
144    }
145    }
146   
 
147  10 toggle @Override
148    public MatrixI preMultiply(MatrixI in)
149    {
150  10 if (in.width() != rows)
151    {
152  2 throw new IllegalArgumentException("Can't pre-multiply " + this.rows
153    + " rows by " + in.width() + " columns");
154    }
155  8 double[][] tmp = new double[in.height()][this.cols];
156   
157  22 for (int i = 0; i < in.height(); i++)
158    {
159  48 for (int j = 0; j < this.cols; j++)
160    {
161    /*
162    * result[i][j] is the vector product of
163    * in.row[i] and this.column[j]
164    */
165  86 for (int k = 0; k < in.width(); k++)
166    {
167  52 tmp[i][j] += (in.getValue(i, k) * this.value[k][j]);
168    }
169    }
170    }
171   
172  8 return new Matrix(tmp);
173    }
174   
175    /**
176    *
177    * @param in
178    *
179    * @return
180    */
 
181  0 toggle public double[] vectorPostMultiply(double[] in)
182    {
183  0 double[] out = new double[in.length];
184   
185  0 for (int i = 0; i < in.length; i++)
186    {
187  0 out[i] = 0.0;
188   
189  0 for (int k = 0; k < in.length; k++)
190    {
191  0 out[i] += (value[i][k] * in[k]);
192    }
193    }
194   
195  0 return out;
196    }
197   
 
198  6 toggle @Override
199    public MatrixI postMultiply(MatrixI in)
200    {
201  6 if (in.height() != this.cols)
202    {
203  0 throw new IllegalArgumentException("Can't post-multiply " + this.cols
204    + " columns by " + in.height() + " rows");
205    }
206  6 return in.preMultiply(this);
207    }
208   
 
209  4 toggle @Override
210    public MatrixI copy()
211    {
212  4 double[][] newmat = new double[rows][cols];
213   
214  44 for (int i = 0; i < rows; i++)
215    {
216  40 System.arraycopy(value[i], 0, newmat[i], 0, value[i].length);
217    }
218   
219  4 Matrix m = new Matrix(newmat);
220  4 if (this.d != null)
221    {
222  2 m.d = Arrays.copyOf(this.d, this.d.length);
223    }
224  4 if (this.e != null)
225    {
226  2 m.e = Arrays.copyOf(this.e, this.e.length);
227    }
228   
229  4 return m;
230    }
231   
232    /**
233    * DOCUMENT ME!
234    */
 
235  9 toggle @Override
236    public void tred()
237    {
238  9 int n = rows;
239  9 int k;
240  9 int j;
241  9 int i;
242   
243  9 double scale;
244  9 double hh;
245  9 double h;
246  9 double g;
247  9 double f;
248   
249  9 this.d = new double[rows];
250  9 this.e = new double[rows];
251   
252  87 for (i = n; i >= 2; i--)
253    {
254  78 final int l = i - 1;
255  78 h = 0.0;
256  78 scale = 0.0;
257   
258  78 if (l > 1)
259    {
260  465 for (k = 1; k <= l; k++)
261    {
262  396 double v = Math.abs(getValue(i - 1, k - 1));
263  396 scale += v;
264    }
265   
266  69 if (scale == 0.0)
267    {
268  0 e[i - 1] = getValue(i - 1, l - 1);
269    }
270    else
271    {
272  465 for (k = 1; k <= l; k++)
273    {
274  396 double v = divideValue(i - 1, k - 1, scale);
275  396 h += v * v;
276    }
277   
278  69 f = getValue(i - 1, l - 1);
279   
280  69 if (f > 0)
281    {
282  26 g = -1.0 * Math.sqrt(h);
283    }
284    else
285    {
286  43 g = Math.sqrt(h);
287    }
288   
289  69 e[i - 1] = scale * g;
290  69 h -= (f * g);
291  69 setValue(i - 1, l - 1, f - g);
292  69 f = 0.0;
293   
294  465 for (j = 1; j <= l; j++)
295    {
296  396 double val = getValue(i - 1, j - 1) / h;
297  396 setValue(j - 1, i - 1, val);
298  396 g = 0.0;
299   
300  2007 for (k = 1; k <= j; k++)
301    {
302  1611 g += (getValue(j - 1, k - 1) * getValue(i - 1, k - 1));
303    }
304   
305  1611 for (k = j + 1; k <= l; k++)
306    {
307  1215 g += (getValue(k - 1, j - 1) * getValue(i - 1, k - 1));
308    }
309   
310  396 e[j - 1] = g / h;
311  396 f += (e[j - 1] * getValue(i - 1, j - 1));
312    }
313   
314  69 hh = f / (h + h);
315   
316  465 for (j = 1; j <= l; j++)
317    {
318  396 f = getValue(i - 1, j - 1);
319  396 g = e[j - 1] - (hh * f);
320  396 e[j - 1] = g;
321   
322  2007 for (k = 1; k <= j; k++)
323    {
324  1611 double val = (f * e[k - 1]) + (g * getValue(i - 1, k - 1));
325  1611 addValue(j - 1, k - 1, -val);
326    }
327    }
328    }
329    }
330    else
331    {
332  9 e[i - 1] = getValue(i - 1, l - 1);
333    }
334   
335  78 d[i - 1] = h;
336    }
337   
338  9 d[0] = 0.0;
339  9 e[0] = 0.0;
340   
341  96 for (i = 1; i <= n; i++)
342    {
343  87 final int l = i - 1;
344   
345  87 if (d[i - 1] != 0.0)
346    {
347  465 for (j = 1; j <= l; j++)
348    {
349  396 g = 0.0;
350   
351  3222 for (k = 1; k <= l; k++)
352    {
353  2826 g += (getValue(i - 1, k - 1) * getValue(k - 1, j - 1));
354    }
355   
356  3222 for (k = 1; k <= l; k++)
357    {
358  2826 addValue(k - 1, j - 1, -(g * getValue(k - 1, i - 1)));
359    }
360    }
361    }
362   
363  87 d[i - 1] = getValue(i - 1, i - 1);
364  87 setValue(i - 1, i - 1, 1.0);
365   
366  492 for (j = 1; j <= l; j++)
367    {
368  405 setValue(j - 1, i - 1, 0.0);
369  405 setValue(i - 1, j - 1, 0.0);
370    }
371    }
372    }
373   
374    /**
375    * Adds f to the value at [i, j] and returns the new value
376    *
377    * @param i
378    * @param j
379    * @param f
380    */
 
381  3005 toggle protected double addValue(int i, int j, double f)
382    {
383  3005 double v = value[i][j] + f;
384  3005 value[i][j] = v;
385  3005 return v;
386    }
387   
388    /**
389    * Divides the value at [i, j] by divisor and returns the new value. If d is
390    * zero, returns the unchanged value.
391    *
392    * @param i
393    * @param j
394    * @param divisor
395    * @return
396    */
 
397  250 toggle protected double divideValue(int i, int j, double divisor)
398    {
399  250 if (divisor == 0d)
400    {
401  0 return getValue(i, j);
402    }
403  250 double v = value[i][j];
404  250 v = v / divisor;
405  250 value[i][j] = v;
406  250 return v;
407    }
408   
409    /**
410    * DOCUMENT ME!
411    */
 
412  3 toggle @Override
413    public void tqli() throws Exception
414    {
415  3 int n = rows;
416   
417  3 int m;
418  3 int l;
419  3 int iter;
420  3 int i;
421  3 int k;
422  3 double s;
423  3 double r;
424  3 double p;
425   
426  3 double g;
427  3 double f;
428  3 double dd;
429  3 double c;
430  3 double b;
431   
432  27 for (i = 2; i <= n; i++)
433    {
434  24 e[i - 2] = e[i - 1];
435    }
436   
437  3 e[n - 1] = 0.0;
438   
439  30 for (l = 1; l <= n; l++)
440    {
441  27 iter = 0;
442   
443  27 do
444    {
445  371 for (m = l; m <= (n - 1); m++)
446    {
447  325 dd = Math.abs(d[m - 1]) + Math.abs(d[m]);
448   
449  325 if ((Math.abs(e[m - 1]) + dd) == dd)
450    {
451  27 break;
452    }
453    }
454   
455  73 if (m != l)
456    {
457  46 iter++;
458   
459  46 if (iter == MAX_ITER)
460    {
461  0 throw new Exception(MessageManager.formatMessage(
462    "exception.matrix_too_many_iteration", new String[]
463    { "tqli", Integer.valueOf(MAX_ITER).toString() }));
464    }
465    else
466    {
467    // System.out.println("Iteration " + iter);
468    }
469   
470  46 g = (d[l] - d[l - 1]) / (2.0 * e[l - 1]);
471  46 r = Math.sqrt((g * g) + 1.0);
472  46 g = d[m - 1] - d[l - 1] + (e[l - 1] / (g + sign(r, g)));
473  46 c = 1.0;
474  46 s = c;
475  46 p = 0.0;
476   
477  344 for (i = m - 1; i >= l; i--)
478    {
479  298 f = s * e[i - 1];
480  298 b = c * e[i - 1];
481   
482  298 if (Math.abs(f) >= Math.abs(g))
483    {
484  34 c = g / f;
485  34 r = Math.sqrt((c * c) + 1.0);
486  34 e[i] = f * r;
487  34 s = 1.0 / r;
488  34 c *= s;
489    }
490    else
491    {
492  264 s = f / g;
493  264 r = Math.sqrt((s * s) + 1.0);
494  264 e[i] = g * r;
495  264 c = 1.0 / r;
496  264 s *= c;
497    }
498   
499  298 g = d[i] - p;
500  298 r = ((d[i - 1] - g) * s) + (2.0 * c * b);
501  298 p = s * r;
502  298 d[i] = g + p;
503  298 g = (c * r) - b;
504   
505  4228 for (k = 1; k <= n; k++)
506    {
507  3930 f = getValue(k - 1, i);
508  3930 setValue(k - 1, i, (s * getValue(k - 1, i - 1)) + (c * f));
509  3930 setValue(k - 1, i - 1,
510    (c * getValue(k - 1, i - 1)) - (s * f));
511    }
512    }
513   
514  46 d[l - 1] = d[l - 1] - p;
515  46 e[l - 1] = g;
516  46 e[m - 1] = 0.0;
517    }
518  73 } while (m != l);
519    }
520    }
521   
 
522  26000 toggle @Override
523    public double getValue(int i, int j)
524    {
525  26000 return value[i][j];
526    }
527   
 
528  8352 toggle @Override
529    public void setValue(int i, int j, double val)
530    {
531  8352 value[i][j] = val;
532    }
533   
534    /**
535    * DOCUMENT ME!
536    */
 
537  0 toggle public void tred2()
538    {
539  0 int n = rows;
540  0 int l;
541  0 int k;
542  0 int j;
543  0 int i;
544   
545  0 double scale;
546  0 double hh;
547  0 double h;
548  0 double g;
549  0 double f;
550   
551  0 this.d = new double[rows];
552  0 this.e = new double[rows];
553   
554  0 for (i = n - 1; i >= 1; i--)
555    {
556  0 l = i - 1;
557  0 h = 0.0;
558  0 scale = 0.0;
559   
560  0 if (l > 0)
561    {
562  0 for (k = 0; k < l; k++)
563    {
564  0 scale += Math.abs(value[i][k]);
565    }
566   
567  0 if (scale == 0.0)
568    {
569  0 e[i] = value[i][l];
570    }
571    else
572    {
573  0 for (k = 0; k < l; k++)
574    {
575  0 value[i][k] /= scale;
576  0 h += (value[i][k] * value[i][k]);
577    }
578   
579  0 f = value[i][l];
580   
581  0 if (f > 0)
582    {
583  0 g = -1.0 * Math.sqrt(h);
584    }
585    else
586    {
587  0 g = Math.sqrt(h);
588    }
589   
590  0 e[i] = scale * g;
591  0 h -= (f * g);
592  0 value[i][l] = f - g;
593  0 f = 0.0;
594   
595  0 for (j = 0; j < l; j++)
596    {
597  0 value[j][i] = value[i][j] / h;
598  0 g = 0.0;
599   
600  0 for (k = 0; k < j; k++)
601    {
602  0 g += (value[j][k] * value[i][k]);
603    }
604   
605  0 for (k = j; k < l; k++)
606    {
607  0 g += (value[k][j] * value[i][k]);
608    }
609   
610  0 e[j] = g / h;
611  0 f += (e[j] * value[i][j]);
612    }
613   
614  0 hh = f / (h + h);
615   
616  0 for (j = 0; j < l; j++)
617    {
618  0 f = value[i][j];
619  0 g = e[j] - (hh * f);
620  0 e[j] = g;
621   
622  0 for (k = 0; k < j; k++)
623    {
624  0 value[j][k] -= ((f * e[k]) + (g * value[i][k]));
625    }
626    }
627    }
628    }
629    else
630    {
631  0 e[i] = value[i][l];
632    }
633   
634  0 d[i] = h;
635    }
636   
637  0 d[0] = 0.0;
638  0 e[0] = 0.0;
639   
640  0 for (i = 0; i < n; i++)
641    {
642  0 l = i - 1;
643   
644  0 if (d[i] != 0.0)
645    {
646  0 for (j = 0; j < l; j++)
647    {
648  0 g = 0.0;
649   
650  0 for (k = 0; k < l; k++)
651    {
652  0 g += (value[i][k] * value[k][j]);
653    }
654   
655  0 for (k = 0; k < l; k++)
656    {
657  0 value[k][j] -= (g * value[k][i]);
658    }
659    }
660    }
661   
662  0 d[i] = value[i][i];
663  0 value[i][i] = 1.0;
664   
665  0 for (j = 0; j < l; j++)
666    {
667  0 value[j][i] = 0.0;
668  0 value[i][j] = 0.0;
669    }
670    }
671    }
672   
673    /**
674    * DOCUMENT ME!
675    */
 
676  0 toggle public void tqli2() throws Exception
677    {
678  0 int n = rows;
679   
680  0 int m;
681  0 int l;
682  0 int iter;
683  0 int i;
684  0 int k;
685  0 double s;
686  0 double r;
687  0 double p;
688  0 ;
689   
690  0 double g;
691  0 double f;
692  0 double dd;
693  0 double c;
694  0 double b;
695   
696  0 for (i = 2; i <= n; i++)
697    {
698  0 e[i - 2] = e[i - 1];
699    }
700   
701  0 e[n - 1] = 0.0;
702   
703  0 for (l = 1; l <= n; l++)
704    {
705  0 iter = 0;
706   
707  0 do
708    {
709  0 for (m = l; m <= (n - 1); m++)
710    {
711  0 dd = Math.abs(d[m - 1]) + Math.abs(d[m]);
712   
713  0 if ((Math.abs(e[m - 1]) + dd) == dd)
714    {
715  0 break;
716    }
717    }
718   
719  0 if (m != l)
720    {
721  0 iter++;
722   
723  0 if (iter == MAX_ITER)
724    {
725  0 throw new Exception(MessageManager.formatMessage(
726    "exception.matrix_too_many_iteration", new String[]
727    { "tqli2", Integer.valueOf(MAX_ITER).toString() }));
728    }
729    else
730    {
731    // System.out.println("Iteration " + iter);
732    }
733   
734  0 g = (d[l] - d[l - 1]) / (2.0 * e[l - 1]);
735  0 r = Math.sqrt((g * g) + 1.0);
736  0 g = d[m - 1] - d[l - 1] + (e[l - 1] / (g + sign(r, g)));
737  0 c = 1.0;
738  0 s = c;
739  0 p = 0.0;
740   
741  0 for (i = m - 1; i >= l; i--)
742    {
743  0 f = s * e[i - 1];
744  0 b = c * e[i - 1];
745   
746  0 if (Math.abs(f) >= Math.abs(g))
747    {
748  0 c = g / f;
749  0 r = Math.sqrt((c * c) + 1.0);
750  0 e[i] = f * r;
751  0 s = 1.0 / r;
752  0 c *= s;
753    }
754    else
755    {
756  0 s = f / g;
757  0 r = Math.sqrt((s * s) + 1.0);
758  0 e[i] = g * r;
759  0 c = 1.0 / r;
760  0 s *= c;
761    }
762   
763  0 g = d[i] - p;
764  0 r = ((d[i - 1] - g) * s) + (2.0 * c * b);
765  0 p = s * r;
766  0 d[i] = g + p;
767  0 g = (c * r) - b;
768   
769  0 for (k = 1; k <= n; k++)
770    {
771  0 f = value[k - 1][i];
772  0 value[k - 1][i] = (s * value[k - 1][i - 1]) + (c * f);
773  0 value[k - 1][i - 1] = (c * value[k - 1][i - 1]) - (s * f);
774    }
775    }
776   
777  0 d[l - 1] = d[l - 1] - p;
778  0 e[l - 1] = g;
779  0 e[m - 1] = 0.0;
780    }
781  0 } while (m != l);
782    }
783    }
784   
785    /**
786    * Answers the first argument with the sign of the second argument
787    *
788    * @param a
789    * @param b
790    *
791    * @return
792    */
 
793  46 toggle static double sign(double a, double b)
794    {
795  46 if (b < 0)
796    {
797  12 return -Math.abs(a);
798    }
799    else
800    {
801  34 return Math.abs(a);
802    }
803    }
804   
805    /**
806    * Returns an array containing the values in the specified column
807    *
808    * @param col
809    *
810    * @return
811    */
 
812  0 toggle public double[] getColumn(int col)
813    {
814  0 double[] out = new double[rows];
815   
816  0 for (int i = 0; i < rows; i++)
817    {
818  0 out[i] = value[i][col];
819    }
820   
821  0 return out;
822    }
823   
824    /**
825    * DOCUMENT ME!
826    *
827    * @param ps
828    * DOCUMENT ME!
829    * @param format
830    */
 
831  0 toggle @Override
832    public void printD(PrintStream ps, String format)
833    {
834  0 for (int j = 0; j < rows; j++)
835    {
836  0 Format.print(ps, format, d[j]);
837    }
838    }
839   
840    /**
841    * DOCUMENT ME!
842    *
843    * @param ps
844    * DOCUMENT ME!
845    * @param format
846    * TODO
847    */
 
848  0 toggle @Override
849    public void printE(PrintStream ps, String format)
850    {
851  0 for (int j = 0; j < rows; j++)
852    {
853  0 Format.print(ps, format, e[j]);
854    }
855    }
856   
 
857  72 toggle @Override
858    public double[] getD()
859    {
860  72 return d;
861    }
862   
 
863  27 toggle @Override
864    public double[] getE()
865    {
866  27 return e;
867    }
868   
 
869  346 toggle @Override
870    public int height()
871    {
872  346 return rows;
873    }
874   
 
875  2450 toggle @Override
876    public int width()
877    {
878  2450 return cols;
879    }
880   
 
881  26 toggle @Override
882    public double[] getRow(int i)
883    {
884  26 double[] row = new double[cols];
885  26 System.arraycopy(value[i], 0, row, 0, cols);
886  26 return row;
887    }
888   
889    /**
890    * Returns a length 2 array of {minValue, maxValue} of all values in the
891    * matrix. Returns null if the matrix is null or empty.
892    *
893    * @return
894    */
 
895  7 toggle double[] findMinMax()
896    {
897  7 if (value == null)
898    {
899  0 return null;
900    }
901  7 double min = Double.MAX_VALUE;
902  7 double max = -Double.MAX_VALUE;
903  7 boolean empty = true;
904  7 for (double[] row : value)
905    {
906  1011 if (row != null)
907    {
908  1011 for (double x : row)
909    {
910  1000030 empty = false;
911  1000030 if (x > max)
912    {
913  29 max = x;
914    }
915  1000030 if (x < min)
916    {
917  27 min = x;
918    }
919    }
920    }
921    }
922  7 return empty ? null : new double[] { min, max };
923    }
924   
925    /**
926    * {@inheritDoc}
927    */
 
928  4 toggle @Override
929    public void reverseRange(boolean maxToZero)
930    {
931  4 if (value == null)
932    {
933  0 return;
934    }
935  4 double[] minMax = findMinMax();
936  4 if (minMax == null)
937    {
938  0 return; // empty matrix
939    }
940  4 double subtractFrom = maxToZero ? minMax[1] : minMax[0] + minMax[1];
941   
942  4 for (double[] row : value)
943    {
944  8 if (row != null)
945    {
946  8 int j = 0;
947  8 for (double x : row)
948    {
949  24 row[j] = subtractFrom - x;
950  24 j++;
951    }
952    }
953    }
954    }
955   
956    /**
957    * Multiplies every entry in the matrix by the given value.
958    *
959    * @param
960    */
 
961  1 toggle @Override
962    public void multiply(double by)
963    {
964  1 for (double[] row : value)
965    {
966  2 if (row != null)
967    {
968  8 for (int i = 0; i < row.length; i++)
969    {
970  6 row[i] *= by;
971    }
972    }
973    }
974    }
975   
 
976  2 toggle @Override
977    public void setD(double[] v)
978    {
979  2 d = v;
980    }
981   
 
982  2 toggle @Override
983    public void setE(double[] v)
984    {
985  2 e = v;
986    }
987   
 
988  0 toggle public double getTotal()
989    {
990  0 double d = 0d;
991  0 for (int i = 0; i < this.height(); i++)
992    {
993  0 for (int j = 0; j < this.width(); j++)
994    {
995  0 d += value[i][j];
996    }
997    }
998  0 return d;
999    }
1000   
1001    /**
1002    * {@inheritDoc}
1003    */
 
1004  12 toggle @Override
1005    public boolean equals(MatrixI m2, double delta)
1006    {
1007  12 if (m2 == null || this.height() != m2.height()
1008    || this.width() != m2.width())
1009    {
1010  2 return false;
1011    }
1012  27 for (int i = 0; i < this.height(); i++)
1013    {
1014  66 for (int j = 0; j < this.width(); j++)
1015    {
1016  49 double diff = this.getValue(i, j) - m2.getValue(i, j);
1017  49 if (Math.abs(diff) > delta)
1018    {
1019  3 return false;
1020    }
1021    }
1022    }
1023  7 return true;
1024    }
1025    }