rb-gsl 1.16.0.3 → 1.16.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ba1fc465df00657b2ba58f3288cd9d94b38f039e
4
- data.tar.gz: a806e6d0fe3f9fd531f4730012da7629048feeab
3
+ metadata.gz: 11528cefa13624ebd32cf6c551a7c7410c281df7
4
+ data.tar.gz: be51641523d240b11ee736eda5f641d6aed7cffa
5
5
  SHA512:
6
- metadata.gz: 7bca1ad78222c1554fd2bf97d882841efb50a5a95ebd0f00915ba958398e0fda8ff6e2c1812eff7103a0914c5cb8a37a1ed7494377bf408ece3badc1ba28e9fb
7
- data.tar.gz: d1307ac0305e32ee08dc93ffc0561dfbcb05d27001c71de3206f8d18f12b051ee0ee3a612b0d02f270f39ab83c5418b25ad9e480ff6f974f10590a07c7d629b1
6
+ metadata.gz: 653c3192a1c62bed18a196398943e690abf4ff14c0f654ef3a63b5132afaaadd7d950be1fd39cd5bfa6c1df2722c8249487b86c580ad92c331f1349a107f62a7
7
+ data.tar.gz: df556cbf1dd73919d566a106a57ff790989f04d942893612c6e03cfae6979b2a5eaa87747248165bcb7e8a6afb0f93134e23d14d590fc5cc46f1d6d40d80647b
data/ChangeLog CHANGED
@@ -1,3 +1,9 @@
1
+ Fri Dec 19 2014
2
+ * Ruby/GSL 1.16.0.4
3
+ * Optimize and extract multiplication and division operations on Fixnum
4
+ and Float. Pull request #8 by Veselin Vasilev.
5
+ * Fixed division in GSL::Oper for GSL::Vector::Col. Issue #9.
6
+
1
7
  Tue Oct 21 2014
2
8
  * Ruby/GSL 1.16.0.3
3
9
  * Fixed RDoc issues. Issue #6 by @bigtunacan.
@@ -770,7 +770,7 @@ static VALUE rb_ool_conmin_pgrad_parameters_default(VALUE klass)
770
770
  VALUE ary;
771
771
  ool_conmin_parameters_default(ool_conmin_minimizer_pgrad, (void*) &P);
772
772
  ary = create_parameters_ary_pgrad(&P);
773
- RBASIC(ary)->klass = cool_conmin_pgrad_parameters;
773
+ RBGSL_SET_CLASS(ary, cool_conmin_pgrad_parameters);
774
774
  return ary;
775
775
  }
776
776
 
@@ -780,7 +780,7 @@ static VALUE rb_ool_conmin_spg_parameters_default(VALUE klass)
780
780
  VALUE ary;
781
781
  ool_conmin_parameters_default(ool_conmin_minimizer_spg, (void*) &P);
782
782
  ary = create_parameters_ary_spg(&P);
783
- RBASIC(ary)->klass = cool_conmin_spg_parameters;
783
+ RBGSL_SET_CLASS(ary, cool_conmin_spg_parameters);
784
784
  return ary;
785
785
  }
786
786
 
@@ -790,7 +790,7 @@ static VALUE rb_ool_conmin_gencan_parameters_default(VALUE klass)
790
790
  VALUE ary;
791
791
  ool_conmin_parameters_default(ool_conmin_minimizer_gencan, (void*) &P);
792
792
  ary = create_parameters_ary_gencan(&P);
793
- RBASIC(ary)->klass = cool_conmin_gencan_parameters;
793
+ RBGSL_SET_CLASS(ary, cool_conmin_gencan_parameters);
794
794
  return ary;
795
795
  }
796
796
 
data/lib/gsl.rb CHANGED
@@ -5,7 +5,8 @@ end
5
5
 
6
6
  begin
7
7
  require "gsl/#{RUBY_VERSION[/\d+.\d+/]}/gsl_native"
8
- rescue LoadError
8
+ rescue LoadError => err
9
+ raise if err.respond_to?(:path) && !err.path
9
10
  require 'gsl/gsl_native'
10
11
  end
11
12
 
@@ -1,68 +1,43 @@
1
- class Fixnum
2
- alias :_orig_mul :*
3
- alias :_orig_div :/
4
- def *(other)
5
- if other.kind_of?(GSL::Matrix) or other.kind_of?(GSL::Vector) or other.kind_of?(GSL::Matrix::Int) or other.kind_of?(GSL::Vector::Int) or other.kind_of?(GSL::Vector::Complex)or other.kind_of?(GSL::Matrix::Complex)
6
- other.scale(self)
7
- else
8
- if GSL.have_tensor?
9
- if other.kind_of?(GSL::Tensor) or other.kind_of?(GSL::Tensor::Int)
10
- other.scale(self)
11
- else
12
- self._orig_mul(other)
13
- end
14
- else
15
- self._orig_mul(other)
16
- end
17
- end
18
- end
1
+ module GSL::Oper
19
2
 
