fftw3-ruby 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,93 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FFTW3
4
+ module Wisdom
5
+ def self.export_to_file(filename, precision: :double)
6
+ ffi = FFTW3::FFI.module_for(precision)
7
+ pfx = FFTW3::FFI.prefix_for(precision)
8
+ ffi.send(:"#{pfx}export_wisdom_to_filename", filename) != 0
9
+ end
10
+
11
+ def self.export_to_string(precision: :double)
12
+ ffi = FFTW3::FFI.module_for(precision)
13
+ pfx = FFTW3::FFI.prefix_for(precision)
14
+ ptr = ffi.send(:"#{pfx}export_wisdom_to_string")
15
+ return nil if ptr.null?
16
+
17
+ str = ptr.read_string
18
+ ffi.send(:"#{pfx}free", ptr)
19
+ str
20
+ end
21
+
22
+ def self.export_to_io(io, precision: :double)
23
+ ffi = FFTW3::FFI.module_for(precision)
24
+ pfx = FFTW3::FFI.prefix_for(precision)
25
+ writer = proc do |char, _data|
26
+ io.write(callback_char_to_string(char))
27
+ end
28
+
29
+ ffi.send(:"#{pfx}export_wisdom", writer, nil)
30
+ io
31
+ end
32
+
33
+ def self.import_from_file(filename, precision: :double)
34
+ ffi = FFTW3::FFI.module_for(precision)
35
+ pfx = FFTW3::FFI.prefix_for(precision)
36
+ ffi.send(:"#{pfx}import_wisdom_from_filename", filename) != 0
37
+ end
38
+
39
+ def self.import_from_string(str, precision: :double)
40
+ ffi = FFTW3::FFI.module_for(precision)
41
+ pfx = FFTW3::FFI.prefix_for(precision)
42
+ ffi.send(:"#{pfx}import_wisdom_from_string", str) != 0
43
+ end
44
+
45
+ def self.import_from_io(io, precision: :double)
46
+ ffi = FFTW3::FFI.module_for(precision)
47
+ pfx = FFTW3::FFI.prefix_for(precision)
48
+ reader = build_reader(io)
49
+ ffi.send(:"#{pfx}import_wisdom", reader, nil) != 0
50
+ end
51
+
52
+ def self.import_system(precision: :double)
53
+ ffi = FFTW3::FFI.module_for(precision)
54
+ pfx = FFTW3::FFI.prefix_for(precision)
55
+ ffi.send(:"#{pfx}import_system_wisdom") != 0
56
+ end
57
+
58
+ def self.forget!(precision: :double)
59
+ ffi = FFTW3::FFI.module_for(precision)
60
+ pfx = FFTW3::FFI.prefix_for(precision)
61
+ ffi.send(:"#{pfx}forget_wisdom")
62
+ end
63
+
64
+ def self.callback_char_to_string(char)
65
+ return char if char.is_a?(String)
66
+
67
+ [char].pack("c")
68
+ end
69
+ private_class_method :callback_char_to_string
70
+
71
+ def self.build_reader(io)
72
+ if io.respond_to?(:getbyte)
73
+ proc do |_data|
74
+ byte = io.getbyte
75
+ byte.nil? ? -1 : byte
76
+ end
77
+ else
78
+ bytes = io.read.to_s.b.bytes
79
+ index = 0
80
+ proc do |_data|
81
+ if index < bytes.length
82
+ byte = bytes[index]
83
+ index += 1
84
+ byte
85
+ else
86
+ -1
87
+ end
88
+ end
89
+ end
90
+ end
91
+ private_class_method :build_reader
92
+ end
93
+ end
data/lib/fftw3.rb ADDED
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "fftw3/version"
4
+ require_relative "fftw3/error"
5
+ require_relative "fftw3/constants"
6
+ require_relative "fftw3/ffi/types"
7
+ require_relative "fftw3/ffi/library_loader"
8
+ require_relative "fftw3/ffi/double"
9
+ require_relative "fftw3/ffi/float"
10
+ require_relative "fftw3/ffi/long_double"
11
+ require_relative "fftw3/ffi/quad"
12
+ require_relative "fftw3/aligned_memory"
13
+ require_relative "fftw3/iodim"
14
+ require_relative "fftw3/plan"
15
+ require_relative "fftw3/wisdom"
16
+ require_relative "fftw3/threads"
17
+ require_relative "fftw3/utils"
18
+
19
+ module FFTW3
20
+ class << self
21
+ def double_available?
22
+ FFI::Double.available?
23
+ end
24
+
25
+ def float_available?
26
+ FFI::Float.available?
27
+ end
28
+
29
+ def long_double_available?
30
+ FFI::LongDouble.available?
31
+ end
32
+
33
+ def quad_available?
34
+ FFI::Quad.available?
35
+ end
36
+
37
+ def available_precisions
38
+ precisions = []
39
+ precisions << :double if double_available?
40
+ precisions << :float if float_available?
41
+ precisions << :long_double if long_double_available?
42
+ precisions << :quad if quad_available?
43
+ precisions
44
+ end
45
+
46
+ def version(precision: :double)
47
+ FFTW3::FFI.string_constant(precision, :version)
48
+ end
49
+
50
+ def compiler(precision: :double)
51
+ FFTW3::FFI.string_constant(precision, :cc)
52
+ end
53
+
54
+ def codelet_optimizations(precision: :double)
55
+ FFTW3::FFI.string_constant(precision, :codelet_optim)
56
+ end
57
+ end
58
+ end
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fftw3-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Yudai Takada
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: bigdecimal
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: ffi
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '1.15'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.15'
40
+ description: Comprehensive Ruby bindings for libfftw3 via FFI. Supports double/float/long_double/quad
41
+ precision, Basic/Advanced/Guru/Guru64 interfaces, Wisdom, and threading.
42
+ email:
43
+ - t.yudai92@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - LICENSE.txt
49
+ - README.md
50
+ - Rakefile
51
+ - lib/fftw3.rb
52
+ - lib/fftw3/aligned_memory.rb
53
+ - lib/fftw3/constants.rb
54
+ - lib/fftw3/error.rb
55
+ - lib/fftw3/ffi/binding_template.rb
56
+ - lib/fftw3/ffi/double.rb
57
+ - lib/fftw3/ffi/float.rb
58
+ - lib/fftw3/ffi/library_loader.rb
59
+ - lib/fftw3/ffi/long_double.rb
60
+ - lib/fftw3/ffi/quad.rb
61
+ - lib/fftw3/ffi/types.rb
62
+ - lib/fftw3/iodim.rb
63
+ - lib/fftw3/plan.rb
64
+ - lib/fftw3/threads.rb
65
+ - lib/fftw3/utils.rb
66
+ - lib/fftw3/version.rb
67
+ - lib/fftw3/wisdom.rb
68
+ homepage: https://github.com/ydah/fftw3
69
+ licenses:
70
+ - MIT
71
+ metadata:
72
+ homepage_uri: https://github.com/ydah/fftw3
73
+ source_code_uri: https://github.com/ydah/fftw3
74
+ changelog_uri: https://github.com/ydah/fftw3/blob/main/CHANGELOG.md
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: 3.1.0
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubygems_version: 4.0.6
90
+ specification_version: 4
91
+ summary: Comprehensive Ruby FFI bindings for FFTW3
92
+ test_files: []