Add polyval to Function1D

This commit is contained in:
Krad
2023-04-23 11:12:00 +08:00
parent 5e85d0f361
commit 57e712a006
5 changed files with 43 additions and 27 deletions

View File

@@ -303,3 +303,22 @@ 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);
}