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 +4 -4
- data/ChangeLog +6 -0
- data/ext/gsl/ool.c +3 -3
- data/lib/gsl.rb +2 -1
- data/lib/gsl/oper.rb +35 -60
- data/lib/gsl/version.rb +1 -1
- data/test/gsl/oper_test.rb +98 -0
- metadata +9 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 11528cefa13624ebd32cf6c551a7c7410c281df7
|
4
|
+
data.tar.gz: be51641523d240b11ee736eda5f641d6aed7cffa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
data/ext/gsl/ool.c
CHANGED
@@ -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
|
-
|
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
|
-
|
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
|
-
|
793
|
+
RBGSL_SET_CLASS(ary, cool_conmin_gencan_parameters);
|
794
794
|
return ary;
|
795
795
|
}
|
796
796
|
|
data/lib/gsl.rb
CHANGED
data/lib/gsl/oper.rb
CHANGED
@@ -1,68 +1,43 @@
|
|
1
|
-
|
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
|
21
|
-
|
22
|
-
|
23
|
-
|
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
|
-
|
36
|
-
|
37
|
-
|
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
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
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
|
-
|
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) }
|
data/lib/gsl/version.rb
CHANGED
@@ -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.
|
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-
|
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.
|
35
|
+
version: '0.8'
|
36
36
|
- - ">="
|
37
37
|
- !ruby/object:Gem::Version
|
38
|
-
version: 0.
|
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.
|
45
|
+
version: '0.8'
|
46
46
|
- - ">="
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version: 0.
|
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.
|
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.
|
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
|