public static DoubleMatrix multiply ( DoubleMatrix m1 , DoubleMatrix m2 ) { if ( m1 . cols != m2 . rows ) { throw new IllegalArgumentException ( "Matrices not comfortable" ) ; } int m = m1 . rows ; int n = m1 . cols ; int p = m2 . cols ; ItemSupplier s1 = m1 . supplier ; ItemSupplier s2 = m2 . supplier ; DoubleMatrix mr = DoubleMatrix . getInstance ( m , p ) ; ItemConsumer c = mr . consumer ; for ( int i = 0 ; i < m ; i ++ ) { for ( int j = 0 ; j < p ; j ++ ) { double s = 0 ; for ( int r = 0 ; r < n ; r ++ ) { s += s1 . get ( i , r ) * s2 . get ( r , j ) ; } c . set ( i , j , s ) ; } } return mr ; }
Returns new DoubleMatrix which is m1 multiplied with m2 .