Add acos and acos's unittest.

This commit is contained in:
sunwen
2023-04-24 09:58:51 +08:00
parent c3462330c1
commit 7bd5b8a829
3 changed files with 26 additions and 1 deletions

View File

@@ -328,9 +328,9 @@ Matrix Aurora::log(const Matrix& aMatrix, int aBaseNum)
{
double baseNum = aBaseNum;
double temp;
vdLn(1, &baseNum, &temp);
for (size_t i = 0; i < size; i++)
{
vdLn(1, &baseNum, &temp);
data[i] /= temp;
}
}
@@ -371,3 +371,17 @@ Matrix Aurora::mod(const Matrix& aMatrix, double aValue)
return Matrix::New(resultData, aMatrix);
}
Matrix Aurora::acos(const Matrix& aMatrix)
{
if(aMatrix.isComplex() || aMatrix.isNull())
{
return Matrix();
}
size_t size = aMatrix.getDataSize();
double* matrixData = aMatrix.getData();
double* resultData = Aurora::malloc(size);
vdAcos(size, matrixData, resultData);
return Matrix::New(resultData, aMatrix);
}

View File

@@ -53,6 +53,8 @@ namespace Aurora {
Matrix mod(const Matrix& aMatrix, double aValue);
Matrix acos(const Matrix& aMatrix);
/**
* 多项式计算
* @brief 例如p[1 0 1],x[3 2 5],代表对多项式 y = x^2 + 1 求(x=3, x=2, x=5)时所有的y

View File

@@ -246,3 +246,12 @@ TEST_F(Function1D_Test, mod) {
EXPECT_DOUBLE_AE(result.getData()[1],0.83);
EXPECT_DOUBLE_AE(result.getData()[2],0.4);
}
TEST_F(Function1D_Test, acos) {
double *data = new double[3]{0.02,0.83,0.4,};
auto matrix = Aurora::Matrix::fromRawData(data, 3);
auto result = Aurora::acos(matrix);
EXPECT_DOUBLE_AE(result.getData()[0],1.5508);
EXPECT_DOUBLE_AE(result.getData()[1],0.5917);
EXPECT_DOUBLE_AE(result.getData()[2],1.1593);
}