Fix std and malloc
This commit is contained in:
@@ -124,21 +124,18 @@ Matrix Aurora::std(const Matrix &aMatrix) {
|
||||
return Matrix();
|
||||
}
|
||||
|
||||
Matrix src = aMatrix.isComplex() ? Aurora::abs(aMatrix) : aMatrix;
|
||||
Matrix src = aMatrix.isComplex() ? Aurora::abs(aMatrix) : aMatrix.deepCopy();
|
||||
int calc_size = src.getDimSize(0) == 1 ? src.getDimSize(1) : src.getDimSize(0);
|
||||
int col = src.getDimSize(0) == 1?1:src.getDimSize(1) ;
|
||||
double *temp = malloc(aMatrix.getDataSize(), aMatrix.getValueType()==Complex);
|
||||
cblas_dcopy(aMatrix.getDataSize() * aMatrix.getValueType(),aMatrix.getData(),1,temp,1);
|
||||
auto std = Aurora::malloc(col);
|
||||
for (int i = 0; i < col; ++i) {
|
||||
double *p = temp + i * calc_size;
|
||||
double *p = src.getData() + i * calc_size;
|
||||
double mean = cblas_dasum(calc_size, p, 1) / calc_size;
|
||||
vdSubI(calc_size, p, 1, &mean, 0, p, 1);
|
||||
vdSqr(calc_size, p, p);
|
||||
std[i] = cblas_dasum(calc_size, p, 1) / (calc_size - 1);
|
||||
}
|
||||
Aurora::free(temp);
|
||||
vdSqrt(src.getDimSize(1), std, std);
|
||||
vdSqrt(col, std, std);
|
||||
return Matrix::New(std, 1, col, aMatrix.getDimSize(2));
|
||||
}
|
||||
|
||||
@@ -644,7 +641,8 @@ Matrix Aurora::ifft(const Matrix &aMatrix) {
|
||||
MKL_LONG status;
|
||||
|
||||
//创建 Descriptor, 精度 double , 输入类型实数, 维度1
|
||||
status = DftiCreateDescriptor(&my_desc_handle, DFTI_DOUBLE, DFTI_COMPLEX, 1, aMatrix.getDimSize(0));
|
||||
int size = aMatrix.getDimSize(0);
|
||||
status = DftiCreateDescriptor(&my_desc_handle, DFTI_DOUBLE, DFTI_COMPLEX, 1, size);
|
||||
if (status != DFTI_NO_ERROR) goto error;
|
||||
//通过 setValue 配置Descriptor
|
||||
//使用单独的输出数据缓存
|
||||
@@ -652,14 +650,14 @@ Matrix Aurora::ifft(const Matrix &aMatrix) {
|
||||
if (status != DFTI_NO_ERROR) goto error;
|
||||
|
||||
//设置DFTI_BACKWARD_SCALE !!!很关键,不然值不对
|
||||
status = DftiSetValue(my_desc_handle, DFTI_BACKWARD_SCALE, 1.0f / aMatrix.getDimSize(0));
|
||||
status = DftiSetValue(my_desc_handle, DFTI_BACKWARD_SCALE, 1.0f / size);
|
||||
if (status != DFTI_NO_ERROR) goto error;
|
||||
|
||||
status = DftiSetValue(my_desc_handle,DFTI_INPUT_DISTANCE,aMatrix.getDimSize(0));
|
||||
status = DftiSetValue(my_desc_handle,DFTI_INPUT_DISTANCE,size);
|
||||
if (status != DFTI_NO_ERROR) goto error;
|
||||
|
||||
//每个傅里叶变换的输出距离
|
||||
status = DftiSetValue(my_desc_handle,DFTI_OUTPUT_DISTANCE,aMatrix.getDimSize(0));
|
||||
status = DftiSetValue(my_desc_handle,DFTI_OUTPUT_DISTANCE,size);
|
||||
if (status != DFTI_NO_ERROR) goto error;
|
||||
|
||||
//傅里叶变换的数量
|
||||
|
||||
Reference in New Issue
Block a user