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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 170eebc1e93586a62ba569d77a3a48bf8c1deb2a
4
- data.tar.gz: a40006057f6538de447002968f1e5d17d7f72ab3
3
+ metadata.gz: 0b5b5dc31d542918a00c130c3397e70f99636dc5
4
+ data.tar.gz: f1e59827f23e783c2d3d3c49e9339ab9bfebddd7
5
5
  SHA512:
6
- metadata.gz: 2a93c018c1f75ad1c903d5235e874ed6e881cddf33523ac9be7ebff7c047e2767561db48204c2a5ec13f72d243cee1e49394bfa0362b63b20f395245801700d9
7
- data.tar.gz: 4c23f877e13768d2641f69ddf000b54603038df559b250179a320f395c0920f31a162cfb76b2bde310add0ea1ce8f8b5540da8429dfaf2b93b9c64dc5ca8539c
6
+ metadata.gz: 2d7ac577d847186df9d7ec726e4403d2218690180df2c244b202fc928cd6919f02381e6a86863034817b027497abfb3ce107df0439ff8f8888b17e28057868ee
7
+ data.tar.gz: 4987a31efec2b173930f94f1e0cc2e84d47d088d36d3953688a07639114e428cfb40259c0b14e653e7e0c6e1af76d10c469ed167a02f2864217610d8f3551fd6
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ # 0.2.0
2
+ - Add fftconvolve method that convolves two arrays with FFT.
3
+
1
4
  # 0.1.1
2
5
  - Add input validation for empty array.
3
6
  - Add input validation for non-Numo::NArray object.
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.1.1)
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 the library in advance.
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
@@ -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
@@ -5,6 +5,6 @@ module Numo
5
5
  # Numo::Pocketfft is the module that has functions for Fourier transform.
6
6
  module Pocketfft
7
7
  # The version of Numo::Pocketfft you are using.
8
- VERSION = '0.1.1'
8
+ VERSION = '0.2.0'
9
9
  end
10
10
  end
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.1.1
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 00:00:00.000000000 Z
11
+ date: 2019-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: numo-narray