gsl 1.16.0.6 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +5 -13
- data/ChangeLog +6 -0
- data/Gemfile +1 -0
- data/README.md +77 -1
- data/Rakefile +7 -1
- data/examples/linalg/QR_solve_narray.rb +2 -1
- data/examples/linalg/SV_narray.rb +10 -0
- data/examples/linalg/chol_narray.rb +3 -0
- data/examples/wavelet/wavelet1.rb +4 -2
- data/ext/gsl_native/array.c +10 -0
- data/ext/gsl_native/bspline.c +15 -2
- data/ext/gsl_native/cheb.c +76 -10
- data/ext/gsl_native/common.c +33 -0
- data/ext/gsl_native/dht.c +26 -0
- data/ext/gsl_native/eigen.c +129 -0
- data/ext/gsl_native/extconf.rb +60 -6
- data/ext/gsl_native/fft.c +42 -0
- data/ext/gsl_native/function.c +18 -0
- data/ext/gsl_native/gsl.c +5 -0
- data/ext/gsl_native/gsl_nmatrix.c +204 -0
- data/ext/gsl_native/histogram.c +42 -0
- data/ext/gsl_native/include/rb_gsl.h +4 -0
- data/ext/gsl_native/include/rb_gsl_array.h +4 -0
- data/ext/gsl_native/include/rb_gsl_common.h +5 -0
- data/ext/gsl_native/include/rb_gsl_interp.h +4 -0
- data/ext/gsl_native/include/rb_gsl_with_nmatrix.h +28 -0
- data/ext/gsl_native/interp.c +14 -0
- data/ext/gsl_native/linalg.c +414 -22
- data/ext/gsl_native/math.c +64 -0
- data/ext/gsl_native/multifit.c +61 -0
- data/ext/gsl_native/randist.c +42 -0
- data/ext/gsl_native/sf.c +6 -0
- data/ext/gsl_native/sf_ellint.c +4 -4
- data/ext/gsl_native/sf_mathieu.c +48 -0
- data/ext/gsl_native/spline.c +30 -0
- data/ext/gsl_native/tamu_anova.c +1 -1
- data/gsl.gemspec +8 -1
- data/lib/gsl.rb +5 -0
- data/lib/gsl/version.rb +1 -1
- data/rdoc/nmatrix.rdoc +129 -0
- data/rdoc/ref.rdoc +1 -0
- data/test.sh +21 -0
- data/test/gsl/bspline_test.rb +15 -14
- data/test/gsl/combination_test.rb +17 -6
- data/test/gsl/dht_test.rb +42 -33
- data/test/gsl/nmatrix_tests/nmatrix_cheb_test.rb +34 -0
- data/test/gsl/nmatrix_tests/nmatrix_eigen_test.rb +28 -0
- data/test/gsl/nmatrix_tests/nmatrix_gsl_test.rb +65 -0
- data/test/gsl/nmatrix_tests/nmatrix_interp_test.rb +45 -0
- data/test/gsl/nmatrix_tests/nmatrix_linalg_test.rb +100 -0
- data/test/gsl/nmatrix_tests/nmatrix_stats_test.rb +88 -0
- data/test/gsl/nmatrix_tests/nmatrix_wavelet_test.rb +5 -0
- data/test/gsl/randist_test.rb +43 -23
- data/test/test_helper.rb +30 -2
- metadata +191 -51
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c5ce03799c95309fda7ce578dc8b81abe735f613
|
4
|
+
data.tar.gz: c0eea330250d7e3489f4255de570afec91770e8b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1937f28127502b386d50d50cc30660c0239cc4ae7f4f4c741a064333c7891573857d91fc864d53c6c6f33f68b85bd02e36d0a5b7b666276c0538ea502f2e88a3
|
7
|
+
data.tar.gz: a5ac077c39549fbfd17be3c6fcb69c00a2e09b77732ca10997cba225d36a2ed15ee37c034987f122bd43e6f12f8fd0ed3ea64b9bb8528cd84c8566468aea598e
|
data/.travis.yml
CHANGED
@@ -2,23 +2,15 @@ language:
|
|
2
2
|
ruby
|
3
3
|
|
4
4
|
rvm:
|
5
|
-
- 1.9
|
5
|
+
- 1.9.3
|
6
6
|
- 2.0
|
7
7
|
- 2.1
|
8
8
|
- 2.2
|
9
|
-
- ruby-head
|
10
|
-
- rbx-2
|
11
|
-
|
12
|
-
env:
|
13
|
-
matrix:
|
14
|
-
- "NARRAY=1"
|
15
|
-
- ""
|
16
|
-
|
17
|
-
matrix:
|
18
|
-
allow_failures:
|
19
|
-
- rvm: ruby-head
|
20
|
-
- rvm: rbx-2
|
21
9
|
|
22
10
|
before_install:
|
23
11
|
- sudo apt-get update -qq
|
24
12
|
- sudo apt-get install -y libgsl0-dev
|
13
|
+
- gem update bundler
|
14
|
+
- bundle install
|
15
|
+
- bundle exec rake compile
|
16
|
+
- bundle exec rake test
|
data/ChangeLog
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# markup: rd
|
2
2
|
|
3
|
+
== Fri March 4 2016
|
4
|
+
* Added compatibility for NMatrix interconversion with GSL::Vector and GSL::Matrix
|
5
|
+
* Added NMatrix compatibility to various to make them compatible with NMatrix data types.
|
6
|
+
* Gem is now compatible with GSL 2.1.
|
7
|
+
* Version bump to 2.1.0
|
8
|
+
|
3
9
|
== Thu Jul 03 2015
|
4
10
|
* Ruby/GSL 1.16.0.6
|
5
11
|
* rb-gsl and gsl are now the same gem
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -8,12 +8,20 @@ the terms of the GNU Free Documentation License.
|
|
8
8
|
Ruby/GSL is a Ruby interface to the [GNU Scientific Library](https://gnu.org/software/gsl/)
|
9
9
|
(GSL), for numerical computing with [Ruby](http://www.ruby-lang.org/).
|
10
10
|
|
11
|
+
Ruby/GSL is compatible with GSL versions upto 2.1.
|
12
|
+
|
13
|
+
## Usage with GSL 2.1
|
14
|
+
|
15
|
+
As of this release, GSL 2.1 has not made it's way into the Debian stable repositories. Hence, after compiling GSL 2.1 from source, you will need to set the installation location in your `LD_LIBRARY_PATH` variable. After following standard GSL 2.1 installation procedures, you should do:
|
16
|
+
export LD_LIBRARY_PATH=/usr/local/lib
|
17
|
+
|
18
|
+
The need to do this should not arise if GSL has been installed from `apt-get`.
|
11
19
|
|
12
20
|
## Installation
|
13
21
|
|
14
22
|
Ruby/GSL may be installed as a Ruby Gem by simply running
|
15
23
|
|
16
|
-
gem install
|
24
|
+
gem install gsl
|
17
25
|
|
18
26
|
Note that the GSL libraries must already be installed before Ruby/GSL
|
19
27
|
can be installed:
|
@@ -29,6 +37,66 @@ package. Some of the example scripts in the +examples/+ directory use the
|
|
29
37
|
binaries of <tt>GNU plotutils</tt> and related packages are available
|
30
38
|
[here](http://gnuwin32.sourceforge.net/packages/plotutils.htm).
|
31
39
|
|
40
|
+
## NMatrix and NArray usage
|
41
|
+
|
42
|
+
Ruby/GSL works with [NMatrix](https://github.com/SciRuby/nmatrix) and [NArray](https://github.com/masa16/narray) for a variety of methods. See the docs for a detailed list.
|
43
|
+
|
44
|
+
### Basic Installation
|
45
|
+
|
46
|
+
In order to use rb-gsl with NMatrix you must first set the `NMATRIX` environment variable and then install rb-gsl:
|
47
|
+
gem install nmatrix
|
48
|
+
export NMATRIX=1
|
49
|
+
gem install rb-gsl
|
50
|
+
|
51
|
+
This will compile rb-gsl with NMatrix specific functions.
|
52
|
+
|
53
|
+
For using rb-gsl with NArray:
|
54
|
+
gem install narray
|
55
|
+
export NARRAY=1
|
56
|
+
gem install rb-gsl
|
57
|
+
|
58
|
+
Note that setting both `NMATRIX` and `NARRAY` variables will lead to undefined behaviour. Only one can be used at a time.
|
59
|
+
|
60
|
+
### NMatrix basic usage
|
61
|
+
|
62
|
+
Convert an NMatrix 1D vector to GSL::Vector:
|
63
|
+
``` ruby
|
64
|
+
require 'gsl'
|
65
|
+
|
66
|
+
nm = NMatrix.new([5], [1,2,3,4,5], dtype: :float64)
|
67
|
+
#=> [1.0, 2.0, 3.0, 4.0, 5.0]
|
68
|
+
nm.to_gslv
|
69
|
+
# => GSL::Vector
|
70
|
+
# [ 1.000e+00 2.000e+00 3.000e+00 4.000e+00 5.000e+00 ]
|
71
|
+
```
|
72
|
+
|
73
|
+
Convert an integer 2D NMatrix to GSL::Matrix::Int:
|
74
|
+
``` ruby
|
75
|
+
|
76
|
+
require 'gsl'
|
77
|
+
nm = NMatrix.new([3,3], [2]*9, dtype: :int32)
|
78
|
+
#=>
|
79
|
+
#[
|
80
|
+
# [2, 2, 2] [2, 2, 2] [2, 2, 2] ]
|
81
|
+
nm.to_gslm
|
82
|
+
#=> GSL::Matrix::Int
|
83
|
+
#[ 2 2 2
|
84
|
+
# 2 2 2
|
85
|
+
# 2 2 2 ]
|
86
|
+
```
|
87
|
+
|
88
|
+
Convert GSL::Vector to 1D NMatrix:
|
89
|
+
``` ruby
|
90
|
+
g = GSL::Vector.alloc(1,2,3,4)
|
91
|
+
# => GSL::Vector
|
92
|
+
# [ 1.000e+00 2.000e+00 3.000e+00 4.000e+00 ]
|
93
|
+
g.to_nm
|
94
|
+
# => [1.0, 2.0, 3.0, 4.0]
|
95
|
+
```
|
96
|
+
|
97
|
+
`to_nm` can be used on all sorts of `GSL::Vector` and `GSL::Matrix` objects to convert them to NMatrix.
|
98
|
+
|
99
|
+
For a detailed list of methods that are compatible with NMatrix, see 'nmatrix' in the [docs](https://sciruby.github.com/rb-gsl).
|
32
100
|
|
33
101
|
## Reference
|
34
102
|
|
@@ -60,6 +128,14 @@ WITHOUT ANY WARRANTY.
|
|
60
128
|
Any bug reports are welcome. If you encounter bugs in Ruby/GSL, please
|
61
129
|
report them on GitHub(https://github.com/SciRuby/rb-gsl/issues).
|
62
130
|
|
131
|
+
## Testing and Contributing
|
132
|
+
|
133
|
+
If you wish to make contributions, run the following commands to clone and test the gem on your local machine:
|
134
|
+
git clone https://github.com/SciRuby/rb-gsl.git
|
135
|
+
cd rb-gsl
|
136
|
+
bash test.sh
|
137
|
+
|
138
|
+
This will run tests with and without NMatrix/NArray.
|
63
139
|
|
64
140
|
## Links
|
65
141
|
|
data/Rakefile
CHANGED
@@ -10,7 +10,13 @@ Bundler::GemHelper.install_tasks
|
|
10
10
|
Rake::TestTask.new do |t|
|
11
11
|
t.libs << 'test'
|
12
12
|
t.libs << 'test/gsl'
|
13
|
-
|
13
|
+
file_list = [ 'test/*.rb', 'test/gsl/*.rb']
|
14
|
+
if ENV['NMATRIX']
|
15
|
+
t.libs << 'test/gsl/nmatrix_tests'
|
16
|
+
file_list << 'test/gsl/nmatrix_tests/*_test.rb'
|
17
|
+
end
|
18
|
+
|
19
|
+
t.test_files = FileList[*file_list]
|
14
20
|
end
|
15
21
|
|
16
22
|
spec = eval(IO.read('gsl.gemspec'))
|
@@ -1,5 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require("gsl")
|
3
|
+
require 'narray'
|
3
4
|
include GSL
|
4
5
|
|
5
6
|
m = NMatrix[[0.18, 0.60, 0.57, 0.96], [0.41, 0.24, 0.99, 0.58],
|
@@ -10,4 +11,4 @@ p qr, tau
|
|
10
11
|
|
11
12
|
b = NVector[1.0, 2, 3, 4]
|
12
13
|
|
13
|
-
p Linalg::QR.solve(qr, tau, b)
|
14
|
+
p Linalg::QR.solve(qr, tau, b)
|
@@ -7,6 +7,16 @@ m = NMatrix[[0.18, 0.60, 0.57, 0.96], [0.41, 0.24, 0.99, 0.58],
|
|
7
7
|
|
8
8
|
u, v, s = Linalg::SV.decomp(m)
|
9
9
|
|
10
|
+
puts "u ->"
|
11
|
+
p u
|
12
|
+
|
13
|
+
puts "v ->"
|
14
|
+
p v
|
15
|
+
|
16
|
+
puts "s ->"
|
17
|
+
p s
|
18
|
+
|
10
19
|
b = NArray[1.0, 2, 3, 4]
|
11
20
|
|
21
|
+
puts "solved ->"
|
12
22
|
p Linalg::SV.solve(u, v, s, b)
|
@@ -5,11 +5,14 @@ include Linalg
|
|
5
5
|
|
6
6
|
m = NArray[[4.0, 2], [2, 3]]
|
7
7
|
c = Cholesky.decomp(m)
|
8
|
+
puts "decomp ->"
|
8
9
|
p c
|
9
10
|
|
10
11
|
b = NArray[1.0, 2]
|
12
|
+
puts "solve ->"
|
11
13
|
p Cholesky.solve(c, b) # Expected [-0.125, 0.75]
|
12
14
|
|
13
15
|
b = NArray[1.0, 2]
|
14
16
|
Cholesky.svx(c, b)
|
17
|
+
puts "svx ->"
|
15
18
|
p b
|
@@ -5,7 +5,9 @@ n = 256
|
|
5
5
|
nc = 20
|
6
6
|
|
7
7
|
data = GSL::Vector.alloc(n)
|
8
|
-
|
8
|
+
File.new(File.dirname(__FILE__) + '/ecg.dat').each_with_index do |l, i|
|
9
|
+
data[i] = l.to_f
|
10
|
+
end
|
9
11
|
|
10
12
|
w = GSL::Wavelet.alloc("daubechies", 4)
|
11
13
|
work = GSL::Wavelet::Workspace.alloc(n)
|
@@ -46,5 +48,5 @@ data3 = w.transform(data2, GSL::Wavelet::BACKWARD, work)
|
|
46
48
|
#data3 = GSL::Wavelet.transform_inverse(w, data2, work)
|
47
49
|
#data3 = GSL::Wavelet.transform_inverse(w, data2)
|
48
50
|
|
49
|
-
GSL::graph(nil, data, data3, "-T X -C -g 3 -x 0 #{data.size} -L 'Red: data, Green: DWT'")
|
51
|
+
# GSL::graph(nil, data, data3, "-T X -C -g 3 -x 0 #{data.size} -L 'Red: data, Green: DWT'")
|
50
52
|
|
data/ext/gsl_native/array.c
CHANGED
@@ -68,6 +68,16 @@ double* get_vector_ptr(VALUE ary, size_t *stride, size_t *n)
|
|
68
68
|
ary2 = na_change_type(ary, NA_DFLOAT);
|
69
69
|
return NA_PTR_TYPE(ary2,double*);
|
70
70
|
#endif
|
71
|
+
|
72
|
+
#ifdef HAVE_NMATRIX_H
|
73
|
+
} else if (NM_IsNMatrix(ary)) {
|
74
|
+
*n = NM_DENSE_COUNT(ary);
|
75
|
+
*stride = 1;
|
76
|
+
if (NM_STORAGE(ary)->dtype != FLOAT64) {
|
77
|
+
rb_raise(rb_eTypeError, "NMatrix must be :float64");
|
78
|
+
}
|
79
|
+
return (double*)NM_DENSE_ELEMENTS(ary);
|
80
|
+
#endif
|
71
81
|
} else {
|
72
82
|
rb_raise(rb_eTypeError,
|
73
83
|
"wrong argument type %s", rb_class2name(CLASS_OF(ary)));
|
data/ext/gsl_native/bspline.c
CHANGED
@@ -37,12 +37,25 @@ static VALUE rb_gsl_bspline_breakpoint(VALUE obj, VALUE i)
|
|
37
37
|
static VALUE rb_gsl_bspline_knots(VALUE obj, VALUE b)
|
38
38
|
{
|
39
39
|
gsl_bspline_workspace *w;
|
40
|
+
Data_Get_Struct(obj, gsl_bspline_workspace, w);
|
41
|
+
|
42
|
+
#ifdef HAVE_NMATRIX_H
|
43
|
+
if (NM_IsNMatrix(b)) {
|
44
|
+
NM_DENSE_STORAGE *nm_bpts;
|
45
|
+
gsl_vector_view v;
|
46
|
+
|
47
|
+
nm_bpts = NM_STORAGE_DENSE(b);
|
48
|
+
v = gsl_vector_view_array((double*) nm_bpts->elements, NM_DENSE_COUNT(b));
|
49
|
+
gsl_bspline_knots(&v.vector, w);
|
50
|
+
return Data_Wrap_Struct(cgsl_vector_view_ro, 0, NULL, w->knots);
|
51
|
+
}
|
52
|
+
#endif
|
53
|
+
|
40
54
|
gsl_vector *bpts;
|
41
55
|
CHECK_VECTOR(b);
|
42
|
-
Data_Get_Struct(obj, gsl_bspline_workspace, w);
|
43
56
|
Data_Get_Struct(b, gsl_vector, bpts);
|
44
57
|
gsl_bspline_knots(bpts, w);
|
45
|
-
return Data_Wrap_Struct(cgsl_vector_view_ro, 0, NULL, w->knots);
|
58
|
+
return Data_Wrap_Struct(cgsl_vector_view_ro, 0, NULL, w->knots);
|
46
59
|
}
|
47
60
|
static VALUE rb_gsl_bspline_knots_uniform(int argc, VALUE *argv, VALUE obj)
|
48
61
|
{
|
data/ext/gsl_native/cheb.c
CHANGED
@@ -115,8 +115,29 @@ static VALUE rb_gsl_cheb_eval(VALUE obj, VALUE xx)
|
|
115
115
|
return ary;
|
116
116
|
break;
|
117
117
|
default:
|
118
|
+
if (VECTOR_P(xx)) {
|
119
|
+
Data_Get_Struct(xx, gsl_vector, v);
|
120
|
+
vnew = gsl_vector_alloc(v->size);
|
121
|
+
for (i = 0; i < v->size; i++) {
|
122
|
+
gsl_vector_set(vnew, i, gsl_cheb_eval(p, gsl_vector_get(v, i)));
|
123
|
+
}
|
124
|
+
return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, vnew);
|
125
|
+
}
|
126
|
+
#ifdef HAVE_NMATRIX_H
|
127
|
+
else if (NM_IsNMatrix(xx)) {
|
128
|
+
NM_DENSE_STORAGE *nm;
|
129
|
+
double *ptr1, *ptr2;
|
130
|
+
nm = NM_STORAGE_DENSE(xx);
|
131
|
+
ptr1 = (double*) nm->elements;
|
132
|
+
n = NM_DENSE_COUNT(xx);
|
133
|
+
ary = rb_nmatrix_dense_create(FLOAT64, nm->shape, nm->dim, nm->elements, n);
|
134
|
+
ptr2 = (double*)NM_DENSE_ELEMENTS(ary);
|
135
|
+
for (i = 0; i < n; i++) ptr2[i] = gsl_cheb_eval(p, ptr1[i]);
|
136
|
+
return ary;
|
137
|
+
}
|
138
|
+
#endif
|
118
139
|
#ifdef HAVE_NARRAY_H
|
119
|
-
if (NA_IsNArray(xx)) {
|
140
|
+
else if (NA_IsNArray(xx)) {
|
120
141
|
struct NARRAY *na;
|
121
142
|
double *ptr1, *ptr2;
|
122
143
|
GetNArray(xx, na);
|
@@ -128,14 +149,7 @@ static VALUE rb_gsl_cheb_eval(VALUE obj, VALUE xx)
|
|
128
149
|
return ary;
|
129
150
|
}
|
130
151
|
#endif
|
131
|
-
if (
|
132
|
-
Data_Get_Struct(xx, gsl_vector, v);
|
133
|
-
vnew = gsl_vector_alloc(v->size);
|
134
|
-
for (i = 0; i < v->size; i++) {
|
135
|
-
gsl_vector_set(vnew, i, gsl_cheb_eval(p, gsl_vector_get(v, i)));
|
136
|
-
}
|
137
|
-
return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, vnew);
|
138
|
-
} else if (MATRIX_P(xx)) {
|
152
|
+
else if (MATRIX_P(xx)) {
|
139
153
|
Data_Get_Struct(xx, gsl_matrix, m);
|
140
154
|
mnew = gsl_matrix_alloc(m->size1, m->size2);
|
141
155
|
for (i = 0; i < m->size1; i++) {
|
@@ -144,7 +158,8 @@ static VALUE rb_gsl_cheb_eval(VALUE obj, VALUE xx)
|
|
144
158
|
}
|
145
159
|
}
|
146
160
|
return Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, mnew);
|
147
|
-
}
|
161
|
+
}
|
162
|
+
else {
|
148
163
|
rb_raise(rb_eTypeError, "wrong argument type");
|
149
164
|
}
|
150
165
|
break;
|
@@ -202,6 +217,25 @@ static VALUE rb_gsl_cheb_eval_err(VALUE obj, VALUE xx)
|
|
202
217
|
}
|
203
218
|
return rb_ary_new3(2, ary, aerr);
|
204
219
|
}
|
220
|
+
#endif
|
221
|
+
#ifdef HAVE_NMATRIX_H
|
222
|
+
if (NM_IsNMatrix(xx)) {
|
223
|
+
NM_DENSE_STORAGE *nm;
|
224
|
+
double *ptr1, *ptr2, *ptr3;
|
225
|
+
nm = NM_STORAGE_DENSE(xx);
|
226
|
+
n = NM_DENSE_COUNT(xx);
|
227
|
+
ptr1 = (double*) nm->elements;
|
228
|
+
ary = rb_nmatrix_dense_create(FLOAT64, nm->shape, nm->dim, nm->elements, n);
|
229
|
+
aerr = rb_nmatrix_dense_create(FLOAT64, nm->shape, nm->dim, nm->elements, n);
|
230
|
+
ptr2 = (double*)NM_DENSE_ELEMENTS(ary);
|
231
|
+
ptr3 = (double*)NM_DENSE_ELEMENTS(aerr);
|
232
|
+
for (i = 0; i < n; i++) {
|
233
|
+
gsl_cheb_eval_err(p, ptr1[i], &result, &err);
|
234
|
+
ptr2[i] = result;
|
235
|
+
ptr3[i] = err;
|
236
|
+
}
|
237
|
+
return rb_ary_new3(2, ary, aerr);
|
238
|
+
}
|
205
239
|
#endif
|
206
240
|
if (VECTOR_P(xx)) {
|
207
241
|
Data_Get_Struct(xx, gsl_vector, v);
|
@@ -278,6 +312,19 @@ static VALUE rb_gsl_cheb_eval_n(VALUE obj, VALUE nn, VALUE xx)
|
|
278
312
|
for (i = 0; i < n; i++) ptr2[i] = gsl_cheb_eval_n(p, order, ptr1[i]);
|
279
313
|
return ary;
|
280
314
|
}
|
315
|
+
#endif
|
316
|
+
#ifdef HAVE_NMATRIX_H
|
317
|
+
if (NM_IsNMatrix(xx)) {
|
318
|
+
NM_DENSE_STORAGE *nm;
|
319
|
+
double *ptr1, *ptr2;
|
320
|
+
nm = NM_STORAGE_DENSE(xx);
|
321
|
+
n = NM_DENSE_COUNT(xx);
|
322
|
+
ptr1 = (double*) nm->elements;
|
323
|
+
ary = rb_nmatrix_dense_create(FLOAT64, nm->shape, nm->dim, nm->elements, n);
|
324
|
+
ptr2 = (double*)NM_DENSE_ELEMENTS(ary);
|
325
|
+
for (i = 0; i < n; i++) ptr2[i] = gsl_cheb_eval_n(p, order, ptr1[i]);
|
326
|
+
return ary;
|
327
|
+
}
|
281
328
|
#endif
|
282
329
|
if (VECTOR_P(xx)) {
|
283
330
|
Data_Get_Struct(xx, gsl_vector, v);
|
@@ -356,6 +403,25 @@ static VALUE rb_gsl_cheb_eval_n_err(VALUE obj, VALUE nn, VALUE xx)
|
|
356
403
|
}
|
357
404
|
return rb_ary_new3(2, ary, aerr);
|
358
405
|
}
|
406
|
+
#endif
|
407
|
+
#ifdef HAVE_NMATRIX_H
|
408
|
+
if (NM_IsNMatrix(xx)) {
|
409
|
+
NM_DENSE_STORAGE *nm;
|
410
|
+
double *ptr1, *ptr2, *ptr3;
|
411
|
+
nm = NM_STORAGE_DENSE(xx);
|
412
|
+
n = NM_DENSE_COUNT(xx);
|
413
|
+
ptr1 = (double*) nm->elements;
|
414
|
+
ary = rb_nmatrix_dense_create(FLOAT64, nm->shape, nm->dim, nm->elements, n);
|
415
|
+
aerr = rb_nmatrix_dense_create(FLOAT64, nm->shape, nm->dim, nm->elements, n);
|
416
|
+
ptr2 = (double*)NM_DENSE_ELEMENTS(ary);
|
417
|
+
ptr3 = (double*)NM_DENSE_ELEMENTS(aerr);
|
418
|
+
for (i = 0; i < n; i++) {
|
419
|
+
gsl_cheb_eval_n_err(p, order, ptr1[i], &result, &err);
|
420
|
+
ptr2[i] = result;
|
421
|
+
ptr3[i] = err;
|
422
|
+
}
|
423
|
+
return rb_ary_new3(2, ary, aerr);
|
424
|
+
}
|
359
425
|
#endif
|
360
426
|
if (VECTOR_P(xx)) {
|
361
427
|
Data_Get_Struct(xx, gsl_vector, v);
|
data/ext/gsl_native/common.c
CHANGED
@@ -203,6 +203,19 @@ double* get_ptr_double3(VALUE obj, size_t *size, size_t *stride, int *flag)
|
|
203
203
|
return ptr;
|
204
204
|
}
|
205
205
|
#endif
|
206
|
+
|
207
|
+
#ifdef HAVE_NMATRIX_H
|
208
|
+
double *ptr;
|
209
|
+
NM_DENSE_STORAGE *nm;
|
210
|
+
if (NM_IsNMatrix(obj)) {
|
211
|
+
nm = NM_STORAGE_DENSE(obj);
|
212
|
+
*size = NM_DENSE_COUNT(obj);
|
213
|
+
ptr = (double *) nm->elements;
|
214
|
+
*stride = 1;
|
215
|
+
*flag = 1;
|
216
|
+
return ptr;
|
217
|
+
}
|
218
|
+
#endif
|
206
219
|
CHECK_VECTOR(obj);
|
207
220
|
Data_Get_Struct(obj, gsl_vector, v);
|
208
221
|
*size = v->size;
|
@@ -291,3 +304,23 @@ VALUE rb_gsl_nary_eval1(VALUE ary, double (*f)(double))
|
|
291
304
|
return ary2;
|
292
305
|
}
|
293
306
|
#endif
|
307
|
+
|
308
|
+
#ifdef HAVE_NMATRIX_H
|
309
|
+
VALUE rb_gsl_nmatrix_eval1(VALUE ary, double (*f)(double))
|
310
|
+
{
|
311
|
+
VALUE ary2;
|
312
|
+
NM_DENSE_STORAGE *nm;
|
313
|
+
double *ptr1, *ptr2;
|
314
|
+
size_t i, n;
|
315
|
+
if (NM_DTYPE(ary) != FLOAT64) {
|
316
|
+
rb_raise(rb_eTypeError, "only accept :float64 dtype NMatrix");
|
317
|
+
}
|
318
|
+
nm = NM_STORAGE_DENSE(ary);
|
319
|
+
n = NM_DENSE_COUNT(ary);
|
320
|
+
ptr1 = (double *) nm->elements;
|
321
|
+
ary2 = rb_nmatrix_dense_create(FLOAT64, nm->shape, nm->dim, nm->elements, n);
|
322
|
+
ptr2 = (double*)NM_DENSE_ELEMENTS(ary2);
|
323
|
+
for (i = 0; i < n; i++) ptr2[i] = (*f)(ptr1[i]);
|
324
|
+
return ary2;
|
325
|
+
}
|
326
|
+
#endif
|