Skip to content

Commit

Permalink
Add fft_c2r numpy based implementation for unittest. (PaddlePaddle#34)
Browse files Browse the repository at this point in the history
* add fft_c2r numpy implementation
  • Loading branch information
Feiyu Chan authored Sep 10, 2021
1 parent 3765c70 commit fcd9069
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
6 changes: 3 additions & 3 deletions paddle/fluid/operators/spectral_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class FFTC2COpMaker : public framework::OpProtoAndCheckerMaker {
"fft_norm_type, the fft normalization type.");
AddAttr<bool>("forward", "bool, the fft direction.");
AddComment(R"DOC(
// add doc here
Compute complex to complex FFT.
)DOC");
}
};
Expand Down Expand Up @@ -135,7 +135,7 @@ class FFTR2COpMaker : public framework::OpProtoAndCheckerMaker {
AddAttr<bool>("forward", "bool, the fft direction.");
AddAttr<bool>("onesided", "bool, perform onesided fft.");
AddComment(R"DOC(
// add doc here
Compute real to complex FFT.
)DOC");
}
};
Expand Down Expand Up @@ -236,7 +236,7 @@ class FFTC2ROpMaker : public framework::OpProtoAndCheckerMaker {
"specified by axis.")
.SetDefault(0L);
AddComment(R"DOC(
// add doc here
Compute complex to complex FFT.
)DOC");
}
};
Expand Down
9 changes: 8 additions & 1 deletion python/paddle/fluid/tests/unittests/fft/spectral_op_np.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,11 @@ def fft_r2c_backward(dy, x, axes, normalization, forward, onesided):


def fft_c2r(x, axes, normalization, forward, last_dim_size):
pass
a = asarray(x)
s, axes = _cook_nd_args(a, axes=axes, invreal=1)
if last_dim_size is not None:
s[-1] = last_dim_size
for ii in range(len(axes) - 1):
a = _fftc2c(a, s[ii], axes[ii], normalization, forward)
a = _fftc2r(a, s[-1], axes[-1], normalization, forward)
return a

0 comments on commit fcd9069

Please sign in to comment.