nmatrix-atlas 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +7 -0
  2. data/ext/nmatrix/data/complex.h +364 -0
  3. data/ext/nmatrix/data/data.h +638 -0
  4. data/ext/nmatrix/data/meta.h +64 -0
  5. data/ext/nmatrix/data/ruby_object.h +389 -0
  6. data/ext/nmatrix/math/asum.h +120 -0
  7. data/ext/nmatrix/math/cblas_enums.h +36 -0
  8. data/ext/nmatrix/math/cblas_templates_core.h +507 -0
  9. data/ext/nmatrix/math/gemm.h +241 -0
  10. data/ext/nmatrix/math/gemv.h +178 -0
  11. data/ext/nmatrix/math/getrf.h +255 -0
  12. data/ext/nmatrix/math/getrs.h +121 -0
  13. data/ext/nmatrix/math/imax.h +79 -0
  14. data/ext/nmatrix/math/laswp.h +165 -0
  15. data/ext/nmatrix/math/long_dtype.h +49 -0
  16. data/ext/nmatrix/math/math.h +744 -0
  17. data/ext/nmatrix/math/nrm2.h +160 -0
  18. data/ext/nmatrix/math/rot.h +117 -0
  19. data/ext/nmatrix/math/rotg.h +106 -0
  20. data/ext/nmatrix/math/scal.h +71 -0
  21. data/ext/nmatrix/math/trsm.h +332 -0
  22. data/ext/nmatrix/math/util.h +148 -0
  23. data/ext/nmatrix/nm_memory.h +60 -0
  24. data/ext/nmatrix/nmatrix.h +408 -0
  25. data/ext/nmatrix/ruby_constants.h +106 -0
  26. data/ext/nmatrix/storage/common.h +176 -0
  27. data/ext/nmatrix/storage/dense/dense.h +128 -0
  28. data/ext/nmatrix/storage/list/list.h +137 -0
  29. data/ext/nmatrix/storage/storage.h +98 -0
  30. data/ext/nmatrix/storage/yale/class.h +1139 -0
  31. data/ext/nmatrix/storage/yale/iterators/base.h +142 -0
  32. data/ext/nmatrix/storage/yale/iterators/iterator.h +130 -0
  33. data/ext/nmatrix/storage/yale/iterators/row.h +449 -0
  34. data/ext/nmatrix/storage/yale/iterators/row_stored.h +139 -0
  35. data/ext/nmatrix/storage/yale/iterators/row_stored_nd.h +168 -0
  36. data/ext/nmatrix/storage/yale/iterators/stored_diagonal.h +123 -0
  37. data/ext/nmatrix/storage/yale/math/transpose.h +110 -0
  38. data/ext/nmatrix/storage/yale/yale.h +202 -0
  39. data/ext/nmatrix/types.h +54 -0
  40. data/ext/nmatrix/util/io.h +115 -0
  41. data/ext/nmatrix/util/sl_list.h +143 -0
  42. data/ext/nmatrix/util/util.h +78 -0
  43. data/ext/nmatrix_atlas/extconf.rb +250 -0
  44. data/ext/nmatrix_atlas/math_atlas.cpp +1206 -0
  45. data/ext/nmatrix_atlas/math_atlas/cblas_templates_atlas.h +72 -0
  46. data/ext/nmatrix_atlas/math_atlas/clapack_templates.h +332 -0
  47. data/ext/nmatrix_atlas/math_atlas/geev.h +82 -0
  48. data/ext/nmatrix_atlas/math_atlas/gesdd.h +83 -0
  49. data/ext/nmatrix_atlas/math_atlas/gesvd.h +81 -0
  50. data/ext/nmatrix_atlas/math_atlas/inc.h +47 -0
  51. data/ext/nmatrix_atlas/nmatrix_atlas.cpp +44 -0
  52. data/lib/nmatrix/atlas.rb +213 -0
  53. data/lib/nmatrix/lapack_ext_common.rb +69 -0
  54. data/spec/00_nmatrix_spec.rb +730 -0
  55. data/spec/01_enum_spec.rb +190 -0
  56. data/spec/02_slice_spec.rb +389 -0
  57. data/spec/03_nmatrix_monkeys_spec.rb +78 -0
  58. data/spec/2x2_dense_double.mat +0 -0
  59. data/spec/4x4_sparse.mat +0 -0
  60. data/spec/4x5_dense.mat +0 -0
  61. data/spec/blas_spec.rb +193 -0
  62. data/spec/elementwise_spec.rb +303 -0
  63. data/spec/homogeneous_spec.rb +99 -0
  64. data/spec/io/fortran_format_spec.rb +88 -0
  65. data/spec/io/harwell_boeing_spec.rb +98 -0
  66. data/spec/io/test.rua +9 -0
  67. data/spec/io_spec.rb +149 -0
  68. data/spec/lapack_core_spec.rb +482 -0
  69. data/spec/leakcheck.rb +16 -0
  70. data/spec/math_spec.rb +730 -0
  71. data/spec/nmatrix_yale_resize_test_associations.yaml +2802 -0
  72. data/spec/nmatrix_yale_spec.rb +286 -0
  73. data/spec/plugins/atlas/atlas_spec.rb +242 -0
  74. data/spec/rspec_monkeys.rb +56 -0
  75. data/spec/rspec_spec.rb +34 -0
  76. data/spec/shortcuts_spec.rb +310 -0
  77. data/spec/slice_set_spec.rb +157 -0
  78. data/spec/spec_helper.rb +140 -0
  79. data/spec/stat_spec.rb +203 -0
  80. data/spec/test.pcd +20 -0
  81. data/spec/utm5940.mtx +83844 -0
  82. metadata +159 -0
