nmatrix-atlas 0.2.0

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.
Files changed (82) hide show
  1. checksums.yaml +7 -0
  2. data/ext/nmatrix/data/complex.h +364 -0
  3. data/ext/nmatrix/data/data.h +638 -0
  4. data/ext/nmatrix/data/meta.h +64 -0
  5. data/ext/nmatrix/data/ruby_object.h +389 -0
  6. data/ext/nmatrix/math/asum.h +120 -0
  7. data/ext/nmatrix/math/cblas_enums.h +36 -0
  8. data/ext/nmatrix/math/cblas_templates_core.h +507 -0
  9. data/ext/nmatrix/math/gemm.h +241 -0
  10. data/ext/nmatrix/math/gemv.h +178 -0
  11. data/ext/nmatrix/math/getrf.h +255 -0
  12. data/ext/nmatrix/math/getrs.h +121 -0
  13. data/ext/nmatrix/math/imax.h +79 -0
  14. data/ext/nmatrix/math/laswp.h +165 -0
  15. data/ext/nmatrix/math/long_dtype.h +49 -0
  16. data/ext/nmatrix/math/math.h +744 -0
  17. data/ext/nmatrix/math/nrm2.h +160 -0
  18. data/ext/nmatrix/math/rot.h +117 -0
  19. data/ext/nmatrix/math/rotg.h +106 -0
  20. data/ext/nmatrix/math/scal.h +71 -0
  21. data/ext/nmatrix/math/trsm.h +332 -0
  22. data/ext/nmatrix/math/util.h +148 -0
  23. data/ext/nmatrix/nm_memory.h +60 -0
  24. data/ext/nmatrix/nmatrix.h +408 -0
  25. data/ext/nmatrix/ruby_constants.h +106 -0
  26. data/ext/nmatrix/storage/common.h +176 -0
  27. data/ext/nmatrix/storage/dense/dense.h +128 -0
  28. data/ext/nmatrix/storage/list/list.h +137 -0
  29. data/ext/nmatrix/storage/storage.h +98 -0
  30. data/ext/nmatrix/storage/yale/class.h +1139 -0
  31. data/ext/nmatrix/storage/yale/iterators/base.h +142 -0
  32. data/ext/nmatrix/storage/yale/iterators/iterator.h +130 -0
  33. data/ext/nmatrix/storage/yale/iterators/row.h +449 -0
  34. data/ext/nmatrix/storage/yale/iterators/row_stored.h +139 -0
  35. data/ext/nmatrix/storage/yale/iterators/row_stored_nd.h +168 -0
  36. data/ext/nmatrix/storage/yale/iterators/stored_diagonal.h +123 -0
  37. data/ext/nmatrix/storage/yale/math/transpose.h +110 -0
  38. data/ext/nmatrix/storage/yale/yale.h +202 -0
  39. data/ext/nmatrix/types.h +54 -0
  40. data/ext/nmatrix/util/io.h +115 -0
  41. data/ext/nmatrix/util/sl_list.h +143 -0
  42. data/ext/nmatrix/util/util.h +78 -0
  43. data/ext/nmatrix_atlas/extconf.rb +250 -0
  44. data/ext/nmatrix_atlas/math_atlas.cpp +1206 -0
  45. data/ext/nmatrix_atlas/math_atlas/cblas_templates_atlas.h +72 -0
  46. data/ext/nmatrix_atlas/math_atlas/clapack_templates.h +332 -0
  47. data/ext/nmatrix_atlas/math_atlas/geev.h +82 -0
  48. data/ext/nmatrix_atlas/math_atlas/gesdd.h +83 -0
  49. data/ext/nmatrix_atlas/math_atlas/gesvd.h +81 -0
  50. data/ext/nmatrix_atlas/math_atlas/inc.h +47 -0
  51. data/ext/nmatrix_atlas/nmatrix_atlas.cpp +44 -0
  52. data/lib/nmatrix/atlas.rb +213 -0
  53. data/lib/nmatrix/lapack_ext_common.rb +69 -0
  54. data/spec/00_nmatrix_spec.rb +730 -0
  55. data/spec/01_enum_spec.rb +190 -0
  56. data/spec/02_slice_spec.rb +389 -0
  57. data/spec/03_nmatrix_monkeys_spec.rb +78 -0
  58. data/spec/2x2_dense_double.mat +0 -0
  59. data/spec/4x4_sparse.mat +0 -0
  60. data/spec/4x5_dense.mat +0 -0
  61. data/spec/blas_spec.rb +193 -0
  62. data/spec/elementwise_spec.rb +303 -0
  63. data/spec/homogeneous_spec.rb +99 -0
  64. data/spec/io/fortran_format_spec.rb +88 -0
  65. data/spec/io/harwell_boeing_spec.rb +98 -0
  66. data/spec/io/test.rua +9 -0
  67. data/spec/io_spec.rb +149 -0
  68. data/spec/lapack_core_spec.rb +482 -0
  69. data/spec/leakcheck.rb +16 -0
  70. data/spec/math_spec.rb +730 -0
  71. data/spec/nmatrix_yale_resize_test_associations.yaml +2802 -0
  72. data/spec/nmatrix_yale_spec.rb +286 -0
  73. data/spec/plugins/atlas/atlas_spec.rb +242 -0
  74. data/spec/rspec_monkeys.rb +56 -0
  75. data/spec/rspec_spec.rb +34 -0
  76. data/spec/shortcuts_spec.rb +310 -0
  77. data/spec/slice_set_spec.rb +157 -0
  78. data/spec/spec_helper.rb +140 -0
  79. data/spec/stat_spec.rb +203 -0
  80. data/spec/test.pcd +20 -0
  81. data/spec/utm5940.mtx +83844 -0
  82. metadata +159 -0