20
- def /(other)
21
- if other.kind_of?(GSL::Poly) or other.kind_of?(GSL::Poly::Int)
22
- a = GSL::Poly[1]; a[0] = self
23
- GSL::Rational.new(a, other)
24
- elsif other.kind_of?(GSL::Vector::Col)
25
- other.scale(1.0/GSL::pow_2(other.dnrm2))
26
- elsif other.kind_of?(GSL::Vector::Int::Col)
27
- v = other.to_f
28
- v.scale(1.0/GSL::pow_2(v.dnrm2))
29
- else
30
- self._orig_div(other)
31
- end
32
- end
33
- end
3
+ def self.included(base)
4
+ base.class_eval {
5
+ alias_method :_gsl_oper_original_mul, :*
6
+ alias_method :_gsl_oper_original_div, :/
34
7
 
35
- class Float
36
- alias :_orig_mul :*
37
- alias :_orig_div :/
8
+ def *(other)
9
+ case other
10
+ when Numeric
11
+ _gsl_oper_original_mul(other)
12
+ when GSL::Matrix, GSL::Vector,
13
+ GSL::Matrix::Int, GSL::Vector::Int,
14
+ GSL::Vector::Complex, GSL::Matrix::Complex,
15
+ *GSL.have_tensor? ? [GSL::Tensor, GSL::Tensor::Int] : []
16
+ other.scale(self)
17
+ else
18
+ _gsl_oper_original_mul(other)
19
+ end
20
+ end
38
21
 
39
- def *(other)
40
- if other.kind_of?(GSL::Matrix) or other.kind_of?(GSL::Vector) or other.kind_of?(GSL::Matrix::Int) or other.kind_of?(GSL::Vector::Int) or other.kind_of?(GSL::Vector::Complex)or other.kind_of?(GSL::Matrix::Complex)
41
- other.scale(self)
42
- else
43
- if GSL.have_tensor?
44
- if other.kind_of?(GSL::Tensor) or other.kind_of?(GSL::Tensor::Int)
45
- other.scale(self)
46
- else
47
- self._orig_mul(other)
22
+ def /(other)
23
+ case other
24
+ when Numeric
25
+ _gsl_oper_original_div(other)
26
+ when GSL::Poly, GSL::Poly::Int
27
+ a = GSL::Poly[1]; a[0] = self
28
+ GSL::Rational.new(a, other)
29
+ when GSL::Vector::Col
30
+ other.scale(self / GSL.pow_2(other.dnrm2))
31
+ when GSL::Vector::Int::Col
32
+ v = other.to_f
33
+ v.scale(self / GSL.pow_2(v.dnrm2))
34
+ else
35
+ _gsl_oper_original_div(other)
48
36
  end
49
- else
50
- self._orig_mul(other)
51
37
  end
52
- end
38
+ }
53
39
  end
54
40
 
55
- def /(other)
56
- if other.kind_of?(GSL::Poly) or other.kind_of?(GSL::Poly::Int)
57
- a = GSL::Poly[1]; a[0] = self
58
- GSL::Rational.new(a, other)
59
- elsif other.kind_of?(GSL::Vector::Col)
60
- other.scale(1.0/GSL::pow_2(other.dnrm2))
61
- elsif other.kind_of?(GSL::Vector::Int::Col)
62
- v = other.to_f
63
- v.scale(1.0/GSL::pow_2(v.dnrm2))
64
- else
65
- self._orig_div(other)
66
- end
67
- end
68
41
  end
42
+
43
+ [Fixnum, Float].each { |klass| klass.send(:include, GSL::Oper) }
@@ -1,5 +1,5 @@
1
1
  module GSL
2
2
 
3
- RUBY_GSL_VERSION = RB_GSL_VERSION = '1.16.0.3'
3
+ RUBY_GSL_VERSION = RB_GSL_VERSION = '1.16.0.4'
4
4
 
5
5
  end