@@ -0,0 +1,202 @@
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 <limits> // for std::numeric_limits<T>::max()
46
+ #include <stdexcept>
47
+
48
+ /*
49
+ * Project Includes
50
+ */
51
+
52
+ #include "../../types.h"
53
+ #include "../../data/data.h"
54
+ #include "../common.h"
55
+ #include "../../nmatrix.h"
56
+
57
+ extern "C" {
58
+
59
+ /*
60
+ * Macros
61
+ */
62
+
63
+ #ifndef NM_CHECK_ALLOC
64
+ #define NM_CHECK_ALLOC(x) if (!x) rb_raise(rb_eNoMemError, "insufficient memory");
65
+ #endif
66
+
67
+ /*
68
+ * Types
69
+ */
70
+
71
+
72
+ /*
73
+ * Data
74
+ */
75
+
76
+
77
+ /*
78
+ * Functions
79
+ */
80
+
81
+ ///////////////
82
+ // Lifecycle //
83
+ ///////////////
84
+
85
+ YALE_STORAGE* nm_yale_storage_create(nm::dtype_t dtype, size_t* shape, size_t dim, size_t init_capacity);
86
+ 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);
87
+ YALE_STORAGE* nm_yale_storage_create_merged(const YALE_STORAGE* merge_template, const YALE_STORAGE* other);
88
+ void nm_yale_storage_delete(STORAGE* s);
89
+ void nm_yale_storage_delete_ref(STORAGE* s);
90
+ void nm_yale_storage_init(YALE_STORAGE* s, void* default_val);
91
+ void nm_yale_storage_mark(STORAGE*);
92
+ void nm_yale_storage_register(const STORAGE* s);
93
+ void nm_yale_storage_unregister(const STORAGE* s);
94
+ void nm_yale_storage_register_a(void* a, size_t size);
95
+ void nm_yale_storage_unregister_a(void* a, size_t size);
96
+
97
+ ///////////////
98
+ // Accessors //
99
+ ///////////////
100
+
101
+ VALUE nm_yale_each_with_indices(VALUE nmatrix);
102
+ VALUE nm_yale_each_stored_with_indices(VALUE nmatrix);
103
+ VALUE nm_yale_stored_diagonal_each_with_indices(VALUE nmatrix);
104
+ VALUE nm_yale_stored_nondiagonal_each_with_indices(VALUE nmatrix);
105
+ VALUE nm_yale_each_ordered_stored_with_indices(VALUE nmatrix);
106
+ void* nm_yale_storage_get(const STORAGE* s, SLICE* slice);
107
+ void* nm_yale_storage_ref(const STORAGE* s, SLICE* slice);
108
+ void nm_yale_storage_set(VALUE left, SLICE* slice, VALUE right);
109
+
110
+ //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);
111
+ //void nm_yale_storage_increment_ia_after(YALE_STORAGE* s, size_t ija_size, size_t i, size_t n);
112
+
113
+ size_t nm_yale_storage_get_size(const YALE_STORAGE* storage);
114
+ VALUE nm_yale_default_value(VALUE self);
115
+ VALUE nm_yale_map_stored(VALUE self);
116
+ VALUE nm_yale_map_merged_stored(VALUE left, VALUE right, VALUE init);
117
+
118
+ ///////////
119
+ // Tests //
120
+ ///////////
121
+
122
+ bool nm_yale_storage_eqeq(const STORAGE* left, const STORAGE* right);
123
+
124
+ //////////
125
+ // Math //
126
+ //////////
127
+
128
+ STORAGE* nm_yale_storage_matrix_multiply(const STORAGE_PAIR& casted_storage, size_t* resulting_shape, bool vector);
129
+
130
+ /////////////
131
+ // Utility //
132
+ /////////////
133
+
134
+
135
+
136
+ /////////////////////////
137
+ // Copying and Casting //
138
+ /////////////////////////
139
+
140
+ STORAGE* nm_yale_storage_cast_copy(const STORAGE* rhs, nm::dtype_t new_dtype, void*);
141
+ STORAGE* nm_yale_storage_copy_transposed(const STORAGE* rhs_base);
142
+
143
+
144
+
145
+ void nm_init_yale_functions(void);
146
+
147
+ VALUE nm_vector_set(int argc, VALUE* argv, VALUE self);
148
+
149
+
150
+ } // end of extern "C" block
151
+
152
+ namespace nm {
153
+
154
+ namespace yale_storage {
155
+
156
+ /*
157
+ * Typedefs
158
+ */
159
+
160
+ typedef size_t IType;
161
+
162
+
163
+ /*
164
+ * Templated Functions
165
+ */
166
+
167
+ int binary_search(YALE_STORAGE* s, IType left, IType right, IType key);
168
+
169
+ /*
170
+ * Clear out the D portion of the A vector (clearing the diagonal and setting
171
+ * the zero value).
172
+ *
173
+ * Note: This sets a literal 0 value. If your dtype is RUBYOBJ (a Ruby object),
174
+ * it'll actually be INT2FIX(0) instead of a string of NULLs. You can actually
175
+ * set a default for Ruby objects other than zero -- you generally want it to
176
+ * be Qfalse, Qnil, or INT2FIX(0). The last is the default.
177
+ */
178
+ template <typename DType>
179
+ inline void clear_diagonal_and_zero(YALE_STORAGE* s, void* init_val) {
180
+ DType* a = reinterpret_cast<DType*>(s->a);
181
+
182
+ // Clear out the diagonal + one extra entry
183
+ if (init_val) {
184
+ for (size_t i = 0; i <= s->shape[0]; ++i) // insert Ruby zeros, falses, or whatever else.
185
+ a[i] = *reinterpret_cast<DType*>(init_val);
186
+ } else {
187
+ for (size_t i = 0; i <= s->shape[0]; ++i) // insert zeros.
188
+ a[i] = 0;
189
+ }
190
+ }
191
+
192
+ template <typename DType>
193
+ void init(YALE_STORAGE* s, void* init_val);
194
+
195
+ size_t get_size(const YALE_STORAGE* storage);
196
+
197
+ IType binary_search_left_boundary(const YALE_STORAGE* s, IType left, IType right, IType bound);
198
+
199
+
200
+ }} // end of namespace nm::yale_storage
201
+
202
+ #endif // YALE_H
@@ -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 - 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 <cstdint>
36
+
37
+ /*
38
+ * Macros
39
+ */
40
+
41
+ #define EPSILON 1E-10
42
+ #define FP_IS_ZERO(n) (-EPSILON < n && n < EPSILON)
43
+ #define FP_EQUAL(a, b) FP_IS_ZERO((a - b))
44
+
45
+ /*
46
+ * Types
47
+ */
48
+
49
+ typedef float float32_t;
50
+ typedef double float64_t;
51
+
52
+ typedef size_t IType;
53
+
54
+ #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,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
+ // == 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 <type_traits>
37
+ #include <cstdlib>
38
+
39
+ /*
40
+ * Project Includes
41
+ */
42
+
43
+ #include "types.h"
44
+
45
+ #include "data/data.h"
46
+
47
+ #include "nmatrix.h"
48
+
49
+ namespace nm { namespace list {
50
+
51
+ /*
52
+ * Macros
53
+ */
54
+
55
+ /*
56
+ * Types
57
+ */
58
+
59
+ /*
60
+ * Data
61
+ */
62
+
63
+
64
+ /*
65
+ * Functions
66
+ */
67
+
68
+ ////////////////
69
+ // Lifecycle //
70
+ ///////////////
71
+
72
+ LIST* create(void);
73
+ void del(LIST* list, size_t recursions);
74
+ void mark(LIST* list, size_t recursions);
75
+
76
+ ///////////////
77
+ // Accessors //
78
+ ///////////////
79
+
80
+ NODE* insert(LIST* list, bool replace, size_t key, void* val);
81
+ NODE* insert_copy(LIST *list, bool replace, size_t key, void *val, size_t size);
82
+ NODE* insert_first_node(LIST* list, size_t key, void* val, size_t val_size);
83
+ NODE* insert_first_list(LIST* list, size_t key, LIST* l);
84
+ NODE* insert_after(NODE* node, size_t key, void* val);
85
+ NODE* replace_insert_after(NODE* node, size_t key, void* val, bool copy, size_t copy_size);
86
+ void* remove(LIST* list, size_t key);
87
+ void* remove_by_node(LIST* list, NODE* prev, NODE* rm);
88
+ bool remove_recursive(LIST* list, const size_t* coords, const size_t* offset, const size_t* lengths, size_t r, const size_t& dim);
89
+ bool node_is_within_slice(NODE* n, size_t coord, size_t len);
90
+
91
+ template <typename Type>
92
+ inline NODE* insert_helper(LIST* list, NODE* node, size_t key, Type val) {
93
+ Type* val_mem = NM_ALLOC(Type);
94
+ *val_mem = val;
95
+
96
+ if (node == NULL) {
97
+ return insert(list, false, key, val_mem);
98
+
99
+ } else {
100
+ return insert_after(node, key, val_mem);
101
+ }
102
+ }
103
+
104
+ template <typename Type>
105
+ inline NODE* insert_helper(LIST* list, NODE* node, size_t key, Type* ptr) {
106
+ if (node == NULL) {
107
+ return insert(list, false, key, ptr);
108
+
109
+ } else {
110
+ return insert_after(node, key, ptr);
111
+ }
112
+ }
113
+
114
+ ///////////
115
+ // Tests //
116
+ ///////////
117
+
118
+
119
+ /////////////
120
+ // Utility //
121
+ /////////////
122
+
123
+ NODE* find(LIST* list, size_t key);
124
+ NODE* find_preceding_from_node(NODE* prev, size_t key);
125
+ NODE* find_preceding_from_list(LIST* l, size_t key);
126
+ NODE* find_nearest(LIST* list, size_t key);
127
+ NODE* find_nearest_from(NODE* prev, size_t key);
128
+
129
+ /////////////////////////
130
+ // Copying and Casting //
131
+ /////////////////////////
132
+
133
+ template <typename LDType, typename RDType>
134
+ void cast_copy_contents(LIST* lhs, const LIST* rhs, size_t recursions);
135
+
136
+ }} // end of namespace nm::list
137
+
138
+ extern "C" {
139
+ void nm_list_cast_copy_contents(LIST* lhs, const LIST* rhs, nm::dtype_t lhs_dtype, nm::dtype_t rhs_dtype, size_t recursions);
140
+ VALUE nm_list_copy_to_hash(const LIST* l, const nm::dtype_t dtype, size_t recursions, VALUE default_value);
141
+ } // end of extern "C" block
142
+
143
+ #endif // SL_LIST_H