nmatrix 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/nmatrix/data/complex.h +20 -55
- data/ext/nmatrix/data/data.cpp +11 -44
- data/ext/nmatrix/data/data.h +174 -311
- data/ext/nmatrix/data/meta.h +1 -7
- data/ext/nmatrix/data/ruby_object.h +3 -85
- data/ext/nmatrix/extconf.rb +2 -73
- data/ext/nmatrix/math.cpp +170 -813
- data/ext/nmatrix/math/asum.h +2 -25
- data/ext/nmatrix/math/{inc.h → cblas_enums.h} +11 -22
- data/ext/nmatrix/math/cblas_templates_core.h +507 -0
- data/ext/nmatrix/math/gemm.h +2 -32
- data/ext/nmatrix/math/gemv.h +1 -35
- data/ext/nmatrix/math/getrf.h +21 -6
- data/ext/nmatrix/math/getrs.h +0 -8
- data/ext/nmatrix/math/imax.h +0 -22
- data/ext/nmatrix/math/long_dtype.h +0 -3
- data/ext/nmatrix/math/math.h +11 -337
- data/ext/nmatrix/math/nrm2.h +2 -23
- data/ext/nmatrix/math/rot.h +1 -25
- data/ext/nmatrix/math/rotg.h +4 -13
- data/ext/nmatrix/math/scal.h +0 -22
- data/ext/nmatrix/math/trsm.h +0 -55
- data/ext/nmatrix/math/util.h +148 -0
- data/ext/nmatrix/nmatrix.cpp +0 -14
- data/ext/nmatrix/nmatrix.h +92 -84
- data/ext/nmatrix/ruby_constants.cpp +0 -2
- data/ext/nmatrix/ruby_constants.h +0 -2
- data/ext/nmatrix/ruby_nmatrix.c +86 -45
- data/ext/nmatrix/storage/dense/dense.cpp +1 -7
- data/ext/nmatrix/storage/storage.h +0 -1
- data/ext/nmatrix/ttable_helper.rb +0 -6
- data/ext/nmatrix/util/io.cpp +1 -1
- data/lib/nmatrix.rb +1 -19
- data/lib/nmatrix/blas.rb +33 -11
- data/lib/nmatrix/io/market.rb +3 -3
- data/lib/nmatrix/lapack_core.rb +181 -0
- data/lib/nmatrix/lapack_plugin.rb +44 -0
- data/lib/nmatrix/math.rb +382 -131
- data/lib/nmatrix/monkeys.rb +2 -3
- data/lib/nmatrix/nmatrix.rb +166 -13
- data/lib/nmatrix/shortcuts.rb +72 -7
- data/lib/nmatrix/version.rb +2 -2
- data/spec/00_nmatrix_spec.rb +154 -5
- data/spec/02_slice_spec.rb +2 -6
- data/spec/03_nmatrix_monkeys_spec.rb +7 -1
- data/spec/blas_spec.rb +60 -33
- data/spec/homogeneous_spec.rb +10 -10
- data/spec/lapack_core_spec.rb +482 -0
- data/spec/math_spec.rb +436 -52
- data/spec/shortcuts_spec.rb +28 -4
- data/spec/spec_helper.rb +14 -2
- data/spec/utm5940.mtx +83844 -0
- metadata +49 -76
- data/.gitignore +0 -27
- data/.rspec +0 -2
- data/.travis.yml +0 -15
- data/CONTRIBUTING.md +0 -82
- data/Gemfile +0 -2
- data/History.txt +0 -677
- data/LICENSE.txt +0 -23
- data/Manifest.txt +0 -92
- data/README.rdoc +0 -150
- data/Rakefile +0 -216
- data/ext/nmatrix/data/rational.h +0 -440
- data/ext/nmatrix/math/geev.h +0 -82
- data/ext/nmatrix/math/ger.h +0 -96
- data/ext/nmatrix/math/gesdd.h +0 -80
- data/ext/nmatrix/math/gesvd.h +0 -78
- data/ext/nmatrix/math/getf2.h +0 -86
- data/ext/nmatrix/math/getri.h +0 -108
- data/ext/nmatrix/math/potrs.h +0 -129
- data/ext/nmatrix/math/swap.h +0 -52
- data/lib/nmatrix/lapack.rb +0 -240
- data/nmatrix.gemspec +0 -55
- data/scripts/mac-brew-gcc.sh +0 -50
- data/scripts/mac-mavericks-brew-gcc.sh +0 -22
- data/spec/lapack_spec.rb +0 -459
data/ext/nmatrix/data/rational.h
DELETED
@@ -1,440 +0,0 @@
|
|
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
|
-
// == rational.h
|
25
|
-
//
|
26
|
-
// Functions and classes for dealing with rational numbers.
|
27
|
-
|
28
|
-
#ifndef RATIONAL_H
|
29
|
-
#define RATIONAL_H
|
30
|
-
|
31
|
-
/*
|
32
|
-
* Standard Includes
|
33
|
-
*/
|
34
|
-
|
35
|
-
#include <type_traits>
|
36
|
-
#include <ruby.h>
|
37
|
-
#include <iostream>
|
38
|
-
|
39
|
-
/*
|
40
|
-
* Project Includes
|
41
|
-
*/
|
42
|
-
|
43
|
-
#include "types.h"
|
44
|
-
|
45
|
-
#include "util/util.h"
|
46
|
-
|
47
|
-
/*
|
48
|
-
* Macros
|
49
|
-
*/
|
50
|
-
|
51
|
-
/*
|
52
|
-
* Types
|
53
|
-
*/
|
54
|
-
|
55
|
-
namespace nm {
|
56
|
-
|
57
|
-
template <typename Type> class Rational;
|
58
|
-
|
59
|
-
typedef Rational<int16_t> Rational32;
|
60
|
-
typedef Rational<int32_t> Rational64;
|
61
|
-
typedef Rational<int64_t> Rational128;
|
62
|
-
|
63
|
-
/*
|
64
|
-
* Data
|
65
|
-
*/
|
66
|
-
|
67
|
-
/*
|
68
|
-
* Classes and Functions
|
69
|
-
*/
|
70
|
-
|
71
|
-
template <typename Type>
|
72
|
-
class Rational {
|
73
|
-
public:
|
74
|
-
// The numerator and denominator of the rational number.
|
75
|
-
Type n;
|
76
|
-
Type d;
|
77
|
-
|
78
|
-
/*
|
79
|
-
* Default constructor.
|
80
|
-
*/
|
81
|
-
inline Rational(Type num = 0, Type den = 1) : n(num), d(den) {}
|
82
|
-
|
83
|
-
/*
|
84
|
-
* Copy constructors.
|
85
|
-
*/
|
86
|
-
template <typename OtherType>
|
87
|
-
inline Rational(const Rational<OtherType>& other) : n(other.n), d(other.d) {}
|
88
|
-
|
89
|
-
template <typename FloatType, typename = typename std::enable_if<std::is_floating_point<FloatType>::value>::type>
|
90
|
-
inline Rational(const Complex<FloatType>& other) : n(0), d(1) {
|
91
|
-
rb_raise(rb_eNotImpError, "cannot convert from complex to rational");
|
92
|
-
}
|
93
|
-
|
94
|
-
Rational(const RubyObject& other);
|
95
|
-
|
96
|
-
/*
|
97
|
-
* Rational inverse function -- creates a copy, but inverted.
|
98
|
-
*/
|
99
|
-
inline Rational<Type> inverse() const {
|
100
|
-
return Rational<Type>(this->d, this->n);
|
101
|
-
}
|
102
|
-
|
103
|
-
/*
|
104
|
-
* Binary operator definitions for varous types.
|
105
|
-
*/
|
106
|
-
|
107
|
-
//////////////////////////////////
|
108
|
-
// Rational-Rational Operations //
|
109
|
-
//////////////////////////////////
|
110
|
-
|
111
|
-
template <typename OtherType>
|
112
|
-
inline Rational<Type> operator+(const Rational<OtherType>& other) const {
|
113
|
-
Rational<Type> result((this->n * other.d) + (other.n * this->d), this->d * other.d);
|
114
|
-
|
115
|
-
long simplify = gcf<Type>(result.n, result.d);
|
116
|
-
|
117
|
-
result.n /= simplify;
|
118
|
-
result.d /= simplify;
|
119
|
-
|
120
|
-
return result;
|
121
|
-
}
|
122
|
-
|
123
|
-
template <typename OtherType>
|
124
|
-
inline Rational<Type>& operator+=(const Rational<OtherType>& other) {
|
125
|
-
this->n = (this->n * other.d) + (other.n * this->d);
|
126
|
-
this->d = this->d * other.d;
|
127
|
-
|
128
|
-
long simplify = gcf<Type>(this->n, this->d);
|
129
|
-
|
130
|
-
this->n /= simplify;
|
131
|
-
this->d /= simplify;
|
132
|
-
|
133
|
-
return *this;
|
134
|
-
}
|
135
|
-
|
136
|
-
template <typename OtherType>
|
137
|
-
inline Rational<Type> operator-(const Rational<OtherType>& other) const {
|
138
|
-
Rational<Type> result((this->n * other.d) - (other.n * this->d), this->d * other.d);
|
139
|
-
|
140
|
-
long simplify = gcf<Type>(result.n, result.d);
|
141
|
-
|
142
|
-
result.n /= simplify;
|
143
|
-
result.d /= simplify;
|
144
|
-
|
145
|
-
return result;
|
146
|
-
}
|
147
|
-
|
148
|
-
template <typename OtherType>
|
149
|
-
inline Rational<Type>& operator-=(const Rational<OtherType>& other) {
|
150
|
-
this->n = (this->n * other.d) - (other.n * this->d);
|
151
|
-
this->d = this->d * other.d;
|
152
|
-
|
153
|
-
long simplify = gcf<Type>(this->n, this->d);
|
154
|
-
|
155
|
-
this->n /= simplify;
|
156
|
-
this->d /= simplify;
|
157
|
-
|
158
|
-
return *this;
|
159
|
-
}
|
160
|
-
|
161
|
-
template <typename OtherType>
|
162
|
-
inline Rational<Type> operator*(const Rational<OtherType>& other) const {
|
163
|
-
int g1 = gcf<Type>(this->n, other.d);
|
164
|
-
int g2 = gcf<Type>(this->d, other.n);
|
165
|
-
|
166
|
-
return Rational<Type>((this->n / g1) * (other.n / g2), (this->d / g2) * (other.d / g1));
|
167
|
-
}
|
168
|
-
|
169
|
-
template <typename OtherType>
|
170
|
-
inline Rational<Type> operator/(const Rational<OtherType>& other) const {
|
171
|
-
Rational<Type> result = *this * Rational<OtherType>(other.d, other.n);
|
172
|
-
|
173
|
-
if (result.d < 0) {
|
174
|
-
return Rational<Type>(-result.n, -result.d);
|
175
|
-
}
|
176
|
-
|
177
|
-
return result;
|
178
|
-
}
|
179
|
-
|
180
|
-
template <typename OtherType>
|
181
|
-
inline Rational<Type>& operator*=(const Rational<OtherType>& other) {
|
182
|
-
int g1 = gcf<Type>(this->n, other.d);
|
183
|
-
int g2 = gcf<Type>(this->d, other.n);
|
184
|
-
|
185
|
-
this->n = (this->n / g1) * (other.n / g2);
|
186
|
-
this->d = (this->d / g2) * (other.d / g1);
|
187
|
-
|
188
|
-
return *this;
|
189
|
-
}
|
190
|
-
|
191
|
-
template <typename OtherType>
|
192
|
-
inline Rational<Type> operator/=(const Rational<OtherType>& other) {
|
193
|
-
*this *= Rational<OtherType>(other.d, other.n);
|
194
|
-
return *this;
|
195
|
-
}
|
196
|
-
|
197
|
-
template <typename OtherType>
|
198
|
-
inline Rational<Type> operator%(const Rational<OtherType>& other) const {
|
199
|
-
long floor_div = (this->n * other.n) / (this->d * other.d);
|
200
|
-
Rational<Type> prod = other * Rational<long>(floor_div, 1);
|
201
|
-
|
202
|
-
return Rational<long>(this->n, other.n) - prod;
|
203
|
-
}
|
204
|
-
|
205
|
-
template <typename OtherType>
|
206
|
-
inline bool operator<(const Rational<OtherType>& other) const {
|
207
|
-
return (this->n * other.d) < (other.n * this->d);
|
208
|
-
}
|
209
|
-
|
210
|
-
template <typename OtherType>
|
211
|
-
inline bool operator>(const Rational<OtherType>& other) const {
|
212
|
-
return (this->n * other.d) > (other.n * this->d);
|
213
|
-
}
|
214
|
-
|
215
|
-
template <typename OtherType>
|
216
|
-
inline bool operator==(const Rational<OtherType>& other) const {
|
217
|
-
return (this->n == other.n) && (this->d == other.d);
|
218
|
-
}
|
219
|
-
|
220
|
-
template <typename OtherType>
|
221
|
-
inline bool operator!=(const Rational<OtherType>& other) const {
|
222
|
-
return !(*this == other);
|
223
|
-
}
|
224
|
-
|
225
|
-
template <typename OtherType>
|
226
|
-
inline bool operator<=(const Rational<OtherType>& other) const {
|
227
|
-
return (*this < other) || (*this == other);
|
228
|
-
}
|
229
|
-
|
230
|
-
template <typename OtherType>
|
231
|
-
inline bool operator>=(const Rational<OtherType>& other) const {
|
232
|
-
return (*this > other) || (*this == other);
|
233
|
-
}
|
234
|
-
|
235
|
-
template <typename OtherType>
|
236
|
-
inline operator Rational<OtherType> () const {
|
237
|
-
return Rational<OtherType>((OtherType)this->n, (OtherType)this->d);
|
238
|
-
}
|
239
|
-
|
240
|
-
////////////////////////////////
|
241
|
-
// Rational-Native Operations //
|
242
|
-
////////////////////////////////
|
243
|
-
|
244
|
-
template <typename IntType, typename = typename std::enable_if<std::is_integral<IntType>::value>::type>
|
245
|
-
inline Rational<Type> operator+(const IntType& other) const {
|
246
|
-
return *this + Rational<Type>(other);
|
247
|
-
}
|
248
|
-
|
249
|
-
template <typename IntType, typename = typename std::enable_if<std::is_integral<IntType>::value>::type>
|
250
|
-
inline Rational<Type> operator-(const IntType& other) const {
|
251
|
-
return *this - Rational<Type>(other);
|
252
|
-
}
|
253
|
-
|
254
|
-
template <typename IntType, typename = typename std::enable_if<std::is_integral<IntType>::value>::type>
|
255
|
-
inline Rational<Type> operator*(const IntType& other) const {
|
256
|
-
return *this * Rational<Type>(other);
|
257
|
-
}
|
258
|
-
|
259
|
-
template <typename IntType, typename = typename std::enable_if<std::is_integral<IntType>::value>::type>
|
260
|
-
inline Rational<Type> operator/(const IntType& other) const {
|
261
|
-
return *this / Rational<Type>(other);
|
262
|
-
}
|
263
|
-
|
264
|
-
template <typename IntType, typename = typename std::enable_if<std::is_integral<IntType>::value>::type>
|
265
|
-
inline Rational<Type> operator%(const IntType& other) const {
|
266
|
-
return *this % Rational<Type>(other);
|
267
|
-
}
|
268
|
-
|
269
|
-
template <typename IntType, typename = typename std::enable_if<std::is_integral<IntType>::value>::type>
|
270
|
-
inline bool operator<(const IntType& other) const {
|
271
|
-
return *this < Rational<Type>(other);
|
272
|
-
}
|
273
|
-
|
274
|
-
template <typename IntType, typename = typename std::enable_if<std::is_integral<IntType>::value>::type>
|
275
|
-
inline bool operator>(const IntType& other) const {
|
276
|
-
return *this > Rational<Type>(other);
|
277
|
-
}
|
278
|
-
|
279
|
-
template <typename IntType, typename = typename std::enable_if<std::is_integral<IntType>::value>::type>
|
280
|
-
inline bool operator==(const IntType& other) const {
|
281
|
-
return *this == Rational<Type>(other);
|
282
|
-
}
|
283
|
-
|
284
|
-
template <typename IntType, typename = typename std::enable_if<std::is_integral<IntType>::value>::type>
|
285
|
-
inline bool operator!=(const IntType& other) const {
|
286
|
-
return *this != Rational<Type>(other);
|
287
|
-
}
|
288
|
-
|
289
|
-
template <typename IntType, typename = typename std::enable_if<std::is_integral<IntType>::value>::type>
|
290
|
-
inline bool operator<=(const IntType& other) const {
|
291
|
-
return *this <= Rational<Type>(other);
|
292
|
-
}
|
293
|
-
|
294
|
-
template <typename IntType, typename = typename std::enable_if<std::is_integral<IntType>::value>::type>
|
295
|
-
inline bool operator>=(const IntType& other) const {
|
296
|
-
return *this >= Rational<Type>(other);
|
297
|
-
}
|
298
|
-
|
299
|
-
template <typename NumType, typename = typename std::enable_if<std::is_arithmetic<NumType>::value>::type>
|
300
|
-
inline operator NumType () const {
|
301
|
-
return (NumType)this->n / (NumType)this->d;
|
302
|
-
}
|
303
|
-
|
304
|
-
/*
|
305
|
-
* Special casting operator for Complex numbers.
|
306
|
-
*/
|
307
|
-
template <typename FloatType, typename = typename std::enable_if<std::is_floating_point<FloatType>::value>::type>
|
308
|
-
inline operator Rational<FloatType> () const {
|
309
|
-
return Rational<FloatType>(((FloatType)this->n) / ((FloatType)this->d));
|
310
|
-
}
|
311
|
-
};
|
312
|
-
|
313
|
-
// Negative operator
|
314
|
-
template <typename Type, typename = typename std::enable_if<std::is_integral<Type>::value>::type>
|
315
|
-
inline Rational<Type> operator-(const Rational<Type>& rhs) {
|
316
|
-
return Rational<Type>(-rhs.n, rhs.d);
|
317
|
-
}
|
318
|
-
|
319
|
-
////////////////////////////////
|
320
|
-
// Native-Rational Operations //
|
321
|
-
////////////////////////////////
|
322
|
-
|
323
|
-
/*
|
324
|
-
* Integer Math
|
325
|
-
*/
|
326
|
-
|
327
|
-
template <typename IntType, typename RationalType, typename = typename std::enable_if<std::is_integral<IntType>::value>::type>
|
328
|
-
inline Rational<RationalType> operator+(const IntType& left, const Rational<RationalType>& right) {
|
329
|
-
return Rational<RationalType>(left) + right;
|
330
|
-
}
|
331
|
-
|
332
|
-
template <typename IntType, typename RationalType, typename = typename std::enable_if<std::is_integral<IntType>::value>::type>
|
333
|
-
inline Rational<RationalType> operator-(const IntType& left, const Rational<RationalType>& right) {
|
334
|
-
return Rational<RationalType>(left) - right;
|
335
|
-
}
|
336
|
-
|
337
|
-
template <typename IntType, typename RationalType, typename = typename std::enable_if<std::is_integral<IntType>::value>::type>
|
338
|
-
inline Rational<RationalType> operator*(const IntType& left, const Rational<RationalType>& right) {
|
339
|
-
return Rational<RationalType>(left) * right;
|
340
|
-
}
|
341
|
-
|
342
|
-
template <typename IntType, typename RationalType, typename = typename std::enable_if<std::is_integral<IntType>::value>::type>
|
343
|
-
inline Rational<RationalType> operator/(const IntType& left, const Rational<RationalType>& right) {
|
344
|
-
return Rational<RationalType>(left) / right;
|
345
|
-
}
|
346
|
-
|
347
|
-
/*
|
348
|
-
* Floating Point Math
|
349
|
-
*/
|
350
|
-
|
351
|
-
template <typename FloatType, typename RationalType, typename = typename std::enable_if<std::is_floating_point<FloatType>::value>::type>
|
352
|
-
inline FloatType operator+(const FloatType& left, const Rational<RationalType>& right) {
|
353
|
-
return left + (FloatType)right;
|
354
|
-
}
|
355
|
-
|
356
|
-
template <typename FloatType, typename RationalType, typename = typename std::enable_if<std::is_floating_point<FloatType>::value>::type>
|
357
|
-
inline FloatType operator-(const FloatType& left, const Rational<RationalType>& right) {
|
358
|
-
return left - (FloatType)right;
|
359
|
-
}
|
360
|
-
|
361
|
-
template <typename FloatType, typename RationalType, typename = typename std::enable_if<std::is_floating_point<FloatType>::value>::type>
|
362
|
-
inline FloatType operator*(const FloatType& left, const Rational<RationalType>& right) {
|
363
|
-
return left * (FloatType)right;
|
364
|
-
}
|
365
|
-
|
366
|
-
template <typename FloatType, typename RationalType, typename = typename std::enable_if<std::is_floating_point<FloatType>::value>::type>
|
367
|
-
inline FloatType operator/(const FloatType& left, const Rational<RationalType>& right) {
|
368
|
-
return left / (FloatType)right;
|
369
|
-
}
|
370
|
-
|
371
|
-
/*
|
372
|
-
* Comparisons
|
373
|
-
*/
|
374
|
-
|
375
|
-
template <typename NativeType, typename RationalType, typename = typename std::enable_if<std::is_arithmetic<NativeType>::value>::type>
|
376
|
-
inline bool operator<(const NativeType left, const Rational<RationalType>& right) {
|
377
|
-
//return Rational<RationalType>(left) < right;
|
378
|
-
return (left * right.d) < right.n;
|
379
|
-
}
|
380
|
-
|
381
|
-
template <typename NativeType, typename RationalType, typename = typename std::enable_if<std::is_arithmetic<NativeType>::value>::type>
|
382
|
-
inline bool operator>(const NativeType left, const Rational<RationalType>& right) {
|
383
|
-
//return Rational<RationalType>(left) > right;
|
384
|
-
return (left * right.d) > right.n;
|
385
|
-
}
|
386
|
-
|
387
|
-
template <typename IntType, typename RationalType>
|
388
|
-
inline bool operator==(const typename std::enable_if<std::is_integral<IntType>::value, IntType>::type left, const Rational<RationalType>& right) {
|
389
|
-
//return Rational<RationalType>(left) == right;
|
390
|
-
return (left * right.d) == right.n;
|
391
|
-
}
|
392
|
-
|
393
|
-
template <typename FloatType, typename RationalType>
|
394
|
-
inline bool operator==(const typename std::enable_if<std::is_floating_point<FloatType>::value, FloatType>::type left, const Rational<RationalType>& right) {
|
395
|
-
//return Rational<RationalType>(left) == right;
|
396
|
-
return FP_EQUAL(left, ((FloatType)right));
|
397
|
-
}
|
398
|
-
|
399
|
-
template <typename NativeType, typename RationalType, typename = typename std::enable_if<std::is_arithmetic<NativeType>::value>::type>
|
400
|
-
inline bool operator!=(const NativeType left, const Rational<RationalType>& right) {
|
401
|
-
//return Rational<RationalType>(left) != right;
|
402
|
-
return !(left == right);
|
403
|
-
}
|
404
|
-
|
405
|
-
template <typename NativeType, typename RationalType, typename = typename std::enable_if<std::is_arithmetic<NativeType>::value>::type>
|
406
|
-
inline bool operator<=(const NativeType left, const Rational<RationalType>& right) {
|
407
|
-
//return Rational<RationalType>(left) <= right;
|
408
|
-
return (left < right) or (left == right);
|
409
|
-
}
|
410
|
-
|
411
|
-
template <typename NativeType, typename RationalType, typename = typename std::enable_if<std::is_arithmetic<NativeType>::value>::type>
|
412
|
-
inline bool operator>=(const NativeType left, const Rational<RationalType>& right) {
|
413
|
-
//return Rational<RationalType>(left) >= right;
|
414
|
-
return (left > right) or (left == right);
|
415
|
-
}
|
416
|
-
|
417
|
-
template <typename Type>
|
418
|
-
inline std::ostream& operator<<(std::ostream& out, const Rational<Type>& rhs) {
|
419
|
-
out << rhs.n << "/" << rhs.d << std::flush;
|
420
|
-
return out;
|
421
|
-
}
|
422
|
-
|
423
|
-
} // end of namespace nm
|
424
|
-
|
425
|
-
namespace std {
|
426
|
-
template <typename IntType, typename = typename std::enable_if<std::is_integral<IntType>::value>::type>
|
427
|
-
nm::Rational<IntType> abs(const nm::Rational<IntType>& value) {
|
428
|
-
if (value.n >= 0) return value;
|
429
|
-
return nm::Rational<IntType>(-value.n, value.d);
|
430
|
-
}
|
431
|
-
|
432
|
-
template <typename IntType, typename = typename std::enable_if<std::is_integral<IntType>::value>::type>
|
433
|
-
nm::Rational<IntType> sqrt(const nm::Rational<IntType>& value) {
|
434
|
-
nm::Rational<IntType> result(std::sqrt(value.n), std::sqrt(value.d));
|
435
|
-
if (value * value == result) return result;
|
436
|
-
else rb_raise(rb_eArgError, "square root of the given rational is not rational");
|
437
|
-
}
|
438
|
-
}
|
439
|
-
|
440
|
-
#endif // RATIONAL_H
|
data/ext/nmatrix/math/geev.h
DELETED
@@ -1,82 +0,0 @@
|
|
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
|
-
// == geev.h
|
25
|
-
//
|
26
|
-
// Header file for interface with LAPACK's xGEEV functions.
|
27
|
-
//
|
28
|
-
|
29
|
-
#ifndef GEEV_H
|
30
|
-
# define GEEV_H
|
31
|
-
|
32
|
-
extern "C" {
|
33
|
-
void sgeev_(char* jobvl, char* jobvr, int* n, float* a, int* lda, float* wr, float* wi, float* vl, int* ldvl, float* vr, int* ldvr, float* work, int* lwork, int* info);
|
34
|
-
void dgeev_(char* jobvl, char* jobvr, int* n, double* a, int* lda, double* wr, double* wi, double* vl, int* ldvl, double* vr, int* ldvr, double* work, int* lwork, int* info);
|
35
|
-
void cgeev_(char* jobvl, char* jobvr, int* n, nm::Complex64* a, int* lda, nm::Complex64* w, nm::Complex64* vl, int* ldvl, nm::Complex64* vr, int* ldvr, nm::Complex64* work, int* lwork, float* rwork, int* info);
|
36
|
-
void zgeev_(char* jobvl, char* jobvr, int* n, nm::Complex128* a, int* lda, nm::Complex128* w, nm::Complex128* vl, int* ldvl, nm::Complex128* vr, int* ldvr, nm::Complex128* work, int* lwork, double* rwork, int* info);
|
37
|
-
}
|
38
|
-
|
39
|
-
namespace nm { namespace math {
|
40
|
-
|
41
|
-
template <typename DType, typename CType> // wr
|
42
|
-
inline int geev(char jobvl, char jobvr, int n, DType* a, int lda, DType* w, DType* wi, DType* vl, int ldvl, DType* vr, int ldvr, DType* work, int lwork, CType* rwork) {
|
43
|
-
rb_raise(rb_eNotImpError, "not yet implemented for non-BLAS dtypes");
|
44
|
-
return -1;
|
45
|
-
}
|
46
|
-
|
47
|
-
template <>
|
48
|
-
inline int geev(char jobvl, char jobvr, int n, float* a, int lda, float* w, float* wi, float* vl, int ldvl, float* vr, int ldvr, float* work, int lwork, float* rwork) {
|
49
|
-
int info;
|
50
|
-
sgeev_(&jobvl, &jobvr, &n, a, &lda, w, wi, vl, &ldvl, vr, &ldvr, work, &lwork, &info);
|
51
|
-
return info;
|
52
|
-
}
|
53
|
-
|
54
|
-
template <>
|
55
|
-
inline int geev(char jobvl, char jobvr, int n, double* a, int lda, double* w, double* wi, double* vl, int ldvl, double* vr, int ldvr, double* work, int lwork, double* rwork) {
|
56
|
-
int info;
|
57
|
-
dgeev_(&jobvl, &jobvr, &n, a, &lda, w, wi, vl, &ldvl, vr, &ldvr, work, &lwork, &info);
|
58
|
-
return info;
|
59
|
-
}
|
60
|
-
|
61
|
-
template <>
|
62
|
-
inline int geev(char jobvl, char jobvr, int n, Complex64* a, int lda, Complex64* w, Complex64* wi, Complex64* vl, int ldvl, Complex64* vr, int ldvr, Complex64* work, int lwork, float* rwork) {
|
63
|
-
int info;
|
64
|
-
cgeev_(&jobvl, &jobvr, &n, a, &lda, w, vl, &ldvl, vr, &ldvr, work, &lwork, rwork, &info);
|
65
|
-
return info;
|
66
|
-
}
|
67
|
-
|
68
|
-
template <>
|
69
|
-
inline int geev(char jobvl, char jobvr, int n, Complex128* a, int lda, Complex128* w, Complex128* wi, Complex128* vl, int ldvl, Complex128* vr, int ldvr, Complex128* work, int lwork, double* rwork) {
|
70
|
-
int info;
|
71
|
-
zgeev_(&jobvl, &jobvr, &n, a, &lda, w, vl, &ldvl, vr, &ldvr, work, &lwork, rwork, &info);
|
72
|
-
return info;
|
73
|
-
}
|
74
|
-
|
75
|
-
template <typename DType, typename CType>
|
76
|
-
inline int lapack_geev(char jobvl, char jobvr, int n, void* a, int lda, void* w, void* wi, void* vl, int ldvl, void* vr, int ldvr, void* work, int lwork, void* rwork) {
|
77
|
-
return geev<DType,CType>(jobvl, jobvr, n, reinterpret_cast<DType*>(a), lda, reinterpret_cast<DType*>(w), reinterpret_cast<DType*>(wi), reinterpret_cast<DType*>(vl), ldvl, reinterpret_cast<DType*>(vr), ldvr, reinterpret_cast<DType*>(work), lwork, reinterpret_cast<CType*>(rwork));
|
78
|
-
}
|
79
|
-
|
80
|
-
}} // end nm::math
|
81
|
-
|
82
|
-
#endif // GEEV_H
|