00001 #ifndef Impala_Core_Matrix_MatReplicateMatrix_h
00002 #define Impala_Core_Matrix_MatReplicateMatrix_h
00003
00004 #include "Core/Matrix/MatFunc.h"
00005
00006 namespace Impala
00007 {
00008 namespace Core
00009 {
00010 namespace Matrix
00011 {
00012
00013 template<class ArrayT>
00014 inline ArrayT*
00015 MatReplicateMatrixOneRow(ArrayT* m, int columnCount)
00016 {
00017 ArrayT* ones = MatCreate<ArrayT>(1, columnCount);
00018 for(int a = 0; a < columnCount; a++)
00019 {
00020 *MatE(ones, 0, a) = 1.0;
00021 }
00022 ArrayT* res = MatMul(m, ones);
00023 delete ones;
00024 return res;
00025 }
00026
00027 template<class ArrayT>
00028 inline ArrayT*
00029 MatReplicateMatrix(ArrayT* m, int rowCount, int columnCount)
00030 {
00031 if((rowCount == 1) && (MatNrCol(m) == 1))
00032 {
00033
00034
00035 return MatReplicateMatrixOneRow(m, columnCount);
00036 }
00037 ArrayT* res = MatCreate<ArrayT>(MatNrRow(m) * rowCount, MatNrCol(m) * columnCount);
00038 for (int a = 0; a < rowCount; a++)
00039 {
00040 for (int b = 0; b < columnCount; b++)
00041 {
00042 int c = MatNrRow(m) * a;
00043 int d = MatNrCol(m) * b;
00044 for (int i=0; i<MatNrRow(m); i++)
00045 {
00046 for (int j=0; j<MatNrCol(m); j++)
00047 {
00048 *MatE(res, c+i, d+j) = *MatE(m, i, j);
00049 }
00050 }
00051 }
00052 }
00053 return res;
00054 }
00055
00056 }
00057 }
00058 }
00059
00060 #endif