Fix std and malloc
This commit is contained in:
@@ -132,7 +132,8 @@ namespace Aurora {
|
||||
|
||||
double *malloc(size_t size, bool complex) {
|
||||
if (!complex) return (double *) mkl_malloc(size * sizeof(double), 64);
|
||||
return (double *) mkl_malloc(size * sizeof(std::complex<double>), 64);
|
||||
size_t complex_size = size * sizeof(std::complex<double>);
|
||||
return (double *) mkl_malloc(complex_size, 64);
|
||||
}
|
||||
|
||||
void free(void* ptr){
|
||||
|
||||
@@ -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;
|
||||
|
||||
//傅里叶变换的数量
|
||||
|
||||
@@ -349,10 +349,7 @@ namespace Aurora {
|
||||
|
||||
Matrix Matrix::deepCopy() const {
|
||||
double *newBuffer = malloc(getDataSize(), getValueType()==Complex);
|
||||
// size_t data_size = getDataSize() * getValueType();
|
||||
cblas_dcopy(getDataSize() * getValueType(),getData(),1,newBuffer,1);
|
||||
// std::memcpy(newBuffer,getData(),data_size*sizeof(double));
|
||||
|
||||
cblas_dcopy(getDataSize() * getValueType(),getData(),1,newBuffer,1);
|
||||
return New(newBuffer,
|
||||
getDimSize(0),
|
||||
getDimSize(1),
|
||||
|
||||
Reference in New Issue
Block a user