numo-pocketfft 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +2 -2
- data/lib/numo/pocketfft.rb +40 -0
- data/lib/numo/pocketfft/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b5b5dc31d542918a00c130c3397e70f99636dc5
|
4
|
+
data.tar.gz: f1e59827f23e783c2d3d3c49e9339ab9bfebddd7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d7ac577d847186df9d7ec726e4403d2218690180df2c244b202fc928cd6919f02381e6a86863034817b027497abfb3ce107df0439ff8f8888b17e28057868ee
|
7
|
+
data.tar.gz: 4987a31efec2b173930f94f1e0cc2e84d47d088d36d3953688a07639114e428cfb40259c0b14e653e7e0c6e1af76d10c469ed167a02f2864217610d8f3551fd6
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
[![Build Status](https://travis-ci.org/yoshoku/numo-pocketfft.svg?branch=master)](https://travis-ci.org/yoshoku/numo-pocketfft)
|
5
5
|
[![Coverage Status](https://coveralls.io/repos/github/yoshoku/numo-pocketfft/badge.svg?branch=master)](https://coveralls.io/github/yoshoku/numo-pocketfft?branch=master)
|
6
6
|
[![BSD 3-Clause License](https://img.shields.io/badge/License-BSD%203--Clause-orange.svg)](https://github.com/yoshoku/numo-liblinear/blob/master/LICENSE.txt)
|
7
|
-
[![Documentation](http://img.shields.io/badge/docs-rdoc.info-blue.svg)](http://www.rubydoc.info/gems/numo-pocketfft/0.
|
7
|
+
[![Documentation](http://img.shields.io/badge/docs-rdoc.info-blue.svg)](http://www.rubydoc.info/gems/numo-pocketfft/0.2.0)
|
8
8
|
|
9
9
|
Numo::Pocketfft provides functions for performing descrete Fourier Transform with
|
10
10
|
[Numo::NArray](https://github.com/ruby-numo/numo-narray) by using
|
@@ -15,7 +15,7 @@ Note: There are other useful Ruby gems perform descrete Fourier Transform with N
|
|
15
15
|
|
16
16
|
## Installation
|
17
17
|
|
18
|
-
Numo::Pocketfft bundles pocketfft codes, so there is no need to install
|
18
|
+
Numo::Pocketfft bundles pocketfft codes, so there is no need to install another external library in advance.
|
19
19
|
Add this line to your application's Gemfile:
|
20
20
|
|
21
21
|
```ruby
|
data/lib/numo/pocketfft.rb
CHANGED
@@ -146,6 +146,46 @@ module Numo
|
|
146
146
|
raw_fft(b, last_axis_id, inverse: true, real: true)
|
147
147
|
end
|
148
148
|
|
149
|
+
# Convolve two N-dimensinal arrays using dscrete Fourier Transform.
|
150
|
+
# @example
|
151
|
+
# require 'numo/pocketfftw'
|
152
|
+
#
|
153
|
+
# a = Numo::DFloat[1, 2, 3]
|
154
|
+
# b = Numo::DFloat[4, 5]
|
155
|
+
# p Numo::Pocketfft.fftconvolve(a, b)
|
156
|
+
# # Numo::DFloat#shape=[4]
|
157
|
+
# # [4, 13, 22, 15]
|
158
|
+
#
|
159
|
+
# a = Numo::DFloat[[1, 2], [3, 4]]
|
160
|
+
# b = Numo::DFloat[[5, 6], [7, 8]]
|
161
|
+
# p Numo::Pocketfft.fftconvolve(a, b)
|
162
|
+
# # Numo::DFloat#shape=[3,3]
|
163
|
+
# # [[5, 16, 12],
|
164
|
+
# # [22, 60, 40],
|
165
|
+
# # [21, 52, 32]]
|
166
|
+
# @param a [Numo::DFloat/Numo::DComplex] Fisrt input array with any-dimension.
|
167
|
+
# @param b [Numo::DFloat/Numo::DComplex] Second input array with the same number of dimensions as first input array.
|
168
|
+
# @return [Numo::DFloat/Numo::DComplex] The discrete linear convolution of 'a' with 'b'.
|
169
|
+
def fftconvolve(a, b)
|
170
|
+
raise ArgumentError, 'Expect class of input array to be Numo::NArray.' unless a.is_a?(Numo::NArray) && b.is_a?(Numo::NArray)
|
171
|
+
raise ArgumentError, 'Expect input array to be non-empty.' if a.empty? || b.empty?
|
172
|
+
raise ArgumentError, 'Input arrays should have the same dimensionarity' if a.ndim != b.ndim
|
173
|
+
|
174
|
+
ashp = a.shape
|
175
|
+
bshp = b.shape
|
176
|
+
|
177
|
+
return a * b if (ashp + bshp).all? { |el| el == 1 }
|
178
|
+
|
179
|
+
retshp = Array.new(a.ndim) { |n| ashp[n] + bshp[n] - 1 }
|
180
|
+
a_zp = Numo::DComplex.zeros(*retshp).tap { |arr| arr[*ashp.map { |n| 0...n }] = a }
|
181
|
+
b_zp = Numo::DComplex.zeros(*retshp).tap { |arr| arr[*bshp.map { |n| 0...n }] = b }
|
182
|
+
ret = ifftn(fftn(a_zp) * fftn(b_zp))
|
183
|
+
|
184
|
+
return ret if a.is_a?(Numo::DComplex) || a.is_a?(Numo::SComplex) || b.is_a?(Numo::DComplex) || b.is_a?(Numo::SComplex)
|
185
|
+
|
186
|
+
ret.real
|
187
|
+
end
|
188
|
+
|
149
189
|
# @!visibility private
|
150
190
|
def raw_fft(a, axis_id, inverse:, real:)
|
151
191
|
if axis_id == a.ndim - 1
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: numo-pocketfft
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- yoshoku
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-08-
|
11
|
+
date: 2019-08-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: numo-narray
|