Fix commmit bug.

This commit is contained in:
sunwen
2023-04-23 13:10:52 +08:00
5 changed files with 42 additions and 26 deletions

View File

@@ -20,24 +20,6 @@ namespace Aurora {
return result;
}
double *polyval(double *pX, double *pP, int size) {
auto result = new double[size];
auto powArg = new double[size];
for (int j = size, i = 0; j > 0; --j, ++i) {
powArg[i] = (double) (j - 1);
}
auto temp = new double[size];
for (int i = 0; i < size; ++i) {
vdPowI(size, pX + i, 0, powArg, 1, temp, 1);
vdMul(size, pP, temp, temp);
result[i] = cblas_dasum(3, temp, 1);
}
delete[] powArg;
delete[] temp;
return result;
}
double *std(int rows, int cols, double *input) {
auto std = new double[cols];
// #pragma omp parallel for num_threads(4)

View File

@@ -14,7 +14,6 @@ namespace Aurora{
double* mul( double* inputA, double * inputB, int size);
double* mulz( std::complex<double> *inputA, std::complex<double> * inputB, int size);
double immse(double * dataA, double * dataB, int size);
double* polyval(double *pX, double *pP, int size);
double* std(int rows, int cols, double * input);
double* inv(int cols,double *pMatrix);

View File

@@ -304,6 +304,25 @@ Matrix Aurora::repmat(const Matrix& aMatrix,int aRowTimes, int aColumnTimes, int
return Matrix(std::shared_ptr<double>(resultData, Aurora::free), resultInfo, aMatrix.getValueType());
}
Matrix Aurora::polyval(const Matrix &aP, const Matrix &aX) {
auto result = malloc(aX.getDataSize());
auto powArg = new double[aP.getDataSize()];
for (int j = aP.getDataSize(), i = 0; j > 0; --j, ++i) {
powArg[i] = (double) (j - 1);
}
auto temp = new double[aP.getDataSize()];
for (int i = 0; i < aX.getDataSize(); ++i) {
vdPowI(aP.getDataSize(), aX.getData() + i, 0, powArg, 1, temp, 1);
vdMul(aP.getDataSize(), aP.getData(), temp, temp);
result[i] = cblas_dasum(3, temp, 1);
}
delete[] powArg;
delete[] temp;
return Matrix::New(result,aX);
}
Matrix Aurora::log(const Matrix& aMatrix, int aBaseNum)
{
size_t size = aMatrix.getDataSize();

View File

@@ -48,6 +48,16 @@ namespace Aurora {
Matrix repmat(const Matrix& aMatrix,int aRowTimes, int aColumnTimes, int aSliceTimes);
Matrix log(const Matrix& aMatrix, int aBaseNum = -1);
/**
* 多项式计算
* @brief 例如p[1 0 1],x[3 2 5],代表对多项式 y = x^2 + 1 求(x=3, x=2, x=5)时所有的y
* @attention 本函数的数据一律视为向量,在计算时会完全忽视维度,值考虑作为数组输入
* @param aP 多项式系数,指定为向量
* @param aX 查询点,指定为向量
* @return 查询结果
*/
Matrix polyval(const Matrix& aP, const Matrix& aX);
};

View File

@@ -38,6 +38,11 @@ TEST_F(Function1D_Test, sign) {
EXPECT_EQ(-1, result[0]);
EXPECT_EQ(0, result[3]);
EXPECT_EQ(1, result[4]);
C = sign(A);
result = C.getData();
EXPECT_EQ(-1, result[0]);
EXPECT_EQ(0, result[3]);
EXPECT_EQ(1, result[4]);
}
TEST_F(Function1D_Test, repmat) {
@@ -102,13 +107,14 @@ TEST_F(Function1D_Test, interp1) {
}
TEST_F(Function1D_Test, polyval){
double dataP[3]={3,2,1};
double dataX[3]={5,7,9};
double*resultP = Aurora::polyval(dataX,dataP,3);
EXPECT_DOUBLE_EQ(86., resultP[0])<<" polyval error;";
EXPECT_DOUBLE_EQ(162., resultP[1])<<" polyval error;";
EXPECT_DOUBLE_EQ(262., resultP[2])<<" polyval error;";
delete [] resultP;
double *dataP = new double[3]{3,2,1};
double *dataX = new double[3]{5,7,9};
auto matrixP = Aurora::Matrix::fromRawData(dataP,3);
auto matrixX = Aurora::Matrix::fromRawData(dataX,3);
auto result = Aurora::polyval(matrixP,matrixX);
EXPECT_DOUBLE_EQ(86., result.getData()[0]);
EXPECT_DOUBLE_EQ(162., result.getData()[1]);
EXPECT_DOUBLE_EQ(262., result.getData()[2]);
}
TEST_F(Function1D_Test, complexAndEtc){