@@ -0,0 +1,98 @@
1
+ require 'test_helper'
2
+
3
+ class OperTest < GSL::TestCase
4
+
5
+ def test_multiplication_matrix
6
+ matrix = GSL::Matrix.ones(1)
7
+
8
+ mul_int = 2 * matrix
9
+ mul_float = 0.2 * matrix
10
+
11
+ assert_equal 2, mul_int[0, 0]
12
+ assert_equal 0.2, mul_float[0, 0]
13
+ end
14
+
15
+ def test_multiplication_matrix_int
16
+ matrix = GSL::Matrix::Int.ones(1)
17
+
18
+ mul_int = 2 * matrix
19
+ mul_float = 0.2 * matrix
20
+
21
+ assert_equal 2, mul_int[0, 0]
22
+ assert_equal 0, mul_float[0, 0]
23
+ end
24
+
25
+ def test_multiplication_matrix_complex
26
+ matrix = GSL::Matrix::Complex.eye(1)
27
+
28
+ result = 0.2 * matrix
29
+
30
+ assert_equal 0.2, result[0][0]
31
+ end
32
+
33
+ def test_multiplication_vector
34
+ vector = GSL::Vector[1, 2]
35
+
36
+ mul_int = 2 * vector
37
+ mul_float = 0.2 * vector
38
+
39
+ assert_equal 2, mul_int[0]
40
+ assert_equal 0.2, mul_float[0]
41
+ end
42
+
43
+ def test_multiplication_vector_int
44
+ vector = GSL::Vector::Int[1, 2]
45
+
46
+ mul_int = 2 * vector
47
+ mul_float = 0.2 * vector
48
+
49
+ assert_equal 2, mul_int[0]
50
+ assert_equal 0, mul_float[0]
51
+ end
52
+
53
+ def test_multiplication_vector_complex
54
+ re = GSL::Vector[1..4]
55
+ im = GSL::Vector[5..8]
56
+
57
+ vector = GSL::Vector::Complex[re, im]
58
+
59
+ mul_int = 2 * vector
60
+ mul_float = 0.2 * vector
61
+
62
+ assert_equal 10, mul_int[0][1]
63
+ assert_equal 1.0, mul_float[0][1]
64
+ end
65
+
66
+ def test_division_poly
67
+ poly = GSL::Poly.alloc([2])
68
+
69
+ a = GSL::Poly[1]; a[0] = 2
70
+
71
+ result = 2 / poly
72
+ expected = GSL::Rational.new(a, poly)
73
+
74
+ assert_equal expected.num, result.num
75
+ assert_equal expected.den, result.den
76
+ end
77
+
78
+ def test_division_vector_col
79
+ vector = GSL::Vector[1, 2].col
80
+
81
+ result1 = 2 / vector
82
+ result2 = 2 / result1
83
+
84
+ assert_in_epsilon 0.4, result1[0]
85
+ assert_equal result2, vector
86
+ end
87
+
88
+ def test_division_vector_int_col
89
+ vector = GSL::Vector::Int[1, 2].col
90
+
91
+ result1 = 2 / vector
92
+ result2 = 2 / result1
93
+
94
+ assert_in_epsilon 0.4, result1[0]
95
+ assert_equal result2.to_a.map(&:to_i), vector.to_a
96
+ end
97
+
98
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rb-gsl
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.16.0.3
4
+ version: 1.16.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yoshiki Tsunesada
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-10-21 00:00:00.000000000 Z
13
+ date: 2014-12-19 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: narray
@@ -32,20 +32,20 @@ dependencies:
32
32
  requirements:
33
33
  - - "~>"
34
34
  - !ruby/object:Gem::Version
35
- version: '0.7'
35
+ version: '0.8'
36
36
  - - ">="
37
37
  - !ruby/object:Gem::Version
38
- version: 0.7.1
38
+ version: 0.8.1
39
39
  type: :development
40
40
  prerelease: false
41
41
  version_requirements: !ruby/object:Gem::Requirement
42
42
  requirements:
43
43
  - - "~>"
44
44
  - !ruby/object:Gem::Version
45
- version: '0.7'
45
+ version: '0.8'
46
46
  - - ">="
47
47
  - !ruby/object:Gem::Version
48
- version: 0.7.1
48
+ version: 0.8.1
49
49
  - !ruby/object:Gem::Dependency
50
50
  name: rake
51
51
  requirement: !ruby/object:Gem::Requirement
@@ -744,6 +744,7 @@ files:
744
744
  - test/gsl/multiroot_test.rb
745
745
  - test/gsl/multiset_test.rb
746
746
  - test/gsl/odeiv_test.rb
747
+ - test/gsl/oper_test.rb
747
748
  - test/gsl/poly_test.rb
748
749
  - test/gsl/qrng_test.rb
749
750
  - test/gsl/quartic_test.rb
@@ -765,7 +766,7 @@ metadata: {}
765
766
  post_install_message:
766
767
  rdoc_options:
767
768
  - "--title"
768
- - Ruby/GSL (v1.16.0.3)
769
+ - Ruby/GSL (v1.16.0.4)
769
770
  - "--charset"
770
771
  - UTF-8
771
772
  - "--line-numbers"
@@ -789,7 +790,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
789
790
  requirements:
790
791
  - GSL (http://www.gnu.org/software/gsl/)
791
792
  rubyforge_project:
792
- rubygems_version: 2.4.2
793
+ rubygems_version: 2.4.5
793
794
  signing_key:
794
795
  specification_version: 4
795
796
  summary: Ruby interface to the GNU Scientific Library [Ruby 2.x and GSL 1.16 compatible