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,143 @@
|
|
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
|
+
// == base.h
|
25
|
+
//
|
26
|
+
// Yale storage pure virtual basic_iterator class.
|
27
|
+
//
|
28
|
+
|
29
|
+
#ifndef YALE_ITERATORS_BASE_H
|
30
|
+
# define YALE_ITERATORS_BASE_H
|
31
|
+
|
32
|
+
#include <ruby.h>
|
33
|
+
#include <type_traits>
|
34
|
+
#include <typeinfo>
|
35
|
+
#include <stdexcept>
|
36
|
+
|
37
|
+
namespace nm {
|
38
|
+
|
39
|
+
template <typename D> class YaleStorage;
|
40
|
+
|
41
|
+
namespace yale_storage {
|
42
|
+
|
43
|
+
template <typename D>
|
44
|
+
VALUE nm_rb_dereference(D const& v) {
|
45
|
+
return nm::RubyObject(v).rval;
|
46
|
+
}
|
47
|
+
|
48
|
+
template <>
|
49
|
+
VALUE nm_rb_dereference<nm::RubyObject>(nm::RubyObject const& v) {
|
50
|
+
return v.rval;
|
51
|
+
}
|
52
|
+
|
53
|
+
/*
|
54
|
+
* Iterator base class (pure virtual).
|
55
|
+
*/
|
56
|
+
template <typename D,
|
57
|
+
typename RefType,
|
58
|
+
typename YaleRef = typename std::conditional<
|
59
|
+
std::is_const<RefType>::value,
|
60
|
+
const nm::YaleStorage<D>,
|
61
|
+
nm::YaleStorage<D>
|
62
|
+
>::type>
|
63
|
+
class basic_iterator_T {
|
64
|
+
|
65
|
+
protected:
|
66
|
+
YaleRef& y;
|
67
|
+
size_t i_;
|
68
|
+
size_t p_;
|
69
|
+
|
70
|
+
public:
|
71
|
+
size_t offset(size_t d) const { return y.offset(d); }
|
72
|
+
size_t shape(size_t d) const { return y.shape(d); }
|
73
|
+
size_t real_shape(size_t d) const { return y.real_shape(d); }
|
74
|
+
|
75
|
+
size_t dense_location() const {
|
76
|
+
return i()*shape(1) + j();
|
77
|
+
}
|
78
|
+
|
79
|
+
template <typename T = typename std::conditional<std::is_const<RefType>::value, const size_t, size_t>::type>
|
80
|
+
T& ija(size_t pp) const { return y.ija(pp); }
|
81
|
+
|
82
|
+
template <typename T = typename std::conditional<std::is_const<RefType>::value, const size_t, size_t>::type>
|
83
|
+
T& ija(size_t pp) { return y.ija(pp); }
|
84
|
+
|
85
|
+
virtual bool diag() const {
|
86
|
+
return p_ < std::min(y.real_shape(0), y.real_shape(1));
|
87
|
+
}
|
88
|
+
virtual bool done_with_diag() const {
|
89
|
+
return p_ == std::min(y.real_shape(0), y.real_shape(1));
|
90
|
+
}
|
91
|
+
virtual bool nondiag() const {
|
92
|
+
return p_ > std::min(y.real_shape(0), y.real_shape(1));
|
93
|
+
}
|
94
|
+
|
95
|
+
basic_iterator_T(YaleRef& obj, size_t ii = 0, size_t pp = 0) : y(obj), i_(ii), p_(pp) { }
|
96
|
+
|
97
|
+
basic_iterator_T<D,RefType,YaleRef>& operator=(const basic_iterator_T<D,RefType,YaleRef>& rhs) {
|
98
|
+
if (&y != &(rhs.y)) throw std::logic_error("can only be used on iterators with the same matrix");
|
99
|
+
i_ = rhs.i_;
|
100
|
+
p_ = rhs.p_;
|
101
|
+
return *this;
|
102
|
+
}
|
103
|
+
|
104
|
+
virtual inline size_t i() const { return i_; }
|
105
|
+
virtual size_t j() const = 0;
|
106
|
+
|
107
|
+
virtual inline VALUE rb_i() const { return LONG2NUM(i()); }
|
108
|
+
virtual inline VALUE rb_j() const { return LONG2NUM(j()); }
|
109
|
+
|
110
|
+
virtual size_t real_i() const { return offset(0) + i(); }
|
111
|
+
virtual size_t real_j() const { return offset(1) + j(); }
|
112
|
+
virtual size_t p() const { return p_; }
|
113
|
+
virtual bool real_ndnz_exists() const { return !y.real_row_empty(real_i()) && ija(p_) == real_j(); }
|
114
|
+
|
115
|
+
virtual RefType& operator*() = 0;
|
116
|
+
virtual RefType& operator*() const = 0;
|
117
|
+
|
118
|
+
|
119
|
+
// Ruby VALUE de-reference
|
120
|
+
inline VALUE operator~() const {
|
121
|
+
return nm_rb_dereference<D>(**this);
|
122
|
+
//virtual VALUE operator~() const {
|
123
|
+
// if (typeid(D) == typeid(RubyObject)) return (**this); // FIXME: return rval instead, faster;
|
124
|
+
// else return RubyObject(*(*this)).rval;
|
125
|
+
}
|
126
|
+
|
127
|
+
virtual bool operator==(const std::pair<size_t,size_t>& ij) {
|
128
|
+
if (p() >= ija(real_shape(0))) return false;
|
129
|
+
else return i() == ij.first && j() == ij.second;
|
130
|
+
}
|
131
|
+
|
132
|
+
virtual bool operator==(const basic_iterator_T<D,RefType,YaleRef>& rhs) const {
|
133
|
+
return i() == rhs.i() && j() == rhs.j();
|
134
|
+
}
|
135
|
+
virtual bool operator!=(const basic_iterator_T<D,RefType,YaleRef>& rhs) const {
|
136
|
+
return i() != rhs.i() || j() != rhs.j();
|
137
|
+
}
|
138
|
+
};
|
139
|
+
|
140
|
+
|
141
|
+
} } // end of namespace nm::yale_storage
|
142
|
+
|
143
|
+
#endif // YALE_ITERATORS_BASE_H
|
@@ -0,0 +1,131 @@
|
|
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
|
+
// == iterator.h
|
25
|
+
//
|
26
|
+
// Iterate over yale as if dense
|
27
|
+
//
|
28
|
+
|
29
|
+
#ifndef YALE_ITERATORS_ITERATOR_H
|
30
|
+
# define YALE_ITERATORS_ITERATOR_H
|
31
|
+
|
32
|
+
#include <ruby.h>
|
33
|
+
#include <type_traits>
|
34
|
+
#include <typeinfo>
|
35
|
+
|
36
|
+
namespace nm { namespace yale_storage {
|
37
|
+
|
38
|
+
/*
|
39
|
+
* Iterator for traversing matrix class as if it were dense (visits each entry in order).
|
40
|
+
*/
|
41
|
+
template <typename D,
|
42
|
+
typename RefType,
|
43
|
+
typename YaleRef = typename std::conditional<
|
44
|
+
std::is_const<RefType>::value,
|
45
|
+
const nm::YaleStorage<D>,
|
46
|
+
nm::YaleStorage<D>
|
47
|
+
>::type>
|
48
|
+
class iterator_T : public basic_iterator_T<D,RefType,YaleRef> {
|
49
|
+
using basic_iterator_T<D,RefType,YaleRef>::i_;
|
50
|
+
using basic_iterator_T<D,RefType,YaleRef>::p_;
|
51
|
+
using basic_iterator_T<D,RefType,YaleRef>::y;
|
52
|
+
using basic_iterator_T<D,RefType,YaleRef>::offset;
|
53
|
+
using basic_iterator_T<D,RefType,YaleRef>::shape;
|
54
|
+
using basic_iterator_T<D,RefType,YaleRef>::ija;
|
55
|
+
|
56
|
+
protected:
|
57
|
+
size_t j_; // These are relative to the slice.
|
58
|
+
|
59
|
+
public:
|
60
|
+
// Create an iterator. May select the row since this is O(1).
|
61
|
+
iterator_T(YaleRef& obj, size_t ii = 0)
|
62
|
+
: basic_iterator_T<D,RefType,YaleRef>(obj, ii, obj.ija(ii + obj.offset(0))), j_(0)
|
63
|
+
{
|
64
|
+
// advance to the beginning of the row
|
65
|
+
if (obj.offset(1) > 0)
|
66
|
+
p_ = y.find_pos_for_insertion(i_,j_);
|
67
|
+
}
|
68
|
+
|
69
|
+
// Prefix ++
|
70
|
+
iterator_T<D,RefType,YaleRef>& operator++() {
|
71
|
+
size_t prev_j = j_++;
|
72
|
+
if (j_ >= shape(1)) {
|
73
|
+
j_ = 0;
|
74
|
+
++i_;
|
75
|
+
|
76
|
+
// Do a binary search to find the beginning of the slice
|
77
|
+
p_ = offset(0) > 0 ? y.find_pos_for_insertion(i_,j_) : ija(i_);
|
78
|
+
} else {
|
79
|
+
// If the last j was actually stored in this row of the matrix, need to advance p.
|
80
|
+
|
81
|
+
if (!y.real_row_empty(i_ + offset(0)) && ija(p_) <= prev_j + offset(1)) ++p_; // this test is the same as real_ndnz_exists
|
82
|
+
}
|
83
|
+
|
84
|
+
return *this;
|
85
|
+
}
|
86
|
+
|
87
|
+
iterator_T<D,RefType,YaleRef> operator++(int dummy) const {
|
88
|
+
iterator_T<D,RefType,YaleRef> iter(*this);
|
89
|
+
return ++iter;
|
90
|
+
}
|
91
|
+
|
92
|
+
virtual bool operator!=(const iterator_T<D,RefType,YaleRef>& rhs) const {
|
93
|
+
return this->dense_location() != rhs.dense_location();
|
94
|
+
}
|
95
|
+
|
96
|
+
virtual bool operator==(const iterator_T<D,RefType,YaleRef>& rhs) const {
|
97
|
+
return this->dense_location() == rhs.dense_location();
|
98
|
+
}
|
99
|
+
|
100
|
+
bool operator<(const iterator_T<D,RefType,YaleRef>& rhs) const {
|
101
|
+
return this->dense_location() < rhs.dense_location();
|
102
|
+
}
|
103
|
+
|
104
|
+
bool operator>(const iterator_T<D,RefType,YaleRef>& rhs) const {
|
105
|
+
return this->dense_location() > rhs.dense_location();
|
106
|
+
}
|
107
|
+
|
108
|
+
virtual bool diag() const { return i_ + offset(0) == j_ + offset(1); }
|
109
|
+
|
110
|
+
// De-reference
|
111
|
+
RefType& operator*() {
|
112
|
+
if (diag()) return y.a( i_ + offset(0) );
|
113
|
+
else if (p_ >= ija(i_+offset(0)+1)) return y.const_default_obj();
|
114
|
+
else if (!y.real_row_empty(i_ + offset(0)) && ija(p_) == j_ + offset(1)) return y.a( p_ );
|
115
|
+
else return y.const_default_obj();
|
116
|
+
}
|
117
|
+
|
118
|
+
RefType& operator*() const {
|
119
|
+
if (diag()) return y.a( i_ + offset(0) );
|
120
|
+
else if (p_ >= ija(i_+offset(0)+1)) return y.const_default_obj();
|
121
|
+
else if (!y.real_row_empty(i_ + offset(0)) && ija(p_) == j_ + offset(1)) return y.a( p_ );
|
122
|
+
else return y.const_default_obj();
|
123
|
+
}
|
124
|
+
|
125
|
+
virtual size_t j() const { return j_; }
|
126
|
+
};
|
127
|
+
|
128
|
+
|
129
|
+
} } // end of namespace nm::yale_storage
|
130
|
+
|
131
|
+
#endif // YALE_ITERATORS_ITERATOR_H
|