nmatrix-fftw 0.2.1
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 +388 -0
- data/ext/nmatrix/data/data.h +652 -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 +745 -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 +438 -0
- data/ext/nmatrix/ruby_constants.h +106 -0
- data/ext/nmatrix/storage/common.h +177 -0
- data/ext/nmatrix/storage/dense/dense.h +129 -0
- data/ext/nmatrix/storage/list/list.h +138 -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.h +203 -0
- data/ext/nmatrix/types.h +55 -0
- data/ext/nmatrix/util/io.h +115 -0
- data/ext/nmatrix/util/sl_list.h +144 -0
- data/ext/nmatrix/util/util.h +78 -0
- data/ext/nmatrix_fftw/extconf.rb +122 -0
- data/ext/nmatrix_fftw/nmatrix_fftw.cpp +274 -0
- data/lib/nmatrix/fftw.rb +343 -0
- data/spec/00_nmatrix_spec.rb +736 -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 +807 -0
- data/spec/nmatrix_yale_resize_test_associations.yaml +2802 -0
- data/spec/nmatrix_yale_spec.rb +286 -0
- data/spec/plugins/fftw/fftw_spec.rb +348 -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 +149 -0
- data/spec/stat_spec.rb +203 -0
- data/spec/test.pcd +20 -0
- data/spec/utm5940.mtx +83844 -0
- metadata +151 -0
@@ -0,0 +1,203 @@
|
|
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
|
+
// == yale.h
|
25
|
+
//
|
26
|
+
// "new yale" storage format for 2D matrices (like yale, but with
|
27
|
+
// the diagonal pulled out for O(1) access).
|
28
|
+
//
|
29
|
+
// Specifications:
|
30
|
+
// * dtype and index dtype must necessarily differ
|
31
|
+
// * index dtype is defined by whatever unsigned type can store
|
32
|
+
// max(rows,cols)
|
33
|
+
// * that means vector ija stores only index dtype, but a stores
|
34
|
+
// dtype
|
35
|
+
// * vectors must be able to grow as necessary
|
36
|
+
// * maximum size is rows*cols+1
|
37
|
+
|
38
|
+
#ifndef YALE_H
|
39
|
+
#define YALE_H
|
40
|
+
|
41
|
+
/*
|
42
|
+
* Standard Includes
|
43
|
+
*/
|
44
|
+
|
45
|
+
#include <ruby.h>
|
46
|
+
#include <limits> // for std::numeric_limits<T>::max()
|
47
|
+
#include <stdexcept>
|
48
|
+
|
49
|
+
/*
|
50
|
+
* Project Includes
|
51
|
+
*/
|
52
|
+
|
53
|
+
#include "../../types.h"
|
54
|
+
#include "../../data/data.h"
|
55
|
+
#include "../common.h"
|
56
|
+
#include "../../nmatrix.h"
|
57
|
+
|
58
|
+
extern "C" {
|
59
|
+
|
60
|
+
/*
|
61
|
+
* Macros
|
62
|
+
*/
|
63
|
+
|
64
|
+
#ifndef NM_CHECK_ALLOC
|
65
|
+
#define NM_CHECK_ALLOC(x) if (!x) rb_raise(rb_eNoMemError, "insufficient memory");
|
66
|
+
#endif
|
67
|
+
|
68
|
+
/*
|
69
|
+
* Types
|
70
|
+
*/
|
71
|
+
|
72
|
+
|
73
|
+
/*
|
74
|
+
* Data
|
75
|
+
*/
|
76
|
+
|
77
|
+
|
78
|
+
/*
|
79
|
+
* Functions
|
80
|
+
*/
|
81
|
+
|
82
|
+
///////////////
|
83
|
+
// Lifecycle //
|
84
|
+
///////////////
|
85
|
+
|
86
|
+
YALE_STORAGE* nm_yale_storage_create(nm::dtype_t dtype, size_t* shape, size_t dim, size_t init_capacity);
|
87
|
+
YALE_STORAGE* nm_yale_storage_create_from_old_yale(nm::dtype_t dtype, size_t* shape, char* ia, char* ja, char* a, nm::dtype_t from_dtype);
|
88
|
+
YALE_STORAGE* nm_yale_storage_create_merged(const YALE_STORAGE* merge_template, const YALE_STORAGE* other);
|
89
|
+
void nm_yale_storage_delete(STORAGE* s);
|
90
|
+
void nm_yale_storage_delete_ref(STORAGE* s);
|
91
|
+
void nm_yale_storage_init(YALE_STORAGE* s, void* default_val);
|
92
|
+
void nm_yale_storage_mark(STORAGE*);
|
93
|
+
void nm_yale_storage_register(const STORAGE* s);
|
94
|
+
void nm_yale_storage_unregister(const STORAGE* s);
|
95
|
+
void nm_yale_storage_register_a(void* a, size_t size);
|
96
|
+
void nm_yale_storage_unregister_a(void* a, size_t size);
|
97
|
+
|
98
|
+
///////////////
|
99
|
+
// Accessors //
|
100
|
+
///////////////
|
101
|
+
|
102
|
+
VALUE nm_yale_each_with_indices(VALUE nmatrix);
|
103
|
+
VALUE nm_yale_each_stored_with_indices(VALUE nmatrix);
|
104
|
+
VALUE nm_yale_stored_diagonal_each_with_indices(VALUE nmatrix);
|
105
|
+
VALUE nm_yale_stored_nondiagonal_each_with_indices(VALUE nmatrix);
|
106
|
+
VALUE nm_yale_each_ordered_stored_with_indices(VALUE nmatrix);
|
107
|
+
void* nm_yale_storage_get(const STORAGE* s, SLICE* slice);
|
108
|
+
void* nm_yale_storage_ref(const STORAGE* s, SLICE* slice);
|
109
|
+
void nm_yale_storage_set(VALUE left, SLICE* slice, VALUE right);
|
110
|
+
|
111
|
+
//char nm_yale_storage_vector_insert(YALE_STORAGE* s, size_t pos, size_t* js, void* vals, size_t n, bool struct_only, nm::dtype_t dtype, nm::itype_t itype);
|
112
|
+
//void nm_yale_storage_increment_ia_after(YALE_STORAGE* s, size_t ija_size, size_t i, size_t n);
|
113
|
+
|
114
|
+
size_t nm_yale_storage_get_size(const YALE_STORAGE* storage);
|
115
|
+
VALUE nm_yale_default_value(VALUE self);
|
116
|
+
VALUE nm_yale_map_stored(VALUE self);
|
117
|
+
VALUE nm_yale_map_merged_stored(VALUE left, VALUE right, VALUE init);
|
118
|
+
|
119
|
+
///////////
|
120
|
+
// Tests //
|
121
|
+
///////////
|
122
|
+
|
123
|
+
bool nm_yale_storage_eqeq(const STORAGE* left, const STORAGE* right);
|
124
|
+
|
125
|
+
//////////
|
126
|
+
// Math //
|
127
|
+
//////////
|
128
|
+
|
129
|
+
STORAGE* nm_yale_storage_matrix_multiply(const STORAGE_PAIR& casted_storage, size_t* resulting_shape, bool vector);
|
130
|
+
|
131
|
+
/////////////
|
132
|
+
// Utility //
|
133
|
+
/////////////
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
/////////////////////////
|
138
|
+
// Copying and Casting //
|
139
|
+
/////////////////////////
|
140
|
+
|
141
|
+
STORAGE* nm_yale_storage_cast_copy(const STORAGE* rhs, nm::dtype_t new_dtype, void*);
|
142
|
+
STORAGE* nm_yale_storage_copy_transposed(const STORAGE* rhs_base);
|
143
|
+
|
144
|
+
|
145
|
+
|
146
|
+
void nm_init_yale_functions(void);
|
147
|
+
|
148
|
+
VALUE nm_vector_set(int argc, VALUE* argv, VALUE self);
|
149
|
+
|
150
|
+
|
151
|
+
} // end of extern "C" block
|
152
|
+
|
153
|
+
namespace nm {
|
154
|
+
|
155
|
+
namespace yale_storage {
|
156
|
+
|
157
|
+
/*
|
158
|
+
* Typedefs
|
159
|
+
*/
|
160
|
+
|
161
|
+
typedef size_t IType;
|
162
|
+
|
163
|
+
|
164
|
+
/*
|
165
|
+
* Templated Functions
|
166
|
+
*/
|
167
|
+
|
168
|
+
int binary_search(YALE_STORAGE* s, IType left, IType right, IType key);
|
169
|
+
|
170
|
+
/*
|
171
|
+
* Clear out the D portion of the A vector (clearing the diagonal and setting
|
172
|
+
* the zero value).
|
173
|
+
*
|
174
|
+
* Note: This sets a literal 0 value. If your dtype is RUBYOBJ (a Ruby object),
|
175
|
+
* it'll actually be INT2FIX(0) instead of a string of NULLs. You can actually
|
176
|
+
* set a default for Ruby objects other than zero -- you generally want it to
|
177
|
+
* be Qfalse, Qnil, or INT2FIX(0). The last is the default.
|
178
|
+
*/
|
179
|
+
template <typename DType>
|
180
|
+
inline void clear_diagonal_and_zero(YALE_STORAGE* s, void* init_val) {
|
181
|
+
DType* a = reinterpret_cast<DType*>(s->a);
|
182
|
+
|
183
|
+
// Clear out the diagonal + one extra entry
|
184
|
+
if (init_val) {
|
185
|
+
for (size_t i = 0; i <= s->shape[0]; ++i) // insert Ruby zeros, falses, or whatever else.
|
186
|
+
a[i] = *reinterpret_cast<DType*>(init_val);
|
187
|
+
} else {
|
188
|
+
for (size_t i = 0; i <= s->shape[0]; ++i) // insert zeros.
|
189
|
+
a[i] = 0;
|
190
|
+
}
|
191
|
+
}
|
192
|
+
|
193
|
+
template <typename DType>
|
194
|
+
void init(YALE_STORAGE* s, void* init_val);
|
195
|
+
|
196
|
+
size_t get_size(const YALE_STORAGE* storage);
|
197
|
+
|
198
|
+
IType binary_search_left_boundary(const YALE_STORAGE* s, IType left, IType right, IType bound);
|
199
|
+
|
200
|
+
|
201
|
+
}} // end of namespace nm::yale_storage
|
202
|
+
|
203
|
+
#endif // YALE_H
|
data/ext/nmatrix/types.h
ADDED
@@ -0,0 +1,55 @@
|
|
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
|
+
// == types.h
|
25
|
+
//
|
26
|
+
// Definition of simple types used throughout NMatrix.
|
27
|
+
|
28
|
+
#ifndef NMATRIX_TYPES_H
|
29
|
+
#define NMATRIX_TYPES_H
|
30
|
+
|
31
|
+
/*
|
32
|
+
* Standard Includes
|
33
|
+
*/
|
34
|
+
|
35
|
+
#include <ruby.h>
|
36
|
+
#include <cstdint>
|
37
|
+
|
38
|
+
/*
|
39
|
+
* Macros
|
40
|
+
*/
|
41
|
+
|
42
|
+
#define EPSILON 1E-10
|
43
|
+
#define FP_IS_ZERO(n) (-EPSILON < n && n < EPSILON)
|
44
|
+
#define FP_EQUAL(a, b) FP_IS_ZERO((a - b))
|
45
|
+
|
46
|
+
/*
|
47
|
+
* Types
|
48
|
+
*/
|
49
|
+
|
50
|
+
typedef float float32_t;
|
51
|
+
typedef double float64_t;
|
52
|
+
|
53
|
+
typedef size_t IType;
|
54
|
+
|
55
|
+
#endif
|
@@ -0,0 +1,115 @@
|
|
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
|
+
// == io.h
|
25
|
+
//
|
26
|
+
// Header file for input/output support functions.
|
27
|
+
|
28
|
+
#ifndef NMATRIX_IO_H
|
29
|
+
#define NMATRIX_IO_H
|
30
|
+
|
31
|
+
/*
|
32
|
+
* Project Includes
|
33
|
+
*/
|
34
|
+
|
35
|
+
#include "nmatrix.h"
|
36
|
+
|
37
|
+
#include "data/data.h"
|
38
|
+
#include "storage/storage.h"
|
39
|
+
|
40
|
+
/*
|
41
|
+
* Extern Types
|
42
|
+
*/
|
43
|
+
extern const char* const DTYPE_NAMES[nm::NUM_DTYPES];
|
44
|
+
|
45
|
+
namespace nm { namespace io {
|
46
|
+
/*
|
47
|
+
* Types
|
48
|
+
*/
|
49
|
+
enum matlab_dtype_t {
|
50
|
+
miINT8 = 1,
|
51
|
+
miUINT8 = 2,
|
52
|
+
miINT16 = 3,
|
53
|
+
miUINT16 = 4,
|
54
|
+
miINT32 = 5,
|
55
|
+
miUINT32 = 6,
|
56
|
+
miSINGLE = 7,
|
57
|
+
miDOUBLE = 9,
|
58
|
+
miINT64 = 12,
|
59
|
+
miUINT64 = 13,
|
60
|
+
miMATRIX = 14
|
61
|
+
};
|
62
|
+
|
63
|
+
/*
|
64
|
+
* Constants
|
65
|
+
*/
|
66
|
+
|
67
|
+
const size_t NUM_MATLAB_DTYPES = 15;
|
68
|
+
}} // end of namespace nm::io
|
69
|
+
|
70
|
+
extern "C" {
|
71
|
+
|
72
|
+
/*
|
73
|
+
* C accessors.
|
74
|
+
*/
|
75
|
+
nm::dtype_t nm_dtype_from_rbsymbol(VALUE sym);
|
76
|
+
nm::dtype_t nm_dtype_from_rbstring(VALUE str);
|
77
|
+
nm::stype_t nm_stype_from_rbsymbol(VALUE sym);
|
78
|
+
nm::stype_t nm_stype_from_rbstring(VALUE str);
|
79
|
+
|
80
|
+
void nm_init_io(void);
|
81
|
+
|
82
|
+
|
83
|
+
/*
|
84
|
+
* Macros.
|
85
|
+
*/
|
86
|
+
|
87
|
+
/*
|
88
|
+
* Macro for a function pointer table between NMatrix dtypes and MATLAB dtypes.
|
89
|
+
*
|
90
|
+
* You can't convert as freely between these two as you can between NMatrix dtypes, but there's no reason to. MATLAB
|
91
|
+
* stores its complex numbers in two separate arrays, for example, not as a single unit of data. If you want to convert
|
92
|
+
* to a VALUE, convert first to an appropriate integer or float type.
|
93
|
+
*
|
94
|
+
* FIXME: Maybe be a little more selective about which conversions we DO allow. This is really just for loading an
|
95
|
+
* already-constructed MATLAB matrix into memory, and most of these functions will never get called.
|
96
|
+
*/
|
97
|
+
#define NM_MATLAB_DTYPE_TEMPLATE_TABLE(name,fun,ret,...) \
|
98
|
+
static ret (*(name)[7][nm::io::NUM_MATLAB_DTYPES])(__VA_ARGS__) = { \
|
99
|
+
{ NULL, fun<uint8_t,int8_t>, fun<uint8_t,uint8_t>, fun<uint8_t,int16_t>, fun<uint8_t,uint16_t>, fun<uint8_t,int32_t>, fun<uint8_t,uint32_t>, fun<uint8_t,float>, NULL, fun<uint8_t,double>, NULL, NULL, fun<uint8_t,int64_t>, fun<uint8_t,uint64_t>, NULL }, \
|
100
|
+
{ NULL, fun<int8_t,int8_t>, fun<int8_t,uint8_t>, fun<int8_t,int16_t>, fun<int8_t,uint16_t>, fun<int8_t,int32_t>, fun<int8_t,uint32_t>, fun<int8_t,float>, NULL, fun<int8_t,double>, NULL, NULL, fun<int8_t,int64_t>, fun<int8_t,uint64_t>, NULL }, \
|
101
|
+
{ NULL, fun<int16_t,int8_t>, fun<int16_t,uint8_t>, fun<int16_t,int16_t>, fun<int16_t,uint16_t>, fun<int16_t,int32_t>, fun<int16_t,uint32_t>, fun<int16_t,float>, NULL, fun<int16_t,double>, NULL, NULL, fun<int16_t,int64_t>, fun<int16_t,uint64_t>, NULL }, \
|
102
|
+
{ NULL, fun<int32_t,int8_t>, fun<int32_t,uint8_t>, fun<int32_t,int16_t>, fun<int32_t,uint16_t>, fun<int32_t,int32_t>, fun<int32_t,uint32_t>, fun<int32_t,float>, NULL, fun<int32_t,double>, NULL, NULL, fun<int32_t,int64_t>, fun<int32_t,uint64_t>, NULL }, \
|
103
|
+
{ NULL, fun<int64_t,int8_t>, fun<int64_t,uint8_t>, fun<int64_t,int16_t>, fun<int64_t,uint16_t>, fun<int64_t,int32_t>, fun<int64_t,uint32_t>, fun<int64_t,float>, NULL, fun<int64_t,double>, NULL, NULL, fun<int64_t,int64_t>, fun<int64_t,uint64_t>, NULL }, \
|
104
|
+
{ NULL, fun<float,int8_t>, fun<float,uint8_t>, fun<float,int16_t>, fun<float,uint16_t>, fun<float,int32_t>, fun<float,uint32_t>, fun<float,float>, NULL, fun<float,double>, NULL, NULL, fun<float,int64_t>, fun<float,uint64_t>, NULL }, \
|
105
|
+
{ NULL, fun<double,int8_t>, fun<double,uint8_t>, fun<double,int16_t>, fun<double,uint16_t>, fun<double,int32_t>, fun<double,uint32_t>, fun<double,float>, NULL, fun<double,double>, NULL, NULL, fun<double,int64_t>, fun<double,uint64_t>, NULL } \
|
106
|
+
};
|
107
|
+
|
108
|
+
/*
|
109
|
+
* Hash#has_key? for symbols. Arguments are: hash (VALUE), string (char*).
|
110
|
+
*/
|
111
|
+
#define RB_HASH_HAS_SYMBOL_KEY(hash, str) (rb_funcall((hash), rb_intern("has_key?"), 1, ID2SYM(rb_intern(str))) == Qtrue)
|
112
|
+
}
|
113
|
+
|
114
|
+
|
115
|
+
#endif
|
@@ -0,0 +1,144 @@
|
|
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
|
+
// == sl_list.h
|
25
|
+
//
|
26
|
+
// Singly-linked list implementation used for List Storage.
|
27
|
+
|
28
|
+
#ifndef SL_LIST_H
|
29
|
+
#define SL_LIST_H
|
30
|
+
|
31
|
+
|
32
|
+
/*
|
33
|
+
* Standard Includes
|
34
|
+
*/
|
35
|
+
|
36
|
+
#include <ruby.h>
|
37
|
+
#include <type_traits>
|
38
|
+
#include <cstdlib>
|
39
|
+
|
40
|
+
/*
|
41
|
+
* Project Includes
|
42
|
+
*/
|
43
|
+
|
44
|
+
#include "types.h"
|
45
|
+
|
46
|
+
#include "data/data.h"
|
47
|
+
|
48
|
+
#include "nmatrix.h"
|
49
|
+
|
50
|
+
namespace nm { namespace list {
|
51
|
+
|
52
|
+
/*
|
53
|
+
* Macros
|
54
|
+
*/
|
55
|
+
|
56
|
+
/*
|
57
|
+
* Types
|
58
|
+
*/
|
59
|
+
|
60
|
+
/*
|
61
|
+
* Data
|
62
|
+
*/
|
63
|
+
|
64
|
+
|
65
|
+
/*
|
66
|
+
* Functions
|
67
|
+
*/
|
68
|
+
|
69
|
+
////////////////
|
70
|
+
// Lifecycle //
|
71
|
+
///////////////
|
72
|
+
|
73
|
+
LIST* create(void);
|
74
|
+
void del(LIST* list, size_t recursions);
|
75
|
+
void mark(LIST* list, size_t recursions);
|
76
|
+
|
77
|
+
///////////////
|
78
|
+
// Accessors //
|
79
|
+
///////////////
|
80
|
+
|
81
|
+
NODE* insert(LIST* list, bool replace, size_t key, void* val);
|
82
|
+
NODE* insert_copy(LIST *list, bool replace, size_t key, void *val, size_t size);
|
83
|
+
NODE* insert_first_node(LIST* list, size_t key, void* val, size_t val_size);
|
84
|
+
NODE* insert_first_list(LIST* list, size_t key, LIST* l);
|
85
|
+
NODE* insert_after(NODE* node, size_t key, void* val);
|
86
|
+
NODE* replace_insert_after(NODE* node, size_t key, void* val, bool copy, size_t copy_size);
|
87
|
+
void* remove(LIST* list, size_t key);
|
88
|
+
void* remove_by_node(LIST* list, NODE* prev, NODE* rm);
|
89
|
+
bool remove_recursive(LIST* list, const size_t* coords, const size_t* offset, const size_t* lengths, size_t r, const size_t& dim);
|
90
|
+
bool node_is_within_slice(NODE* n, size_t coord, size_t len);
|
91
|
+
|
92
|
+
template <typename Type>
|
93
|
+
inline NODE* insert_helper(LIST* list, NODE* node, size_t key, Type val) {
|
94
|
+
Type* val_mem = NM_ALLOC(Type);
|
95
|
+
*val_mem = val;
|
96
|
+
|
97
|
+
if (node == NULL) {
|
98
|
+
return insert(list, false, key, val_mem);
|
99
|
+
|
100
|
+
} else {
|
101
|
+
return insert_after(node, key, val_mem);
|
102
|
+
}
|
103
|
+
}
|
104
|
+
|
105
|
+
template <typename Type>
|
106
|
+
inline NODE* insert_helper(LIST* list, NODE* node, size_t key, Type* ptr) {
|
107
|
+
if (node == NULL) {
|
108
|
+
return insert(list, false, key, ptr);
|
109
|
+
|
110
|
+
} else {
|
111
|
+
return insert_after(node, key, ptr);
|
112
|
+
}
|
113
|
+
}
|
114
|
+
|
115
|
+
///////////
|
116
|
+
// Tests //
|
117
|
+
///////////
|
118
|
+
|
119
|
+
|
120
|
+
/////////////
|
121
|
+
// Utility //
|
122
|
+
/////////////
|
123
|
+
|
124
|
+
NODE* find(LIST* list, size_t key);
|
125
|
+
NODE* find_preceding_from_node(NODE* prev, size_t key);
|
126
|
+
NODE* find_preceding_from_list(LIST* l, size_t key);
|
127
|
+
NODE* find_nearest(LIST* list, size_t key);
|
128
|
+
NODE* find_nearest_from(NODE* prev, size_t key);
|
129
|
+
|
130
|
+
/////////////////////////
|
131
|
+
// Copying and Casting //
|
132
|
+
/////////////////////////
|
133
|
+
|
134
|
+
template <typename LDType, typename RDType>
|
135
|
+
void cast_copy_contents(LIST* lhs, const LIST* rhs, size_t recursions);
|
136
|
+
|
137
|
+
}} // end of namespace nm::list
|
138
|
+
|
139
|
+
extern "C" {
|
140
|
+
void nm_list_cast_copy_contents(LIST* lhs, const LIST* rhs, nm::dtype_t lhs_dtype, nm::dtype_t rhs_dtype, size_t recursions);
|
141
|
+
VALUE nm_list_copy_to_hash(const LIST* l, const nm::dtype_t dtype, size_t recursions, VALUE default_value);
|
142
|
+
} // end of extern "C" block
|
143
|
+
|
144
|
+
#endif // SL_LIST_H
|