diff --git a/src/Function1D.cpp b/src/Function1D.cpp index 8f529c1..8fb42c9 100644 --- a/src/Function1D.cpp +++ b/src/Function1D.cpp @@ -67,7 +67,6 @@ Aurora::Matrix Aurora::ceil(const Aurora::Matrix &matrix) { } Aurora::Matrix Aurora::ceil(const Aurora::Matrix &&matrix) { - std::cout<<"RR ceil"< retV(matrix.getData(),matrix.getDataSize()); retV = retV.array().sign(); diff --git a/src/Function3D.cpp b/src/Function3D.cpp index 40b4a2c..cb28306 100644 --- a/src/Function3D.cpp +++ b/src/Function3D.cpp @@ -1,7 +1,10 @@ +#include #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); +} diff --git a/src/Function3D.h b/src/Function3D.h index 222816d..772cf8e 100644 --- a/src/Function3D.h +++ b/src/Function3D.h @@ -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); diff --git a/test/Function3D_Test.cpp b/test/Function3D_Test.cpp index d90850a..da2e7de 100644 --- a/test/Function3D_Test.cpp +++ b/test/Function3D_Test.cpp @@ -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:"<