Class: Digiproc::Strategies::BFConvolutionStrategy
- Inherits:
-
Object
- Object
- Digiproc::Strategies::BFConvolutionStrategy
- Defined in:
- lib/strategies/convolution/bf_conv.rb
Overview
Strategy for convolving two arrays of numbers This is an O(n^2) operation, it is more time efficient to use FFT to perform this calculation
Class Method Summary collapse
Class Method Details
.conv(data1, data2) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/strategies/convolution/bf_conv.rb', line 13 def self.conv(data1, data2) dynamic_data = data1.dup static_data = data2.dup conv_sum = [] n = 0 start, stop = conv_overlap_area(static_data.length, dynamic_data.length, n) while start <= stop sum = 0 for val in start..stop sum += static_data[val] * dynamic_data[transform_to_local_index(val, n)] end conv_sum << sum n = conv_sum.length start, stop = conv_overlap_area(static_data.length, dynamic_data.length, n) end conv_sum end |