Module: Numo::FFTW
- Defined in:
- ext/numo/fftw/fftw.c
Class Method Summary collapse
-
.dft(narray, sign) ⇒ Numo::DComplex
Multi-dimentional Complex Discrete Fourier Transform.
-
.dft_1d(narray, sign) ⇒ Numo::DComplex
1-dimentional Complex Discrete Fourier Transform along the last 1 dimension.
-
.dft_2d(narray, sign) ⇒ Numo::DComplex
2-dimentional Complex Discrete Fourier Transform along the last 2 dimensions.
-
.dft_3d(narray, sign) ⇒ Numo::DComplex
3-dimentional Complex Discrete Fourier Transform along the last 3 dimensions.
Class Method Details
.dft(narray, sign) ⇒ Numo::DComplex
Multi-dimentional Complex Discrete Fourier Transform
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 |
# File 'ext/numo/fftw/fftw.c', line 232
static VALUE
numo_fftw_dft(VALUE mod, VALUE vna, VALUE vsign)
{
VALUE vans;
int sign;
narray_t *na;
int ndim, i;
int *shape;
fftw_complex *in, *out;
fftw_plan plan;
sign = NUM2INT(vsign);
if (sign != 1 && sign != -1) {
rb_raise(rb_eArgError,"second argument (sign) must be 1 or -1");
}
if (CLASS_OF(vna) != numo_cDComplex) {
vna = rb_funcall(numo_cDComplex, id_cast, 1, vna);
}
if (!RTEST(nary_check_contiguous(vna))) {
vna = nary_dup(vna);
}
GetNArray(vna,na);
ndim = NA_NDIM(na);
shape = ALLOCA_N(int,ndim);
for (i=0; i<ndim; i++) {
shape[i] = NA_SHAPE(na)[i];
}
if (TEST_INPLACE(vna)) {
vans = vna;
in = out = (fftw_complex*)na_get_pointer_for_read_write(vna);
} else {
vans = nary_s_new_like(numo_cDComplex, vna);
in = (fftw_complex*)na_get_pointer_for_read(vna);
out = (fftw_complex*)na_get_pointer_for_write(vans);
}
plan = fftw_plan_dft(ndim, shape, in, out, sign, FFTW_ESTIMATE);
fftw_execute(plan);
fftw_destroy_plan(plan);
RB_GC_GUARD(vna);
return vans;
}
|
.dft_1d(narray, sign) ⇒ Numo::DComplex
1-dimentional Complex Discrete Fourier Transform along the last 1 dimension.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'ext/numo/fftw/fftw.c', line 55
static VALUE
numo_fftw_dft_1d(VALUE mod, VALUE vna, VALUE vsign)
{
narray_t *na;
VALUE vans;
int ndim;
int sign=-1;
size_t shape[1];
ndfunc_arg_in_t ain[1] = {{cDC,1}};
ndfunc_arg_out_t aout[1] = {{cDC,1,shape}};
ndfunc_t ndf = { iter_fftw_dft_1d, NO_LOOP|NDF_INPLACE, 1, 1, ain, aout };
sign = NUM2INT(vsign);
if (sign != 1 && sign != -1) {
rb_raise(rb_eArgError,"second argument (sign) must be 1 or -1");
}
GetNArray(vna,na);
ndim = NA_NDIM(na);
if (ndim<1) {
rb_raise(nary_eDimensionError,"ndim(=%d) should >= 1",ndim);
}
shape[0] = NA_SHAPE(na)[ndim-1];
vans = na_ndloop3(&ndf, &sign, 1, vna);
RB_GC_GUARD(vna);
return vans;
}
|
.dft_2d(narray, sign) ⇒ Numo::DComplex
2-dimentional Complex Discrete Fourier Transform along the last 2 dimensions.
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'ext/numo/fftw/fftw.c', line 119
static VALUE
numo_fftw_dft_2d(VALUE mod, VALUE vna, VALUE vsign)
{
narray_t *na;
VALUE vans;
int ndim;
int sign=-1;
size_t shape[2];
ndfunc_arg_in_t ain[1] = {{cDC,2}};
ndfunc_arg_out_t aout[1] = {{cDC,2,shape}};
ndfunc_t ndf = { iter_fftw_dft_2d, NO_LOOP|NDF_INPLACE, 1, 1, ain, aout };
sign = NUM2INT(vsign);
if (sign != 1 && sign != -1) {
rb_raise(rb_eArgError,"second argument (sign) must be 1 or -1");
}
GetNArray(vna,na);
ndim = NA_NDIM(na);
if (ndim<2) {
rb_raise(nary_eDimensionError,"ndim(=%d) should >= 2",ndim);
}
shape[1] = NA_SHAPE(na)[ndim-1];
shape[0] = NA_SHAPE(na)[ndim-2];
vans = na_ndloop3(&ndf, &sign, 1, vna);
RB_GC_GUARD(vna);
return vans;
}
|
.dft_3d(narray, sign) ⇒ Numo::DComplex
3-dimentional Complex Discrete Fourier Transform along the last 3 dimensions.
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'ext/numo/fftw/fftw.c', line 187
static VALUE
numo_fftw_dft_3d(VALUE mod, VALUE vna, VALUE vsign)
{
narray_t *na;
VALUE vans;
int ndim;
int sign=-1;
size_t shape[3];
ndfunc_arg_in_t ain[1] = {{cDC,3}};
ndfunc_arg_out_t aout[1] = {{cDC,3,shape}};
ndfunc_t ndf = { iter_fftw_dft_3d, NO_LOOP|NDF_INPLACE, 1, 1, ain, aout };
sign = NUM2INT(vsign);
if (sign != 1 && sign != -1) {
rb_raise(rb_eArgError,"second argument (sign) must be 1 or -1");
}
GetNArray(vna,na);
ndim = NA_NDIM(na);
if (ndim<3) {
rb_raise(nary_eDimensionError,"ndim(=%d) should >= 3",ndim);
}
shape[2] = NA_SHAPE(na)[ndim-1];
shape[1] = NA_SHAPE(na)[ndim-2];
shape[0] = NA_SHAPE(na)[ndim-3];
vans = na_ndloop3(&ndf, &sign, 1, vna);
RB_GC_GUARD(vna);
return vans;
}
|