Add interp and repmat function.
This commit is contained in:
@@ -1 +1,45 @@
|
||||
#include "Function2D.h"
|
||||
#include "Function1D.h"
|
||||
#include "Function.h"
|
||||
|
||||
using namespace Aurora;
|
||||
|
||||
Matrix Aurora::interp2(const Matrix& aX, const Matrix& aY, const Matrix& aV, const Matrix& aX1, const Matrix& aY1, InterpnMethod aMethod)
|
||||
{
|
||||
if (aV.getDims() != 2)
|
||||
{
|
||||
return Matrix();
|
||||
}
|
||||
|
||||
if (aX1.getDimSize(0) != aY1.getDimSize(0))
|
||||
{
|
||||
return Matrix();
|
||||
}
|
||||
|
||||
int columnNum = aV.getDimSize(1);
|
||||
int rowNum = aV.getDimSize(0);
|
||||
|
||||
if(aX.getDimSize(0) != columnNum || aY.getDimSize(0) != rowNum)
|
||||
{
|
||||
return Matrix();
|
||||
}
|
||||
|
||||
int nx1 = aX1.getDimSize(0);
|
||||
std::shared_ptr<double> resultData = std::shared_ptr<double>(Aurora::malloc(nx1), Aurora::free);
|
||||
for (int i = 0; i < nx1; ++i)
|
||||
{
|
||||
std::shared_ptr<double> xResultData = std::shared_ptr<double>(Aurora::malloc(columnNum), Aurora::free);
|
||||
for(int j =0; j < columnNum; ++j)
|
||||
{
|
||||
xResultData.get()[j] = interp1(aY,aV($,j).toMatrix(),aY1(i).toMatrix(),aMethod).getData()[0];
|
||||
}
|
||||
Matrix xResult(xResultData,std::vector<int>{columnNum});
|
||||
resultData.get()[i] = interp1(aX,xResult,aX1(i).toMatrix(),aMethod).getData()[0];
|
||||
}
|
||||
return Matrix(resultData,std::vector<int>{nx1});
|
||||
}
|
||||
|
||||
Matrix Aurora::interpn(const Matrix& aX, const Matrix& aY, const Matrix& aV, const Matrix& aX1, const Matrix& aY1, InterpnMethod aMethod)
|
||||
{
|
||||
return Aurora::interp2(aY,aX,aV,aY1,aX1,aMethod);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user