numo-fftw 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ec645a03722200a65ce8f059b2fea6eeda1f27ab
4
+ data.tar.gz: b564acfb52fa35cbd907063be6d149c8279fdc4c
5
+ SHA512:
6
+ metadata.gz: b9221bfe095e69c2299d322e2933a2fe2b0803f09863e97a5f942b62343d6c4dcaf3c4b4b58c66b30e4e44f0819e626181e17b1a56ee5d7db401d673f6998e28
7
+ data.tar.gz: '069577773e93ccb3a299258c29e7159639ef7f113181517aa993bdbc53028f2df8aabeaa31424625cccf9393c002924482f22eea50d172ecfffce20a90d603c4'
@@ -0,0 +1,18 @@
1
+ # FFTW3 interface for Ruby with Numo::NArray
2
+
3
+ ## FFTW
4
+ * FFTW is a C subroutine library for computing the discrete Fourier transform (DFT) in one or more dimensions, of arbitrary input size, and of both real and complex data.
5
+ * [FFTW site](http://www.fftw.org/)
6
+
7
+ ## Numo::FFTW
8
+ * [GitHub site](https://github.com/ruby-numo/fftw)
9
+ * [Tentative API Document]()
10
+
11
+ ## Installation
12
+ * Install [FFTW3](http://www.fftw.org/)
13
+ * Install [Numo::NArray](https://github.com/ruby-numo/narray)
14
+ * Install Numo::FFTW :
15
+
16
+ ```shell
17
+ $ gem install numo-fftw
18
+ ```
@@ -0,0 +1,13 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ task :doc do
4
+ dir = "ext/numo/fftw"
5
+ src = %w[fftw.c]
6
+ path = src.map{|s| File.join(dir,s)}
7
+ sh "cd #{dir}; ruby extconf.rb; make #{src.join(' ')}"
8
+ sh "rm -rf yard .yardoc; yard doc -o yard -m markdown -r README.md #{path.join(' ')}"
9
+ end
10
+
11
+ task :cleandoc do
12
+ rm_rf %w[yard .yardoc]
13
+ end
@@ -0,0 +1,14 @@
1
+ CLEANOBJS = *.o */*.o *.bak *~
2
+ ERB = erb -T-
3
+
4
+ fftw.c: fftw.erb.c
5
+ $(ERB) fftw.erb.c > fftw.c
6
+
7
+ doc : fftw.c
8
+ yard doc -o yard -m markdown $<
9
+
10
+ clean: cleansrc cleandoc
11
+ cleansrc:
12
+ -$(Q)$(RM) fftw.c
13
+ cleandoc:
14
+ -$(Q)$(RM_RF) yard .yardoc
@@ -0,0 +1,43 @@
1
+ require 'rbconfig.rb'
2
+ require 'numo/narray'
3
+ require 'mkmf'
4
+
5
+ dir_config("fftw")
6
+
7
+ #$CFLAGS="-g -O0"
8
+ #$INCFLAGS = "-I../ext -I../ext/types #$INCFLAGS"
9
+
10
+ $LOAD_PATH.each do |x|
11
+ if File.exist? File.join(x,'numo/numo/narray.h')
12
+ $INCFLAGS = "-I#{x}/numo " + $INCFLAGS
13
+ break
14
+ end
15
+ end
16
+
17
+ if !have_header('numo/narray.h')
18
+ print <<EOL
19
+ Header numo/narray.h was not found. Give pathname as follows:
20
+ % ruby extconf.rb --with-narray-include=narray_h_dir
21
+ EOL
22
+ exit(1)
23
+ end
24
+
25
+ if !have_header('fftw3.h')
26
+ print <<EOL
27
+ Header fftw3.h was not found. Give pathname as follows:
28
+ % ruby extconf.rb --with-fftw-include=header_dir
29
+ EOL
30
+ exit(1)
31
+ end
32
+
33
+ if !have_library('fftw3')
34
+ print <<EOL
35
+ Library libfftw3.so was not found. Give pathname as follows:
36
+ % ruby extconf.rb --with-fftw-lib=library_dir
37
+ EOL
38
+ exit(1)
39
+ end
40
+
41
+ $objs = %w[fftw.o]
42
+
43
+ create_makefile('numo/fftw')
@@ -0,0 +1,164 @@
1
+ /*
2
+ FFTW interface for Numo::NArray
3
+ Copyright(C) 2017 Masahiro TANAKA
4
+
5
+ FFTW: C subroutine library for computing the discrete Fourier transform (DFT)
6
+ http://www.fftw.org/
7
+ */
8
+
9
+ #include <fftw3.h>
10
+
11
+ #include <ruby.h>
12
+ #include "numo/narray.h"
13
+ #include "numo/template.h"
14
+ #define cDC numo_cDComplex
15
+ #define cDF numo_cDFloat
16
+
17
+ static ID id_cast;
18
+
19
+ <%
20
+ def argmap(arg)
21
+ case arg
22
+ when Numeric
23
+ arg = 1..arg
24
+ end
25
+ arg.map do |x|
26
+ yield(x)
27
+ end.join(",")
28
+ end
29
+ $funcs = []
30
+ %>
31
+
32
+ <% (1..3).each do |d| %>
33
+ <% $funcs.push func="dft_#{d}d" %>
34
+ static void
35
+ iter_fftw_<%=func%>(na_loop_t *const lp)
36
+ {
37
+ char *p1, *p2;
38
+ int sign;
39
+ int <%=argmap(d){|i|"n#{i}"}%>;
40
+ fftw_plan plan;
41
+
42
+ <% (1..d).each do |i| %>
43
+ n<%=i%> = lp->args[0].shape[<%=i-1%>];
44
+ <% end %>
45
+ p1 = ((lp)->args[0]).ptr + ((lp)->args[0].iter[0]).pos;
46
+ p2 = ((lp)->args[1]).ptr + ((lp)->args[1].iter[0]).pos;
47
+
48
+ sign = *(int*)(lp->opt_ptr);
49
+ plan = fftw_plan_dft_<%=d%>d(<%=argmap(d){|i|"n#{i}"}%>,
50
+ (fftw_complex*)p1, (fftw_complex*)p2,
51
+ sign, FFTW_ESTIMATE);
52
+ fftw_execute(plan);
53
+ fftw_destroy_plan(plan);
54
+ }
55
+
56
+ /*
57
+ <%=d%>-dimentional Complex Discrete Fourier Transform
58
+ @overload dft_<%=d%>d(narray,sign)
59
+ @param [Numo::DComplex] narray Input NArray with at least <%=d%> dimension<%="s" if d>1%>.
60
+ @param [Numeric] sign the sign of the exponent in the formula
61
+ that defines the Fourier transform.
62
+ It can be -1 (= FFTW_FORWARD) or +1 (= FFTW_BACKWARD).
63
+ @return [Numo::DComplex] Result DComplex NArray with
64
+ `shape = [.., <%if d>2%>nz, <%end;if d>1%>ny, <%end%>nx]`.
65
+ */
66
+ static VALUE
67
+ numo_fftw_<%=func%>(VALUE mod, VALUE vna, VALUE vsign)
68
+ {
69
+ narray_t *na;
70
+ VALUE vans;
71
+ int ndim;
72
+ int sign=-1;
73
+ size_t shape[<%=d%>];
74
+ ndfunc_arg_in_t ain[1] = {{cDC,<%=d%>}};
75
+ ndfunc_arg_out_t aout[1] = {{cDC,<%=d%>,shape}};
76
+ ndfunc_t ndf = { iter_fftw_<%=func%>, NO_LOOP|NDF_INPLACE, 1, 1, ain, aout };
77
+
78
+ sign = NUM2INT(vsign);
79
+ if (sign != 1 && sign != -1) {
80
+ rb_raise(rb_eArgError,"second argument (sign) must be 1 or -1");
81
+ }
82
+ GetNArray(vna,na);
83
+ ndim = NA_NDIM(na);
84
+ if (ndim<<%=d%>) {
85
+ rb_raise(nary_eDimensionError,"ndim(=%d) should >= <%=d%>",ndim);
86
+ }
87
+ <% (1..d).each do |i| %>
88
+ shape[<%=d-i%>] = NA_SHAPE(na)[ndim-<%=i%>];
89
+ <% end %>
90
+ vans = na_ndloop3(&ndf, &sign, 1, vna);
91
+ RB_GC_GUARD(vna);
92
+ return vans;
93
+ }
94
+ <% end %>
95
+
96
+ <% $funcs.push func="dft" %>
97
+ /*
98
+ Multi-dimentional Complex Discrete Fourier Transform
99
+ @overload dft(narray,sign)
100
+ @param [Numo::DComplex] narray Input NArray with any dimension.
101
+ @param [Numeric] sign the sign of the exponent in the formula
102
+ that defines the Fourier transform.
103
+ It can be -1 (= FFTW_FORWARD) or +1 (= FFTW_BACKWARD).
104
+ @return [Numo::DComplex] Result DComplex NArray with the same shape
105
+ as input NArray.
106
+ */
107
+ static VALUE
108
+ numo_fftw_<%=func%>(VALUE mod, VALUE vna, VALUE vsign)
109
+ {
110
+ VALUE vans;
111
+ int sign;
112
+ narray_t *na;
113
+ int ndim, i;
114
+ int *shape;
115
+ fftw_complex *in, *out;
116
+ fftw_plan plan;
117
+
118
+ sign = NUM2INT(vsign);
119
+ if (sign != 1 && sign != -1) {
120
+ rb_raise(rb_eArgError,"second argument (sign) must be 1 or -1");
121
+ }
122
+ if (CLASS_OF(vna) != numo_cDComplex) {
123
+ vna = rb_funcall(numo_cDComplex, id_cast, 1, vna);
124
+ }
125
+ if (!RTEST(nary_check_contiguous(vna))) {
126
+ vna = nary_dup(vna);
127
+ }
128
+ GetNArray(vna,na);
129
+ ndim = NA_NDIM(na);
130
+ shape = ALLOCA_N(int,ndim);
131
+ for (i=0; i<ndim; i++) {
132
+ shape[i] = NA_SHAPE(na)[i];
133
+ }
134
+ if (TEST_INPLACE(vna)) {
135
+ vans = vna;
136
+ in = out = (fftw_complex*)na_get_pointer_for_read_write(vna);
137
+ } else {
138
+ vans = nary_s_new_like(numo_cDComplex, vna);
139
+ in = (fftw_complex*)na_get_pointer_for_read(vna);
140
+ out = (fftw_complex*)na_get_pointer_for_write(vans);
141
+ }
142
+ plan = fftw_plan_dft(ndim, shape, in, out, sign, FFTW_ESTIMATE);
143
+ fftw_execute(plan);
144
+ fftw_destroy_plan(plan);
145
+
146
+ RB_GC_GUARD(vna);
147
+ return vans;
148
+ }
149
+
150
+ void
151
+ Init_fftw()
152
+ {
153
+ VALUE mNumo,mFFTW;
154
+
155
+ rb_require("numo/narray");
156
+ mNumo = rb_define_module("Numo");
157
+ mFFTW = rb_define_module_under(mNumo,"FFTW");
158
+
159
+ <% $funcs.each do |f| %>
160
+ rb_define_module_function(mFFTW,"<%=f%>",numo_fftw_<%=f%>,2);
161
+ <% end %>
162
+
163
+ id_cast = rb_intern("cast");
164
+ }
@@ -0,0 +1 @@
1
+ #define NUMO_FFTW_VERSION "0.1.0"
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ open("ext/numo/fftw/version.h") do |f|
6
+ f.each_line do |l|
7
+ if /NUMO_FFTW_VERSION "([\d.]+)"/ =~ l
8
+ VERSION = $1
9
+ break
10
+ end
11
+ end
12
+ end
13
+
14
+ Gem::Specification.new do |spec|
15
+ spec.name = "numo-fftw"
16
+ spec.version = VERSION
17
+ spec.authors = ["Masahiro TANAKA"]
18
+ spec.email = ["masa16.tanaka@gmail.com"]
19
+ spec.description = %q{Numo::FFTW development version.}
20
+ spec.summary = %q{Numo::FFTW development version}
21
+ spec.homepage = "https://github.com/ruby-numo/fftw"
22
+ spec.licenses = ["GPL2"]
23
+
24
+ spec.files = `git ls-files Gemfile README.md Rakefile ext numo-fftw.gemspec spec`.split($/)
25
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
26
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
27
+ spec.require_paths = ["lib"]
28
+ spec.extensions = ["ext/numo/fftw/extconf.rb"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.3"
31
+ spec.add_development_dependency "rake", "~> 0"
32
+ spec.add_runtime_dependency "numo-narray", "~> 0.9.0.8"
33
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: numo-fftw
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Masahiro TANAKA
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-09-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: numo-narray
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.9.0.8
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.9.0.8
55
+ description: Numo::FFTW development version.
56
+ email:
57
+ - masa16.tanaka@gmail.com
58
+ executables: []
59
+ extensions:
60
+ - ext/numo/fftw/extconf.rb
61
+ extra_rdoc_files: []
62
+ files:
63
+ - README.md
64
+ - Rakefile
65
+ - ext/numo/fftw/depend
66
+ - ext/numo/fftw/extconf.rb
67
+ - ext/numo/fftw/fftw.erb.c
68
+ - ext/numo/fftw/version.h
69
+ - numo-fftw.gemspec
70
+ homepage: https://github.com/ruby-numo/fftw
71
+ licenses:
72
+ - GPL2
73
+ metadata: {}
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 2.6.11
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: Numo::FFTW development version
94
+ test_files: []