Add vertcat
This commit is contained in:
@@ -17,6 +17,7 @@
|
|||||||
#include <Eigen/Eigen>
|
#include <Eigen/Eigen>
|
||||||
#include <Eigen/Dense>
|
#include <Eigen/Dense>
|
||||||
#include <Eigen/SVD>
|
#include <Eigen/SVD>
|
||||||
|
#include <mkl_cblas.h>
|
||||||
#include <mkl_lapack.h>
|
#include <mkl_lapack.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
@@ -694,6 +695,26 @@ Matrix Aurora::horzcat(const Matrix& aMatrix1, const Matrix& aMatrix2)
|
|||||||
return Matrix::New(resultData, row, column1+column2, 1, aMatrix1.getValueType());
|
return Matrix::New(resultData, row, column1+column2, 1, aMatrix1.getValueType());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Matrix Aurora::vertcat(const Matrix& aMatrix1, const Matrix& aMatrix2){
|
||||||
|
{
|
||||||
|
if(aMatrix1.isNull() || aMatrix2.isNull() || aMatrix1.getDims() !=2 || aMatrix2.getDims() !=2 ||
|
||||||
|
aMatrix1.getDimSize(1) != aMatrix2.getDimSize(1) || aMatrix1.getValueType() != aMatrix2.getValueType())
|
||||||
|
{
|
||||||
|
return Matrix();
|
||||||
|
}
|
||||||
|
int row1 = aMatrix1.getDimSize(0);
|
||||||
|
int row2 = aMatrix2.getDimSize(0);
|
||||||
|
int column = aMatrix1.getDimSize(1);
|
||||||
|
size_t size1= aMatrix1.getDataSize();
|
||||||
|
size_t size2= aMatrix2.getDataSize();
|
||||||
|
double* resultData = Aurora::malloc(size1 + size2,aMatrix1.getValueType());
|
||||||
|
cblas_dcopy_batch_strided(row1, aMatrix1.getData(), 1,row1, resultData, 1, row1+row2, column);
|
||||||
|
cblas_dcopy_batch_strided(row2, aMatrix2.getData(), 1,row2, resultData + row1, 1, row1+row2, column);
|
||||||
|
|
||||||
|
return Matrix::New(resultData, row1+row2, column, 1, aMatrix1.getValueType());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Matrix Aurora::vecnorm(const Matrix& aMatrix, NormMethod aNormMethod, int aDim)
|
Matrix Aurora::vecnorm(const Matrix& aMatrix, NormMethod aNormMethod, int aDim)
|
||||||
{
|
{
|
||||||
//only surpport aDim = 1 for now.
|
//only surpport aDim = 1 for now.
|
||||||
|
|||||||
@@ -77,6 +77,8 @@ namespace Aurora {
|
|||||||
|
|
||||||
Matrix horzcat(const Matrix& aMatrix1, const Matrix& aMatrix2);
|
Matrix horzcat(const Matrix& aMatrix1, const Matrix& aMatrix2);
|
||||||
|
|
||||||
|
Matrix vertcat(const Matrix& aMatrix1, const Matrix& aMatrix2);
|
||||||
|
|
||||||
Matrix vecnorm(const Matrix& aMatrix, NormMethod aNormMethod, int aDim);
|
Matrix vecnorm(const Matrix& aMatrix, NormMethod aNormMethod, int aDim);
|
||||||
|
|
||||||
Matrix linspace(double aStart, double aEnd, int aNum);
|
Matrix linspace(double aStart, double aEnd, int aNum);
|
||||||
|
|||||||
@@ -431,6 +431,21 @@ TEST_F(Function1D_Test, horzcat) {
|
|||||||
EXPECT_DOUBLE_EQ(result.getDimSize(1),2);
|
EXPECT_DOUBLE_EQ(result.getDimSize(1),2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(Function1D_Test, vertcat) {
|
||||||
|
double *data1 = new double[6]{1,2,3,4,5,6};
|
||||||
|
auto matrix1 = Aurora::Matrix::fromRawData(data1, 2,3);
|
||||||
|
double *data2 = new double[9]{7,8,9,10,11,12,13,14,15};
|
||||||
|
auto matrix2 = Aurora::Matrix::fromRawData(data2, 3,3);
|
||||||
|
auto result = Aurora::vertcat(matrix1,matrix2);
|
||||||
|
EXPECT_DOUBLE_EQ(result.getData()[0],1);
|
||||||
|
EXPECT_DOUBLE_EQ(result.getData()[1],2);
|
||||||
|
EXPECT_DOUBLE_EQ(result.getData()[5],3);
|
||||||
|
EXPECT_DOUBLE_EQ(result.getData()[8],11);
|
||||||
|
EXPECT_DOUBLE_EQ(result.getDimSize(0),5);
|
||||||
|
EXPECT_DOUBLE_EQ(result.getDimSize(1),3);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST_F(Function1D_Test, vecnrom) {
|
TEST_F(Function1D_Test, vecnrom) {
|
||||||
//1Dim
|
//1Dim
|
||||||
double *data = new double[3]{1,2,-3};
|
double *data = new double[3]{1,2,-3};
|
||||||
|
|||||||
Reference in New Issue
Block a user