ruby-gsl-ng 0.2.4.1 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,8 +11,10 @@ module GSLng
11
11
  attr_reader :owner
12
12
 
13
13
  def initialize(ptr, owner, size, stride = 1) # @private
14
+ @backend = GSLng.backend
14
15
  @owner,@size,@stride = owner,size,stride
15
16
  @ptr = FFI::AutoPointer.new(ptr, View.method(:release))
17
+ @ptr_value = @ptr.to_i
16
18
  end
17
19
 
18
20
  def View.release(ptr)
@@ -24,7 +26,7 @@ module GSLng
24
26
  # @return [Vector]
25
27
  def dup
26
28
  v = Vector.new(@size)
27
- GSLng.backend::gsl_vector_memcpy(v.ptr, @ptr)
29
+ @backend.gsl_vector_memcpy(v.ptr, @ptr)
28
30
  return v
29
31
  end
30
32
  alias_method :clone, :dup
@@ -2,16 +2,16 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{ruby-gsl-ng}
5
- s.version = "0.2.4.1"
5
+ s.version = "0.2.6"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["v01d"]
9
- s.date = %q{2010-09-24}
9
+ s.date = %q{2011-03-07}
10
10
  s.description = %q{Ruby/GSL new-generation wrapper}
11
11
  s.email = %q{}
12
12
  s.extensions = ["ext/extconf.rb"]
