org.ejml.alg.block.BlockInnerMultiplication Maven / Gradle / Ivy
/*
* Copyright (c) 2009-2013, Peter Abeles. All Rights Reserved.
*
* This file is part of Efficient Java Matrix Library (EJML).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.ejml.alg.block;
/**
*
* Matrix multiplication for the inner row major blocks, typically inside of a {@link org.ejml.data.BlockMatrix64F}.
*
*
*
* This code was auto generated by {@link GeneratorBlockInnerMultiplication} and should not be modified directly.
*
*
* @author Peter Abeles
*/
public class BlockInnerMultiplication {
/**
*
* Performs the follow operation on individual inner blocks:
*
* C = C + A * B
*
*/
public static void blockMultPlus( final double[] dataA, final double []dataB, final double []dataC,
int indexA, int indexB, int indexC,
final int heightA, final int widthA, final int widthC) {
// for( int i = 0; i < heightA; i++ ) {
// for( int k = 0; k < widthA; k++ ) {
// for( int j = 0; j < widthC; j++ ) {
// dataC[ i*widthC + j + indexC ] += dataA[i*widthA + k + indexA] * dataB[k*widthC + j + indexB];
// }
// }
// }
int a = indexA;
int rowC = indexC;
for( int i = 0; i < heightA; i++ , rowC += widthC ) {
int b = indexB;
final int endC = rowC + widthC;
final int endA = a + widthA;
while( a != endA ) {//for( int k = 0; k < widthA; k++ ) {
double valA = dataA[a++];
int c = rowC;
while( c != endC ) {//for( int j = 0; j < widthC; j++ ) {
dataC[ c++ ] += valA * dataB[ b++ ];
}
}
}
}
/**
*
* Performs the follow operation on individual inner blocks:
*
* C = C + AT * B
*
*/
public static void blockMultPlusTransA( final double[] dataA, final double []dataB, final double []dataC,
int indexA, int indexB, int indexC,
final int heightA, final int widthA, final int widthC) {
// for( int i = 0; i < widthA; i++ ) {
// for( int k = 0; k < heightA; k++ ) {
// double valA = dataA[k*widthA + i + indexA];
// for( int j = 0; j < widthC; j++ ) {
// dataC[ i*widthC + j + indexC ] += valA * dataB[k*widthC + j + indexB];
// }
// }
// }
int rowC = indexC;
for( int i = 0; i < widthA; i++ , rowC += widthC) {
int colA = i + indexA;
int endA = colA + widthA*heightA;
int b = indexB;
// for( int k = 0; k < heightA; k++ ) {
while(colA != endA ) {
double valA = dataA[colA];
int c = rowC;
final int endB = b + widthC;
//for( int j = 0; j < widthC; j++ ) {
while( b != endB ) {
dataC[ c++ ] += valA * dataB[b++];
}
colA += widthA;
}
}
}
/**
*
* Performs the follow operation on individual inner blocks:
*
* C = C + A * BT
*
*/
public static void blockMultPlusTransB( final double[] dataA, final double []dataB, final double []dataC,
int indexA, int indexB, int indexC,
final int heightA, final int widthA, final int widthC) {
for( int i = 0; i < heightA; i++ ) {
for( int j = 0; j < widthC; j++ ) {
double val = 0;
for( int k = 0; k < widthA; k++ ) {
val += dataA[i*widthA + k + indexA] * dataB[j*widthA + k + indexB];
}
dataC[ i*widthC + j + indexC ] += val;
}
}
}
/**
*
* Performs the follow operation on individual inner blocks:
*
* C = C - A * B
*
*/
public static void blockMultMinus( final double[] dataA, final double []dataB, final double []dataC,
int indexA, int indexB, int indexC,
final int heightA, final int widthA, final int widthC) {
// for( int i = 0; i < heightA; i++ ) {
// for( int k = 0; k < widthA; k++ ) {
// for( int j = 0; j < widthC; j++ ) {
// dataC[ i*widthC + j + indexC ] += dataA[i*widthA + k + indexA] * dataB[k*widthC + j + indexB];
// }
// }
// }
int a = indexA;
int rowC = indexC;
for( int i = 0; i < heightA; i++ , rowC += widthC ) {
int b = indexB;
final int endC = rowC + widthC;
final int endA = a + widthA;
while( a != endA ) {//for( int k = 0; k < widthA; k++ ) {
double valA = dataA[a++];
int c = rowC;
while( c != endC ) {//for( int j = 0; j < widthC; j++ ) {
dataC[ c++ ] -= valA * dataB[ b++ ];
}
}
}
}
/**
*
* Performs the follow operation on individual inner blocks:
*
* C = C - AT * B
*
*/
public static void blockMultMinusTransA( final double[] dataA, final double []dataB, final double []dataC,
int indexA, int indexB, int indexC,
final int heightA, final int widthA, final int widthC) {
// for( int i = 0; i < widthA; i++ ) {
// for( int k = 0; k < heightA; k++ ) {
// double valA = dataA[k*widthA + i + indexA];
// for( int j = 0; j < widthC; j++ ) {
// dataC[ i*widthC + j + indexC ] += valA * dataB[k*widthC + j + indexB];
// }
// }
// }
int rowC = indexC;
for( int i = 0; i < widthA; i++ , rowC += widthC) {
int colA = i + indexA;
int endA = colA + widthA*heightA;
int b = indexB;
// for( int k = 0; k < heightA; k++ ) {
while(colA != endA ) {
double valA = dataA[colA];
int c = rowC;
final int endB = b + widthC;
//for( int j = 0; j < widthC; j++ ) {
while( b != endB ) {
dataC[ c++ ] -= valA * dataB[b++];
}
colA += widthA;
}
}
}
/**
*
* Performs the follow operation on individual inner blocks:
*
* C = C - A * BT
*
*/
public static void blockMultMinusTransB( final double[] dataA, final double []dataB, final double []dataC,
int indexA, int indexB, int indexC,
final int heightA, final int widthA, final int widthC) {
for( int i = 0; i < heightA; i++ ) {
for( int j = 0; j < widthC; j++ ) {
double val = 0;
for( int k = 0; k < widthA; k++ ) {
val += dataA[i*widthA + k + indexA] * dataB[j*widthA + k + indexB];
}
dataC[ i*widthC + j + indexC ] -= val;
}
}
}
/**
*
* Performs the follow operation on individual inner blocks:
*
* C = A * B
*
*/
public static void blockMultSet( final double[] dataA, final double []dataB, final double []dataC,
int indexA, int indexB, int indexC,
final int heightA, final int widthA, final int widthC) {
// for( int i = 0; i < heightA; i++ ) {
// for( int k = 0; k < widthA; k++ ) {
// for( int j = 0; j < widthC; j++ ) {
// dataC[ i*widthC + j + indexC ] += dataA[i*widthA + k + indexA] * dataB[k*widthC + j + indexB];
// }
// }
// }
int a = indexA;
int rowC = indexC;
for( int i = 0; i < heightA; i++ , rowC += widthC ) {
int b = indexB;
final int endC = rowC + widthC;
final int endA = a + widthA;
while( a != endA ) {//for( int k = 0; k < widthA; k++ ) {
double valA = dataA[a++];
int c = rowC;
if( b == indexB ) {
while( c != endC ) {//for( int j = 0; j < widthC; j++ ) {
dataC[ c++ ] = valA * dataB[ b++ ];
}
} else {
while( c != endC ) {//for( int j = 0; j < widthC; j++ ) {
dataC[ c++ ] += valA * dataB[ b++ ];
}
}
}
}
}
/**
*
* Performs the follow operation on individual inner blocks:
*
* C = AT * B
*
*/
public static void blockMultSetTransA( final double[] dataA, final double []dataB, final double []dataC,
int indexA, int indexB, int indexC,
final int heightA, final int widthA, final int widthC) {
// for( int i = 0; i < widthA; i++ ) {
// for( int k = 0; k < heightA; k++ ) {
// double valA = dataA[k*widthA + i + indexA];
// for( int j = 0; j < widthC; j++ ) {
// dataC[ i*widthC + j + indexC ] += valA * dataB[k*widthC + j + indexB];
// }
// }
// }
int rowC = indexC;
for( int i = 0; i < widthA; i++ , rowC += widthC) {
int colA = i + indexA;
int endA = colA + widthA*heightA;
int b = indexB;
// for( int k = 0; k < heightA; k++ ) {
while(colA != endA ) {
double valA = dataA[colA];
int c = rowC;
final int endB = b + widthC;
//for( int j = 0; j < widthC; j++ ) {
if( b == indexB ) {
while( b != endB ) {
dataC[ c++ ] = valA * dataB[b++];
}
} else {
while( b != endB ) {
dataC[ c++ ] += valA * dataB[b++];
}
}
colA += widthA;
}
}
}
/**
*
* Performs the follow operation on individual inner blocks:
*
* C = A * BT
*
*/
public static void blockMultSetTransB( final double[] dataA, final double []dataB, final double []dataC,
int indexA, int indexB, int indexC,
final int heightA, final int widthA, final int widthC) {
for( int i = 0; i < heightA; i++ ) {
for( int j = 0; j < widthC; j++ ) {
double val = 0;
for( int k = 0; k < widthA; k++ ) {
val += dataA[i*widthA + k + indexA] * dataB[j*widthA + k + indexB];
}
dataC[ i*widthC + j + indexC ] = val;
}
}
}
/**
*
* Performs the follow operation on individual inner blocks:
*
* C = C + α A * B
*
*/
public static void blockMultPlus( double alpha , final double[] dataA, final double []dataB, final double []dataC,
int indexA, int indexB, int indexC,
final int heightA, final int widthA, final int widthC) {
// for( int i = 0; i < heightA; i++ ) {
// for( int k = 0; k < widthA; k++ ) {
// for( int j = 0; j < widthC; j++ ) {
// dataC[ i*widthC + j + indexC ] += dataA[i*widthA + k + indexA] * dataB[k*widthC + j + indexB];
// }
// }
// }
int a = indexA;
int rowC = indexC;
for( int i = 0; i < heightA; i++ , rowC += widthC ) {
int b = indexB;
final int endC = rowC + widthC;
final int endA = a + widthA;
while( a != endA ) {//for( int k = 0; k < widthA; k++ ) {
double valA = alpha*dataA[a++];
int c = rowC;
while( c != endC ) {//for( int j = 0; j < widthC; j++ ) {
dataC[ c++ ] += valA * dataB[ b++ ];
}
}
}
}
/**
*
* Performs the follow operation on individual inner blocks:
*
* C = C + α AT * B
*
*/
public static void blockMultPlusTransA( double alpha , final double[] dataA, final double []dataB, final double []dataC,
int indexA, int indexB, int indexC,
final int heightA, final int widthA, final int widthC) {
// for( int i = 0; i < widthA; i++ ) {
// for( int k = 0; k < heightA; k++ ) {
// double valA = dataA[k*widthA + i + indexA];
// for( int j = 0; j < widthC; j++ ) {
// dataC[ i*widthC + j + indexC ] += valA * dataB[k*widthC + j + indexB];
// }
// }
// }
int rowC = indexC;
for( int i = 0; i < widthA; i++ , rowC += widthC) {
int colA = i + indexA;
int endA = colA + widthA*heightA;
int b = indexB;
// for( int k = 0; k < heightA; k++ ) {
while(colA != endA ) {
double valA = alpha*dataA[colA];
int c = rowC;
final int endB = b + widthC;
//for( int j = 0; j < widthC; j++ ) {
while( b != endB ) {
dataC[ c++ ] += valA * dataB[b++];
}
colA += widthA;
}
}
}
/**
*
* Performs the follow operation on individual inner blocks:
*
* C = C + α A * BT
*
*/
public static void blockMultPlusTransB( double alpha , final double[] dataA, final double []dataB, final double []dataC,
int indexA, int indexB, int indexC,
final int heightA, final int widthA, final int widthC) {
for( int i = 0; i < heightA; i++ ) {
for( int j = 0; j < widthC; j++ ) {
double val = 0;
for( int k = 0; k < widthA; k++ ) {
val += dataA[i*widthA + k + indexA] * dataB[j*widthA + k + indexB];
}
dataC[ i*widthC + j + indexC ] += alpha * val;
}
}
}
/**
*
* Performs the follow operation on individual inner blocks:
*
* C = α A * B
*
*/
public static void blockMultSet( double alpha , final double[] dataA, final double []dataB, final double []dataC,
int indexA, int indexB, int indexC,
final int heightA, final int widthA, final int widthC) {
// for( int i = 0; i < heightA; i++ ) {
// for( int k = 0; k < widthA; k++ ) {
// for( int j = 0; j < widthC; j++ ) {
// dataC[ i*widthC + j + indexC ] += dataA[i*widthA + k + indexA] * dataB[k*widthC + j + indexB];
// }
// }
// }
int a = indexA;
int rowC = indexC;
for( int i = 0; i < heightA; i++ , rowC += widthC ) {
int b = indexB;
final int endC = rowC + widthC;
final int endA = a + widthA;
while( a != endA ) {//for( int k = 0; k < widthA; k++ ) {
double valA = alpha*dataA[a++];
int c = rowC;
if( b == indexB ) {
while( c != endC ) {//for( int j = 0; j < widthC; j++ ) {
dataC[ c++ ] = valA * dataB[ b++ ];
}
} else {
while( c != endC ) {//for( int j = 0; j < widthC; j++ ) {
dataC[ c++ ] += valA * dataB[ b++ ];
}
}
}
}
}
/**
*
* Performs the follow operation on individual inner blocks:
*
* C = α AT * B
*
*/
public static void blockMultSetTransA( double alpha , final double[] dataA, final double []dataB, final double []dataC,
int indexA, int indexB, int indexC,
final int heightA, final int widthA, final int widthC) {
// for( int i = 0; i < widthA; i++ ) {
// for( int k = 0; k < heightA; k++ ) {
// double valA = dataA[k*widthA + i + indexA];
// for( int j = 0; j < widthC; j++ ) {
// dataC[ i*widthC + j + indexC ] += valA * dataB[k*widthC + j + indexB];
// }
// }
// }
int rowC = indexC;
for( int i = 0; i < widthA; i++ , rowC += widthC) {
int colA = i + indexA;
int endA = colA + widthA*heightA;
int b = indexB;
// for( int k = 0; k < heightA; k++ ) {
while(colA != endA ) {
double valA = alpha*dataA[colA];
int c = rowC;
final int endB = b + widthC;
//for( int j = 0; j < widthC; j++ ) {
if( b == indexB ) {
while( b != endB ) {
dataC[ c++ ] = valA * dataB[b++];
}
} else {
while( b != endB ) {
dataC[ c++ ] += valA * dataB[b++];
}
}
colA += widthA;
}
}
}
/**
*
* Performs the follow operation on individual inner blocks:
*
* C = α A * BT
*
*/
public static void blockMultSetTransB( double alpha , final double[] dataA, final double []dataB, final double []dataC,
int indexA, int indexB, int indexC,
final int heightA, final int widthA, final int widthC) {
for( int i = 0; i < heightA; i++ ) {
for( int j = 0; j < widthC; j++ ) {
double val = 0;
for( int k = 0; k < widthA; k++ ) {
val += dataA[i*widthA + k + indexA] * dataB[j*widthA + k + indexB];
}
dataC[ i*widthC + j + indexC ] = alpha * val;
}
}
}
}