gsl 1.14.7 → 1.15.3
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/ChangeLog +139 -134
- data/Rakefile +4 -3
- data/VERSION +1 -1
- data/ext/array.c +0 -24
- data/ext/array_complex.c +11 -10
- data/ext/blas1.c +9 -6
- data/ext/block_source.c +4 -3
- data/ext/dirac.c +0 -6
- data/ext/error.c +1 -2
- data/ext/extconf.rb +9 -4
- data/ext/fft.c +22 -12
- data/ext/function.c +2 -2
- data/ext/graph.c +2 -0
- data/ext/gsl_narray.c +1 -7
- data/ext/histogram.c +0 -8
- data/ext/ieee.c +3 -1
- data/ext/integration.c +5 -3
- data/ext/linalg.c +11 -16
- data/ext/linalg_complex.c +1 -3
- data/ext/matrix_complex.c +10 -5
- data/ext/matrix_int.c +10 -10
- data/ext/matrix_source.c +3 -2
- data/ext/multifit.c +21 -29
- data/ext/multimin.c +1 -3
- data/ext/odeiv.c +9 -6
- data/ext/poly_source.c +82 -52
- data/ext/sf_bessel.c +8 -4
- data/ext/sf_coulomb.c +8 -8
- data/ext/sf_coupling.c +9 -6
- data/ext/sf_dilog.c +3 -2
- data/ext/sf_elementary.c +6 -4
- data/ext/sf_elljac.c +3 -2
- data/ext/sf_exp.c +15 -10
- data/ext/sf_gamma.c +9 -6
- data/ext/sf_gegenbauer.c +3 -2
- data/ext/sf_hyperg.c +18 -12
- data/ext/sf_laguerre.c +3 -2
- data/ext/sf_legendre.c +3 -2
- data/ext/sf_log.c +3 -2
- data/ext/sf_power.c +3 -2
- data/ext/sf_trigonometric.c +9 -6
- data/ext/signal.c +1 -3
- data/ext/siman.c +1 -2
- data/ext/stats.c +1 -0
- data/ext/vector_complex.c +5 -2
- data/ext/vector_double.c +13 -8
- data/ext/vector_source.c +6 -5
- data/ext/wavelet.c +16 -8
- data/include/rb_gsl_common.h +5 -6
- data/include/rb_gsl_config.h +62 -0
- data/include/rb_gsl_with_narray.h +6 -1
- data/lib/gsl.rb +3 -0
- data/lib/rbgsl.rb +3 -0
- data/rdoc/fit.rdoc +5 -5
- data/rdoc/ndlinear.rdoc +5 -2
- data/tests/gsl_test2.rb +3 -0
- data/tests/matrix/matrix_complex_test.rb +36 -0
- data/tests/narray/blas_dnrm2.rb +20 -0
- data/tests/poly/poly.rb +48 -0
- data/tests/sf/test_mode.rb +19 -0
- data/tests/stats_mt.rb +16 -0
- metadata +15 -11
- data/ext/MANIFEST +0 -119
data/ext/vector_double.c
CHANGED
@@ -499,13 +499,16 @@ VALUE rb_gsl_vector_to_i(VALUE obj)
|
|
499
499
|
}
|
500
500
|
|
501
501
|
/* singleton */
|
502
|
+
#ifdef HAVE_GNU_GRAPH
|
502
503
|
static void draw_hist(VALUE obj, FILE *fp);
|
503
504
|
static void draw_vector(VALUE obj, FILE *fp);
|
504
505
|
static void draw_vector2(VALUE xx, VALUE yy, FILE *fp);
|
505
506
|
static void draw_vector_array(VALUE ary, FILE *fp);
|
506
507
|
#ifdef HAVE_NARRAY_H
|
507
508
|
static void draw_narray(VALUE obj, FILE *fp);
|
508
|
-
#endif
|
509
|
+
#endif // HAVE_NARRAY_H
|
510
|
+
#endif // HAVE_GNU_GRAPH
|
511
|
+
|
509
512
|
static VALUE rb_gsl_vector_graph2(int argc, VALUE *argv, VALUE obj)
|
510
513
|
{
|
511
514
|
#ifdef HAVE_GNU_GRAPH
|
@@ -621,6 +624,7 @@ static VALUE rb_gsl_vector_graph2(int argc, VALUE *argv, VALUE obj)
|
|
621
624
|
#endif
|
622
625
|
}
|
623
626
|
|
627
|
+
#ifdef HAVE_GNU_GRAPH
|
624
628
|
static void draw_vector(VALUE obj, FILE *fp)
|
625
629
|
{
|
626
630
|
gsl_vector *x = NULL;
|
@@ -635,7 +639,7 @@ static void draw_vector2(VALUE xx, VALUE yy, FILE *fp)
|
|
635
639
|
{
|
636
640
|
#ifdef HAVE_NARRAY_H
|
637
641
|
struct NARRAY *nax, *nay;
|
638
|
-
#endif
|
642
|
+
#endif // HAVE_NARRAY_H
|
639
643
|
double *ptr1 = NULL, *ptr2 = NULL;
|
640
644
|
gsl_vector *vx, *vy;
|
641
645
|
size_t j, n, stridex = 1, stridey = 1;
|
@@ -650,7 +654,7 @@ static void draw_vector2(VALUE xx, VALUE yy, FILE *fp)
|
|
650
654
|
ptr1 = (double *) nax->ptr;
|
651
655
|
n = nax->total;
|
652
656
|
stridex = 1;
|
653
|
-
#endif
|
657
|
+
#endif // HAVE_NARRAY_H
|
654
658
|
} else {
|
655
659
|
rb_raise(rb_eTypeError, "wrong argument type %s (Vector expected)",
|
656
660
|
rb_class2name(CLASS_OF(xx)));
|
@@ -665,7 +669,7 @@ static void draw_vector2(VALUE xx, VALUE yy, FILE *fp)
|
|
665
669
|
GetNArray(yy, nay);
|
666
670
|
ptr2 = (double *) nay->ptr;
|
667
671
|
stridey = 1;
|
668
|
-
#endif
|
672
|
+
#endif // HAVE_NARRAY_H
|
669
673
|
} else {
|
670
674
|
rb_raise(rb_eTypeError, "wrong argument type %s (Vector expected)",
|
671
675
|
rb_class2name(CLASS_OF(yy)));
|
@@ -687,7 +691,7 @@ static void draw_narray(VALUE obj, FILE *fp)
|
|
687
691
|
fprintf(fp, "%d %g\n", (int) j, ptr[j]);
|
688
692
|
fflush(fp);
|
689
693
|
}
|
690
|
-
#endif
|
694
|
+
#endif // HAVE_NARRAY_H
|
691
695
|
|
692
696
|
static void draw_hist(VALUE obj, FILE *fp)
|
693
697
|
{
|
@@ -757,6 +761,7 @@ static void draw_vector_array(VALUE ary, FILE *fp)
|
|
757
761
|
}
|
758
762
|
fflush(fp);
|
759
763
|
}
|
764
|
+
#endif // HAVE_GNU_GRAPH
|
760
765
|
|
761
766
|
/* singleton */
|
762
767
|
static VALUE rb_gsl_vector_plot2(int argc, VALUE *argv, VALUE obj)
|
@@ -869,7 +874,7 @@ static VALUE rb_gsl_vector_normalize(int argc, VALUE *argv, VALUE obj)
|
|
869
874
|
static VALUE rb_gsl_vector_normalize_bang(int argc, VALUE *argv, VALUE obj)
|
870
875
|
{
|
871
876
|
gsl_vector *v = NULL;
|
872
|
-
double mean;
|
877
|
+
// double mean;
|
873
878
|
double nrm;
|
874
879
|
double factor;
|
875
880
|
switch (argc) {
|
@@ -885,8 +890,8 @@ static VALUE rb_gsl_vector_normalize_bang(int argc, VALUE *argv, VALUE obj)
|
|
885
890
|
break;
|
886
891
|
}
|
887
892
|
Data_Get_Vector(obj, v);
|
888
|
-
mean = gsl_stats_mean(v->data, v->stride, v->size);
|
889
|
-
|
893
|
+
/* mean = gsl_stats_mean(v->data, v->stride, v->size);
|
894
|
+
gsl_vector_add_constant(v, -mean);
|
890
895
|
sd = gsl_stats_sd(v->data, v->stride, v->size);
|
891
896
|
gsl_vector_scale(v, sqrt(nrm)/sd);*/
|
892
897
|
factor = nrm/gsl_blas_dnrm2(v);
|
data/ext/vector_source.c
CHANGED
@@ -1299,18 +1299,19 @@ VALUE FUNCTION(rb_gsl_vector,to_s)(VALUE obj)
|
|
1299
1299
|
char buf[32], format[32], format2[32];
|
1300
1300
|
size_t i;
|
1301
1301
|
VALUE str;
|
1302
|
-
BASE x
|
1302
|
+
BASE x;
|
1303
1303
|
int dig = 8;
|
1304
1304
|
#ifdef BASE_INT
|
1305
|
+
BASE min;
|
1305
1306
|
BASE max;
|
1306
1307
|
dig = 1;
|
1307
1308
|
#endif
|
1308
1309
|
Data_Get_Struct(obj, GSL_TYPE(gsl_vector), v);
|
1309
1310
|
if (v->size == 0) return rb_str_new2("[ ]");
|
1310
|
-
min = FUNCTION(gsl_vector,min)(v);
|
1311
1311
|
str = rb_str_new2("[ ");
|
1312
1312
|
if (VEC_COL_P(obj)) {
|
1313
1313
|
#ifdef BASE_INT
|
1314
|
+
min = FUNCTION(gsl_vector,min)(v);
|
1314
1315
|
max = gsl_vector_int_max(v);
|
1315
1316
|
dig = (int) GSL_MAX(fabs(max),fabs(min));
|
1316
1317
|
if (dig > 0) dig = ceil(log10(dig+1e-10));
|
@@ -2559,7 +2560,7 @@ static VALUE FUNCTION(rb_gsl_vector,compare)(VALUE aa, VALUE bb,
|
|
2559
2560
|
GSL_TYPE(gsl_vector) *a, *b;
|
2560
2561
|
/* gsl_vector_int *c;*/
|
2561
2562
|
gsl_block_uchar *c;
|
2562
|
-
int status;
|
2563
|
+
//int status;
|
2563
2564
|
Data_Get_Struct(aa, GSL_TYPE(gsl_vector), a);
|
2564
2565
|
c = gsl_block_uchar_alloc(a->size);
|
2565
2566
|
if (VEC_P(bb)) {
|
@@ -2567,9 +2568,9 @@ static VALUE FUNCTION(rb_gsl_vector,compare)(VALUE aa, VALUE bb,
|
|
2567
2568
|
if (a->size != b->size)
|
2568
2569
|
rb_raise(rb_eRuntimeError, "Vector size mismatch, %d and %d", (int) a->size,
|
2569
2570
|
(int) b->size);
|
2570
|
-
status
|
2571
|
+
/*status =*/ (*cmp)(a, b, c);
|
2571
2572
|
} else {
|
2572
|
-
status
|
2573
|
+
/*status =*/ (*cmp2)(a, NUMCONV(bb), c);
|
2573
2574
|
}
|
2574
2575
|
return Data_Wrap_Struct(cgsl_block_uchar, 0, gsl_block_uchar_free, c);
|
2575
2576
|
}
|
data/ext/wavelet.c
CHANGED
@@ -193,7 +193,9 @@ static VALUE rb_gsl_wavelet_transform0(int argc, VALUE *argv, VALUE obj,
|
|
193
193
|
gsl_vector *v = NULL, *vnew;
|
194
194
|
gsl_wavelet_direction dir = forward;
|
195
195
|
gsl_wavelet_workspace *work = NULL;
|
196
|
-
int itmp, flag = 0
|
196
|
+
int itmp, flag = 0;
|
197
|
+
// local variable "status" declared and set, but never used
|
198
|
+
//int status;
|
197
199
|
double *ptr1, *ptr2;
|
198
200
|
size_t n, stride;
|
199
201
|
int naflag = 0;
|
@@ -332,7 +334,7 @@ static VALUE rb_gsl_wavelet_transform0(int argc, VALUE *argv, VALUE obj,
|
|
332
334
|
}
|
333
335
|
#endif
|
334
336
|
}
|
335
|
-
status
|
337
|
+
/*status =*/ gsl_wavelet_transform(w, ptr2, stride, n, dir, work);
|
336
338
|
if (flag) gsl_wavelet_workspace_free(work);
|
337
339
|
return ary;
|
338
340
|
}
|
@@ -356,7 +358,9 @@ static VALUE rb_gsl_wavelet_trans(int argc, VALUE *argv, VALUE obj,
|
|
356
358
|
gsl_wavelet *w = NULL;
|
357
359
|
gsl_vector *v = NULL, *vnew;
|
358
360
|
gsl_wavelet_workspace *work = NULL;
|
359
|
-
int itmp, flag = 0,
|
361
|
+
int itmp, flag = 0, naflag = 0;
|
362
|
+
// local variable "status" declared and set, but never used
|
363
|
+
//int status;
|
360
364
|
double *ptr1 = NULL, *ptr2 = NULL;
|
361
365
|
size_t n, stride;
|
362
366
|
VALUE ary, ret;
|
@@ -489,7 +493,7 @@ static VALUE rb_gsl_wavelet_trans(int argc, VALUE *argv, VALUE obj,
|
|
489
493
|
}
|
490
494
|
#endif
|
491
495
|
}
|
492
|
-
status
|
496
|
+
/*status =*/ (*trans)(w, ptr2, stride, n, work);
|
493
497
|
if (flag) gsl_wavelet_workspace_free(work);
|
494
498
|
return ary;
|
495
499
|
}
|
@@ -530,7 +534,9 @@ static VALUE rb_gsl_wavelet2d(int argc, VALUE *argv, VALUE obj,
|
|
530
534
|
gsl_wavelet_direction dir = forward;
|
531
535
|
gsl_wavelet_workspace *work = NULL;
|
532
536
|
VALUE ary, ret;
|
533
|
-
int itmp, flag = 0
|
537
|
+
int itmp, flag = 0;
|
538
|
+
// local variable "status" declared and set, but never used
|
539
|
+
//int status;
|
534
540
|
switch (TYPE(obj)) {
|
535
541
|
case T_MODULE:
|
536
542
|
case T_CLASS:
|
@@ -592,7 +598,7 @@ static VALUE rb_gsl_wavelet2d(int argc, VALUE *argv, VALUE obj,
|
|
592
598
|
mnew = m;
|
593
599
|
ary = ret;
|
594
600
|
}
|
595
|
-
status
|
601
|
+
/*status =*/ (*trans)(w, mnew, dir, work);
|
596
602
|
if (flag) gsl_wavelet_workspace_free(work);
|
597
603
|
return ary;
|
598
604
|
}
|
@@ -619,7 +625,9 @@ static VALUE rb_gsl_wavelet2d_trans(int argc, VALUE *argv, VALUE obj,
|
|
619
625
|
gsl_matrix *m = NULL, *mnew;
|
620
626
|
gsl_wavelet_workspace *work = NULL;
|
621
627
|
VALUE ary, ret;
|
622
|
-
int itmp, flag = 0
|
628
|
+
int itmp, flag = 0;
|
629
|
+
// local variable "status" declared and set, but never used
|
630
|
+
//int status;
|
623
631
|
switch (TYPE(obj)) {
|
624
632
|
case T_MODULE:
|
625
633
|
case T_CLASS:
|
@@ -668,7 +676,7 @@ static VALUE rb_gsl_wavelet2d_trans(int argc, VALUE *argv, VALUE obj,
|
|
668
676
|
mnew = m;
|
669
677
|
ary = ret;
|
670
678
|
}
|
671
|
-
status
|
679
|
+
/*status =*/ (*trans)(w, mnew, work);
|
672
680
|
if (flag) gsl_wavelet_workspace_free(work);
|
673
681
|
return ary;
|
674
682
|
}
|
data/include/rb_gsl_common.h
CHANGED
@@ -25,6 +25,7 @@
|
|
25
25
|
#include <gsl/gsl_ieee_utils.h>
|
26
26
|
#ifdef HAVE_NARRAY_H
|
27
27
|
#include "narray.h"
|
28
|
+
#include "rb_gsl_with_narray.h"
|
28
29
|
#endif
|
29
30
|
|
30
31
|
EXTERN ID rb_gsl_id_beg, rb_gsl_id_end, rb_gsl_id_excl, rb_gsl_id_to_a;
|
@@ -135,13 +136,11 @@ EXTERN ID rb_gsl_id_beg, rb_gsl_id_end, rb_gsl_id_excl, rb_gsl_id_to_a;
|
|
135
136
|
#ifdef HAVE_NARRAY_H
|
136
137
|
#define Data_Get_Vector(obj,sval) do {\
|
137
138
|
if (NA_IsNArray(obj)) {\
|
138
|
-
|
139
|
-
|
140
|
-
(sval)->stride = 1;\
|
141
|
-
} else {\
|
142
|
-
CHECK_VECTOR(obj);\
|
143
|
-
Data_Get_Struct(obj,gsl_vector,sval);\
|
139
|
+
/* Convert obj to GSL::Vector::View */\
|
140
|
+
obj = rb_gsl_na_to_gsl_vector_view_method(obj);\
|
144
141
|
}\
|
142
|
+
CHECK_VECTOR(obj);\
|
143
|
+
Data_Get_Struct(obj,gsl_vector,sval);\
|
145
144
|
} while (0)
|
146
145
|
#else
|
147
146
|
#define Data_Get_Vector(obj,sval) do {\
|
@@ -0,0 +1,62 @@
|
|
1
|
+
#ifndef ___RB_GSL_CONFIG_H___
|
2
|
+
#define ___RB_GSL_CONFIG_H___
|
3
|
+
|
4
|
+
#ifndef GSL_VERSION
|
5
|
+
#define GSL_VERSION "1.15"
|
6
|
+
#endif
|
7
|
+
#ifndef GSL_0_9_4_LATER
|
8
|
+
#define GSL_0_9_4_LATER
|
9
|
+
#endif
|
10
|
+
#ifndef GSL_1_0_LATER
|
11
|
+
#define GSL_1_0_LATER
|
12
|
+
#endif
|
13
|
+
#ifndef GSL_1_1_LATER
|
14
|
+
#define GSL_1_1_LATER
|
15
|
+
#endif
|
16
|
+
#ifndef GSL_1_1_1_LATER
|
17
|
+
#define GSL_1_1_1_LATER
|
18
|
+
#endif
|
19
|
+
#ifndef GSL_1_2_LATER
|
20
|
+
#define GSL_1_2_LATER
|
21
|
+
#endif
|
22
|
+
#ifndef GSL_1_3_LATER
|
23
|
+
#define GSL_1_3_LATER
|
24
|
+
#endif
|
25
|
+
#ifndef GSL_1_4_LATER
|
26
|
+
#define GSL_1_4_LATER
|
27
|
+
#endif
|
28
|
+
#ifndef GSL_1_4_9_LATER
|
29
|
+
#define GSL_1_4_9_LATER
|
30
|
+
#endif
|
31
|
+
#ifndef GSL_1_6_LATER
|
32
|
+
#define GSL_1_6_LATER
|
33
|
+
#endif
|
34
|
+
#ifndef GSL_1_8_LATER
|
35
|
+
#define GSL_1_8_LATER
|
36
|
+
#endif
|
37
|
+
#ifndef GSL_1_9_LATER
|
38
|
+
#define GSL_1_9_LATER
|
39
|
+
#endif
|
40
|
+
#ifndef GSL_1_10_LATER
|
41
|
+
#define GSL_1_10_LATER
|
42
|
+
#endif
|
43
|
+
#ifndef GSL_1_11_LATER
|
44
|
+
#define GSL_1_11_LATER
|
45
|
+
#endif
|
46
|
+
#ifndef GSL_1_13_LATER
|
47
|
+
#define GSL_1_13_LATER
|
48
|
+
#endif
|
49
|
+
#ifndef GSL_1_14_LATER
|
50
|
+
#define GSL_1_14_LATER
|
51
|
+
#endif
|
52
|
+
#ifndef GSL_1_15_LATER
|
53
|
+
#define GSL_1_15_LATER
|
54
|
+
#endif
|
55
|
+
#ifndef RUBY_GSL_VERSION
|
56
|
+
#define RUBY_GSL_VERSION "1.15.0"
|
57
|
+
#endif
|
58
|
+
#ifndef RUBY_1_8_LATER
|
59
|
+
#define RUBY_1_8_LATER
|
60
|
+
#endif
|
61
|
+
|
62
|
+
#endif
|
@@ -1,3 +1,6 @@
|
|
1
|
+
#ifndef RB_GSL_WITH_NARRAY_H
|
2
|
+
#define RB_GSL_WITH_NARRAY_H
|
3
|
+
|
1
4
|
#ifdef HAVE_NARRAY_H
|
2
5
|
|
3
6
|
#include "narray.h"
|
@@ -7,6 +10,7 @@ gsl_vector* make_cvector_from_narray(VALUE);
|
|
7
10
|
void cvector_set_from_narray(gsl_vector*, VALUE);
|
8
11
|
void carray_set_from_narray(double*, VALUE);
|
9
12
|
|
13
|
+
VALUE rb_gsl_na_to_gsl_vector_view_method(VALUE na);
|
10
14
|
VALUE rb_gsl_na_to_gsl_matrix(VALUE obj, VALUE nna);
|
11
15
|
gsl_vector_view* na_to_gv_view(VALUE na);
|
12
16
|
gsl_matrix_view* na_to_gm_view(VALUE nna);
|
@@ -21,4 +25,5 @@ extern VALUE cNVector, cNMatrix;
|
|
21
25
|
|
22
26
|
gsl_vector_complex* na_to_gv_complex(VALUE na);
|
23
27
|
gsl_vector_complex_view* na_to_gv_complex_view(VALUE na);
|
24
|
-
#endif
|
28
|
+
#endif // HAVE_NARRAY_H
|
29
|
+
#endif // RB_GSL_WITH_NARRAY_H
|
data/lib/gsl.rb
ADDED
data/lib/rbgsl.rb
ADDED
data/rdoc/fit.rdoc
CHANGED
@@ -28,11 +28,11 @@
|
|
28
28
|
# == {}[link:index.html"name="1] Overview
|
29
29
|
# Least-squares fits are found by minimizing \chi^2 (chi-squared), the weighted
|
30
30
|
# sum of squared residuals over n experimental datapoints (x_i, y_i) for the
|
31
|
-
# model Y(c,x), The p parameters of the model are c = {c_0, c_1,
|
32
|
-
# factors w_i are given by w_i = 1/\sigma_i^2, where \sigma_i is the
|
33
|
-
# experimental error on the data-point y_i. The errors are assumed to be
|
34
|
-
# gaussian and uncorrelated. For unweighted data the chi-squared sum is
|
35
|
-
# without any weight factors.
|
31
|
+
# model Y(c,x), The p parameters of the model are c = {c_0, c_1, ...}. The
|
32
|
+
# weight factors w_i are given by w_i = 1/\sigma_i^2, where \sigma_i is the
|
33
|
+
# experimental error on the data-point y_i. The errors are assumed to be
|
34
|
+
# gaussian and uncorrelated. For unweighted data the chi-squared sum is
|
35
|
+
# computed without any weight factors.
|
36
36
|
#
|
37
37
|
# The fitting routines return the best-fit parameters c and their p \times p
|
38
38
|
# covariance matrix. The covariance matrix measures the statistical errors on
|
data/rdoc/ndlinear.rdoc
CHANGED
@@ -19,7 +19,7 @@
|
|
19
19
|
# design matrix X_{ij = F_j(x_i) in the special case that the basis functions
|
20
20
|
# separate: Here the superscript value j indicates the basis function
|
21
21
|
# corresponding to the independent variable x_j. The subscripts (i_1, i_2, i_3,
|
22
|
-
#
|
22
|
+
# ...) refer to which basis function to use from the complete set. These
|
23
23
|
# subscripts are related to the index i in a complex way, which is the main
|
24
24
|
# problem this extension addresses. The model then becomes where n is the
|
25
25
|
# dimension of the fit and N_i is the number of basis functions for the variable
|
@@ -111,7 +111,10 @@
|
|
111
111
|
# * GSL::MultiFit::Ndlinear.calc(x, c, w)
|
112
112
|
# * GSL::MultiFit::Ndlinear::Workspace#calc(x, c)
|
113
113
|
#
|
114
|
-
# This method is similar to <tt>GSL::MultiFit::Ndlinear.est</tt>, but does
|
114
|
+
# This method is similar to <tt>GSL::MultiFit::Ndlinear.est</tt>, but does
|
115
|
+
# not compute the model error. It computes the model value at the data point
|
116
|
+
# <tt>x</tt> using the coefficient vector <tt>c</tt> and returns the model
|
117
|
+
# value.
|
115
118
|
#
|
116
119
|
# == {}[link:index.html"name="3] Examples
|
117
120
|
# This example program generates data from the 3D isotropic harmonic oscillator
|
data/tests/gsl_test2.rb
CHANGED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'minitest/unit'
|
3
|
+
|
4
|
+
require 'gsl'
|
5
|
+
|
6
|
+
class MatrixComplex < MiniTest::Unit::TestCase
|
7
|
+
|
8
|
+
def test_eye
|
9
|
+
z = GSL::Complex[1,0]
|
10
|
+
m = GSL::Matrix::Complex.eye(2, z)
|
11
|
+
assert_equal(z, m[0,0])
|
12
|
+
assert_equal(GSL::Complex[0,0], m[0,1])
|
13
|
+
assert_equal(GSL::Complex[0,0], m[1,0])
|
14
|
+
assert_equal(z, m[1,1])
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_set_row
|
18
|
+
z0 = GSL::Complex[1,0]
|
19
|
+
z1 = GSL::Complex[2,0]
|
20
|
+
m = GSL::Matrix::Complex[2,2]
|
21
|
+
m.set_row(0,z0,z1)
|
22
|
+
assert_equal(z0, m[0,0])
|
23
|
+
assert_equal(z1, m[0,1])
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_set_col
|
27
|
+
z0 = GSL::Complex[1,0]
|
28
|
+
z1 = GSL::Complex[2,0]
|
29
|
+
m = GSL::Matrix::Complex[2,2]
|
30
|
+
m.set_col(0,z0,z1)
|
31
|
+
assert_equal(z0, m[0,0])
|
32
|
+
assert_equal(z1, m[1,0])
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'narray'
|
5
|
+
require 'gsl'
|
6
|
+
require '../gsl_test.rb'
|
7
|
+
include GSL::Test
|
8
|
+
|
9
|
+
dbleps = 1e-6
|
10
|
+
expected = Math.sqrt((0..4).inject {|m,x| m+=x*x})
|
11
|
+
|
12
|
+
v = GSL::Vector.indgen(5)
|
13
|
+
v_dnrm2 = GSL::Blas.dnrm2(v)
|
14
|
+
GSL::Test.test_rel(v_dnrm2, expected, dbleps, "GSL::Blas.dnrm2(GSL::Vector)")
|
15
|
+
|
16
|
+
na = NArray.float(5).indgen!
|
17
|
+
na_dnrm2 = GSL::Blas.dnrm2(na)
|
18
|
+
GSL::Test.test_rel(na_dnrm2, expected, dbleps, "GSL::Blas.dnrm2(NArray)")
|
19
|
+
|
20
|
+
GSL::Test.test_rel(na_dnrm2, v_dnrm2, 0, "GSL::Blas.dnrm2(NArray) == GSL::Blas.dnrm2(GSL::Vector)")
|
data/tests/poly/poly.rb
CHANGED
@@ -33,14 +33,26 @@ x0, x1 = GSL::Poly.solve_quadratic(5.0, 0.0, -20.0).to_a
|
|
33
33
|
test_rel(x0, -2.0, 1e-9, "x0, 5 x^2 = 20")
|
34
34
|
test_rel(x1, 2.0, 1e-9, "x1, 5 x^2 = 20")
|
35
35
|
|
36
|
+
# Quadratic single real root (technically not a quadratic)
|
37
|
+
x0, x1 = GSL::Poly.solve_quadratic(0.0, 1.0, 0.0).to_a
|
38
|
+
test_rel(x0, 0.0, 0, "x0, x = 0")
|
39
|
+
test2(x1.nil?, "x1, x = 0 is nil")
|
40
|
+
|
41
|
+
# Quadratic no real root
|
42
|
+
x0, x1 = GSL::Poly.solve_quadratic(1.0, 0.0, 1.0).to_a
|
43
|
+
test2(x0.nil?, "x0, x^2 = -1 is nil")
|
44
|
+
test2(x1.nil?, "x1, x^2 = -1 is nil")
|
45
|
+
|
36
46
|
x0, x1, x2 = GSL::Poly.solve_cubic(0.0, 0.0, -27.0).to_a
|
37
47
|
test_rel(x0, 3.0, 1e-9, "x0, x^3 = 27")
|
38
48
|
|
49
|
+
# Cubic triple real root
|
39
50
|
x0, x1, x2 = GSL::Poly.solve_cubic(-51.0, 867.0, -4913.0).to_a
|
40
51
|
test_rel(x0, 17.0, 1e-9, "x0, (x-17)^3=0")
|
41
52
|
test_rel(x1, 17.0, 1e-9, "x1, (x-17)^3=0")
|
42
53
|
test_rel(x2, 17.0, 1e-9, "x2, (x-17)^3=0")
|
43
54
|
|
55
|
+
# Cubic double real root plus single real root
|
44
56
|
x0, x1, x2 = GSL::Poly.solve_cubic(-57.0, 1071.0, -6647.0).to_a
|
45
57
|
test_rel(x0, 17.0, 1e-9, "x0, (x-17)(x-17)(x-23)=0")
|
46
58
|
test_rel(x1, 17.0, 1e-9, "x1, (x-17)(x-17)(x-23)=0")
|
@@ -61,6 +73,16 @@ test_rel(x0, -17.0, 1e-9, "x0, (x+17)(x-31)(x-95)=0")
|
|
61
73
|
test_rel(x1, 31.0, 1e-9, "x1, (x+17)(x-31)(x-95)=0")
|
62
74
|
test_rel(x2, 95.0, 1e-9, "x2, (x+17)(x-31)(x-95)=0")
|
63
75
|
|
76
|
+
# Cubic double real root only is impossible
|
77
|
+
|
78
|
+
# Cubic single real root (and two complex roots, not returned)
|
79
|
+
x0, x1, x2 = GSL::Poly.solve_cubic(0.0, 0.0, -1.0).to_a
|
80
|
+
test_rel(x0, 1.0, 1e-9, "x0, x^3 = 1")
|
81
|
+
test2(x1.nil?, "x1, x^3 = 1 is nil")
|
82
|
+
test2(x2.nil?, "x2, x^3 = 1 is nil")
|
83
|
+
|
84
|
+
# Cubic no real root is impossible
|
85
|
+
|
64
86
|
#z0, z1 = GSL::Poly.complex_solve_quadratic(4.0, -20.0, 26.0).to_a
|
65
87
|
r = GSL::Poly::Complex.solve_quadratic(4.0, -20.0, 26.0)
|
66
88
|
z0 = r[0]
|
@@ -104,6 +126,18 @@ test_rel(z[0].im, -2.0, 1e-9, "z[0].imag, 5 x^2 = -20")
|
|
104
126
|
test_rel(z[1].re, 0.0, 1e-9, "z[1].real, 5 x^2 = -20")
|
105
127
|
test_rel(z[1].im, 2.0, 1e-9, "z[1].imag, 5 x^2 = -20")
|
106
128
|
|
129
|
+
# Quadratic single complex root (technically not quadratic and root not
|
130
|
+
# complex since imaginary component is 0, but the data type is complex)
|
131
|
+
z = GSL::Poly.complex_solve_quadratic(0.0, 1.0, -1.0)
|
132
|
+
test_rel(z[0].re, 1.0, 1e-9, "z[0].real, x = 1 (complex)")
|
133
|
+
test_rel(z[0].im, 0.0, 0.0, "z[0].imag, x = 1 (complex)")
|
134
|
+
test2(x1.nil?, "z[1], x = 0 is nil")
|
135
|
+
|
136
|
+
# Quadratic no complex root (technically not quadratic)
|
137
|
+
z = GSL::Poly.complex_solve_quadratic(0.0, 0.0, 1.0)
|
138
|
+
test2(z[0].nil?, "z[0], 1 = 0 is nil")
|
139
|
+
test2(z[1].nil?, "z[1], 1 = 0 is nil")
|
140
|
+
|
107
141
|
z = GSL::Poly.complex_solve_cubic(0.0, 0.0, -27.0)
|
108
142
|
test_rel(z[0].re, -1.5, 1e-9, "z[0].real, x^3 = 27");
|
109
143
|
test_rel(z[0].im, -1.5 * sqrt(3.0), 1e-9,
|
@@ -240,3 +274,17 @@ test_rel(dc[2], 2.0*c[2] + 3.0*2.0*c[3]*x + 4.0*3.0*c[4]*x*x + 5.0*4.0*c[5]*x*x*
|
|
240
274
|
test_rel(dc[3], 3.0*2.0*c[3] + 4.0*3.0*2.0*c[4]*x + 5.0*4.0*3.0*c[5]*x*x , eps,"eval_derivs({+1, -2, +3, -4, +5, -6} deriv 3, -174.0)");
|
241
275
|
test_rel(dc[4], 4.0*3.0*2.0*c[4] + 5.0*4.0*3.0*2.0*c[5]*x, eps, "eval_derivs({+1, -2, +3, -4, +5, -6} deriv 4, +480.0)");
|
242
276
|
test_rel(dc[5], 5.0*4.0*3.0*2.0*c[5] , eps, "eval_derivs({+1, -2, +3, -4, +5, -6} deriv 5, -720.0)");
|
277
|
+
|
278
|
+
# Test Poly::fit and Poly::wfit
|
279
|
+
x = GSL::Vector[0, 2, 2]
|
280
|
+
y = GSL::Vector[0, 1, -1]
|
281
|
+
coef, cov, chisq, status = Poly.fit(x, y, 1)
|
282
|
+
test_rel(coef[0], 0.0, 1e-9, "y intercept == 0")
|
283
|
+
test_rel(coef[1], 0.0, 1e-9, "slope == 0")
|
284
|
+
test_rel(chisq, 2.0, 1e-9, "chisq == 2")
|
285
|
+
|
286
|
+
w = GSL::Vector[1, 1, 0]
|
287
|
+
coef, cov, chisq, status = Poly.wfit(x, w, y, 1)
|
288
|
+
test_rel(coef[0], 0.0, 1e-9, "y intercept == 0")
|
289
|
+
test_rel(coef[1], 0.5, 1e-9, "slope == 0.5")
|
290
|
+
test_rel(chisq, 0.0, 1e-9, "chisq == 0")
|