Add padding and test
This commit is contained in:
@@ -633,3 +633,23 @@ void Aurora::nantoval(Matrix& aMatrix, double val2) {
|
||||
Eigen::Map<Eigen::VectorXd> srcV(aMatrix.getData(),aMatrix.getDataSize());
|
||||
srcV = srcV.array().isNaN().select(val2,srcV);
|
||||
}
|
||||
|
||||
void Aurora::padding(Matrix &aMatrix, int aIndex, double aValue)
|
||||
{
|
||||
if(aMatrix.isNull() || !aMatrix.isVector())
|
||||
{
|
||||
std::cerr<<"padding only support vector"<<std::endl;
|
||||
return;
|
||||
}
|
||||
if (aMatrix.getDataSize()>aIndex){
|
||||
aMatrix.getData()[aIndex] = aValue;
|
||||
return;
|
||||
}
|
||||
int size = (aIndex+1);
|
||||
double* newData = malloc(size,aMatrix.isComplex());
|
||||
cblas_dcopy(aMatrix.getDataSize()*aMatrix.getValueType(),
|
||||
aMatrix.getData(),1,newData,1);
|
||||
cblas_dcopy((size-aMatrix.getDataSize())*aMatrix.getValueType(),
|
||||
&aValue,0,newData+aMatrix.getDataSize()*aMatrix.getValueType(),1);
|
||||
aMatrix = Matrix::New(newData,size,1,1,aMatrix.getValueType());
|
||||
}
|
||||
|
||||
@@ -96,7 +96,22 @@ namespace Aurora {
|
||||
*/
|
||||
Matrix polyval(const Matrix& aP, const Matrix& aX);
|
||||
|
||||
/**
|
||||
* 将所有nan值设置为特定值
|
||||
* @attention 直接在原数据上进行修改!
|
||||
* @param aMatrix 向量
|
||||
* @param val 指定值
|
||||
*/
|
||||
void nantoval(Matrix& aMatrix,double val);
|
||||
|
||||
/**
|
||||
* 使用特定值补齐矩阵,默认为设置原数据矩阵数据到制定长度索引的所有值为制定值
|
||||
* @attention 直接在原数据上进行修改!
|
||||
* @param aMatrix 向量
|
||||
* @param aIndex 长度索引
|
||||
* @param aValue 指定值
|
||||
*/
|
||||
void padding(Matrix& aMatrix, int aIndex, double aValue);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -493,3 +493,11 @@ TEST_F(Function1D_Test, reshape) {
|
||||
EXPECT_DOUBLE_AE(result.getDimSize(1),3);
|
||||
EXPECT_DOUBLE_AE(result.getDimSize(2),3);
|
||||
}
|
||||
|
||||
TEST_F(Function1D_Test, padding) {
|
||||
double *input = new double[18]{10,2,1,3,4,4,16,3,1,2,15,-2,1,-3,4,-4,1,-3};
|
||||
auto ma = Aurora::Matrix::fromRawData(input,18,1,1);
|
||||
Aurora::padding(ma,20,1);
|
||||
auto result = ma.getData();
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user