13
- s.extra_rdoc_files = ["README.rdoc", "ext/extconf.rb", "ext/gslng_extensions.cpp", "ext/plotting.cpp", "lib/gslng.rb", "lib/gslng/backend.rb", "lib/gslng/backend_components/error_handling.rb", "lib/gslng/backend_components/matrix.rb", "lib/gslng/backend_components/rng.rb", "lib/gslng/backend_components/special.rb", "lib/gslng/backend_components/stats.rb", "lib/gslng/backend_components/vector.rb", "lib/gslng/matrix.rb", "lib/gslng/matrix_view.rb", "lib/gslng/plotter.rb", "lib/gslng/rng/gaussian.rb", "lib/gslng/rng/rng.rb", "lib/gslng/rng/uniform.rb", "lib/gslng/special.rb", "lib/gslng/vector.rb", "lib/gslng/vector_view.rb"]
14
- s.files = ["History.txt", "README.rdoc", "Rakefile", "ext/extconf.rb", "ext/gslng_extensions.cpp", "ext/plotting.cpp", "lib/gslng.rb", "lib/gslng/backend.rb", "lib/gslng/backend_components/error_handling.rb", "lib/gslng/backend_components/matrix.rb", "lib/gslng/backend_components/rng.rb", "lib/gslng/backend_components/special.rb", "lib/gslng/backend_components/stats.rb", "lib/gslng/backend_components/vector.rb", "lib/gslng/matrix.rb", "lib/gslng/matrix_view.rb", "lib/gslng/plotter.rb", "lib/gslng/rng/gaussian.rb", "lib/gslng/rng/rng.rb", "lib/gslng/rng/uniform.rb", "lib/gslng/special.rb", "lib/gslng/vector.rb", "lib/gslng/vector_view.rb", "ruby-gsl-ng.gemspec", "test/benchmark.rb", "test/benchmark_results", "test/matrix_test.rb", "test/rng_test.rb", "test/test_gsl.rb", "test/test_special.rb", "test/vector_test.rb", "Manifest"]
13
+ s.extra_rdoc_files = ["README.rdoc", "ext/extconf.rb", "ext/gslng_extensions.cpp", "ext/plotting.cpp", "lib/core_extensions/array.rb", "lib/gslng.rb", "lib/gslng/backend.rb", "lib/gslng/backend_components/error_handling.rb", "lib/gslng/backend_components/matrix.rb", "lib/gslng/backend_components/rng.rb", "lib/gslng/backend_components/special.rb", "lib/gslng/backend_components/stats.rb", "lib/gslng/backend_components/vector.rb", "lib/gslng/matrix.rb", "lib/gslng/matrix_view.rb", "lib/gslng/plotter.rb", "lib/gslng/rng/gaussian.rb", "lib/gslng/rng/rng.rb", "lib/gslng/rng/uniform.rb", "lib/gslng/special.rb", "lib/gslng/vector.rb", "lib/gslng/vector_view.rb"]
14
+ s.files = ["History.txt", "Manifest", "README.rdoc", "Rakefile", "ext/extconf.rb", "ext/gslng_extensions.cpp", "ext/plotting.cpp", "lib/core_extensions/array.rb", "lib/gslng.rb", "lib/gslng/backend.rb", "lib/gslng/backend_components/error_handling.rb", "lib/gslng/backend_components/matrix.rb", "lib/gslng/backend_components/rng.rb", "lib/gslng/backend_components/special.rb", "lib/gslng/backend_components/stats.rb", "lib/gslng/backend_components/vector.rb", "lib/gslng/matrix.rb", "lib/gslng/matrix_view.rb", "lib/gslng/plotter.rb", "lib/gslng/rng/gaussian.rb", "lib/gslng/rng/rng.rb", "lib/gslng/rng/uniform.rb", "lib/gslng/special.rb", "lib/gslng/vector.rb", "lib/gslng/vector_view.rb", "ruby-gsl-ng.gemspec", "test/benchmark.rb", "test/benchmark_results", "test/matrix_test.rb", "test/rng_test.rb", "test/test_gsl.rb", "test/test_special.rb", "test/vector_test.rb"]
15
15
  s.homepage = %q{http://github.com/v01d/ruby-gsl-ng}
16
16
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Ruby-gsl-ng", "--main", "README.rdoc"]
17
17
  s.require_paths = ["lib", "ext"]
@@ -1,80 +1,92 @@
1
+ #################################### Vector ####################################
2
+ Vector#[]
3
+ Rehearsal --------------------------------------------
4
+ rb-gsl : 0.300000 0.000000 0.300000 ( 0.301650)
5
+ GSLng : 0.360000 0.000000 0.360000 ( 0.369323)
6
+ ----------------------------------- total: 0.660000sec
7
+
8
+ user system total real
9
+ rb-gsl : 0.310000 0.000000 0.310000 ( 0.387314)
10
+ GSLng : 0.340000 0.000000 0.340000 ( 0.348130)
11
+
1
12
  Vector#each - vector of 5000 elements
2
- Rehearsal ------------------------------------------------
3
- rb-gsl each: 0.470000 0.000000 0.470000 ( 0.477971)
4
- each : 0.560000 0.000000 0.560000 ( 0.578515)
5
- --------------------------------------- total: 1.030000sec
13
+ Rehearsal --------------------------------------------
14
+ rb-gsl : 0.220000 0.000000 0.220000 ( 0.218779)
15
+ GSLng : 0.200000 0.000000 0.200000 ( 0.205919)
16
+ ----------------------------------- total: 0.420000sec
6
17
 
7
- user system total real
8
- rb-gsl each: 0.490000 0.000000 0.490000 ( 0.502347)
9
- each : 0.550000 0.000000 0.550000 ( 0.558975)
18
+ user system total real
19
+ rb-gsl : 0.220000 0.000000 0.220000 ( 0.231055)
20
+ GSLng : 0.200000 0.000000 0.200000 ( 0.203754)
10
21
 
11
22
  Norm (BLAS) - vector of 50000 elements
12
23
  Rehearsal --------------------------------------------
13
- rb-gsl : 0.520000 0.000000 0.520000 ( 0.521736)
14
- GSLng : 0.520000 0.010000 0.530000 ( 0.523737)
15
- ----------------------------------- total: 1.050000sec
24
+ rb-gsl : 0.520000 0.000000 0.520000 ( 0.521935)
25
+ GSLng : 0.520000 0.000000 0.520000 ( 0.521729)
26
+ ----------------------------------- total: 1.040000sec
16
27
 
17
28
  user system total real
18
- rb-gsl : 0.520000 0.000000 0.520000 ( 0.522474)
19
- GSLng : 0.520000 0.000000 0.520000 ( 0.522003)
29
+ rb-gsl : 0.520000 0.000000 0.520000 ( 0.521828)
30
+ GSLng : 0.520000 0.000000 0.520000 ( 0.521704)
20
31
 
21
32
  Vector#map!
22
33
  Rehearsal --------------------------------------------
23
- rb-gsl : 0.340000 0.000000 0.340000 ( 0.334862)
24
- GSLng : 0.370000 0.000000 0.370000 ( 0.367723)
25
- ----------------------------------- total: 0.710000sec
34
+ rb-gsl : 0.240000 0.000000 0.240000 ( 0.239012)
35
+ GSLng : 0.260000 0.000000 0.260000 ( 0.259632)
36
+ ----------------------------------- total: 0.500000sec
26
37
 
27
38
  user system total real
28
- rb-gsl : 0.340000 0.000000 0.340000 ( 0.336404)
29
- GSLng : 0.360000 0.000000 0.360000 ( 0.366505)
39
+ rb-gsl : 0.250000 0.000000 0.250000 ( 0.245187)
40
+ GSLng : 0.240000 0.000000 0.240000 ( 0.235865)
30
41
 
31
42
  Vector product - two vectors of 5000 elements
32
43
  Rehearsal --------------------------------------------
33
- rb-gsl : 0.620000 0.000000 0.620000 ( 0.623600)
34
- GSLng : 0.630000 0.000000 0.630000 ( 0.630987)
44
+ rb-gsl : 0.620000 0.000000 0.620000 ( 0.655681)
45
+ GSLng : 0.620000 0.010000 0.630000 ( 0.652757)
35
46
  ----------------------------------- total: 1.250000sec
36
47
 
37
48
  user system total real
38
- rb-gsl : 1.160000 0.000000 1.160000 ( 1.162675)
39
- GSLng : 1.170000 0.000000 1.170000 ( 1.176573)
49
+ rb-gsl : 1.170000 0.000000 1.170000 ( 1.178990)
50
+ GSLng : 1.170000 0.000000 1.170000 ( 1.172545)
40
51
 
41
52
  Sort - vector of 5000 elements
42
53
  Rehearsal --------------------------------------------
43
- rb-gsl : 0.440000 0.000000 0.440000 ( 0.441015)
44
- GSLng : 0.440000 0.000000 0.440000 ( 0.439851)
54
+ rb-gsl : 0.440000 0.000000 0.440000 ( 0.441440)
55
+ GSLng : 0.440000 0.000000 0.440000 ( 0.444755)
45
56
  ----------------------------------- total: 0.880000sec
46
57
 
47
58
  user system total real
48
- rb-gsl : 0.440000 0.000000 0.440000 ( 0.440670)
49
- GSLng : 0.440000 0.000000 0.440000 ( 0.440308)
59
+ rb-gsl : 0.430000 0.000000 0.430000 ( 0.440950)
60
+ GSLng : 0.450000 0.010000 0.460000 ( 0.447733)
50
61
 
51
62
  Vector#to_a
52
63
  Rehearsal --------------------------------------------
53
- rb-gsl : 0.680000 0.000000 0.680000 ( 0.676765)
54
- GSLng : 0.720000 0.010000 0.730000 ( 0.724891)
55
- ----------------------------------- total: 1.410000sec
64
+ rb-gsl : 0.470000 0.000000 0.470000 ( 0.490407)
65
+ GSLng : 0.470000 0.000000 0.470000 ( 0.472971)
66
+ ----------------------------------- total: 0.940000sec
56
67
 
57
68
  user system total real
58
- rb-gsl : 0.650000 0.000000 0.650000 ( 0.649093)
59
- GSLng : 0.680000 0.000000 0.680000 ( 0.678858)
69
+ rb-gsl : 0.450000 0.000000 0.450000 ( 0.452365)
70
+ GSLng : 0.460000 0.000000 0.460000 ( 0.450768)
60
71
 
61
72
  Vector::from_array
62
73
  Rehearsal --------------------------------------------
63
- rb-gsl : 0.050000 0.030000 0.080000 ( 0.082630)
64
- GSLng : 0.070000 0.010000 0.080000 ( 0.075172)
65
- ----------------------------------- total: 0.160000sec
74
+ rb-gsl : 0.730000 0.140000 0.870000 ( 0.868696)
75
+ GSLng : 0.650000 0.160000 0.810000 ( 0.811343)
76
+ ----------------------------------- total: 1.680000sec
66
77
 
67
78
  user system total real
68
- rb-gsl : 0.060000 0.020000 0.080000 ( 0.082620)
69
- GSLng : 0.050000 0.020000 0.070000 ( 0.072373)
79
+ rb-gsl : 0.730000 0.000000 0.730000 ( 0.727155)
80
+ GSLng : 0.650000 0.000000 0.650000 ( 0.644819)
70
81
 
71
- Vector#[]
82
+ #################################### Matrix ####################################
83
+ Matrix#[] - 50 x 50
72
84
  Rehearsal --------------------------------------------
73
- rb-gsl : 0.230000 0.010000 0.240000 ( 0.233887)
74
- GSLng : 0.500000 0.000000 0.500000 ( 0.503229)
75
- ----------------------------------- total: 0.740000sec
85
+ rb-gsl : 0.380000 0.080000 0.460000 ( 0.455793)
86
+ GSLng : 0.530000 0.000000 0.530000 ( 0.542278)
87
+ ----------------------------------- total: 0.990000sec
76
88
 
77
89
  user system total real
78
- rb-gsl : 0.230000 0.000000 0.230000 ( 0.232901)
79
- GSLng : 0.510000 0.000000 0.510000 ( 0.510925)
90
+ rb-gsl : 0.360000 0.000000 0.360000 ( 0.367216)
91
+ GSLng : 0.510000 0.000000 0.510000 ( 0.510689)
80
92
 
@@ -111,6 +111,15 @@ class TestMatrix < Test::Unit::TestCase
111
111
  assert_equal(Matrix[[2,3,4],[1,2,3],[3,4,5]], m.swap_rows(0,1))
112
112
  assert_equal(Matrix[[3,2,4],[2,1,3],[4,3,5]], m.swap_columns(0,1))
113
113
  assert_equal(Matrix[[3,2,4],[2,1,3],[4,3,5]], m.swap_rowcol(0,0))
114
+
115
+ m = Matrix[[1,2,3],[4,5,6],[7,8,9]]
116
+ assert_equal(Matrix[[0, 0, 0],[0, 1, 2],[0, 4, 5]], m.slide(1, 1))
117
+
118
+ m = Matrix[[1,2,3],[4,5,6],[7,8,9]]
119
+ assert_equal(Matrix[[5, 6, 0],[8, 9, 0],[0, 0, 0]], m.slide(-1, -1))
120
+
121
+ m = Matrix[[1,2,3],[4,5,6],[7,8,9]]
122
+ assert_equal(Matrix[[4, 5, 6],[7, 8, 9],[0, 0, 0]], m.slide(-1, 0))
114
123
  end
115
124
 
116
125
  def test_view
@@ -7,4 +7,5 @@ require 'test/unit'
7
7
 
8
8
  require 'vector_test'
9
9
  require 'matrix_test'
10
-
10
+ require 'rng_test'
11
+ require 'test_special'
@@ -4,6 +4,7 @@
4
4
  $:.unshift File.join(File.dirname(__FILE__),'..','lib')
5
5
  $:.unshift File.join(File.dirname(__FILE__),'..','ext')
6
6
 
7
+ require 'rubygems'
7
8
  require 'test/unit'
8
9
  require 'gslng'
9
10
 
@@ -15,6 +16,10 @@ class VectorTest < Test::Unit::TestCase
15
16
  assert_equal(10, Vector.zero(10).size)
16
17
  assert(Vector.zero(10).zero?)
17
18
  assert_nothing_raised { Vector.random(10) }
19
+ assert_equal(Vector[0], Vector.linspace(0, 1, 1.5))
20
+ assert_equal(Vector[0,1], Vector.linspace(0, 1, 1))
21
+ assert_equal(Vector[0,0.5,1], Vector.linspace(0, 1, 0.5))
22
+ assert_equal(Vector[0,0.7], Vector.linspace(0, 1, 0.7))
18
23
  end
19
24
 
20
25
  def test_to_s
@@ -31,7 +36,10 @@ class VectorTest < Test::Unit::TestCase
31
36
  assert_equal(Vector[1,2,3], Vector[1,2,3])
32
37
  assert_equal(Vector[0...3], [0,1,2])
33
38
  assert_equal(Vector.zero(3), Vector.zero(3))
34
- assert_not_equal(Vector.zero(4), Vector.zero(3))
39
+ assert_not_equal(Vector.zero(4), Vector.zero(3))
40
+
41
+ assert(Vector[1,2,3].eql?(Vector[1,2,3]))
42
+ assert(!Vector[1,2,3].eql?(Vector[1,2,4]))
35
43
  end
36
44
 
37
45
  def test_each
@@ -49,6 +57,11 @@ class VectorTest < Test::Unit::TestCase
49
57
  assert_equal(v1.dup, v2)
50
58
  end
51
59
 
60
+ def test_stats
61
+ assert_equal(Vector[1, 2, 3, 4, 5].median, 3)
62
+ assert_equal(Vector[1, 2, 3, 4].median, 2.5)
63
+ end
64
+
52
65
  def test_sets
53
66
  assert_equal(Vector.zero(3).set!(1), Vector[1,1,1])
54
67
  assert_equal(Vector.zero(3).set!(1).zero!, Vector.zero(3))
@@ -115,9 +128,9 @@ class VectorTest < Test::Unit::TestCase
115
128
  end
116
129
 
117
130
  def test_wrap
118
- v = Vector[1,2,8]
119
- assert_equal(Vector[0,0,-1],v.wrap!(0, 5))
120
- assert_equal(Vector[1,2,3], v)
131
+ v = Vector[1,2,8,-1,11]
132
+ assert_equal(Vector[0,0,-1,1,-2],v.wrap!(5))
133
+ assert_equal(Vector[1,2,3,4,1], v)
121
134
  end
122
135
 
123
136
  def test_predicate
metadata CHANGED
@@ -5,9 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 4
9
- - 1
10
- version: 0.2.4.1
8
+ - 6
9
+ version: 0.2.6
11
10
  platform: ruby
12
11
  authors:
13
12
  - v01d
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2010-09-24 00:00:00 -03:00
17
+ date: 2011-03-07 00:00:00 -03:00
19
18
  default_executable:
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
@@ -55,6 +54,7 @@ extra_rdoc_files:
55
54
  - ext/extconf.rb
56
55
  - ext/gslng_extensions.cpp
57
56
  - ext/plotting.cpp
57
+ - lib/core_extensions/array.rb
58
58
  - lib/gslng.rb
59
59
  - lib/gslng/backend.rb
60
60
  - lib/gslng/backend_components/error_handling.rb
@@ -74,11 +74,13 @@ extra_rdoc_files:
74
74
  - lib/gslng/vector_view.rb
75
75
  files:
76
76
  - History.txt
77
+ - Manifest
77
78
  - README.rdoc
78
79
  - Rakefile
79
80
  - ext/extconf.rb
80
81
  - ext/gslng_extensions.cpp
81
82
  - ext/plotting.cpp
83
+ - lib/core_extensions/array.rb
82
84
  - lib/gslng.rb
83
85
  - lib/gslng/backend.rb
84
86
  - lib/gslng/backend_components/error_handling.rb
@@ -104,7 +106,6 @@ files:
104
106
  - test/test_gsl.rb
105
107
  - test/test_special.rb
106
108
  - test/vector_test.rb
107
- - Manifest
108
109
  has_rdoc: true
109
110
  homepage: http://github.com/v01d/ruby-gsl-ng
110
111
  licenses: []