romanbsd-gsl 1.11.2.2
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.
- data/README.rdoc +29 -0
- data/Rakefile +54 -0
- data/VERSION +1 -0
- data/ext/MANIFEST +116 -0
- data/ext/array.c +665 -0
- data/ext/array_complex.c +247 -0
- data/ext/blas.c +29 -0
- data/ext/blas1.c +729 -0
- data/ext/blas2.c +1093 -0
- data/ext/blas3.c +881 -0
- data/ext/block.c +44 -0
- data/ext/block_source.c +885 -0
- data/ext/bspline.c +116 -0
- data/ext/bundle.c +3 -0
- data/ext/cdf.c +754 -0
- data/ext/cheb.c +538 -0
- data/ext/combination.c +283 -0
- data/ext/common.c +310 -0
- data/ext/complex.c +1005 -0
- data/ext/const.c +668 -0
- data/ext/const_additional.c +120 -0
- data/ext/cqp.c +283 -0
- data/ext/deriv.c +194 -0
- data/ext/dht.c +360 -0
- data/ext/diff.c +165 -0
- data/ext/dirac.c +395 -0
- data/ext/eigen.c +2373 -0
- data/ext/error.c +194 -0
- data/ext/extconf.rb +272 -0
- data/ext/fcmp.c +66 -0
- data/ext/fft.c +1092 -0
- data/ext/fit.c +205 -0
- data/ext/fresnel.c +312 -0
- data/ext/function.c +522 -0
- data/ext/graph.c +1634 -0
- data/ext/gsl.c +265 -0
- data/ext/gsl_narray.c +652 -0
- data/ext/histogram.c +1717 -0
- data/ext/histogram2d.c +1067 -0
- data/ext/histogram3d.c +883 -0
- data/ext/histogram3d_source.c +750 -0
- data/ext/histogram_find.c +101 -0
- data/ext/histogram_oper.c +159 -0
- data/ext/ieee.c +98 -0
- data/ext/integration.c +1138 -0
- data/ext/interp.c +511 -0
- data/ext/jacobi.c +737 -0
- data/ext/linalg.c +4045 -0
- data/ext/linalg_complex.c +743 -0
- data/ext/math.c +724 -0
- data/ext/matrix.c +39 -0
- data/ext/matrix_complex.c +1731 -0
- data/ext/matrix_double.c +560 -0
- data/ext/matrix_int.c +256 -0
- data/ext/matrix_source.c +2678 -0
- data/ext/min.c +234 -0
- data/ext/monte.c +759 -0
- data/ext/multifit.c +1810 -0
- data/ext/multimin.c +793 -0
- data/ext/multimin_fsdf.c +156 -0
- data/ext/multiroots.c +952 -0
- data/ext/ndlinear.c +320 -0
- data/ext/nmf.c +159 -0
- data/ext/nmf_wrap.c +63 -0
- data/ext/ntuple.c +469 -0
- data/ext/odeiv.c +958 -0
- data/ext/ool.c +879 -0
- data/ext/oper_complex_source.c +253 -0
- data/ext/permutation.c +596 -0
- data/ext/poly.c +42 -0
- data/ext/poly2.c +265 -0
- data/ext/poly_source.c +1799 -0
- data/ext/qrng.c +171 -0
- data/ext/randist.c +1869 -0
- data/ext/rational.c +480 -0
- data/ext/rng.c +612 -0
- data/ext/root.c +408 -0
- data/ext/sf.c +1494 -0
- data/ext/sf_airy.c +200 -0
- data/ext/sf_bessel.c +867 -0
- data/ext/sf_clausen.c +28 -0
- data/ext/sf_coulomb.c +206 -0
- data/ext/sf_coupling.c +118 -0
- data/ext/sf_dawson.c +29 -0
- data/ext/sf_debye.c +157 -0
- data/ext/sf_dilog.c +42 -0
- data/ext/sf_elementary.c +44 -0
- data/ext/sf_ellint.c +206 -0
- data/ext/sf_elljac.c +29 -0
- data/ext/sf_erfc.c +93 -0
- data/ext/sf_exp.c +164 -0
- data/ext/sf_expint.c +211 -0
- data/ext/sf_fermi_dirac.c +148 -0
- data/ext/sf_gamma.c +344 -0
- data/ext/sf_gegenbauer.c +96 -0
- data/ext/sf_hyperg.c +197 -0
- data/ext/sf_laguerre.c +112 -0
- data/ext/sf_lambert.c +47 -0
- data/ext/sf_legendre.c +367 -0
- data/ext/sf_log.c +104 -0
- data/ext/sf_mathieu.c +238 -0
- data/ext/sf_power.c +46 -0
- data/ext/sf_psi.c +98 -0
- data/ext/sf_synchrotron.c +48 -0
- data/ext/sf_transport.c +76 -0
- data/ext/sf_trigonometric.c +207 -0
- data/ext/sf_zeta.c +119 -0
- data/ext/signal.c +310 -0
- data/ext/siman.c +718 -0
- data/ext/sort.c +208 -0
- data/ext/spline.c +393 -0
- data/ext/stats.c +799 -0
- data/ext/sum.c +168 -0
- data/ext/tamu_anova.c +56 -0
- data/ext/tensor.c +38 -0
- data/ext/tensor_source.c +1121 -0
- data/ext/vector.c +38 -0
- data/ext/vector_complex.c +2139 -0
- data/ext/vector_double.c +1445 -0
- data/ext/vector_int.c +204 -0
- data/ext/vector_source.c +3325 -0
- data/ext/wavelet.c +937 -0
- data/include/rb_gsl.h +140 -0
- data/include/rb_gsl_array.h +230 -0
- data/include/rb_gsl_cheb.h +21 -0
- data/include/rb_gsl_common.h +343 -0
- data/include/rb_gsl_complex.h +25 -0
- data/include/rb_gsl_const.h +29 -0
- data/include/rb_gsl_dirac.h +15 -0
- data/include/rb_gsl_eigen.h +17 -0
- data/include/rb_gsl_fft.h +62 -0
- data/include/rb_gsl_fit.h +25 -0
- data/include/rb_gsl_function.h +27 -0
- data/include/rb_gsl_graph.h +70 -0
- data/include/rb_gsl_histogram.h +65 -0
- data/include/rb_gsl_histogram3d.h +97 -0
- data/include/rb_gsl_integration.h +17 -0
- data/include/rb_gsl_interp.h +46 -0
- data/include/rb_gsl_linalg.h +25 -0
- data/include/rb_gsl_math.h +26 -0
- data/include/rb_gsl_odeiv.h +21 -0
- data/include/rb_gsl_poly.h +71 -0
- data/include/rb_gsl_rational.h +37 -0
- data/include/rb_gsl_rng.h +21 -0
- data/include/rb_gsl_root.h +22 -0
- data/include/rb_gsl_sf.h +119 -0
- data/include/rb_gsl_statistics.h +17 -0
- data/include/rb_gsl_tensor.h +45 -0
- data/include/rb_gsl_with_narray.h +22 -0
- data/include/templates_off.h +87 -0
- data/include/templates_on.h +241 -0
- data/lib/gsl/gnuplot.rb +41 -0
- data/lib/gsl/oper.rb +68 -0
- data/lib/ool.rb +22 -0
- data/lib/ool/conmin.rb +30 -0
- metadata +221 -0
data/README.rdoc
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
== Description
|
|
2
|
+
Ruby/GSL, a ruby interface to GSL (GNU Scientific library)
|
|
3
|
+
|
|
4
|
+
== Installation
|
|
5
|
+
(0) Make sure the command "gsl-config" is in search path.
|
|
6
|
+
(1) % ruby setup.rb config
|
|
7
|
+
(2) % ruby setup.rb setup
|
|
8
|
+
(3) % ruby setup.rb install (as root)
|
|
9
|
+
|
|
10
|
+
See also html/index.html.
|
|
11
|
+
|
|
12
|
+
== Reference
|
|
13
|
+
|
|
14
|
+
See ((<URL:http://rb-gsl.rubyforge.org/ref.html>)).
|
|
15
|
+
|
|
16
|
+
== Licence
|
|
17
|
+
Ruby/GSL is free software: you can redistribute it and/or modify it
|
|
18
|
+
under the terms of the GNU General Public License.
|
|
19
|
+
This library is distributed in the hope that it will be useful, but
|
|
20
|
+
WITHOUT ANY WARRANTY.
|
|
21
|
+
|
|
22
|
+
== Bug Report
|
|
23
|
+
Any bug reports are welcome.
|
|
24
|
+
If you encounter bugs in Ruby/GSL, please e-mail to me, or
|
|
25
|
+
submit reports from http://rubyforge.org/projects/rb-gsl/.
|
|
26
|
+
|
|
27
|
+
== Author
|
|
28
|
+
Yoshiki Tsunesada
|
|
29
|
+
y-tsunesada at mm dot em-net dot ne dot jp
|
data/Rakefile
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'rake/gempackagetask'
|
|
3
|
+
|
|
4
|
+
spec = Gem::Specification.new do |s|
|
|
5
|
+
# Basics
|
|
6
|
+
s.name = 'gsl'
|
|
7
|
+
s.version = File.readlines('VERSION')[0].chomp
|
|
8
|
+
s.summary = 'Ruby interface to GSL'
|
|
9
|
+
s.description = 'RubyGSL is a Ruby interface to the GNU Scientific Library, for numerical computing with Ruby'
|
|
10
|
+
#s.platform = Gem::Platform::Ruby
|
|
11
|
+
s.required_ruby_version = '>= 1.8.1'
|
|
12
|
+
s.requirements << 'GSL (http://www.gnu.org/software/gsl/)'
|
|
13
|
+
# plotlib?
|
|
14
|
+
s.add_dependency('narray', '>= 0.5.9')
|
|
15
|
+
|
|
16
|
+
# About
|
|
17
|
+
s.authors = ['Yoshiki Tsunesada', 'David MacMahon']
|
|
18
|
+
s.email = 'y-tsunesada@mm.em-net.ne.jp'
|
|
19
|
+
s.homepage = 'http://rb-gsl.rubyforge.org/'
|
|
20
|
+
s.rubyforge_project = 'rb-gsl'
|
|
21
|
+
|
|
22
|
+
# Files, Libraries, and Extensions
|
|
23
|
+
s.files = FileList[
|
|
24
|
+
'README.rdoc',
|
|
25
|
+
'VERSION',
|
|
26
|
+
'Rakefile',
|
|
27
|
+
'ext/*',
|
|
28
|
+
'lib/**/*',
|
|
29
|
+
'include/*'
|
|
30
|
+
].to_a
|
|
31
|
+
s.require_paths = ['lib', 'lib/gsl', 'lib/ool', 'ext']
|
|
32
|
+
#s.autorequire = nil
|
|
33
|
+
#s.bindir = 'bin'
|
|
34
|
+
#s.executables = []
|
|
35
|
+
#s.default_executable = nil
|
|
36
|
+
|
|
37
|
+
# C compilation
|
|
38
|
+
s.extensions = %w[ ext/extconf.rb ]
|
|
39
|
+
|
|
40
|
+
# Documentation TODO
|
|
41
|
+
#s.rdoc_options = []
|
|
42
|
+
#s.has_rdoc = false
|
|
43
|
+
#s.extra_rdoc_files = []
|
|
44
|
+
|
|
45
|
+
# Testing TODO
|
|
46
|
+
#s.test_files = []
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
|
50
|
+
pkg.need_zip = true
|
|
51
|
+
pkg.need_tar = true
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
task :default => :gem
|
data/VERSION
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
1.11.2
|
data/ext/MANIFEST
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
[0m[0marray.c[0m
|
|
2
|
+
[0marray_complex.c[0m
|
|
3
|
+
[0mblas.c[0m
|
|
4
|
+
[0mblas1.c[0m
|
|
5
|
+
[0mblas2.c[0m
|
|
6
|
+
[0mblas3.c[0m
|
|
7
|
+
[0mblock.c[0m
|
|
8
|
+
[0mblock_source.c[0m
|
|
9
|
+
[0mbspline.c[0m
|
|
10
|
+
[0mbundle.c[0m
|
|
11
|
+
[0mcdf.c[0m
|
|
12
|
+
[0mcheb.c[0m
|
|
13
|
+
[0mcombination.c[0m
|
|
14
|
+
[0mcommon.c[0m
|
|
15
|
+
[0mcomplex.c[0m
|
|
16
|
+
[0mconst.c[0m
|
|
17
|
+
[0mconst_additional.c[0m
|
|
18
|
+
[0mcqp.c[0m
|
|
19
|
+
[0mderiv.c[0m
|
|
20
|
+
[0mdht.c[0m
|
|
21
|
+
[0mdiff.c[0m
|
|
22
|
+
[0mdirac.c[0m
|
|
23
|
+
[0meigen.c[0m
|
|
24
|
+
[0merror.c[0m
|
|
25
|
+
[0mfcmp.c[0m
|
|
26
|
+
[0mfft.c[0m
|
|
27
|
+
[0mfit.c[0m
|
|
28
|
+
[0mfresnel.c[0m
|
|
29
|
+
[0mfunction.c[0m
|
|
30
|
+
[0mgraph.c[0m
|
|
31
|
+
[0mgsl.c[0m
|
|
32
|
+
[0mgsl_narray.c[0m
|
|
33
|
+
[0mhistogram.c[0m
|
|
34
|
+
[0mhistogram2d.c[0m
|
|
35
|
+
[0mhistogram3d.c[0m
|
|
36
|
+
[0mhistogram3d_source.c[0m
|
|
37
|
+
[0mhistogram_find.c[0m
|
|
38
|
+
[0mhistogram_oper.c[0m
|
|
39
|
+
[0mieee.c[0m
|
|
40
|
+
[0mintegration.c[0m
|
|
41
|
+
[0minterp.c[0m
|
|
42
|
+
[0mjacobi.c[0m
|
|
43
|
+
[0mlinalg.c[0m
|
|
44
|
+
[0mlinalg_complex.c[0m
|
|
45
|
+
[0mmath.c[0m
|
|
46
|
+
[0mmatrix.c[0m
|
|
47
|
+
[0mmatrix_complex.c[0m
|
|
48
|
+
[0mmatrix_double.c[0m
|
|
49
|
+
[0mmatrix_int.c[0m
|
|
50
|
+
[0mmatrix_source.c[0m
|
|
51
|
+
[0mmin.c[0m
|
|
52
|
+
[0mmonte.c[0m
|
|
53
|
+
[0mmultifit.c[0m
|
|
54
|
+
[0mmultimin.c[0m
|
|
55
|
+
[0mmultimin_fsdf.c[0m
|
|
56
|
+
[0mmultiroots.c[0m
|
|
57
|
+
[0mndlinear.c[0m
|
|
58
|
+
[0mntuple.c[0m
|
|
59
|
+
[0modeiv.c[0m
|
|
60
|
+
[0mool.c[0m
|
|
61
|
+
[0moper_complex_source.c[0m
|
|
62
|
+
[0mpermutation.c[0m
|
|
63
|
+
[0mpoly.c[0m
|
|
64
|
+
[0mpoly2.c[0m
|
|
65
|
+
[0mpoly_source.c[0m
|
|
66
|
+
[0mqrng.c[0m
|
|
67
|
+
[0mrandist.c[0m
|
|
68
|
+
[0mrational.c[0m
|
|
69
|
+
[0mrng.c[0m
|
|
70
|
+
[0mroot.c[0m
|
|
71
|
+
[0msf.c[0m
|
|
72
|
+
[0msf_airy.c[0m
|
|
73
|
+
[0msf_bessel.c[0m
|
|
74
|
+
[0msf_clausen.c[0m
|
|
75
|
+
[0msf_coulomb.c[0m
|
|
76
|
+
[0msf_coupling.c[0m
|
|
77
|
+
[0msf_dawson.c[0m
|
|
78
|
+
[0msf_debye.c[0m
|
|
79
|
+
[0msf_dilog.c[0m
|
|
80
|
+
[0msf_elementary.c[0m
|
|
81
|
+
[0msf_ellint.c[0m
|
|
82
|
+
[0msf_elljac.c[0m
|
|
83
|
+
[0msf_erfc.c[0m
|
|
84
|
+
[0msf_exp.c[0m
|
|
85
|
+
[0msf_expint.c[0m
|
|
86
|
+
[0msf_fermi_dirac.c[0m
|
|
87
|
+
[0msf_gamma.c[0m
|
|
88
|
+
[0msf_gegenbauer.c[0m
|
|
89
|
+
[0msf_hyperg.c[0m
|
|
90
|
+
[0msf_laguerre.c[0m
|
|
91
|
+
[0msf_lambert.c[0m
|
|
92
|
+
[0msf_legendre.c[0m
|
|
93
|
+
[0msf_log.c[0m
|
|
94
|
+
[0msf_mathieu.c[0m
|
|
95
|
+
[0msf_power.c[0m
|
|
96
|
+
[0msf_psi.c[0m
|
|
97
|
+
[0msf_synchrotron.c[0m
|
|
98
|
+
[0msf_transport.c[0m
|
|
99
|
+
[0msf_trigonometric.c[0m
|
|
100
|
+
[0msf_zeta.c[0m
|
|
101
|
+
[0msignal.c[0m
|
|
102
|
+
[0msiman.c[0m
|
|
103
|
+
[0msort.c[0m
|
|
104
|
+
[0mspline.c[0m
|
|
105
|
+
[0mstats.c[0m
|
|
106
|
+
[0msum.c[0m
|
|
107
|
+
[0mtamu_anova.c[0m
|
|
108
|
+
[0mtensor.c[0m
|
|
109
|
+
[0mtensor_source.c[0m
|
|
110
|
+
[0mvector.c[0m
|
|
111
|
+
[0mvector_complex.c[0m
|
|
112
|
+
[0mvector_double.c[0m
|
|
113
|
+
[0mvector_int.c[0m
|
|
114
|
+
[0mvector_source.c[0m
|
|
115
|
+
[0mwavelet.c[0m
|
|
116
|
+
[m
|
data/ext/array.c
ADDED
|
@@ -0,0 +1,665 @@
|
|
|
1
|
+
/*
|
|
2
|
+
array.c
|
|
3
|
+
Ruby/GSL: Ruby extension library for GSL (GNU Scientific Library)
|
|
4
|
+
(C) Copyright 2001-2006 by Yoshiki Tsunesada
|
|
5
|
+
|
|
6
|
+
Ruby/GSL is free software: you can redistribute it and/or modify it
|
|
7
|
+
under the terms of the GNU General Public License.
|
|
8
|
+
This library is distributed in the hope that it will be useful, but
|
|
9
|
+
WITHOUT ANY WARRANTY.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
#include "rb_gsl_config.h"
|
|
13
|
+
|
|
14
|
+
#include "rb_gsl_common.h"
|
|
15
|
+
#include "rb_gsl_array.h"
|
|
16
|
+
#include "rb_gsl_complex.h"
|
|
17
|
+
#ifdef HAVE_NARRAY_H
|
|
18
|
+
#include "rb_gsl_with_narray.h"
|
|
19
|
+
#endif
|
|
20
|
+
|
|
21
|
+
/* global variables */
|
|
22
|
+
VALUE cgsl_block, cgsl_block_int;
|
|
23
|
+
VALUE cgsl_block_uchar;
|
|
24
|
+
VALUE cgsl_block_complex;
|
|
25
|
+
VALUE cgsl_vector, cgsl_vector_view;
|
|
26
|
+
VALUE cgsl_vector_view_ro;
|
|
27
|
+
VALUE cgsl_vector_col_view_ro;
|
|
28
|
+
VALUE cgsl_matrix_view_ro;
|
|
29
|
+
VALUE cgsl_vector_complex;
|
|
30
|
+
VALUE cgsl_vector_complex_view;
|
|
31
|
+
VALUE cgsl_matrix;
|
|
32
|
+
VALUE cgsl_matrix_view;
|
|
33
|
+
VALUE cgsl_matrix_complex;
|
|
34
|
+
VALUE cgsl_matrix_complex_view;
|
|
35
|
+
VALUE cgsl_vector_complex_view_ro;
|
|
36
|
+
VALUE cgsl_matrix_complex_view_ro;
|
|
37
|
+
VALUE cgsl_permutation;
|
|
38
|
+
VALUE cgsl_index;
|
|
39
|
+
VALUE cgsl_vector_col, cgsl_vector_col_view;
|
|
40
|
+
VALUE cgsl_vector_complex_col, cgsl_vector_complex_col_view;
|
|
41
|
+
|
|
42
|
+
VALUE cgsl_vector_int, cgsl_vector_int_col;
|
|
43
|
+
VALUE cgsl_vector_int_view, cgsl_vector_int_col_view;
|
|
44
|
+
VALUE cgsl_vector_int_view_ro, cgsl_vector_int_col_view_ro;
|
|
45
|
+
VALUE cgsl_matrix_int, cgsl_matrix_int_view, cgsl_matrix_int_view_ro;
|
|
46
|
+
|
|
47
|
+
double* get_vector_ptr(VALUE ary, size_t *stride, size_t *n)
|
|
48
|
+
{
|
|
49
|
+
gsl_vector *v = NULL;
|
|
50
|
+
gsl_vector_complex *vc = NULL;
|
|
51
|
+
gsl_matrix *m;
|
|
52
|
+
#ifdef HAVE_NARRAY_H
|
|
53
|
+
VALUE ary2;
|
|
54
|
+
#endif
|
|
55
|
+
if (VECTOR_P(ary)) {
|
|
56
|
+
Data_Get_Struct(ary, gsl_vector, v);
|
|
57
|
+
*stride = v->stride;
|
|
58
|
+
*n = v->size;
|
|
59
|
+
return v->data;
|
|
60
|
+
} else if (VECTOR_COMPLEX_P(ary)) {
|
|
61
|
+
Data_Get_Struct(ary, gsl_vector_complex, vc);
|
|
62
|
+
*stride = vc->stride;
|
|
63
|
+
*n = vc->size*2;
|
|
64
|
+
return vc->data;
|
|
65
|
+
} else if (MATRIX_P(ary)) {
|
|
66
|
+
Data_Get_Struct(ary, gsl_matrix, m);
|
|
67
|
+
*stride = 1;
|
|
68
|
+
*n = m->size1*m->size2;
|
|
69
|
+
return m->data;
|
|
70
|
+
#ifdef HAVE_NARRAY_H
|
|
71
|
+
} else if (NA_IsNArray(ary)) {
|
|
72
|
+
*n = NA_TOTAL(ary);
|
|
73
|
+
*stride = 1;
|
|
74
|
+
ary2 = na_change_type(ary, NA_DFLOAT);
|
|
75
|
+
return NA_PTR_TYPE(ary2,double*);
|
|
76
|
+
#endif
|
|
77
|
+
} else {
|
|
78
|
+
rb_raise(rb_eTypeError,
|
|
79
|
+
"wrong argument type %s", rb_class2name(CLASS_OF(ary)));
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
gsl_vector* get_cvector(VALUE obj)
|
|
84
|
+
{
|
|
85
|
+
gsl_vector *v = NULL;
|
|
86
|
+
if (rb_obj_is_kind_of(obj, cgsl_vector)) {
|
|
87
|
+
Data_Get_Struct(obj, gsl_vector, v);
|
|
88
|
+
#ifdef HAVE_NARRAY_H
|
|
89
|
+
} else if (NA_IsArray(obj)) {
|
|
90
|
+
v = make_cvector_from_rarrays(obj);
|
|
91
|
+
#endif
|
|
92
|
+
} else {
|
|
93
|
+
rb_raise(rb_eTypeError,
|
|
94
|
+
"wrong argument type %s", rb_class2name(CLASS_OF(obj)));
|
|
95
|
+
}
|
|
96
|
+
return v;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
VALUE make_rarray_from_cvector(const gsl_vector *v)
|
|
100
|
+
{
|
|
101
|
+
size_t i;
|
|
102
|
+
VALUE ary;
|
|
103
|
+
ary = rb_ary_new2(v->size);
|
|
104
|
+
for (i = 0; i < v->size; i++) {
|
|
105
|
+
rb_ary_store(ary, i, rb_float_new(gsl_vector_get(v, i)));
|
|
106
|
+
}
|
|
107
|
+
return ary;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
VALUE make_rarray_from_cvector_int(const gsl_vector_int *v)
|
|
111
|
+
{
|
|
112
|
+
size_t i;
|
|
113
|
+
VALUE ary;
|
|
114
|
+
ary = rb_ary_new2(v->size);
|
|
115
|
+
for (i = 0; i < v->size; i++) {
|
|
116
|
+
rb_ary_store(ary, i, INT2FIX(gsl_vector_int_get(v, i)));
|
|
117
|
+
}
|
|
118
|
+
return ary;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
VALUE make_rarray_from_cpermutation(const gsl_permutation *v)
|
|
122
|
+
{
|
|
123
|
+
size_t i;
|
|
124
|
+
VALUE ary;
|
|
125
|
+
ary = rb_ary_new2(v->size);
|
|
126
|
+
for (i = 0; i < v->size; i++) {
|
|
127
|
+
rb_ary_store(ary, i, rb_float_new(gsl_permutation_get(v, i)));
|
|
128
|
+
}
|
|
129
|
+
return ary;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
gsl_vector* get_vector(VALUE ary)
|
|
133
|
+
{
|
|
134
|
+
gsl_vector *v = NULL;
|
|
135
|
+
if (CLASS_OF(ary) == rb_cRange) ary = rb_gsl_range2ary(ary);
|
|
136
|
+
if (TYPE(ary) == T_ARRAY) {
|
|
137
|
+
return make_cvector_from_rarray(ary);
|
|
138
|
+
#ifdef HAVE_NARRAY_H
|
|
139
|
+
} else if (NA_IsNArray(ary)) {
|
|
140
|
+
return make_cvector_from_narray(ary);
|
|
141
|
+
#endif
|
|
142
|
+
} else if (VECTOR_P(ary)) {
|
|
143
|
+
Data_Get_Struct(ary, gsl_vector, v);
|
|
144
|
+
return v;
|
|
145
|
+
} else {
|
|
146
|
+
rb_raise(rb_eTypeError,
|
|
147
|
+
"wrong argument type %s", rb_class2name(CLASS_OF(ary)));
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
gsl_vector* make_cvector_from_rarrays(VALUE ary)
|
|
152
|
+
{
|
|
153
|
+
if (CLASS_OF(ary) == rb_cRange) ary = rb_gsl_range2ary(ary);
|
|
154
|
+
if (TYPE(ary) == T_ARRAY) {
|
|
155
|
+
return make_cvector_from_rarray(ary);
|
|
156
|
+
#ifdef HAVE_NARRAY_H
|
|
157
|
+
} else if (NA_IsNArray(ary)) {
|
|
158
|
+
return make_cvector_from_narray(ary);
|
|
159
|
+
#endif
|
|
160
|
+
} else {
|
|
161
|
+
rb_raise(rb_eTypeError,
|
|
162
|
+
"wrong argument type %s", rb_class2name(CLASS_OF(ary)));
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
void cvector_set_from_carray(gsl_vector *v, const double *a)
|
|
167
|
+
{
|
|
168
|
+
size_t i;
|
|
169
|
+
for (i = 0; i < v->size; i++) gsl_vector_set(v, i, a[i]);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
void cvector_set_from_rarrays(gsl_vector *v, VALUE ary)
|
|
173
|
+
{
|
|
174
|
+
if (CLASS_OF(ary) == rb_cRange) ary = rb_gsl_range2ary(ary);
|
|
175
|
+
if (TYPE(ary) == T_ARRAY) {
|
|
176
|
+
return cvector_set_from_rarray(v, ary);
|
|
177
|
+
#ifdef HAVE_NARRAY_H
|
|
178
|
+
} else if (NA_IsNArray(ary)) {
|
|
179
|
+
return cvector_set_from_narray(v, ary);
|
|
180
|
+
#endif
|
|
181
|
+
} else {
|
|
182
|
+
rb_raise(rb_eTypeError,
|
|
183
|
+
"wrong argument type %s", rb_class2name(CLASS_OF(ary)));
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
void carray_set_from_cvector(double *a, const gsl_vector *v)
|
|
188
|
+
{
|
|
189
|
+
size_t i;
|
|
190
|
+
for (i = 0; i < v->size; i++) a[i] = gsl_vector_get(v, i);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
void carray_set_from_rarrays(double *a, VALUE ary)
|
|
194
|
+
{
|
|
195
|
+
if (CLASS_OF(ary) == rb_cRange) ary = rb_gsl_range2ary(ary);
|
|
196
|
+
if (TYPE(ary) == T_ARRAY) {
|
|
197
|
+
return carray_set_from_rarray(a, ary);
|
|
198
|
+
#ifdef HAVE_NARRAY_H
|
|
199
|
+
} else if (NA_IsNArray(ary)) {
|
|
200
|
+
return carray_set_from_narray(a, ary);
|
|
201
|
+
#endif
|
|
202
|
+
} else {
|
|
203
|
+
rb_raise(rb_eTypeError,
|
|
204
|
+
"wrong argument type %s", rb_class2name(CLASS_OF(ary)));
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
void carray_set_from_rarray(double *a, VALUE ary)
|
|
209
|
+
{
|
|
210
|
+
size_t i, size;
|
|
211
|
+
VALUE val;
|
|
212
|
+
if (CLASS_OF(ary) == rb_cRange) ary = rb_gsl_range2ary(ary);
|
|
213
|
+
Check_Type(ary, T_ARRAY);
|
|
214
|
+
size = RARRAY(ary)->len;
|
|
215
|
+
if (size == 0) return;
|
|
216
|
+
for (i = 0; i < size; i++) {
|
|
217
|
+
val = rb_ary_entry(ary, i);
|
|
218
|
+
Need_Float(val);
|
|
219
|
+
a[i] = NUM2DBL(val);
|
|
220
|
+
// a[i] = RFLOAT(val)->value;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
#ifdef HAVE_NARRAY_H
|
|
225
|
+
/* NArray -> CArray */
|
|
226
|
+
void carray_set_from_narray(double *a, VALUE ary)
|
|
227
|
+
{
|
|
228
|
+
int size;
|
|
229
|
+
VALUE ary2;
|
|
230
|
+
if (!NA_IsNArray(ary))
|
|
231
|
+
rb_raise(rb_eTypeError,
|
|
232
|
+
"wrong argument type %s", rb_class2name(CLASS_OF(ary)));
|
|
233
|
+
size = NA_TOTAL(ary);
|
|
234
|
+
if (size == 0) return;
|
|
235
|
+
ary2 = na_change_type(ary, NA_DFLOAT);
|
|
236
|
+
memcpy(a, NA_PTR_TYPE(ary2,double*), size*sizeof(double));
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/* NArray -> GSL::Vector */
|
|
240
|
+
gsl_vector* make_cvector_from_narray(VALUE ary)
|
|
241
|
+
{
|
|
242
|
+
gsl_vector *v = NULL;
|
|
243
|
+
size_t size;
|
|
244
|
+
VALUE ary2;
|
|
245
|
+
if (!NA_IsNArray(ary))
|
|
246
|
+
rb_raise(rb_eTypeError,
|
|
247
|
+
"wrong argument type %s", rb_class2name(CLASS_OF(ary)));
|
|
248
|
+
size = NA_TOTAL(ary);
|
|
249
|
+
v = gsl_vector_alloc(size);
|
|
250
|
+
if (v == NULL) rb_raise(rb_eNoMemError, "gsl_vector_alloc failed");
|
|
251
|
+
ary2 = na_change_type(ary, NA_DFLOAT);
|
|
252
|
+
memcpy(v->data, NA_PTR_TYPE(ary2,double*), size*sizeof(double));
|
|
253
|
+
/* cvector_set_from_narray(v, ary);*/
|
|
254
|
+
return v;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
void cvector_set_from_narray(gsl_vector *v, VALUE ary)
|
|
258
|
+
{
|
|
259
|
+
int size;
|
|
260
|
+
if (!NA_IsNArray(ary))
|
|
261
|
+
rb_raise(rb_eTypeError,
|
|
262
|
+
"wrong argument type %s", rb_class2name(CLASS_OF(ary)));
|
|
263
|
+
size = NA_TOTAL(ary);
|
|
264
|
+
carray_set_from_narray(v->data, ary);
|
|
265
|
+
}
|
|
266
|
+
#endif
|
|
267
|
+
|
|
268
|
+
gsl_vector_complex* make_vector_complex_clone(const gsl_vector_complex *v)
|
|
269
|
+
{
|
|
270
|
+
gsl_vector_complex *vnew = NULL;
|
|
271
|
+
vnew = gsl_vector_complex_alloc(v->size);
|
|
272
|
+
if (vnew == NULL) rb_raise(rb_eNoMemError, "gsl_vector_complex_alloc failed");
|
|
273
|
+
gsl_vector_complex_memcpy(vnew, v);
|
|
274
|
+
return vnew;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
gsl_matrix* make_matrix_clone(const gsl_matrix *m)
|
|
278
|
+
{
|
|
279
|
+
gsl_matrix *mnew = NULL;
|
|
280
|
+
mnew = gsl_matrix_alloc(m->size1, m->size2);
|
|
281
|
+
if (mnew == NULL) rb_raise(rb_eNoMemError, "gsl_matrix_alloc failed");
|
|
282
|
+
gsl_matrix_memcpy(mnew, m);
|
|
283
|
+
return mnew;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
gsl_matrix_int* make_matrix_int_clone(const gsl_matrix_int *m)
|
|
287
|
+
{
|
|
288
|
+
gsl_matrix_int *mnew = NULL;
|
|
289
|
+
mnew = gsl_matrix_int_alloc(m->size1, m->size2);
|
|
290
|
+
if (mnew == NULL) rb_raise(rb_eNoMemError, "gsl_matrix_alloc failed");
|
|
291
|
+
gsl_matrix_int_memcpy(mnew, m);
|
|
292
|
+
return mnew;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
VALUE make_matrix_clone2(VALUE vm)
|
|
296
|
+
{
|
|
297
|
+
gsl_matrix *m = NULL, *mnew = NULL;
|
|
298
|
+
Data_Get_Struct(vm, gsl_matrix, m);
|
|
299
|
+
mnew = gsl_matrix_alloc(m->size1, m->size2);
|
|
300
|
+
if (mnew == NULL) rb_raise(rb_eNoMemError, "gsl_matrix_alloc failed");
|
|
301
|
+
gsl_matrix_memcpy(mnew, m);
|
|
302
|
+
return Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, mnew);;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
gsl_matrix_complex* make_matrix_complex_clone(const gsl_matrix_complex *m)
|
|
306
|
+
{
|
|
307
|
+
gsl_matrix_complex *mnew = NULL;
|
|
308
|
+
mnew = gsl_matrix_complex_alloc(m->size1, m->size2);
|
|
309
|
+
if (mnew == NULL) rb_raise(rb_eNoMemError, "gsl_matrix_complex_alloc failed");
|
|
310
|
+
gsl_matrix_complex_memcpy(mnew, m);
|
|
311
|
+
return mnew;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
gsl_vector_complex* vector_to_complex(const gsl_vector *v)
|
|
315
|
+
{
|
|
316
|
+
gsl_vector_complex *cv = NULL;
|
|
317
|
+
gsl_complex z;
|
|
318
|
+
size_t i;
|
|
319
|
+
cv = gsl_vector_complex_alloc(v->size);
|
|
320
|
+
if (cv == NULL) rb_raise(rb_eNoMemError, "gsl_vector_complex_alloc failed");
|
|
321
|
+
for (i = 0; i < v->size; i++) {
|
|
322
|
+
z = gsl_complex_rect(gsl_vector_get(v, i), 0.0);
|
|
323
|
+
gsl_vector_complex_set(cv, i, z);
|
|
324
|
+
}
|
|
325
|
+
return cv;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
gsl_matrix_complex* matrix_to_complex(const gsl_matrix *m)
|
|
329
|
+
{
|
|
330
|
+
gsl_matrix_complex *cm = NULL;
|
|
331
|
+
gsl_complex z;
|
|
332
|
+
size_t i, j;
|
|
333
|
+
cm = gsl_matrix_complex_alloc(m->size1, m->size2);
|
|
334
|
+
if (cm == NULL) rb_raise(rb_eNoMemError, "gsl_matrix_complex_alloc failed");
|
|
335
|
+
for (i = 0; i < m->size1; i++) {
|
|
336
|
+
for (j = 0; j < m->size2; j++) {
|
|
337
|
+
z = gsl_complex_rect(gsl_matrix_get(m, i, j), 0.0);
|
|
338
|
+
gsl_matrix_complex_set(cm, i, j, z);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
return cm;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
void gsl_matrix_complex_mul(gsl_matrix_complex *mnew, const gsl_matrix_complex *m,
|
|
345
|
+
const gsl_matrix_complex *mb)
|
|
346
|
+
{
|
|
347
|
+
gsl_complex a, b, c, sum;
|
|
348
|
+
size_t i, j, k;
|
|
349
|
+
for (i = 0; i < m->size1; i++) {
|
|
350
|
+
for (j = 0; j < m->size2; j++) {
|
|
351
|
+
sum = gsl_complex_rect(0.0, 0.0);
|
|
352
|
+
for (k = 0; k < m->size2; k++) {
|
|
353
|
+
a = gsl_matrix_complex_get(m, j, k);
|
|
354
|
+
b = gsl_matrix_complex_get(mb, k, i);
|
|
355
|
+
c = gsl_complex_mul(a, b);
|
|
356
|
+
sum = gsl_complex_add(sum, c);
|
|
357
|
+
}
|
|
358
|
+
gsl_matrix_complex_set(mnew, j, i, sum);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
void gsl_matrix_mul_vector(gsl_vector *vnew,
|
|
364
|
+
const gsl_matrix *m, const gsl_vector *v)
|
|
365
|
+
{
|
|
366
|
+
size_t i, j;
|
|
367
|
+
double val;
|
|
368
|
+
for (i = 0; i < m->size1; i++) {
|
|
369
|
+
val = 0;
|
|
370
|
+
for (j = 0; j < m->size2; j++)
|
|
371
|
+
val += gsl_matrix_get(m, i, j)*gsl_vector_get(v, j);
|
|
372
|
+
gsl_vector_set(vnew, i, val);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
void gsl_matrix_int_mul_vector(gsl_vector_int *vnew,
|
|
377
|
+
const gsl_matrix_int *m, const gsl_vector_int *v)
|
|
378
|
+
{
|
|
379
|
+
size_t i, j;
|
|
380
|
+
int val;
|
|
381
|
+
for (i = 0; i < m->size1; i++) {
|
|
382
|
+
val = 0;
|
|
383
|
+
for (j = 0; j < m->size2; j++)
|
|
384
|
+
val += gsl_matrix_int_get(m, i, j)*gsl_vector_int_get(v, j);
|
|
385
|
+
gsl_vector_int_set(vnew, i, val);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
void gsl_matrix_complex_mul_vector(gsl_vector_complex *vnew,
|
|
390
|
+
const gsl_matrix_complex *m,
|
|
391
|
+
const gsl_vector_complex *v)
|
|
392
|
+
{
|
|
393
|
+
gsl_complex a, b, c, sum;
|
|
394
|
+
size_t i, j;
|
|
395
|
+
for (i = 0; i < m->size1; i++) {
|
|
396
|
+
sum = gsl_complex_rect(0.0, 0.0);
|
|
397
|
+
for (j = 0; j < m->size2; j++) {
|
|
398
|
+
a = gsl_matrix_complex_get(m, i, j);
|
|
399
|
+
b = gsl_vector_complex_get(v, j);
|
|
400
|
+
c = gsl_complex_mul(a, b);
|
|
401
|
+
sum = gsl_complex_add(sum, c);
|
|
402
|
+
}
|
|
403
|
+
gsl_vector_complex_set(vnew, i, sum);
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/*****/
|
|
409
|
+
#ifndef GSL_1_12_LATER
|
|
410
|
+
int gsl_vector_complex_add(gsl_vector_complex *cv, const gsl_vector_complex *cv2)
|
|
411
|
+
{
|
|
412
|
+
size_t i;
|
|
413
|
+
gsl_complex a, b, c;
|
|
414
|
+
for (i = 0; i < cv->size; i++) {
|
|
415
|
+
a = gsl_vector_complex_get(cv, i);
|
|
416
|
+
b = gsl_vector_complex_get(cv2, i);
|
|
417
|
+
c = gsl_complex_add(a, b);
|
|
418
|
+
gsl_vector_complex_set(cv, i, c);
|
|
419
|
+
}
|
|
420
|
+
return 0;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
int gsl_vector_complex_add_constant(gsl_vector_complex *cv, gsl_complex b)
|
|
424
|
+
{
|
|
425
|
+
size_t i;
|
|
426
|
+
gsl_complex a, c;
|
|
427
|
+
for (i = 0; i < cv->size; i++) {
|
|
428
|
+
a = gsl_vector_complex_get(cv, i);
|
|
429
|
+
c = gsl_complex_add(a, b);
|
|
430
|
+
gsl_vector_complex_set(cv, i, c);
|
|
431
|
+
}
|
|
432
|
+
return 0;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
int gsl_vector_complex_scale(gsl_vector_complex *cv, gsl_complex b)
|
|
436
|
+
{
|
|
437
|
+
size_t i;
|
|
438
|
+
gsl_complex a, c;
|
|
439
|
+
for (i = 0; i < cv->size; i++) {
|
|
440
|
+
a = gsl_vector_complex_get(cv, i);
|
|
441
|
+
c = gsl_complex_mul(a, b);
|
|
442
|
+
gsl_vector_complex_set(cv, i, c);
|
|
443
|
+
}
|
|
444
|
+
return 0;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
|
|
448
|
+
int gsl_vector_complex_sub(gsl_vector_complex *cv, const gsl_vector_complex *cv2)
|
|
449
|
+
{
|
|
450
|
+
size_t i;
|
|
451
|
+
gsl_complex a, b, c;
|
|
452
|
+
for (i = 0; i < cv->size; i++) {
|
|
453
|
+
a = gsl_vector_complex_get(cv, i);
|
|
454
|
+
b = gsl_vector_complex_get(cv2, i);
|
|
455
|
+
c = gsl_complex_sub(a, b);
|
|
456
|
+
gsl_vector_complex_set(cv, i, c);
|
|
457
|
+
}
|
|
458
|
+
return 0;
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
int gsl_vector_complex_mul(gsl_vector_complex *cv, const gsl_vector_complex *cv2)
|
|
462
|
+
{
|
|
463
|
+
size_t i;
|
|
464
|
+
gsl_complex a, b, c;
|
|
465
|
+
for (i = 0; i < cv->size; i++) {
|
|
466
|
+
a = gsl_vector_complex_get(cv, i);
|
|
467
|
+
b = gsl_vector_complex_get(cv2, i);
|
|
468
|
+
c = gsl_complex_mul(a, b);
|
|
469
|
+
gsl_vector_complex_set(cv, i, c);
|
|
470
|
+
}
|
|
471
|
+
return 0;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
int gsl_vector_complex_div(gsl_vector_complex *cv, const gsl_vector_complex *cv2)
|
|
475
|
+
{
|
|
476
|
+
size_t i;
|
|
477
|
+
gsl_complex a, b, c;
|
|
478
|
+
for (i = 0; i < cv->size; i++) {
|
|
479
|
+
a = gsl_vector_complex_get(cv, i);
|
|
480
|
+
b = gsl_vector_complex_get(cv2, i);
|
|
481
|
+
c = gsl_complex_div(a, b);
|
|
482
|
+
gsl_vector_complex_set(cv, i, c);
|
|
483
|
+
}
|
|
484
|
+
return 0;
|
|
485
|
+
}
|
|
486
|
+
#endif
|
|
487
|
+
|
|
488
|
+
VALUE rb_gsl_range2ary(VALUE obj)
|
|
489
|
+
{
|
|
490
|
+
// double beg, en;
|
|
491
|
+
// size_t n;
|
|
492
|
+
// int step;
|
|
493
|
+
VALUE ary;
|
|
494
|
+
if (CLASS_OF(obj) != rb_cRange)
|
|
495
|
+
rb_raise(rb_eTypeError, "wrong argument type %s (Range expected)",
|
|
496
|
+
rb_class2name(CLASS_OF(obj)));
|
|
497
|
+
ary = rb_funcall(obj, rb_gsl_id_to_a, 0);
|
|
498
|
+
return ary;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
void get_range_beg_en_n(VALUE range, double *beg, double *en, size_t *n, int *step);
|
|
502
|
+
VALUE rb_gsl_range2vector(VALUE obj)
|
|
503
|
+
{
|
|
504
|
+
double beg, en;
|
|
505
|
+
size_t n;
|
|
506
|
+
int i, step;
|
|
507
|
+
gsl_vector *v;
|
|
508
|
+
if (CLASS_OF(obj) != rb_cRange)
|
|
509
|
+
rb_raise(rb_eTypeError, "wrong argument type %s (Range expected)",
|
|
510
|
+
rb_class2name(CLASS_OF(obj)));
|
|
511
|
+
get_range_beg_en_n(obj, &beg, &en, &n, &step);
|
|
512
|
+
v = gsl_vector_alloc(n);
|
|
513
|
+
for (i = 0; i < n; i++) gsl_vector_set(v, i, (double) (beg+i));
|
|
514
|
+
return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, v);
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
void get_range_int_beg_en_n(VALUE range, int *beg, int *en, size_t *n, int *step);
|
|
518
|
+
VALUE rb_gsl_range2vector_int(VALUE obj)
|
|
519
|
+
{
|
|
520
|
+
int beg, en, i, step;
|
|
521
|
+
size_t n;
|
|
522
|
+
gsl_vector_int *v;
|
|
523
|
+
if (CLASS_OF(obj) != rb_cRange)
|
|
524
|
+
rb_raise(rb_eTypeError, "wrong argument type %s (Range expected)",
|
|
525
|
+
rb_class2name(CLASS_OF(obj)));
|
|
526
|
+
get_range_int_beg_en_n(obj, &beg, &en, &n, &step);
|
|
527
|
+
v = gsl_vector_int_alloc(n);
|
|
528
|
+
for (i = 0; i < n; i++) gsl_vector_int_set(v, i, beg+i);
|
|
529
|
+
return Data_Wrap_Struct(cgsl_vector_int, 0, gsl_vector_int_free, v);
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
gsl_vector_int_view* rb_gsl_vector_int_view_alloc(size_t n)
|
|
533
|
+
{
|
|
534
|
+
gsl_vector_int_view *v;
|
|
535
|
+
v = ALLOC(gsl_vector_int_view);
|
|
536
|
+
v->vector.size = n;
|
|
537
|
+
v->vector.stride = 1;
|
|
538
|
+
v->vector.owner = 0;
|
|
539
|
+
return v;
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
void rb_gsl_vector_int_view_free(gsl_vector_int_view *v)
|
|
543
|
+
{
|
|
544
|
+
free((gsl_vector_int_view *) v);
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
gsl_matrix_view* rb_gsl_matrix_view_alloc()
|
|
548
|
+
{
|
|
549
|
+
gsl_matrix_view *mv = NULL;
|
|
550
|
+
mv = ALLOC(gsl_matrix_view);
|
|
551
|
+
if (mv == NULL) rb_raise(rb_eRuntimeError, "malloc failed");
|
|
552
|
+
return mv;
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
void rb_gsl_matrix_view_free(gsl_matrix_view * mv)
|
|
556
|
+
{
|
|
557
|
+
free((gsl_matrix_view *) mv);
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
gsl_matrix_int_view* rb_gsl_matrix_int_view_alloc()
|
|
561
|
+
{
|
|
562
|
+
gsl_matrix_int_view *mv = NULL;
|
|
563
|
+
mv = ALLOC(gsl_matrix_int_view);
|
|
564
|
+
if (mv == NULL) rb_raise(rb_eRuntimeError, "malloc failed");
|
|
565
|
+
return mv;
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
void rb_gsl_matrix_int_view_free(gsl_matrix_int_view * mv)
|
|
569
|
+
{
|
|
570
|
+
free((gsl_matrix_int_view *) mv);
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
void Init_gsl_array(VALUE module)
|
|
574
|
+
{
|
|
575
|
+
cgsl_block = rb_define_class_under(module, "Block",
|
|
576
|
+
cGSL_Object);
|
|
577
|
+
cgsl_block_int = rb_define_class_under(cgsl_block, "Int",
|
|
578
|
+
cGSL_Object);
|
|
579
|
+
cgsl_block_uchar = rb_define_class_under(cgsl_block, "Byte",
|
|
580
|
+
cGSL_Object);
|
|
581
|
+
|
|
582
|
+
cgsl_block_complex = rb_define_class_under(cgsl_block, "Complex", cgsl_block);
|
|
583
|
+
cgsl_vector = rb_define_class_under(module, "Vector",
|
|
584
|
+
cGSL_Object);
|
|
585
|
+
cgsl_vector_col = rb_define_class_under(cgsl_vector, "Col",
|
|
586
|
+
cgsl_vector);
|
|
587
|
+
cgsl_vector_complex = rb_define_class_under(cgsl_vector, "Complex",
|
|
588
|
+
cGSL_Object);
|
|
589
|
+
cgsl_vector_complex_col = rb_define_class_under(cgsl_vector_complex, "Col",
|
|
590
|
+
cgsl_vector_complex);
|
|
591
|
+
cgsl_matrix = rb_define_class_under(module, "Matrix", cGSL_Object);
|
|
592
|
+
cgsl_matrix_complex = rb_define_class_under(cgsl_matrix, "Complex", cGSL_Object);
|
|
593
|
+
|
|
594
|
+
cgsl_vector_view = rb_define_class_under(cgsl_vector, "View", cgsl_vector);
|
|
595
|
+
cgsl_vector_col_view = rb_define_class_under(cgsl_vector_col, "View", cgsl_vector_col);
|
|
596
|
+
|
|
597
|
+
cgsl_vector_complex_view = rb_define_class_under(cgsl_vector_complex, "View",
|
|
598
|
+
cgsl_vector_complex);
|
|
599
|
+
cgsl_vector_complex_col_view = rb_define_class_under(cgsl_vector_complex_col, "View",
|
|
600
|
+
cgsl_vector_complex_col);
|
|
601
|
+
|
|
602
|
+
cgsl_vector_int = rb_define_class_under(cgsl_vector, "Int", cGSL_Object);
|
|
603
|
+
cgsl_vector_int_col = rb_define_class_under(cgsl_vector_int, "Col", cgsl_vector_int);
|
|
604
|
+
cgsl_vector_int_view = rb_define_class_under(cgsl_vector_int, "View", cgsl_vector_int);
|
|
605
|
+
cgsl_vector_int_col_view = rb_define_class_under(cgsl_vector_int_col, "View", cgsl_vector_int_col);
|
|
606
|
+
|
|
607
|
+
|
|
608
|
+
/*****/
|
|
609
|
+
|
|
610
|
+
cgsl_matrix_view = rb_define_class_under(cgsl_matrix, "View",
|
|
611
|
+
cgsl_matrix);
|
|
612
|
+
cgsl_matrix_complex_view = rb_define_class_under(cgsl_matrix_complex, "View",
|
|
613
|
+
cgsl_matrix_complex);
|
|
614
|
+
cgsl_permutation = rb_define_class_under(module, "Permutation", cGSL_Object);
|
|
615
|
+
cgsl_index = rb_define_class_under(module, "Index", cgsl_permutation);
|
|
616
|
+
|
|
617
|
+
cgsl_vector_view_ro = rb_define_class_under(cgsl_vector_view, "ReadOnly",
|
|
618
|
+
cgsl_vector_view);
|
|
619
|
+
cgsl_vector_col_view_ro = rb_define_class_under(cgsl_vector_col_view, "ReadOnly",
|
|
620
|
+
cgsl_vector_col_view);
|
|
621
|
+
cgsl_vector_int_view_ro = rb_define_class_under(cgsl_vector_int_view, "ReadOnly",
|
|
622
|
+
cgsl_vector_int_view);
|
|
623
|
+
cgsl_vector_int_col_view_ro = rb_define_class_under(cgsl_vector_int_col_view, "ReadOnly",
|
|
624
|
+
cgsl_vector_int_col_view);
|
|
625
|
+
cgsl_matrix_view_ro = rb_define_class_under(cgsl_matrix_view, "ReadOnly",
|
|
626
|
+
cgsl_matrix_view);
|
|
627
|
+
|
|
628
|
+
cgsl_vector_complex_view_ro = rb_define_class_under(cgsl_vector_complex_view,
|
|
629
|
+
"ReadOnly",
|
|
630
|
+
cgsl_vector_complex_view);
|
|
631
|
+
cgsl_matrix_complex_view_ro = rb_define_class_under(cgsl_matrix_complex_view,
|
|
632
|
+
"ReadOnly",
|
|
633
|
+
cgsl_matrix_complex_view);
|
|
634
|
+
|
|
635
|
+
/*****/
|
|
636
|
+
cgsl_matrix_int = rb_define_class_under(cgsl_matrix, "Int", cGSL_Object);
|
|
637
|
+
cgsl_matrix_int_view = rb_define_class_under(cgsl_matrix_int, "View", cgsl_matrix_int);
|
|
638
|
+
cgsl_matrix_int_view_ro = rb_define_class_under(cgsl_matrix_int_view, "ReadOnly",
|
|
639
|
+
cgsl_matrix_int_view);
|
|
640
|
+
/*****/
|
|
641
|
+
Init_gsl_block_init(module);
|
|
642
|
+
Init_gsl_block_int_init(module);
|
|
643
|
+
Init_gsl_block_uchar_init(module);
|
|
644
|
+
Init_gsl_vector(module);
|
|
645
|
+
Init_gsl_vector_int(module);
|
|
646
|
+
|
|
647
|
+
Init_gsl_vector_complex(module);
|
|
648
|
+
Init_gsl_matrix(module);
|
|
649
|
+
Init_gsl_matrix_int(module);
|
|
650
|
+
Init_gsl_matrix_complex(module);
|
|
651
|
+
Init_gsl_permutation(module);
|
|
652
|
+
#ifdef GSL_1_1_LATER
|
|
653
|
+
Init_gsl_combination(module);
|
|
654
|
+
#endif
|
|
655
|
+
Init_gsl_array_complex(module);
|
|
656
|
+
Init_gsl_matrix_nmf();
|
|
657
|
+
|
|
658
|
+
rb_define_method(cgsl_vector_view_ro, "set", rb_gsl_obj_read_only, -1);
|
|
659
|
+
rb_define_method(cgsl_matrix_view_ro, "set", rb_gsl_obj_read_only, -1);
|
|
660
|
+
rb_define_method(cgsl_vector_int_view_ro, "set", rb_gsl_obj_read_only, -1);
|
|
661
|
+
rb_define_method(cgsl_matrix_int_view_ro, "set", rb_gsl_obj_read_only, -1);
|
|
662
|
+
rb_define_method(cgsl_vector_complex_view_ro, "set", rb_gsl_obj_read_only, -1);
|
|
663
|
+
rb_define_method(cgsl_matrix_complex_view_ro, "set", rb_gsl_obj_read_only, -1);
|
|
664
|
+
|
|
665
|
+
}
|