pnmatrix 1.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/ext/nmatrix/binary_format.txt +53 -0
- data/ext/nmatrix/data/complex.h +388 -0
- data/ext/nmatrix/data/data.cpp +274 -0
- data/ext/nmatrix/data/data.h +651 -0
- data/ext/nmatrix/data/meta.h +64 -0
- data/ext/nmatrix/data/ruby_object.h +386 -0
- data/ext/nmatrix/extconf.rb +70 -0
- data/ext/nmatrix/math/asum.h +99 -0
- data/ext/nmatrix/math/cblas_enums.h +36 -0
- data/ext/nmatrix/math/cblas_templates_core.h +507 -0
- data/ext/nmatrix/math/gemm.h +241 -0
- data/ext/nmatrix/math/gemv.h +178 -0
- data/ext/nmatrix/math/getrf.h +255 -0
- data/ext/nmatrix/math/getrs.h +121 -0
- data/ext/nmatrix/math/imax.h +82 -0
- data/ext/nmatrix/math/laswp.h +165 -0
- data/ext/nmatrix/math/long_dtype.h +62 -0
- data/ext/nmatrix/math/magnitude.h +54 -0
- data/ext/nmatrix/math/math.h +751 -0
- data/ext/nmatrix/math/nrm2.h +165 -0
- data/ext/nmatrix/math/rot.h +117 -0
- data/ext/nmatrix/math/rotg.h +106 -0
- data/ext/nmatrix/math/scal.h +71 -0
- data/ext/nmatrix/math/trsm.h +336 -0
- data/ext/nmatrix/math/util.h +162 -0
- data/ext/nmatrix/math.cpp +1368 -0
- data/ext/nmatrix/nm_memory.h +60 -0
- data/ext/nmatrix/nmatrix.cpp +285 -0
- data/ext/nmatrix/nmatrix.h +476 -0
- data/ext/nmatrix/ruby_constants.cpp +151 -0
- data/ext/nmatrix/ruby_constants.h +106 -0
- data/ext/nmatrix/ruby_nmatrix.c +3130 -0
- data/ext/nmatrix/storage/common.cpp +77 -0
- data/ext/nmatrix/storage/common.h +183 -0
- data/ext/nmatrix/storage/dense/dense.cpp +1096 -0
- data/ext/nmatrix/storage/dense/dense.h +129 -0
- data/ext/nmatrix/storage/list/list.cpp +1628 -0
- data/ext/nmatrix/storage/list/list.h +138 -0
- data/ext/nmatrix/storage/storage.cpp +730 -0
- data/ext/nmatrix/storage/storage.h +99 -0
- data/ext/nmatrix/storage/yale/class.h +1139 -0
- data/ext/nmatrix/storage/yale/iterators/base.h +143 -0
- data/ext/nmatrix/storage/yale/iterators/iterator.h +131 -0
- data/ext/nmatrix/storage/yale/iterators/row.h +450 -0
- data/ext/nmatrix/storage/yale/iterators/row_stored.h +140 -0
- data/ext/nmatrix/storage/yale/iterators/row_stored_nd.h +169 -0
- data/ext/nmatrix/storage/yale/iterators/stored_diagonal.h +124 -0
- data/ext/nmatrix/storage/yale/math/transpose.h +110 -0
- data/ext/nmatrix/storage/yale/yale.cpp +2074 -0
- data/ext/nmatrix/storage/yale/yale.h +203 -0
- data/ext/nmatrix/types.h +55 -0
- data/ext/nmatrix/util/io.cpp +279 -0
- data/ext/nmatrix/util/io.h +115 -0
- data/ext/nmatrix/util/sl_list.cpp +627 -0
- data/ext/nmatrix/util/sl_list.h +144 -0
- data/ext/nmatrix/util/util.h +78 -0
- data/lib/nmatrix/blas.rb +378 -0
- data/lib/nmatrix/cruby/math.rb +744 -0
- data/lib/nmatrix/enumerate.rb +253 -0
- data/lib/nmatrix/homogeneous.rb +241 -0
- data/lib/nmatrix/io/fortran_format.rb +138 -0
- data/lib/nmatrix/io/harwell_boeing.rb +221 -0
- data/lib/nmatrix/io/market.rb +263 -0
- data/lib/nmatrix/io/point_cloud.rb +189 -0
- data/lib/nmatrix/jruby/decomposition.rb +24 -0
- data/lib/nmatrix/jruby/enumerable.rb +13 -0
- data/lib/nmatrix/jruby/error.rb +4 -0
- data/lib/nmatrix/jruby/math.rb +501 -0
- data/lib/nmatrix/jruby/nmatrix_java.rb +840 -0
- data/lib/nmatrix/jruby/operators.rb +283 -0
- data/lib/nmatrix/jruby/slice.rb +264 -0
- data/lib/nmatrix/lapack_core.rb +181 -0
- data/lib/nmatrix/lapack_plugin.rb +44 -0
- data/lib/nmatrix/math.rb +953 -0
- data/lib/nmatrix/mkmf.rb +100 -0
- data/lib/nmatrix/monkeys.rb +137 -0
- data/lib/nmatrix/nmatrix.rb +1172 -0
- data/lib/nmatrix/rspec.rb +75 -0
- data/lib/nmatrix/shortcuts.rb +1163 -0
- data/lib/nmatrix/version.rb +39 -0
- data/lib/nmatrix/yale_functions.rb +118 -0
- data/lib/nmatrix.rb +28 -0
- data/spec/00_nmatrix_spec.rb +892 -0
- data/spec/01_enum_spec.rb +196 -0
- data/spec/02_slice_spec.rb +407 -0
- data/spec/03_nmatrix_monkeys_spec.rb +80 -0
- data/spec/2x2_dense_double.mat +0 -0
- data/spec/4x4_sparse.mat +0 -0
- data/spec/4x5_dense.mat +0 -0
- data/spec/blas_spec.rb +215 -0
- data/spec/elementwise_spec.rb +311 -0
- data/spec/homogeneous_spec.rb +100 -0
- data/spec/io/fortran_format_spec.rb +88 -0
- data/spec/io/harwell_boeing_spec.rb +98 -0
- data/spec/io/test.rua +9 -0
- data/spec/io_spec.rb +159 -0
- data/spec/lapack_core_spec.rb +482 -0
- data/spec/leakcheck.rb +16 -0
- data/spec/math_spec.rb +1363 -0
- data/spec/nmatrix_yale_resize_test_associations.yaml +2802 -0
- data/spec/nmatrix_yale_spec.rb +286 -0
- data/spec/rspec_monkeys.rb +56 -0
- data/spec/rspec_spec.rb +35 -0
- data/spec/shortcuts_spec.rb +474 -0
- data/spec/slice_set_spec.rb +162 -0
- data/spec/spec_helper.rb +172 -0
- data/spec/stat_spec.rb +214 -0
- data/spec/test.pcd +20 -0
- data/spec/utm5940.mtx +83844 -0
- metadata +295 -0
@@ -0,0 +1,121 @@
|
|
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
|
+
// == getrs.h
|
25
|
+
//
|
26
|
+
// getrs 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 GETRS_H
|
60
|
+
#define GETRS_H
|
61
|
+
|
62
|
+
namespace nm { namespace math {
|
63
|
+
|
64
|
+
|
65
|
+
/*
|
66
|
+
* Solves a system of linear equations A*X = B with a general NxN matrix A using the LU factorization computed by GETRF.
|
67
|
+
*
|
68
|
+
* From ATLAS 3.8.0.
|
69
|
+
*/
|
70
|
+
template <typename DType>
|
71
|
+
int getrs(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE Trans, const int N, const int NRHS, const DType* A,
|
72
|
+
const int lda, const int* ipiv, DType* B, const int ldb)
|
73
|
+
{
|
74
|
+
// enum CBLAS_DIAG Lunit, Uunit; // These aren't used. Not sure why they're declared in ATLAS' src.
|
75
|
+
|
76
|
+
if (!N || !NRHS) return 0;
|
77
|
+
|
78
|
+
const DType ONE = 1;
|
79
|
+
|
80
|
+
if (Order == CblasColMajor) {
|
81
|
+
if (Trans == CblasNoTrans) {
|
82
|
+
nm::math::laswp<DType>(NRHS, B, ldb, 0, N, ipiv, 1);
|
83
|
+
nm::math::trsm<DType>(Order, CblasLeft, CblasLower, CblasNoTrans, CblasUnit, N, NRHS, ONE, A, lda, B, ldb);
|
84
|
+
nm::math::trsm<DType>(Order, CblasLeft, CblasUpper, CblasNoTrans, CblasNonUnit, N, NRHS, ONE, A, lda, B, ldb);
|
85
|
+
} else {
|
86
|
+
nm::math::trsm<DType>(Order, CblasLeft, CblasUpper, Trans, CblasNonUnit, N, NRHS, ONE, A, lda, B, ldb);
|
87
|
+
nm::math::trsm<DType>(Order, CblasLeft, CblasLower, Trans, CblasUnit, N, NRHS, ONE, A, lda, B, ldb);
|
88
|
+
nm::math::laswp<DType>(NRHS, B, ldb, 0, N, ipiv, -1);
|
89
|
+
}
|
90
|
+
} else {
|
91
|
+
if (Trans == CblasNoTrans) {
|
92
|
+
nm::math::trsm<DType>(Order, CblasRight, CblasLower, CblasTrans, CblasNonUnit, NRHS, N, ONE, A, lda, B, ldb);
|
93
|
+
nm::math::trsm<DType>(Order, CblasRight, CblasUpper, CblasTrans, CblasUnit, NRHS, N, ONE, A, lda, B, ldb);
|
94
|
+
nm::math::laswp<DType>(NRHS, B, ldb, 0, N, ipiv, -1);
|
95
|
+
} else {
|
96
|
+
nm::math::laswp<DType>(NRHS, B, ldb, 0, N, ipiv, 1);
|
97
|
+
nm::math::trsm<DType>(Order, CblasRight, CblasUpper, CblasNoTrans, CblasUnit, NRHS, N, ONE, A, lda, B, ldb);
|
98
|
+
nm::math::trsm<DType>(Order, CblasRight, CblasLower, CblasNoTrans, CblasNonUnit, NRHS, N, ONE, A, lda, B, ldb);
|
99
|
+
}
|
100
|
+
}
|
101
|
+
return 0;
|
102
|
+
}
|
103
|
+
|
104
|
+
|
105
|
+
/*
|
106
|
+
* Function signature conversion for calling LAPACK's getrs functions as directly as possible.
|
107
|
+
*
|
108
|
+
* For documentation: http://www.netlib.org/lapack/double/dgetrs.f
|
109
|
+
*
|
110
|
+
* This function should normally go in math.cpp, but we need it to be available to nmatrix.cpp.
|
111
|
+
*/
|
112
|
+
template <typename DType>
|
113
|
+
inline int clapack_getrs(const enum CBLAS_ORDER order, const enum CBLAS_TRANSPOSE trans, const int n, const int nrhs,
|
114
|
+
const void* a, const int lda, const int* ipiv, void* b, const int ldb) {
|
115
|
+
return getrs<DType>(order, trans, n, nrhs, reinterpret_cast<const DType*>(a), lda, ipiv, reinterpret_cast<DType*>(b), ldb);
|
116
|
+
}
|
117
|
+
|
118
|
+
|
119
|
+
} } // end nm::math
|
120
|
+
|
121
|
+
#endif // GETRS_H
|
@@ -0,0 +1,82 @@
|
|
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 - present, Ruby Science Foundation
|
13
|
+
// NMatrix is Copyright (c) 2012 - present, 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
|
+
// == imax.h
|
25
|
+
//
|
26
|
+
// BLAS level 1 function imax.
|
27
|
+
//
|
28
|
+
|
29
|
+
#ifndef IMAX_H
|
30
|
+
#define IMAX_H
|
31
|
+
|
32
|
+
#include "math/magnitude.h"
|
33
|
+
|
34
|
+
namespace nm { namespace math {
|
35
|
+
|
36
|
+
|
37
|
+
template<typename DType>
|
38
|
+
inline int imax(const int n, const DType *x, const int incx) {
|
39
|
+
|
40
|
+
if (n < 1 || incx <= 0) {
|
41
|
+
return -1;
|
42
|
+
}
|
43
|
+
if (n == 1) {
|
44
|
+
return 0;
|
45
|
+
}
|
46
|
+
|
47
|
+
typename MagnitudeDType<DType>::type dmax;
|
48
|
+
int imax = 0;
|
49
|
+
|
50
|
+
if (incx == 1) { // if incrementing by 1
|
51
|
+
|
52
|
+
dmax = magnitude(x[0]);
|
53
|
+
|
54
|
+
for (int i = 1; i < n; ++i) {
|
55
|
+
if (magnitude(x[i]) > dmax) {
|
56
|
+
imax = i;
|
57
|
+
dmax = magnitude(x[i]);
|
58
|
+
}
|
59
|
+
}
|
60
|
+
|
61
|
+
} else { // if incrementing by more than 1
|
62
|
+
|
63
|
+
dmax = magnitude(x[0]);
|
64
|
+
|
65
|
+
for (int i = 1, ix = incx; i < n; ++i, ix += incx) {
|
66
|
+
if (magnitude(x[ix]) > dmax) {
|
67
|
+
imax = i;
|
68
|
+
dmax = magnitude(x[ix]);
|
69
|
+
}
|
70
|
+
}
|
71
|
+
}
|
72
|
+
return imax;
|
73
|
+
}
|
74
|
+
|
75
|
+
template<typename DType>
|
76
|
+
inline int cblas_imax(const int n, const void* x, const int incx) {
|
77
|
+
return imax<DType>(n, reinterpret_cast<const DType*>(x), incx);
|
78
|
+
}
|
79
|
+
|
80
|
+
}} // end of namespace nm::math
|
81
|
+
|
82
|
+
#endif /* IMAX_H */
|
@@ -0,0 +1,165 @@
|
|
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
|
+
// == laswp.h
|
25
|
+
//
|
26
|
+
// laswp function in native C++.
|
27
|
+
//
|
28
|
+
/*
|
29
|
+
* Automatically Tuned Linear Algebra Software v3.8.4
|
30
|
+
* (C) Copyright 1999 R. Clint Whaley
|
31
|
+
*
|
32
|
+
* Redistribution and use in source and binary forms, with or without
|
33
|
+
* modification, are permitted provided that the following conditions
|
34
|
+
* are met:
|
35
|
+
* 1. Redistributions of source code must retain the above copyright
|
36
|
+
* notice, this list of conditions and the following disclaimer.
|
37
|
+
* 2. Redistributions in binary form must reproduce the above copyright
|
38
|
+
* notice, this list of conditions, and the following disclaimer in the
|
39
|
+
* documentation and/or other materials provided with the distribution.
|
40
|
+
* 3. The name of the ATLAS group or the names of its contributers may
|
41
|
+
* not be used to endorse or promote products derived from this
|
42
|
+
* software without specific written permission.
|
43
|
+
*
|
44
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
45
|
+
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
46
|
+
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
47
|
+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ATLAS GROUP OR ITS CONTRIBUTORS
|
48
|
+
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
49
|
+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
50
|
+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
51
|
+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
52
|
+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
53
|
+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
54
|
+
* POSSIBILITY OF SUCH DAMAGE.
|
55
|
+
*
|
56
|
+
*/
|
57
|
+
|
58
|
+
#ifndef LASWP_H
|
59
|
+
#define LASWP_H
|
60
|
+
|
61
|
+
namespace nm { namespace math {
|
62
|
+
|
63
|
+
|
64
|
+
/*
|
65
|
+
* ATLAS function which performs row interchanges on a general rectangular matrix. Modeled after the LAPACK LASWP function.
|
66
|
+
*
|
67
|
+
* This version is templated for use by template <> getrf().
|
68
|
+
*/
|
69
|
+
template <typename DType>
|
70
|
+
inline void laswp(const int N, DType* A, const int lda, const int K1, const int K2, const int *piv, const int inci) {
|
71
|
+
//const int n = K2 - K1; // not sure why this is declared. commented it out because it's unused.
|
72
|
+
|
73
|
+
int nb = N >> 5;
|
74
|
+
|
75
|
+
const int mr = N - (nb<<5);
|
76
|
+
const int incA = lda << 5;
|
77
|
+
|
78
|
+
if (K2 < K1) return;
|
79
|
+
|
80
|
+
int i1, i2;
|
81
|
+
if (inci < 0) {
|
82
|
+
piv -= (K2-1) * inci;
|
83
|
+
i1 = K2 - 1;
|
84
|
+
i2 = K1;
|
85
|
+
} else {
|
86
|
+
piv += K1 * inci;
|
87
|
+
i1 = K1;
|
88
|
+
i2 = K2-1;
|
89
|
+
}
|
90
|
+
|
91
|
+
if (nb) {
|
92
|
+
|
93
|
+
do {
|
94
|
+
const int* ipiv = piv;
|
95
|
+
int i = i1;
|
96
|
+
int KeepOn;
|
97
|
+
|
98
|
+
do {
|
99
|
+
int ip = *ipiv; ipiv += inci;
|
100
|
+
|
101
|
+
if (ip != i) {
|
102
|
+
DType *a0 = &(A[i]),
|
103
|
+
*a1 = &(A[ip]);
|
104
|
+
|
105
|
+
for (int h = 32; h; h--) {
|
106
|
+
DType r = *a0;
|
107
|
+
*a0 = *a1;
|
108
|
+
*a1 = r;
|
109
|
+
|
110
|
+
a0 += lda;
|
111
|
+
a1 += lda;
|
112
|
+
}
|
113
|
+
|
114
|
+
}
|
115
|
+
if (inci > 0) KeepOn = (++i <= i2);
|
116
|
+
else KeepOn = (--i >= i2);
|
117
|
+
|
118
|
+
} while (KeepOn);
|
119
|
+
A += incA;
|
120
|
+
} while (--nb);
|
121
|
+
}
|
122
|
+
|
123
|
+
if (mr) {
|
124
|
+
const int* ipiv = piv;
|
125
|
+
int i = i1;
|
126
|
+
int KeepOn;
|
127
|
+
|
128
|
+
do {
|
129
|
+
int ip = *ipiv; ipiv += inci;
|
130
|
+
if (ip != i) {
|
131
|
+
DType *a0 = &(A[i]),
|
132
|
+
*a1 = &(A[ip]);
|
133
|
+
|
134
|
+
for (int h = mr; h; h--) {
|
135
|
+
DType r = *a0;
|
136
|
+
*a0 = *a1;
|
137
|
+
*a1 = r;
|
138
|
+
|
139
|
+
a0 += lda;
|
140
|
+
a1 += lda;
|
141
|
+
}
|
142
|
+
}
|
143
|
+
|
144
|
+
if (inci > 0) KeepOn = (++i <= i2);
|
145
|
+
else KeepOn = (--i >= i2);
|
146
|
+
|
147
|
+
} while (KeepOn);
|
148
|
+
}
|
149
|
+
}
|
150
|
+
|
151
|
+
|
152
|
+
/*
|
153
|
+
* Function signature conversion for calling LAPACK's laswp functions as directly as possible.
|
154
|
+
*
|
155
|
+
* For documentation: http://www.netlib.org/lapack/double/dlaswp.f
|
156
|
+
*
|
157
|
+
* This function should normally go in math.cpp, but we need it to be available to nmatrix.cpp.
|
158
|
+
*/
|
159
|
+
template <typename DType>
|
160
|
+
inline void clapack_laswp(const int n, void* a, const int lda, const int k1, const int k2, const int* ipiv, const int incx) {
|
161
|
+
laswp<DType>(n, reinterpret_cast<DType*>(a), lda, k1, k2, ipiv, incx);
|
162
|
+
}
|
163
|
+
|
164
|
+
} } // namespace nm::math
|
165
|
+
#endif // LASWP_H
|
@@ -0,0 +1,62 @@
|
|
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 - present, Ruby Science Foundation
|
13
|
+
// NMatrix is Copyright (c) 2012 - present, 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
|
+
// == long_dtype.h
|
25
|
+
//
|
26
|
+
// Declarations necessary for the native versions of GEMM and GEMV,
|
27
|
+
// as well as for IMAX.
|
28
|
+
//
|
29
|
+
|
30
|
+
#ifndef LONG_DTYPE_H
|
31
|
+
#define LONG_DTYPE_H
|
32
|
+
|
33
|
+
namespace nm { namespace math {
|
34
|
+
// These allow an increase in precision for intermediate values of gemm and gemv.
|
35
|
+
// See also: http://stackoverflow.com/questions/11873694/how-does-one-increase-precision-in-c-templates-in-a-template-typename-dependen
|
36
|
+
template <typename DType> struct LongDType;
|
37
|
+
template <> struct LongDType<uint8_t> { typedef int16_t type; };
|
38
|
+
template <> struct LongDType<int8_t> { typedef int16_t type; };
|
39
|
+
template <> struct LongDType<int16_t> { typedef int32_t type; };
|
40
|
+
template <> struct LongDType<int32_t> { typedef int64_t type; };
|
41
|
+
template <> struct LongDType<int64_t> { typedef int64_t type; };
|
42
|
+
template <> struct LongDType<float> { typedef double type; };
|
43
|
+
template <> struct LongDType<double> { typedef double type; };
|
44
|
+
template <> struct LongDType<Complex64> { typedef Complex128 type; };
|
45
|
+
template <> struct LongDType<Complex128> { typedef Complex128 type; };
|
46
|
+
template <> struct LongDType<RubyObject> { typedef RubyObject type; };
|
47
|
+
|
48
|
+
template <typename DType> struct MagnitudeDType;
|
49
|
+
template <> struct MagnitudeDType<uint8_t> { typedef uint8_t type; };
|
50
|
+
template <> struct MagnitudeDType<int8_t> { typedef int8_t type; };
|
51
|
+
template <> struct MagnitudeDType<int16_t> { typedef int16_t type; };
|
52
|
+
template <> struct MagnitudeDType<int32_t> { typedef int32_t type; };
|
53
|
+
template <> struct MagnitudeDType<int64_t> { typedef int64_t type; };
|
54
|
+
template <> struct MagnitudeDType<float> { typedef float type; };
|
55
|
+
template <> struct MagnitudeDType<double> { typedef double type; };
|
56
|
+
template <> struct MagnitudeDType<Complex64> { typedef float type; };
|
57
|
+
template <> struct MagnitudeDType<Complex128> { typedef double type; };
|
58
|
+
template <> struct MagnitudeDType<RubyObject> { typedef RubyObject type; };
|
59
|
+
|
60
|
+
}} // end of namespace nm::math
|
61
|
+
|
62
|
+
#endif
|
@@ -0,0 +1,54 @@
|
|
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 - present, Ruby Science Foundation
|
13
|
+
// NMatrix is Copyright (c) 2012 - present, 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
|
+
// == math/magnitude.h
|
25
|
+
//
|
26
|
+
// Takes the absolute value (meaning magnitude) of each DType.
|
27
|
+
// Needed for a variety of BLAS/LAPACK functions.
|
28
|
+
//
|
29
|
+
|
30
|
+
#ifndef MAGNITUDE_H
|
31
|
+
#define MAGNITUDE_H
|
32
|
+
|
33
|
+
#include "math/long_dtype.h"
|
34
|
+
|
35
|
+
namespace nm { namespace math {
|
36
|
+
|
37
|
+
/* Magnitude -- may be complicated for unsigned types, and need to call the correct STL abs for floats/doubles */
|
38
|
+
template <typename DType, typename MDType = typename MagnitudeDType<DType>::type>
|
39
|
+
inline MDType magnitude(const DType& v) {
|
40
|
+
return v.abs();
|
41
|
+
}
|
42
|
+
template <> inline float magnitude(const float& v) { return std::abs(v); }
|
43
|
+
template <> inline double magnitude(const double& v) { return std::abs(v); }
|
44
|
+
template <> inline uint8_t magnitude(const uint8_t& v) { return v; }
|
45
|
+
template <> inline int8_t magnitude(const int8_t& v) { return std::abs(v); }
|
46
|
+
template <> inline int16_t magnitude(const int16_t& v) { return std::abs(v); }
|
47
|
+
template <> inline int32_t magnitude(const int32_t& v) { return std::abs(v); }
|
48
|
+
template <> inline int64_t magnitude(const int64_t& v) { return std::abs(v); }
|
49
|
+
template <> inline float magnitude(const nm::Complex64& v) { return std::sqrt(v.r * v.r + v.i * v.i); }
|
50
|
+
template <> inline double magnitude(const nm::Complex128& v) { return std::sqrt(v.r * v.r + v.i * v.i); }
|
51
|
+
|
52
|
+
}}
|
53
|
+
|
54
|
+
#endif // MAGNITUDE_H
|