Add zeros and ones to Function3D.
This commit is contained in:
@@ -67,7 +67,6 @@ Aurora::Matrix Aurora::ceil(const Aurora::Matrix &matrix) {
|
||||
}
|
||||
|
||||
Aurora::Matrix Aurora::ceil(const Aurora::Matrix &&matrix) {
|
||||
std::cout<<"RR ceil"<<std::endl;
|
||||
//for real part
|
||||
vdCeilI(matrix.getDataSize(), matrix.getData(), SAME_STRIDE, matrix.getData(), SAME_STRIDE);
|
||||
if (matrix.getValueType() == Complex) {
|
||||
@@ -89,7 +88,6 @@ Aurora::Matrix Aurora::round(const Aurora::Matrix &matrix) {
|
||||
}
|
||||
|
||||
Aurora::Matrix Aurora::round(const Aurora::Matrix &&matrix) {
|
||||
std::cout<<"RR round"<<std::endl;
|
||||
//for real part
|
||||
vdRoundI(matrix.getDataSize(), matrix.getData(), SAME_STRIDE, matrix.getData(), SAME_STRIDE);
|
||||
if (matrix.getValueType() == Complex) {
|
||||
@@ -111,7 +109,6 @@ Aurora::Matrix Aurora::sqrt(const Aurora::Matrix& matrix) {
|
||||
}
|
||||
|
||||
Aurora::Matrix Aurora::sqrt(Aurora::Matrix&& matrix) {
|
||||
std::cout<<"RR sqrt"<<std::endl;
|
||||
if (matrix.getValueType() != Complex) {
|
||||
vdSqrtI(matrix.getDataSize(), matrix.getData(), SAME_STRIDE, matrix.getData(), SAME_STRIDE);
|
||||
return matrix;
|
||||
@@ -132,7 +129,6 @@ Aurora::Matrix Aurora::abs(const Aurora::Matrix &matrix) {
|
||||
}
|
||||
|
||||
Aurora::Matrix Aurora::abs(Aurora::Matrix&& matrix) {
|
||||
std::cout<<"RR abs"<<std::endl;
|
||||
if (matrix.getValueType()==Normal){
|
||||
vdAbsI(matrix.getDataSize(), matrix.getData(), SAME_STRIDE, matrix.getData(), SAME_STRIDE);
|
||||
return matrix;
|
||||
@@ -166,7 +162,6 @@ Aurora::Matrix Aurora::sign(const Aurora::Matrix &matrix) {
|
||||
}
|
||||
|
||||
Aurora::Matrix Aurora::sign(Aurora::Matrix&& matrix) {
|
||||
std::cout<<"RR sign"<<std::endl;
|
||||
if (matrix.getValueType()==Normal){
|
||||
Eigen::Map<Eigen::VectorXd> retV(matrix.getData(),matrix.getDataSize());
|
||||
retV = retV.array().sign();
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
#include <iostream>
|
||||
#include "Function3D.h"
|
||||
#include "Function2D.h"
|
||||
#include "Function.h"
|
||||
|
||||
#include "mkl.h"
|
||||
|
||||
using namespace Aurora;
|
||||
|
||||
Matrix Aurora::interp3(const Matrix& aX, const Matrix& aY, const Matrix& aZ, const Matrix& aV, const Matrix& aX1, const Matrix& aY1, const Matrix& aZ1,InterpnMethod aMethod)
|
||||
@@ -44,3 +47,43 @@ Matrix Aurora::interpn(const Matrix& aX, const Matrix& aY, const Matrix& aZ, con
|
||||
{
|
||||
return Aurora::interp3(aY,aX,aZ,aV,aY1,aX1,aZ1,aMethod);
|
||||
}
|
||||
|
||||
Matrix Aurora::ones(int aRow, int aColumn, int aSlice) {
|
||||
if (aRow == 0 || aColumn == 0)
|
||||
{
|
||||
std::cerr<<"ones function can create matrix with dim unit cont =0";
|
||||
return Matrix();
|
||||
}
|
||||
int rowSize = aRow;
|
||||
int colSize = aColumn;
|
||||
int sliceSize = aSlice == 0 ? 1 : aSlice;
|
||||
size_t arraySize = rowSize * colSize* sliceSize;
|
||||
double* data = malloc(arraySize);
|
||||
double one = 1.0;
|
||||
cblas_dcopy(arraySize,&one,0,data,1);
|
||||
return Matrix::New(data,rowSize,colSize,aSlice);
|
||||
}
|
||||
|
||||
Matrix Aurora::ones(int aSquareRow) {
|
||||
return Aurora::ones(aSquareRow, aSquareRow);
|
||||
}
|
||||
|
||||
Matrix Aurora::zeros(int aRow, int aColumn, int aSlice) {
|
||||
if (aRow == 0 || aColumn == 0)
|
||||
{
|
||||
std::cerr<<"zeros function can create matrix with dim unit cont =0";
|
||||
return Matrix();
|
||||
}
|
||||
int rowSize = aRow;
|
||||
int colSize = aColumn;
|
||||
int sliceSize = aSlice == 0 ? 1 : aSlice;
|
||||
size_t arraySize = rowSize * colSize* sliceSize;
|
||||
double* data = malloc(arraySize);
|
||||
double zero = 0.0;
|
||||
cblas_dcopy(arraySize,&zero,0,data,1);
|
||||
return Matrix::New(data,rowSize,colSize,aSlice);
|
||||
}
|
||||
|
||||
Matrix Aurora::zeros(int aSquareRow) {
|
||||
return Aurora::zeros(aSquareRow, aSquareRow);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,37 @@
|
||||
|
||||
namespace Aurora {
|
||||
|
||||
/**
|
||||
* 创建全部为1的数组,矩阵
|
||||
* @param aRow 行数,必须大于0
|
||||
* @param aColumn 列数,必须大于0
|
||||
* @param aSlice 层数
|
||||
* @return 全部为1的数组,矩阵
|
||||
*/
|
||||
Matrix ones(int aRow, int aColumn, int aSlice = 0);
|
||||
|
||||
/**
|
||||
* 创建全部为1的方阵
|
||||
* @param aSquareRow
|
||||
* @return 全部为1的方阵
|
||||
*/
|
||||
Matrix ones(int aSquareRow);
|
||||
|
||||
/**
|
||||
* 创建全部为0的数组,矩阵
|
||||
* @param aRow 行数,必须大于0
|
||||
* @param aColumn 列数,必须大于0
|
||||
* @param aSlice 层数
|
||||
* @return 全部为0的数组,矩阵
|
||||
*/
|
||||
Matrix zeros(int aRow, int aColumn, int aSlice = 0);
|
||||
|
||||
/**
|
||||
* 创建全部为0的方阵
|
||||
* @param aSquareRow
|
||||
* @return 全部为0的方阵
|
||||
*/
|
||||
Matrix zeros(int aSquareRow);
|
||||
Matrix interp3(const Matrix& aX, const Matrix& aY, const Matrix& aZ, const Matrix& aV, const Matrix& aX1, const Matrix& aY1, const Matrix& aZ1,InterpnMethod aMethod);
|
||||
Matrix interpn(const Matrix& aX, const Matrix& aY, const Matrix& aZ, const Matrix& aV, const Matrix& aX1, const Matrix& aY1, const Matrix& aZ1,InterpnMethod aMethod);
|
||||
|
||||
|
||||
@@ -91,4 +91,52 @@ TEST_F(Function3D_Test, interpn) {
|
||||
EXPECT_DOUBLE_AE(result.getData()[0],352.1727);
|
||||
EXPECT_DOUBLE_AE(result.getData()[1],269.8596);
|
||||
EXPECT_DOUBLE_AE(result.getData()[2],94.7908);
|
||||
}
|
||||
|
||||
TEST_F(Function3D_Test, zerosAndones){
|
||||
|
||||
Aurora::Matrix zerosM = Aurora::zeros( 3, 4,5);
|
||||
EXPECT_EQ(60,zerosM.getDataSize());
|
||||
for (int i = 0; i < zerosM.getDataSize(); ++i) {
|
||||
EXPECT_EQ(0,zerosM.getData()[i])<<" error at index:"<<i;
|
||||
}
|
||||
zerosM = Aurora::zeros( 3, 4);
|
||||
EXPECT_EQ(12,zerosM.getDataSize());
|
||||
for (int i = 0; i < zerosM.getDataSize(); ++i) {
|
||||
EXPECT_EQ(0,zerosM.getData()[i])<<" error at index:"<<i;
|
||||
}
|
||||
zerosM = Aurora::zeros( 3, 1);
|
||||
EXPECT_EQ(3,zerosM.getDataSize());
|
||||
for (int i = 0; i < zerosM.getDataSize(); ++i) {
|
||||
EXPECT_EQ(0,zerosM.getData()[i])<<" error at index:"<<i;
|
||||
}
|
||||
zerosM = Aurora::zeros( 20);
|
||||
EXPECT_EQ(400,zerosM.getDataSize());
|
||||
for (int i = 0; i < zerosM.getDataSize(); ++i) {
|
||||
EXPECT_EQ(0,zerosM.getData()[i])<<" error at index:"<<i;
|
||||
}
|
||||
Aurora::Matrix onesM = Aurora::ones( 9, 9,9);
|
||||
EXPECT_EQ(729,onesM.getDataSize());
|
||||
for (int i = 0; i < onesM.getDataSize(); ++i) {
|
||||
EXPECT_DOUBLE_EQ(1.0,onesM.getData()[i])<<" error at index:"<<i;
|
||||
}
|
||||
|
||||
onesM = Aurora::ones( 9, 9);
|
||||
EXPECT_EQ(81,onesM.getDataSize());
|
||||
for (int i = 0; i < onesM.getDataSize(); ++i) {
|
||||
EXPECT_DOUBLE_EQ(1.0,onesM.getData()[i])<<" error at index:"<<i;
|
||||
}
|
||||
|
||||
onesM = Aurora::ones( 9, 1);
|
||||
EXPECT_EQ(9,onesM.getDataSize());
|
||||
for (int i = 0; i < onesM.getDataSize(); ++i) {
|
||||
EXPECT_DOUBLE_EQ(1.0,onesM.getData()[i])<<" error at index:"<<i;
|
||||
}
|
||||
|
||||
onesM = Aurora::ones( 9);
|
||||
EXPECT_EQ(81,onesM.getDataSize());
|
||||
for (int i = 0; i < onesM.getDataSize(); ++i) {
|
||||
EXPECT_DOUBLE_EQ(1.0,onesM.getData()[i])<<" error at index:"<<i;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user