@@ -0,0 +1,160 @@
1
+ /////////////////////////////////////////////////////////////////////
2
+ // = NMatrix
3
+ //
4
+ // A linear algebra library for scientific computation in Ruby.
5
+ // NMatrix is part of SciRuby.
6
+ //
7
+ // NMatrix was originally inspired by and derived from NArray, by
8
+ // Masahiro Tanaka: http://narray.rubyforge.org
9
+ //
10
+ // == Copyright Information
11
+ //
12
+ // SciRuby is Copyright (c) 2010 - 2014, Ruby Science Foundation
13
+ // NMatrix is Copyright (c) 2012 - 2014, John Woods and the Ruby Science Foundation
14
+ //
15
+ // Please see LICENSE.txt for additional copyright notices.
16
+ //
17
+ // == Contributing
18
+ //
19
+ // By contributing source code to SciRuby, you agree to be bound by
20
+ // our Contributor Agreement:
21
+ //
22
+ // * https://github.com/SciRuby/sciruby/wiki/Contributor-Agreement
23
+ //
24
+ // == nrm2.h
25
+ //
26
+ // CBLAS nrm2 function
27
+ //
28
+
29
+ /*
30
+ * Automatically Tuned Linear Algebra Software v3.8.4
31
+ * (C) Copyright 1999 R. Clint Whaley
32
+ *
33
+ * Redistribution and use in source and binary forms, with or without
34
+ * modification, are permitted provided that the following conditions
35
+ * are met:
36
+ * 1. Redistributions of source code must retain the above copyright
37
+ * notice, this list of conditions and the following disclaimer.
38
+ * 2. Redistributions in binary form must reproduce the above copyright
39
+ * notice, this list of conditions, and the following disclaimer in the
40
+ * documentation and/or other materials provided with the distribution.
41
+ * 3. The name of the ATLAS group or the names of its contributers may
42
+ * not be used to endorse or promote products derived from this
43
+ * software without specific written permission.
44
+ *
45
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
46
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
47
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
48
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ATLAS GROUP OR ITS CONTRIBUTORS
49
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
50
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
51
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
52
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
53
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
54
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
55
+ * POSSIBILITY OF SUCH DAMAGE.
56
+ *
57
+ */
58
+
59
+ #ifndef NRM2_H
60
+ # define NRM2_H
61
+
62
+ #include "math/long_dtype.h"
63
+
64
+
65
+ namespace nm { namespace math {
66
+
67
+ /*
68
+ * Level 1 BLAS routine which returns the 2-norm of an n-vector x.
69
+ #
70
+ * Based on input types, these are the valid return types:
71
+ * int -> int
72
+ * float -> float or double
73
+ * double -> double
74
+ * complex64 -> float or double
75
+ * complex128 -> double
76
+ */
77
+ template <typename ReturnDType, typename DType>
78
+ ReturnDType nrm2(const int N, const DType* X, const int incX) {
79
+ const DType ONE = 1, ZERO = 0;
80
+ typename LongDType<DType>::type scale = 0, ssq = 1, absxi, temp;
81
+
82
+
83
+ if ((N < 1) || (incX < 1)) return ZERO;
84
+ else if (N == 1) return std::abs(X[0]);
85
+
86
+ for (int i = 0; i < N; ++i) {
87
+ absxi = std::abs(X[i*incX]);
88
+ if (scale < absxi) {
89
+ temp = scale / absxi;
90
+ scale = absxi;
91
+ ssq = ONE + ssq * (temp * temp);
92
+ } else {
93
+ temp = absxi / scale;
94
+ ssq += temp * temp;
95
+ }
96
+ }
97
+
98
+ return scale * std::sqrt( ssq );
99
+ }
100
+
101
+
102
+ template <typename FloatDType>
103
+ static inline void nrm2_complex_helper(const FloatDType& xr, const FloatDType& xi, double& scale, double& ssq) {
104
+ double absx = std::abs(xr);
105
+ if (scale < absx) {
106
+ double temp = scale / absx;
107
+ scale = absx;
108
+ ssq = 1.0 + ssq * (temp * temp);
109
+ } else {
110
+ double temp = absx / scale;
111
+ ssq += temp * temp;
112
+ }
113
+
114
+ absx = std::abs(xi);
115
+ if (scale < absx) {
116
+ double temp = scale / absx;
117
+ scale = absx;
118
+ ssq = 1.0 + ssq * (temp * temp);
119
+ } else {
120
+ double temp = absx / scale;
121
+ ssq += temp * temp;
122
+ }
123
+ }
124
+
125
+ template <>
126
+ float nrm2(const int N, const Complex64* X, const int incX) {
127
+ double scale = 0, ssq = 1, temp;
128
+
129
+ if ((N < 1) || (incX < 1)) return 0.0;
130
+
131
+ for (int i = 0; i < N; ++i) {
132
+ nrm2_complex_helper<float>(X[i*incX].r, X[i*incX].i, scale, temp);
133
+ }
134
+
135
+ return scale * std::sqrt( ssq );
136
+ }
137
+
138
+ template <>
139
+ double nrm2(const int N, const Complex128* X, const int incX) {
140
+ double scale = 0, ssq = 1, temp;
141
+
142
+ if ((N < 1) || (incX < 1)) return 0.0;
143
+
144
+ for (int i = 0; i < N; ++i) {
145
+ nrm2_complex_helper<double>(X[i*incX].r, X[i*incX].i, scale, temp);
146
+ }
147
+
148
+ return scale * std::sqrt( ssq );
149
+ }
150
+
151
+ template <typename ReturnDType, typename DType>
152
+ inline void cblas_nrm2(const int N, const void* X, const int incX, void* result) {
153
+ *reinterpret_cast<ReturnDType*>( result ) = nrm2<ReturnDType, DType>( N, reinterpret_cast<const DType*>(X), incX );
154
+ }
155
+
156
+
157
+
158
+ }} // end of namespace nm::math
159
+
160
+ #endif // NRM2_H
@@ -0,0 +1,117 @@
1
+ /////////////////////////////////////////////////////////////////////
2
+ // = NMatrix
3
+ //
4
+ // A linear algebra library for scientific computation in Ruby.
5
+ // NMatrix is part of SciRuby.
6
+ //
7
+ // NMatrix was originally inspired by and derived from NArray, by
8
+ // Masahiro Tanaka: http://narray.rubyforge.org
9
+ //
10
+ // == Copyright Information
11
+ //
12
+ // SciRuby is Copyright (c) 2010 - 2014, Ruby Science Foundation
13
+ // NMatrix is Copyright (c) 2012 - 2014, John Woods and the Ruby Science Foundation
14
+ //
15
+ // Please see LICENSE.txt for additional copyright notices.
16
+ //
17
+ // == Contributing
18
+ //
19
+ // By contributing source code to SciRuby, you agree to be bound by
20
+ // our Contributor Agreement:
21
+ //
22
+ // * https://github.com/SciRuby/sciruby/wiki/Contributor-Agreement
23
+ //
24
+ // == rot.h
25
+ //
26
+ // BLAS rot function in native C++.
27
+ //
28
+
29
+ /*
30
+ * Automatically Tuned Linear Algebra Software v3.8.4
31
+ * (C) Copyright 1999 R. Clint Whaley
32
+ *
33
+ * Redistribution and use in source and binary forms, with or without
34
+ * modification, are permitted provided that the following conditions
35
+ * are met:
36
+ * 1. Redistributions of source code must retain the above copyright
37
+ * notice, this list of conditions and the following disclaimer.
38
+ * 2. Redistributions in binary form must reproduce the above copyright
39
+ * notice, this list of conditions, and the following disclaimer in the
40
+ * documentation and/or other materials provided with the distribution.
41
+ * 3. The name of the ATLAS group or the names of its contributers may
42
+ * not be used to endorse or promote products derived from this
43
+ * software without specific written permission.
44
+ *
45
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
46
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
47
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
48
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ATLAS GROUP OR ITS CONTRIBUTORS
49
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
50
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
51
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
52
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
53
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
54
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
55
+ * POSSIBILITY OF SUCH DAMAGE.
56
+ *
57
+ */
58
+
59
+ #ifndef ROT_H
60
+ # define ROT_H
61
+
62
+ namespace nm { namespace math {
63
+
64
+
65
+ // TODO: Test this to see if it works properly on complex. ATLAS has a separate algorithm for complex, which looks like
66
+ // TODO: it may actually be the same one.
67
+ //
68
+ // This function is called ATL_rot in ATLAS 3.8.4.
69
+ template <typename DType>
70
+ inline void rot_helper(const int N, DType* X, const int incX, DType* Y, const int incY, const DType c, const DType s) {
71
+ if (c != 1 || s != 0) {
72
+ if (incX == 1 && incY == 1) {
73
+ for (int i = 0; i != N; ++i) {
74
+ DType tmp = X[i] * c + Y[i] * s;
75
+ Y[i] = Y[i] * c - X[i] * s;
76
+ X[i] = tmp;
77
+ }
78
+ } else {
79
+ for (int i = N; i > 0; --i, Y += incY, X += incX) {
80
+ DType tmp = *X * c + *Y * s;
81
+ *Y = *Y * c - *X * s;
82
+ *X = tmp;
83
+ }
84
+ }
85
+ }
86
+ }
87
+
88
+
89
+ /* Applies a plane rotation. From ATLAS 3.8.4. */
90
+ template <typename DType, typename CSDType>
91
+ inline void rot(const int N, DType* X, const int incX, DType* Y, const int incY, const CSDType c, const CSDType s) {
92
+ int incx = incX, incy = incY;
93
+ DType *x = X, *y = Y;
94
+
95
+ if (N > 0) {
96
+ if (incX < 0) {
97
+ if (incY < 0) { incx = -incx; incy = -incy; }
98
+ else x += -incX * (N-1);
99
+ } else if (incY < 0) {
100
+ incy = -incy;
101
+ incx = -incx;
102
+ x += (N-1) * incX;
103
+ }
104
+ rot_helper<DType>(N, x, incx, y, incy, c, s);
105
+ }
106
+ }
107
+
108
+ template <typename DType, typename CSDType>
109
+ inline void cblas_rot(const int N, void* X, const int incX, void* Y, const int incY, const void* c, const void* s) {
110
+ rot<DType,CSDType>(N, reinterpret_cast<DType*>(X), incX, reinterpret_cast<DType*>(Y), incY,
111
+ *reinterpret_cast<const CSDType*>(c), *reinterpret_cast<const CSDType*>(s));
112
+ }
113
+
114
+
115
+ } } //nm::math
116
+
117
+ #endif // ROT_H
@@ -0,0 +1,106 @@
1
+ /////////////////////////////////////////////////////////////////////
2
+ // = NMatrix
3
+ //
4
+ // A linear algebra library for scientific computation in Ruby.
5
+ // NMatrix is part of SciRuby.
6
+ //
7
+ // NMatrix was originally inspired by and derived from NArray, by
8
+ // Masahiro Tanaka: http://narray.rubyforge.org
9
+ //
10
+ // == Copyright Information
11
+ //
12
+ // SciRuby is Copyright (c) 2010 - 2014, Ruby Science Foundation
13
+ // NMatrix is Copyright (c) 2012 - 2014, John Woods and the Ruby Science Foundation
14
+ //
15
+ // Please see LICENSE.txt for additional copyright notices.
16
+ //
17
+ // == Contributing
18
+ //
19
+ // By contributing source code to SciRuby, you agree to be bound by
20
+ // our Contributor Agreement:
21
+ //
22
+ // * https://github.com/SciRuby/sciruby/wiki/Contributor-Agreement
23
+ //
24
+ // == rotg.h
25
+ //
26
+ // BLAS rotg function in native C++.
27
+ //
28
+
29
+ /*
30
+ * Automatically Tuned Linear Algebra Software v3.8.4
31
+ * (C) Copyright 1999 R. Clint Whaley
32
+ *
33
+ * Redistribution and use in source and binary forms, with or without
34
+ * modification, are permitted provided that the following conditions
35
+ * are met:
36
+ * 1. Redistributions of source code must retain the above copyright
37
+ * notice, this list of conditions and the following disclaimer.
38
+ * 2. Redistributions in binary form must reproduce the above copyright
39
+ * notice, this list of conditions, and the following disclaimer in the
40
+ * documentation and/or other materials provided with the distribution.
41
+ * 3. The name of the ATLAS group or the names of its contributers may
42
+ * not be used to endorse or promote products derived from this
43
+ * software without specific written permission.
44
+ *
45
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
46
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
47
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
48
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ATLAS GROUP OR ITS CONTRIBUTORS
49
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
50
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
51
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
52
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
53
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
54
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
55
+ * POSSIBILITY OF SUCH DAMAGE.
56
+ *
57
+ */
58
+
59
+ #ifndef ROTG_H
60
+ # define ROTG_H
61
+
62
+ namespace nm { namespace math {
63
+
64
+ /* Givens plane rotation. From ATLAS 3.8.4. */
65
+ // FIXME: Not working properly for Ruby objects.
66
+ template <typename DType>
67
+ inline void rotg(DType* a, DType* b, DType* c, DType* s) {
68
+ DType aa = std::abs(*a), ab = std::abs(*b);
69
+ DType roe = aa > ab ? *a : *b;
70
+ DType scal = aa + ab;
71
+
72
+ if (scal == 0) {
73
+ *c = 1;
74
+ *s = *a = *b = 0;
75
+ } else {
76
+ DType t0 = aa / scal, t1 = ab / scal;
77
+ DType r = scal * std::sqrt(t0 * t0 + t1 * t1);
78
+ if (roe < 0) r = -r;
79
+ *c = *a / r;
80
+ *s = *b / r;
81
+ DType z = (*c != 0) ? (1 / *c) : DType(1);
82
+ *a = r;
83
+ *b = z;
84
+ }
85
+ }
86
+
87
+ template <>
88
+ inline void rotg(Complex64* a, Complex64* b, Complex64* c, Complex64* s) {
89
+ rb_raise(rb_eNotImpError, "BLAS not available, and existing template requires modification for complex");
90
+ }
91
+
92
+ template <>
93
+ inline void rotg(Complex128* a, Complex128* b, Complex128* c, Complex128* s) {
94
+ rb_raise(rb_eNotImpError, "BLAS not available, and existing template requires modification for complex");
95
+ }
96
+
97
+
98
+ template <typename DType>
99
+ inline void cblas_rotg(void* a, void* b, void* c, void* s) {
100
+ rotg<DType>(reinterpret_cast<DType*>(a), reinterpret_cast<DType*>(b), reinterpret_cast<DType*>(c), reinterpret_cast<DType*>(s));
101
+ }
102
+
103
+
104
+ } } //nm::math
105
+
106
+ #endif // ROTG_H
@@ -0,0 +1,71 @@
1
+ /////////////////////////////////////////////////////////////////////
2
+ // = NMatrix
3
+ //
4
+ // A linear algebra library for scientific computation in Ruby.
5
+ // NMatrix is part of SciRuby.
6
+ //
7
+ // NMatrix was originally inspired by and derived from NArray, by
8
+ // Masahiro Tanaka: http://narray.rubyforge.org
9
+ //
10
+ // == Copyright Information
11
+ //
12
+ // SciRuby is Copyright (c) 2010 - 2014, Ruby Science Foundation
13
+ // NMatrix is Copyright (c) 2012 - 2014, John Woods and the Ruby Science Foundation
14
+ //
15
+ // Please see LICENSE.txt for additional copyright notices.
16
+ //
17
+ // == Contributing
18
+ //
19
+ // By contributing source code to SciRuby, you agree to be bound by
20
+ // our Contributor Agreement:
21
+ //
22
+ // * https://github.com/SciRuby/sciruby/wiki/Contributor-Agreement
23
+ //
24
+ // == scal.h
25
+ //
26
+ // BLAS scal function.
27
+ //
28
+
29
+ #ifndef SCAL_H
30
+ #define SCAL_H
31
+
32
+ namespace nm { namespace math {
33
+
34
+ /* Purpose */
35
+ /* ======= */
36
+
37
+ /* DSCAL scales a vector by a constant. */
38
+ /* uses unrolled loops for increment equal to one. */
39
+
40
+ /* Further Details */
41
+ /* =============== */
42
+
43
+ /* jack dongarra, linpack, 3/11/78. */
44
+ /* modified 3/93 to return if incx .le. 0. */
45
+ /* modified 12/3/93, array(1) declarations changed to array(*) */
46
+
47
+ /* ===================================================================== */
48
+
49
+ template <typename DType>
50
+ inline void scal(const int n, const DType scalar, DType* x, const int incx) {
51
+
52
+ if (n <= 0 || incx <= 0) {
53
+ return;
54
+ }
55
+
56
+ for (int i = 0; incx < 0 ? i > n*incx : i < n*incx; i += incx) {
57
+ x[i] = scalar * x[i];
58
+ }
59
+ }
60
+
61
+ /*
62
+ * Function signature conversion for LAPACK's scal function.
63
+ */
64
+ template <typename DType>
65
+ inline void cblas_scal(const int n, const void* scalar, void* x, const int incx) {
66
+ scal<DType>(n, *reinterpret_cast<const DType*>(scalar), reinterpret_cast<DType*>(x), incx);
67
+ }
68
+
69
+ }} // end of nm::math
70
+
71
+ #endif