nmatrix-atlas 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/ext/nmatrix/data/complex.h +364 -0
- data/ext/nmatrix/data/data.h +638 -0
- data/ext/nmatrix/data/meta.h +64 -0
- data/ext/nmatrix/data/ruby_object.h +389 -0
- data/ext/nmatrix/math/asum.h +120 -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 +79 -0
- data/ext/nmatrix/math/laswp.h +165 -0
- data/ext/nmatrix/math/long_dtype.h +49 -0
- data/ext/nmatrix/math/math.h +744 -0
- data/ext/nmatrix/math/nrm2.h +160 -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 +332 -0
- data/ext/nmatrix/math/util.h +148 -0
- data/ext/nmatrix/nm_memory.h +60 -0
- data/ext/nmatrix/nmatrix.h +408 -0
- data/ext/nmatrix/ruby_constants.h +106 -0
- data/ext/nmatrix/storage/common.h +176 -0
- data/ext/nmatrix/storage/dense/dense.h +128 -0
- data/ext/nmatrix/storage/list/list.h +137 -0
- data/ext/nmatrix/storage/storage.h +98 -0
- data/ext/nmatrix/storage/yale/class.h +1139 -0
- data/ext/nmatrix/storage/yale/iterators/base.h +142 -0
- data/ext/nmatrix/storage/yale/iterators/iterator.h +130 -0
- data/ext/nmatrix/storage/yale/iterators/row.h +449 -0
- data/ext/nmatrix/storage/yale/iterators/row_stored.h +139 -0
- data/ext/nmatrix/storage/yale/iterators/row_stored_nd.h +168 -0
- data/ext/nmatrix/storage/yale/iterators/stored_diagonal.h +123 -0
- data/ext/nmatrix/storage/yale/math/transpose.h +110 -0
- data/ext/nmatrix/storage/yale/yale.h +202 -0
- data/ext/nmatrix/types.h +54 -0
- data/ext/nmatrix/util/io.h +115 -0
- data/ext/nmatrix/util/sl_list.h +143 -0
- data/ext/nmatrix/util/util.h +78 -0
- data/ext/nmatrix_atlas/extconf.rb +250 -0
- data/ext/nmatrix_atlas/math_atlas.cpp +1206 -0
- data/ext/nmatrix_atlas/math_atlas/cblas_templates_atlas.h +72 -0
- data/ext/nmatrix_atlas/math_atlas/clapack_templates.h +332 -0
- data/ext/nmatrix_atlas/math_atlas/geev.h +82 -0
- data/ext/nmatrix_atlas/math_atlas/gesdd.h +83 -0
- data/ext/nmatrix_atlas/math_atlas/gesvd.h +81 -0
- data/ext/nmatrix_atlas/math_atlas/inc.h +47 -0
- data/ext/nmatrix_atlas/nmatrix_atlas.cpp +44 -0
- data/lib/nmatrix/atlas.rb +213 -0
- data/lib/nmatrix/lapack_ext_common.rb +69 -0
- data/spec/00_nmatrix_spec.rb +730 -0
- data/spec/01_enum_spec.rb +190 -0
- data/spec/02_slice_spec.rb +389 -0
- data/spec/03_nmatrix_monkeys_spec.rb +78 -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 +193 -0
- data/spec/elementwise_spec.rb +303 -0
- data/spec/homogeneous_spec.rb +99 -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 +149 -0
- data/spec/lapack_core_spec.rb +482 -0
- data/spec/leakcheck.rb +16 -0
- data/spec/math_spec.rb +730 -0
- data/spec/nmatrix_yale_resize_test_associations.yaml +2802 -0
- data/spec/nmatrix_yale_spec.rb +286 -0
- data/spec/plugins/atlas/atlas_spec.rb +242 -0
- data/spec/rspec_monkeys.rb +56 -0
- data/spec/rspec_spec.rb +34 -0
- data/spec/shortcuts_spec.rb +310 -0
- data/spec/slice_set_spec.rb +157 -0
- data/spec/spec_helper.rb +140 -0
- data/spec/stat_spec.rb +203 -0
- data/spec/test.pcd +20 -0
- data/spec/utm5940.mtx +83844 -0
- metadata +159 -0
@@ -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
|
+
// == data.h
|
25
|
+
//
|
26
|
+
// Header file for dealing with data types.
|
27
|
+
|
28
|
+
#ifndef RUBY_CONSTANTS_H
|
29
|
+
#define RUBY_CONSTANTS_H
|
30
|
+
|
31
|
+
/*
|
32
|
+
* Standard Includes
|
33
|
+
*/
|
34
|
+
|
35
|
+
#include <ruby.h>
|
36
|
+
|
37
|
+
/*
|
38
|
+
* Data
|
39
|
+
*/
|
40
|
+
|
41
|
+
extern ID nm_rb_dtype,
|
42
|
+
nm_rb_stype,
|
43
|
+
|
44
|
+
nm_rb_capacity,
|
45
|
+
nm_rb_default,
|
46
|
+
|
47
|
+
nm_rb_real,
|
48
|
+
nm_rb_imag,
|
49
|
+
|
50
|
+
nm_rb_numer,
|
51
|
+
nm_rb_denom,
|
52
|
+
|
53
|
+
nm_rb_complex_conjugate,
|
54
|
+
nm_rb_transpose,
|
55
|
+
nm_rb_no_transpose,
|
56
|
+
nm_rb_left,
|
57
|
+
nm_rb_right,
|
58
|
+
nm_rb_upper,
|
59
|
+
nm_rb_lower,
|
60
|
+
nm_rb_unit,
|
61
|
+
nm_rb_nonunit,
|
62
|
+
|
63
|
+
nm_rb_dense,
|
64
|
+
nm_rb_list,
|
65
|
+
nm_rb_yale,
|
66
|
+
|
67
|
+
nm_rb_row,
|
68
|
+
nm_rb_column,
|
69
|
+
|
70
|
+
nm_rb_add,
|
71
|
+
nm_rb_sub,
|
72
|
+
nm_rb_mul,
|
73
|
+
nm_rb_div,
|
74
|
+
|
75
|
+
nm_rb_negate,
|
76
|
+
|
77
|
+
nm_rb_percent,
|
78
|
+
nm_rb_gt,
|
79
|
+
nm_rb_lt,
|
80
|
+
nm_rb_eql,
|
81
|
+
nm_rb_neql,
|
82
|
+
nm_rb_gte,
|
83
|
+
nm_rb_lte,
|
84
|
+
|
85
|
+
nm_rb_hash;
|
86
|
+
|
87
|
+
extern VALUE cNMatrix,
|
88
|
+
cNMatrix_IO,
|
89
|
+
cNMatrix_IO_Matlab,
|
90
|
+
cNMatrix_YaleFunctions,
|
91
|
+
|
92
|
+
cNMatrix_GC_holder,
|
93
|
+
|
94
|
+
nm_eDataTypeError,
|
95
|
+
nm_eConvergenceError,
|
96
|
+
nm_eStorageTypeError,
|
97
|
+
nm_eShapeError,
|
98
|
+
nm_eNotInvertibleError;
|
99
|
+
|
100
|
+
/*
|
101
|
+
* Functions
|
102
|
+
*/
|
103
|
+
|
104
|
+
void nm_init_ruby_constants(void);
|
105
|
+
|
106
|
+
#endif // RUBY_CONSTANTS_H
|
@@ -0,0 +1,176 @@
|
|
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
|
+
// == common.h
|
25
|
+
//
|
26
|
+
// Header file for code common to all storage types.
|
27
|
+
|
28
|
+
#ifndef STORAGE_COMMON_H
|
29
|
+
#define STORAGE_COMMON_H
|
30
|
+
|
31
|
+
/*
|
32
|
+
* Standard Includes
|
33
|
+
*/
|
34
|
+
|
35
|
+
#include <cmath> // pow().
|
36
|
+
|
37
|
+
/*
|
38
|
+
* Project Includes
|
39
|
+
*/
|
40
|
+
#include "data/data.h"
|
41
|
+
#include "nmatrix.h"
|
42
|
+
|
43
|
+
/*
|
44
|
+
* Macros
|
45
|
+
*/
|
46
|
+
|
47
|
+
extern "C" {
|
48
|
+
|
49
|
+
/*
|
50
|
+
* Types
|
51
|
+
*/
|
52
|
+
|
53
|
+
// For binary operations involving matrices that need to be casted.
|
54
|
+
struct STORAGE_PAIR {
|
55
|
+
STORAGE* left;
|
56
|
+
STORAGE* right;
|
57
|
+
};
|
58
|
+
|
59
|
+
struct SLICE {
|
60
|
+
size_t* coords; // Coordinate of first element
|
61
|
+
size_t* lengths; // Lengths of slice
|
62
|
+
bool single; // true if all lengths equal to 1 (represents single matrix element)
|
63
|
+
};
|
64
|
+
|
65
|
+
/*
|
66
|
+
* Data
|
67
|
+
*/
|
68
|
+
|
69
|
+
/*
|
70
|
+
* Functions
|
71
|
+
*/
|
72
|
+
|
73
|
+
size_t nm_storage_count_max_elements(const STORAGE* storage);
|
74
|
+
VALUE nm_enumerator_length(VALUE nmatrix);
|
75
|
+
|
76
|
+
} // end of extern "C" block
|
77
|
+
|
78
|
+
namespace nm {
|
79
|
+
|
80
|
+
/*
|
81
|
+
* Templated helper function for element-wise operations, used by dense, yale, and list.
|
82
|
+
*/
|
83
|
+
template <ewop_t op, typename LDType, typename RDType>
|
84
|
+
inline VALUE ew_op_switch(LDType left, RDType right) {
|
85
|
+
switch (op) {
|
86
|
+
case EW_ADD:
|
87
|
+
return RubyObject(left + right).rval;
|
88
|
+
|
89
|
+
case EW_SUB:
|
90
|
+
return RubyObject(left - right).rval;
|
91
|
+
|
92
|
+
case EW_MUL:
|
93
|
+
return RubyObject(left * right).rval;
|
94
|
+
|
95
|
+
case EW_DIV:
|
96
|
+
return RubyObject(left / right).rval;
|
97
|
+
|
98
|
+
case EW_POW:
|
99
|
+
return RubyObject(pow(left, right)).rval;
|
100
|
+
|
101
|
+
case EW_MOD:
|
102
|
+
rb_raise(rb_eNotImpError, "Element-wise modulo is currently not supported.");
|
103
|
+
break;
|
104
|
+
|
105
|
+
default:
|
106
|
+
rb_raise(rb_eStandardError, "This should not happen.");
|
107
|
+
}
|
108
|
+
return Qnil;
|
109
|
+
}
|
110
|
+
|
111
|
+
#define EWOP_INT_INT_DIV(ltype, rtype) template <> \
|
112
|
+
inline VALUE ew_op_switch<EW_DIV>( ltype left, rtype right) { \
|
113
|
+
if (right == 0) rb_raise(rb_eZeroDivError, "cannot divide type by 0, would throw SIGFPE"); \
|
114
|
+
if ((left > 0 && right > 0) || (left < 0 && right < 0)) \
|
115
|
+
return left / right; \
|
116
|
+
else \
|
117
|
+
return ( ltype )(std::floor((double)(left) / (double)(right))); \
|
118
|
+
}
|
119
|
+
|
120
|
+
#define EWOP_UINT_UINT_DIV(ltype, rtype) template <> \
|
121
|
+
inline VALUE ew_op_switch<EW_DIV>( ltype left, rtype right) { \
|
122
|
+
if (right == 0) rb_raise(rb_eZeroDivError, "cannot divide type by 0, would throw SIGFPE"); \
|
123
|
+
return left / right; \
|
124
|
+
}
|
125
|
+
|
126
|
+
#define EWOP_INT_UINT_DIV(ltype, rtype) template <> \
|
127
|
+
inline VALUE ew_op_switch<EW_DIV>( ltype left, rtype right) { \
|
128
|
+
if (right == 0) rb_raise(rb_eZeroDivError, "cannot divide type by 0, would throw SIGFPE"); \
|
129
|
+
if (left > 0 ) return left / right; \
|
130
|
+
else return ( ltype )(std::floor((double)(left) / (double)(right))); \
|
131
|
+
}
|
132
|
+
|
133
|
+
#define EWOP_UINT_INT_DIV(ltype, rtype) template <> \
|
134
|
+
inline VALUE ew_op_switch<EW_DIV>( ltype left, rtype right) { \
|
135
|
+
if (right == 0) rb_raise(rb_eZeroDivError, "cannot divide type by 0, would throw SIGFPE"); \
|
136
|
+
if (right > 0) return left / right; \
|
137
|
+
else return ( ltype )(std::floor((double)(left) / (double)(right))); \
|
138
|
+
}
|
139
|
+
|
140
|
+
#define EWOP_FLOAT_INT_DIV(ltype, rtype) template <> \
|
141
|
+
inline VALUE ew_op_switch<EW_DIV>( ltype left, rtype right) { \
|
142
|
+
return left / (ltype)(right); \
|
143
|
+
}
|
144
|
+
|
145
|
+
// Ensure that divisions are done in the Ruby way, and that (int)x/0 always raises a Ruby error instead
|
146
|
+
// of throwing a SIGFPE.
|
147
|
+
EWOP_INT_INT_DIV(int64_t, int64_t)
|
148
|
+
EWOP_INT_INT_DIV(int32_t, int32_t)
|
149
|
+
EWOP_INT_INT_DIV(int32_t, int64_t)
|
150
|
+
EWOP_INT_INT_DIV(int16_t, int16_t)
|
151
|
+
EWOP_INT_INT_DIV(int16_t, int32_t)
|
152
|
+
EWOP_INT_INT_DIV(int16_t, int64_t)
|
153
|
+
EWOP_INT_INT_DIV(int8_t, int8_t)
|
154
|
+
EWOP_INT_UINT_DIV(int8_t, u_int8_t)
|
155
|
+
EWOP_INT_INT_DIV(int8_t, int16_t)
|
156
|
+
EWOP_INT_INT_DIV(int8_t, int32_t)
|
157
|
+
EWOP_INT_INT_DIV(int8_t, int64_t)
|
158
|
+
EWOP_UINT_UINT_DIV(uint8_t, uint8_t)
|
159
|
+
EWOP_UINT_INT_DIV(uint8_t, int8_t)
|
160
|
+
EWOP_UINT_INT_DIV(uint8_t, int16_t)
|
161
|
+
EWOP_UINT_INT_DIV(uint8_t, int32_t)
|
162
|
+
EWOP_UINT_INT_DIV(uint8_t, int64_t)
|
163
|
+
EWOP_FLOAT_INT_DIV(float, int8_t)
|
164
|
+
EWOP_FLOAT_INT_DIV(float, u_int8_t)
|
165
|
+
EWOP_FLOAT_INT_DIV(float, int16_t)
|
166
|
+
EWOP_FLOAT_INT_DIV(float, int32_t)
|
167
|
+
EWOP_FLOAT_INT_DIV(float, int64_t)
|
168
|
+
EWOP_FLOAT_INT_DIV(double, int8_t)
|
169
|
+
EWOP_FLOAT_INT_DIV(double, u_int8_t)
|
170
|
+
EWOP_FLOAT_INT_DIV(double, int16_t)
|
171
|
+
EWOP_FLOAT_INT_DIV(double, int32_t)
|
172
|
+
EWOP_FLOAT_INT_DIV(double, int64_t)
|
173
|
+
|
174
|
+
}
|
175
|
+
|
176
|
+
#endif // STORAGE_COMMON_H
|
@@ -0,0 +1,128 @@
|
|
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
|
+
// == dense.h
|
25
|
+
//
|
26
|
+
// Dense n-dimensional matrix storage.
|
27
|
+
|
28
|
+
#ifndef DENSE_H
|
29
|
+
#define DENSE_H
|
30
|
+
|
31
|
+
/*
|
32
|
+
* Standard Includes
|
33
|
+
*/
|
34
|
+
|
35
|
+
#include <stdlib.h>
|
36
|
+
|
37
|
+
/*
|
38
|
+
* Project Includes
|
39
|
+
*/
|
40
|
+
|
41
|
+
#include "types.h"
|
42
|
+
//#include "util/math.h"
|
43
|
+
|
44
|
+
#include "data/data.h"
|
45
|
+
|
46
|
+
#include "../common.h"
|
47
|
+
|
48
|
+
#include "nmatrix.h"
|
49
|
+
|
50
|
+
/*
|
51
|
+
* Macros
|
52
|
+
*/
|
53
|
+
|
54
|
+
/*
|
55
|
+
* Types
|
56
|
+
*/
|
57
|
+
|
58
|
+
/*
|
59
|
+
* Data
|
60
|
+
*/
|
61
|
+
|
62
|
+
extern "C" {
|
63
|
+
|
64
|
+
/*
|
65
|
+
* Functions
|
66
|
+
*/
|
67
|
+
|
68
|
+
///////////////
|
69
|
+
// Lifecycle //
|
70
|
+
///////////////
|
71
|
+
|
72
|
+
DENSE_STORAGE* nm_dense_storage_create(nm::dtype_t dtype, size_t* shape, size_t dim, void* elements, size_t elements_length);
|
73
|
+
void nm_dense_storage_delete(STORAGE* s);
|
74
|
+
void nm_dense_storage_delete_ref(STORAGE* s);
|
75
|
+
void nm_dense_storage_mark(STORAGE*);
|
76
|
+
void nm_dense_storage_register(const STORAGE* s);
|
77
|
+
void nm_dense_storage_unregister(const STORAGE* s);
|
78
|
+
|
79
|
+
|
80
|
+
///////////////
|
81
|
+
// Accessors //
|
82
|
+
///////////////
|
83
|
+
|
84
|
+
|
85
|
+
VALUE nm_dense_map_pair(VALUE self, VALUE right);
|
86
|
+
VALUE nm_dense_map(VALUE self);
|
87
|
+
VALUE nm_dense_each(VALUE nmatrix);
|
88
|
+
VALUE nm_dense_each_with_indices(VALUE nmatrix);
|
89
|
+
void* nm_dense_storage_get(const STORAGE* s, SLICE* slice);
|
90
|
+
void* nm_dense_storage_ref(const STORAGE* s, SLICE* slice);
|
91
|
+
void nm_dense_storage_set(VALUE left, SLICE* slice, VALUE right);
|
92
|
+
|
93
|
+
///////////
|
94
|
+
// Tests //
|
95
|
+
///////////
|
96
|
+
|
97
|
+
bool nm_dense_storage_eqeq(const STORAGE* left, const STORAGE* right);
|
98
|
+
bool nm_dense_storage_is_symmetric(const DENSE_STORAGE* mat, int lda);
|
99
|
+
bool nm_dense_storage_is_hermitian(const DENSE_STORAGE* mat, int lda);
|
100
|
+
|
101
|
+
//////////
|
102
|
+
// Math //
|
103
|
+
//////////
|
104
|
+
|
105
|
+
STORAGE* nm_dense_storage_matrix_multiply(const STORAGE_PAIR& casted_storage, size_t* resulting_shape, bool vector);
|
106
|
+
|
107
|
+
/////////////
|
108
|
+
// Utility //
|
109
|
+
/////////////
|
110
|
+
|
111
|
+
size_t nm_dense_storage_pos(const DENSE_STORAGE* s, const size_t* coords);
|
112
|
+
void nm_dense_storage_coords(const DENSE_STORAGE* s, const size_t slice_pos, size_t* coords_out);
|
113
|
+
|
114
|
+
/////////////////////////
|
115
|
+
// Copying and Casting //
|
116
|
+
/////////////////////////
|
117
|
+
|
118
|
+
DENSE_STORAGE* nm_dense_storage_copy(const DENSE_STORAGE* rhs);
|
119
|
+
STORAGE* nm_dense_storage_copy_transposed(const STORAGE* rhs_base);
|
120
|
+
STORAGE* nm_dense_storage_cast_copy(const STORAGE* rhs, nm::dtype_t new_dtype, void*);
|
121
|
+
|
122
|
+
} // end of extern "C" block
|
123
|
+
|
124
|
+
namespace nm {
|
125
|
+
std::pair<NMATRIX*,bool> interpret_arg_as_dense_nmatrix(VALUE right, nm::dtype_t dtype);
|
126
|
+
} // end of namespace nm
|
127
|
+
|
128
|
+
#endif // DENSE_H
|
@@ -0,0 +1,137 @@
|
|
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
|
+
// == list.h
|
25
|
+
//
|
26
|
+
// List-of-lists n-dimensional matrix storage. Uses singly-linked
|
27
|
+
// lists.
|
28
|
+
|
29
|
+
#ifndef LIST_H
|
30
|
+
#define LIST_H
|
31
|
+
|
32
|
+
/*
|
33
|
+
* Standard Includes
|
34
|
+
*/
|
35
|
+
|
36
|
+
#include <stdlib.h>
|
37
|
+
#include <list>
|
38
|
+
/*
|
39
|
+
* Project Includes
|
40
|
+
*/
|
41
|
+
|
42
|
+
#include "types.h"
|
43
|
+
#include "data/data.h"
|
44
|
+
#include "../common.h"
|
45
|
+
#include "util/sl_list.h"
|
46
|
+
#include "nmatrix.h"
|
47
|
+
|
48
|
+
/*
|
49
|
+
* Macros
|
50
|
+
*/
|
51
|
+
|
52
|
+
/*
|
53
|
+
* Types
|
54
|
+
*/
|
55
|
+
|
56
|
+
|
57
|
+
|
58
|
+
/*
|
59
|
+
* Data
|
60
|
+
*/
|
61
|
+
|
62
|
+
extern "C" {
|
63
|
+
|
64
|
+
/*
|
65
|
+
* Functions
|
66
|
+
*/
|
67
|
+
|
68
|
+
////////////////
|
69
|
+
// Lifecycle //
|
70
|
+
///////////////
|
71
|
+
|
72
|
+
LIST_STORAGE* nm_list_storage_create(nm::dtype_t dtype, size_t* shape, size_t dim, void* init_val);
|
73
|
+
void nm_list_storage_delete(STORAGE* s);
|
74
|
+
void nm_list_storage_delete_ref(STORAGE* s);
|
75
|
+
void nm_list_storage_mark(STORAGE*);
|
76
|
+
void nm_list_storage_register(const STORAGE* s);
|
77
|
+
void nm_list_storage_unregister(const STORAGE* s);
|
78
|
+
void nm_list_storage_register_list(const LIST* l, size_t recursions);
|
79
|
+
void nm_list_storage_unregister_list(const LIST* l, size_t recursions);
|
80
|
+
void nm_list_storage_register_node(const NODE* n);
|
81
|
+
void nm_list_storage_unregister_node(const NODE* n);
|
82
|
+
void nm_list_storage_completely_unregister_node(const NODE* curr);
|
83
|
+
///////////////
|
84
|
+
// Accessors //
|
85
|
+
///////////////
|
86
|
+
|
87
|
+
VALUE nm_list_each_with_indices(VALUE nmatrix, bool stored);
|
88
|
+
void* nm_list_storage_ref(const STORAGE* s, SLICE* slice);
|
89
|
+
void* nm_list_storage_get(const STORAGE* s, SLICE* slice);
|
90
|
+
NODE* nm_list_storage_insert(STORAGE* s, SLICE* slice, void* val);
|
91
|
+
void nm_list_storage_set(VALUE left, SLICE* slice, VALUE right);
|
92
|
+
void nm_list_storage_remove(STORAGE* s, SLICE* slice);
|
93
|
+
|
94
|
+
///////////
|
95
|
+
// Tests //
|
96
|
+
///////////
|
97
|
+
|
98
|
+
bool nm_list_storage_eqeq(const STORAGE* left, const STORAGE* right);
|
99
|
+
|
100
|
+
//////////
|
101
|
+
// Math //
|
102
|
+
//////////
|
103
|
+
|
104
|
+
STORAGE* nm_list_storage_matrix_multiply(const STORAGE_PAIR& casted_storage, size_t* resulting_shape, bool vector);
|
105
|
+
|
106
|
+
|
107
|
+
/////////////
|
108
|
+
// Utility //
|
109
|
+
/////////////
|
110
|
+
|
111
|
+
size_t nm_list_storage_count_elements_r(const LIST* l, size_t recursions);
|
112
|
+
size_t nm_list_storage_count_nd_elements(const LIST_STORAGE* s);
|
113
|
+
|
114
|
+
/*
|
115
|
+
* Count non-zero elements. See also count_list_storage_nd_elements.
|
116
|
+
*/
|
117
|
+
inline size_t nm_list_storage_count_elements(const LIST_STORAGE* s) {
|
118
|
+
return nm_list_storage_count_elements_r(s->rows, s->dim - 1);
|
119
|
+
}
|
120
|
+
|
121
|
+
/////////////////////////
|
122
|
+
// Copying and Casting //
|
123
|
+
/////////////////////////
|
124
|
+
|
125
|
+
LIST_STORAGE* nm_list_storage_copy(const LIST_STORAGE* rhs);
|
126
|
+
STORAGE* nm_list_storage_copy_transposed(const STORAGE* rhs_base);
|
127
|
+
STORAGE* nm_list_storage_cast_copy(const STORAGE* rhs, nm::dtype_t new_dtype, void*);
|
128
|
+
VALUE nm_list_storage_to_hash(const LIST_STORAGE* s, const nm::dtype_t dtype);
|
129
|
+
|
130
|
+
// Exposed functions
|
131
|
+
VALUE nm_to_hash(VALUE self);
|
132
|
+
VALUE nm_list_map_merged_stored(VALUE left, VALUE right, VALUE init);
|
133
|
+
VALUE nm_list_map_stored(VALUE left, VALUE init);
|
134
|
+
VALUE nm_list_default_value(VALUE self);
|
135
|
+
} // end of extern "C" block
|
136
|
+
|
137
|
+
#endif // LIST_H
|