convolver 0.1.1 → 0.1.2

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: 88d7660efc3504ac86b924689050754185e69f8c
4
- data.tar.gz: 69786c83e478d75db709e00d46346ec6f0bbef8f
3
+ metadata.gz: a0f2badf8733818f128a1c6f1456ae37e114f549
4
+ data.tar.gz: 81889f084e50d4789ec202082422dd9b24304210
5
5
  SHA512:
6
- metadata.gz: 58bf4eb7b7b44fae9f46b79e33e62b2a8148cb9f9d8f40525c74e152b1d3b3ffabfdbb106cce09af350e30bd923fe40d62f38b24f19ef8ee169bc0c5696315f6
7
- data.tar.gz: 4cbafca71dc5399d05950c6ebda268f5533541069bd71130388634edd4530101dc16e689abdd9393493de2e299cf89e7d189a3a510c0deecc491bf9314a0dc4a
6
+ metadata.gz: 557d6b5738041165a5a22f4ede39d4d0cc7333aa6bfd2937cf3334e16e8daa7c12672ed6377be31003974b90b4a8a942f93fdf812d886202894d46088a2c30a5
7
+ data.tar.gz: d598375b28278a5ac14619280068cfaeab82fe2d1c4aac9aeae817bb4b4958c913c1fb6674af1b9f4af901f7844621863e2ffd9d4991dc7ca31e7c8e32818c48
data/.gitignore CHANGED
@@ -16,3 +16,4 @@ spec/reports
16
16
  test/tmp
17
17
  test/version_tmp
18
18
  tmp
19
+ benchmarks
@@ -28,8 +28,51 @@ module Convolver
28
28
  (FFTW3.ifft( cfreqs ).real * (1.0/mod_a.size))[*ranges]
29
29
  end
30
30
 
31
+ # A rough estimate of time that #convolve_fftw3 will take, based on complexity
32
+ # of its operations, and some rough benchmarking. A value of 1.0 corresponds to results
33
+ # varying between 1 and 12 milliseconds on the test computer.
34
+ # @param [NArray] signal must be same size or larger than kernel in each dimension
35
+ # @param [NArray] kernel must be same size or smaller than signal in each dimension
36
+ # @return [Float] rough estimate of time for convolution compared to baseline
37
+ def self.predict_convolve_fft_time signal, kernel
38
+ 16 * 4.55e-08 * combined_shape(signal.shape,kernel.shape).inject(1) { |t,x| t * x * Math.log(x) }
39
+ end
40
+
41
+ # A rough estimate of time that #convolve will take, based on complexity
42
+ # of its operations, and some rough benchmarking. A value of 1.0 corresponds to results
43
+ # varying bewteen 2 and 8 milliseconds on the test computer.
44
+ # @param [NArray] signal must be same size or larger than kernel in each dimension
45
+ # @param [NArray] kernel must be same size or smaller than signal in each dimension
46
+ # @return [Float] rough estimate of time for convolution compared to baseline
47
+ def self.predict_convolve_basic_time signal, kernel
48
+ outputs = shape_to_size( result_shape( signal.shape, kernel.shape ) )
49
+ 4.54e-12 * (outputs * shape_to_size( signal.shape ) * shape_to_size( kernel.shape ))
50
+ end
51
+
31
52
  private
32
53
 
54
+ def self.shape_to_size shape
55
+ shape.inject(1) { |t,x| t * x }
56
+ end
57
+
58
+ def self.combined_shape signal_shape, kernel_shape
59
+ combined_shape = [ ]
60
+ signal_shape.each_with_index do |signal_size, i|
61
+ kernel_size = kernel_shape[i]
62
+ combined_shape[i] = signal_size + kernel_size - 1
63
+ end
64
+ combined_shape
65
+ end
66
+
67
+ def self.result_shape signal_shape, kernel_shape
68
+ result_shape = [ ]
69
+ signal_shape.each_with_index do |signal_size, i|
70
+ kernel_size = kernel_shape[i]
71
+ result_shape[i] = signal_size - kernel_size + 1
72
+ end
73
+ result_shape
74
+ end
75
+
33
76
  def self.fft_offsets signal_shape, kernel_shape
34
77
  combined_shape = []
35
78
  shift_by = []
@@ -1,3 +1,3 @@
1
1
  module Convolver
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: convolver
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Neil Slater
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-26 00:00:00.000000000 Z
11
+ date: 2013-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: narray
@@ -123,7 +123,6 @@ files:
123
123
  - README.md
124
124
  - Rakefile
125
125
  - benchmarks/convolve_benchmark.rb
126
- - benchmarks/convolver_vs_fftw3.rb
127
126
  - benchmarks/nn_layer_benchmark.rb
128
127
  - convolver.gemspec
129
128
  - ext/convolver/cnn_components.c
@@ -1,46 +0,0 @@
1
- require 'convolver'
2
- require 'benchmark'
3
-
4
- class Convolver2DBenchmark
5
- attr_reader :image, :kernel
6
-
7
- def initialize
8
- # These show Convolver.convolve as 3x faster than FFTW3
9
- @image = NArray.sfloat(256 * 256).random
10
- @kernel = NArray.sfloat(16 * 16).random
11
-
12
- # These are roughly even (10% advantage to FFTW3)
13
- # @image = NArray.sfloat(256 * 256).random
14
- # @kernel = NArray.sfloat(32 * 32).random
15
-
16
- # These show FFTW3 as 4x faster than Convolver.convolve
17
- # @image = NArray.sfloat(256 * 256).random
18
- # @kernel = NArray.sfloat(64 * 64).random
19
-
20
- # These show Convolver.convolve as 200x faster than FFTW3
21
- # @image = NArray.sfloat(50 * 64 * 64).random
22
- # @kernel = NArray.sfloat(50 * 64 * 64).random
23
-
24
- # These show FFTW3 as 2x faster than Convolver.convolve
25
- # @image = NArray.sfloat(128 * 128).random
26
- # @kernel = NArray.sfloat(64 * 64).random
27
-
28
- # These show FFTW3 and Convolver.convolve roughly equal
29
- # @image = NArray.sfloat(80 * 80).random
30
- # @kernel = NArray.sfloat(64 * 64).random
31
-
32
- # These show FFTW3 as 2x faster than Convolver.convolve
33
- # @image = NArray.sfloat(2 * 80 * 80).random
34
- # @kernel = NArray.sfloat(2 * 64 * 64).random
35
-
36
- # These are roughly even - increasing size of image favours FFTW3
37
- #@image = NArray.sfloat(2000 + 80 * 80).random
38
- #@kernel = NArray.sfloat(80 * 80).random
39
- end
40
- end
41
-
42
- Benchmark.bm do |x|
43
- source = Convolver2DBenchmark.new
44
- x.report('convolver') { 100.times { Convolver.convolve( source.image, source.kernel ) } }
45
- x.report('fftw3') { 100.times { Convolver.convolve_fftw3( source.image, source.kernel ) } }
46
- end