Add interp and repmat function.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "Function1D.h"
|
||||
#include "Function.h"
|
||||
#include <complex>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
@@ -10,6 +11,8 @@
|
||||
#include <Eigen/Eigen>
|
||||
#include <Eigen/Dense>
|
||||
|
||||
using namespace Aurora;
|
||||
|
||||
namespace {
|
||||
const int COMPLEX_STRIDE = 2;
|
||||
const int REAL_STRIDE = 1;
|
||||
@@ -179,3 +182,130 @@ Aurora::Matrix Aurora::sign(const Aurora::Matrix&& matrix) {
|
||||
return matrix;
|
||||
}
|
||||
}
|
||||
|
||||
Matrix Aurora::interp1(const Matrix& aX, const Matrix& aV, const Matrix& aX1, InterpnMethod aMethod)
|
||||
{
|
||||
const int nx = aX.getDimSize(0);
|
||||
const int ny = 1;
|
||||
int nx1 = aX1.getDimSize(0);
|
||||
std::shared_ptr<double> resultData = std::shared_ptr<double>(Aurora::malloc(nx1), Aurora::free);
|
||||
std::vector<int> resultInfo = {nx1};
|
||||
Aurora::Matrix result(resultData, resultInfo);
|
||||
DFTaskPtr task ;
|
||||
int status = dfdNewTask1D(&task, nx, aX.getData(), DF_NO_HINT, ny, aV.getData(), DF_NO_HINT);
|
||||
if (status != DF_STATUS_OK)
|
||||
{
|
||||
return Matrix();
|
||||
}
|
||||
MKL_INT sorder;
|
||||
MKL_INT stype;
|
||||
if (aMethod == InterpnMethod::Spline)
|
||||
{
|
||||
sorder = DF_PP_CUBIC;
|
||||
stype = DF_PP_BESSEL;
|
||||
}
|
||||
else
|
||||
{
|
||||
sorder = DF_PP_LINEAR;
|
||||
stype = DF_PP_BESSEL;
|
||||
}
|
||||
double* scoeffs = Aurora::malloc(ny * (nx-1) * sorder);
|
||||
status = dfdEditPPSpline1D(task, sorder,DF_PP_NATURAL , DF_BC_NOT_A_KNOT, 0, DF_NO_IC, 0, scoeffs, DF_NO_HINT);
|
||||
if (status != DF_STATUS_OK)
|
||||
{
|
||||
return Matrix();
|
||||
}
|
||||
status = dfdConstruct1D( task, DF_PP_SPLINE, DF_METHOD_STD );
|
||||
if (status != DF_STATUS_OK)
|
||||
{
|
||||
return Matrix();
|
||||
}
|
||||
|
||||
int dorder = 1;
|
||||
status = dfdInterpolate1D(task, DF_INTERP, DF_METHOD_PP, nx1, aX1.getData(), DF_NO_HINT, 1, &dorder,
|
||||
DF_NO_APRIORI_INFO, resultData.get(), DF_MATRIX_STORAGE_ROWS, nullptr);
|
||||
|
||||
status = dfDeleteTask(&task);
|
||||
|
||||
Aurora::free(scoeffs);
|
||||
return result;
|
||||
}
|
||||
|
||||
Matrix Aurora::repmat(const Matrix& aMatrix,int aRowTimes, int aColumnTimes)
|
||||
{
|
||||
if(aRowTimes < 1 || aColumnTimes < 1 || aMatrix.getDims() > 2 || aMatrix.isNull())
|
||||
{
|
||||
return Matrix();
|
||||
}
|
||||
int originalDataSize = aMatrix.getDataSize();
|
||||
double* resultData = Aurora::malloc(originalDataSize * aRowTimes * aColumnTimes);
|
||||
int row = aMatrix.getDimSize(0);
|
||||
int column = 1;
|
||||
if(aMatrix.getDims() > 1)
|
||||
{
|
||||
column = aMatrix.getDimSize(1);
|
||||
}
|
||||
|
||||
double* originalData = aMatrix.getData();
|
||||
double* resultDataTemp = resultData;
|
||||
for(int i=0; i<column; ++i)
|
||||
{
|
||||
for(int j=1; j<=aRowTimes; ++j)
|
||||
{
|
||||
std::copy(originalData, originalData+row, resultDataTemp);
|
||||
resultDataTemp += row;
|
||||
}
|
||||
originalData += row;
|
||||
}
|
||||
|
||||
resultDataTemp = resultData;
|
||||
int step = originalDataSize * aRowTimes;
|
||||
for(int i=1; i<aColumnTimes; ++i)
|
||||
{
|
||||
std::copy(resultData, resultData + step, resultData + i*step);
|
||||
}
|
||||
|
||||
std::vector<int> resultInfo;
|
||||
resultInfo.push_back(aRowTimes * row);
|
||||
column = aColumnTimes*column;
|
||||
if (column > 1)
|
||||
{
|
||||
resultInfo.push_back(column);
|
||||
}
|
||||
|
||||
return Matrix(std::shared_ptr<double>(resultData, Aurora::free),resultInfo);
|
||||
}
|
||||
|
||||
Matrix Aurora::repmat(const Matrix& aMatrix,int aRowTimes, int aColumnTimes, int aSliceTimes)
|
||||
{
|
||||
if(aRowTimes < 1 || aColumnTimes < 1 || aSliceTimes < 1 || aMatrix.getDims() > 2 || aMatrix.isNull())
|
||||
{
|
||||
return Matrix();
|
||||
}
|
||||
Matrix resultTemp = Aurora::repmat(aMatrix, aRowTimes, aColumnTimes);
|
||||
int resultTempDataSize = resultTemp.getDataSize();
|
||||
double* resultData = Aurora::malloc(resultTempDataSize * aSliceTimes);
|
||||
std::copy(resultTemp.getData(), resultTemp.getData() + resultTempDataSize, resultData);
|
||||
for(int i=1; i<aSliceTimes; ++i)
|
||||
{
|
||||
std::copy(resultData, resultData + resultTempDataSize, resultData + i*resultTempDataSize);
|
||||
}
|
||||
std::vector<int> resultInfo;
|
||||
int row = resultTemp.getDimSize(0);
|
||||
int column = 1;
|
||||
if(resultTemp.getDims() > 1)
|
||||
{
|
||||
column = resultTemp.getDimSize(1);
|
||||
}
|
||||
resultInfo.push_back(row);
|
||||
if (column > 1 || aSliceTimes > 1)
|
||||
{
|
||||
resultInfo.push_back(column);
|
||||
}
|
||||
if (aSliceTimes > 1)
|
||||
{
|
||||
resultInfo.push_back(aSliceTimes);
|
||||
}
|
||||
|
||||
return Matrix(std::shared_ptr<double>(resultData, Aurora::free),resultInfo);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user