pnmatrix 1.2.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (111) hide show
  1. checksums.yaml +7 -0
  2. data/ext/nmatrix/binary_format.txt +53 -0
  3. data/ext/nmatrix/data/complex.h +388 -0
  4. data/ext/nmatrix/data/data.cpp +274 -0
  5. data/ext/nmatrix/data/data.h +651 -0
  6. data/ext/nmatrix/data/meta.h +64 -0
  7. data/ext/nmatrix/data/ruby_object.h +386 -0
  8. data/ext/nmatrix/extconf.rb +70 -0
  9. data/ext/nmatrix/math/asum.h +99 -0
  10. data/ext/nmatrix/math/cblas_enums.h +36 -0
  11. data/ext/nmatrix/math/cblas_templates_core.h +507 -0
  12. data/ext/nmatrix/math/gemm.h +241 -0
  13. data/ext/nmatrix/math/gemv.h +178 -0
  14. data/ext/nmatrix/math/getrf.h +255 -0
  15. data/ext/nmatrix/math/getrs.h +121 -0
  16. data/ext/nmatrix/math/imax.h +82 -0
  17. data/ext/nmatrix/math/laswp.h +165 -0
  18. data/ext/nmatrix/math/long_dtype.h +62 -0
  19. data/ext/nmatrix/math/magnitude.h +54 -0
  20. data/ext/nmatrix/math/math.h +751 -0
  21. data/ext/nmatrix/math/nrm2.h +165 -0
  22. data/ext/nmatrix/math/rot.h +117 -0
  23. data/ext/nmatrix/math/rotg.h +106 -0
  24. data/ext/nmatrix/math/scal.h +71 -0
  25. data/ext/nmatrix/math/trsm.h +336 -0
  26. data/ext/nmatrix/math/util.h +162 -0
  27. data/ext/nmatrix/math.cpp +1368 -0
  28. data/ext/nmatrix/nm_memory.h +60 -0
  29. data/ext/nmatrix/nmatrix.cpp +285 -0
  30. data/ext/nmatrix/nmatrix.h +476 -0
  31. data/ext/nmatrix/ruby_constants.cpp +151 -0
  32. data/ext/nmatrix/ruby_constants.h +106 -0
  33. data/ext/nmatrix/ruby_nmatrix.c +3130 -0
  34. data/ext/nmatrix/storage/common.cpp +77 -0
  35. data/ext/nmatrix/storage/common.h +183 -0
  36. data/ext/nmatrix/storage/dense/dense.cpp +1096 -0
  37. data/ext/nmatrix/storage/dense/dense.h +129 -0
  38. data/ext/nmatrix/storage/list/list.cpp +1628 -0
  39. data/ext/nmatrix/storage/list/list.h +138 -0
  40. data/ext/nmatrix/storage/storage.cpp +730 -0
  41. data/ext/nmatrix/storage/storage.h +99 -0
  42. data/ext/nmatrix/storage/yale/class.h +1139 -0
  43. data/ext/nmatrix/storage/yale/iterators/base.h +143 -0
  44. data/ext/nmatrix/storage/yale/iterators/iterator.h +131 -0
  45. data/ext/nmatrix/storage/yale/iterators/row.h +450 -0
  46. data/ext/nmatrix/storage/yale/iterators/row_stored.h +140 -0
  47. data/ext/nmatrix/storage/yale/iterators/row_stored_nd.h +169 -0
  48. data/ext/nmatrix/storage/yale/iterators/stored_diagonal.h +124 -0
  49. data/ext/nmatrix/storage/yale/math/transpose.h +110 -0
  50. data/ext/nmatrix/storage/yale/yale.cpp +2074 -0
  51. data/ext/nmatrix/storage/yale/yale.h +203 -0
  52. data/ext/nmatrix/types.h +55 -0
  53. data/ext/nmatrix/util/io.cpp +279 -0
  54. data/ext/nmatrix/util/io.h +115 -0
  55. data/ext/nmatrix/util/sl_list.cpp +627 -0
  56. data/ext/nmatrix/util/sl_list.h +144 -0
  57. data/ext/nmatrix/util/util.h +78 -0
  58. data/lib/nmatrix/blas.rb +378 -0
  59. data/lib/nmatrix/cruby/math.rb +744 -0
  60. data/lib/nmatrix/enumerate.rb +253 -0
  61. data/lib/nmatrix/homogeneous.rb +241 -0
  62. data/lib/nmatrix/io/fortran_format.rb +138 -0
  63. data/lib/nmatrix/io/harwell_boeing.rb +221 -0
  64. data/lib/nmatrix/io/market.rb +263 -0
  65. data/lib/nmatrix/io/point_cloud.rb +189 -0
  66. data/lib/nmatrix/jruby/decomposition.rb +24 -0
  67. data/lib/nmatrix/jruby/enumerable.rb +13 -0
  68. data/lib/nmatrix/jruby/error.rb +4 -0
  69. data/lib/nmatrix/jruby/math.rb +501 -0
  70. data/lib/nmatrix/jruby/nmatrix_java.rb +840 -0
  71. data/lib/nmatrix/jruby/operators.rb +283 -0
  72. data/lib/nmatrix/jruby/slice.rb +264 -0
  73. data/lib/nmatrix/lapack_core.rb +181 -0
  74. data/lib/nmatrix/lapack_plugin.rb +44 -0
  75. data/lib/nmatrix/math.rb +953 -0
  76. data/lib/nmatrix/mkmf.rb +100 -0
  77. data/lib/nmatrix/monkeys.rb +137 -0
  78. data/lib/nmatrix/nmatrix.rb +1172 -0
  79. data/lib/nmatrix/rspec.rb +75 -0
  80. data/lib/nmatrix/shortcuts.rb +1163 -0
  81. data/lib/nmatrix/version.rb +39 -0
  82. data/lib/nmatrix/yale_functions.rb +118 -0
  83. data/lib/nmatrix.rb +28 -0
  84. data/spec/00_nmatrix_spec.rb +892 -0
  85. data/spec/01_enum_spec.rb +196 -0
  86. data/spec/02_slice_spec.rb +407 -0
  87. data/spec/03_nmatrix_monkeys_spec.rb +80 -0
  88. data/spec/2x2_dense_double.mat +0 -0
  89. data/spec/4x4_sparse.mat +0 -0
  90. data/spec/4x5_dense.mat +0 -0
  91. data/spec/blas_spec.rb +215 -0
  92. data/spec/elementwise_spec.rb +311 -0
  93. data/spec/homogeneous_spec.rb +100 -0
  94. data/spec/io/fortran_format_spec.rb +88 -0
  95. data/spec/io/harwell_boeing_spec.rb +98 -0
  96. data/spec/io/test.rua +9 -0
  97. data/spec/io_spec.rb +159 -0
  98. data/spec/lapack_core_spec.rb +482 -0
  99. data/spec/leakcheck.rb +16 -0
  100. data/spec/math_spec.rb +1363 -0
  101. data/spec/nmatrix_yale_resize_test_associations.yaml +2802 -0
  102. data/spec/nmatrix_yale_spec.rb +286 -0
  103. data/spec/rspec_monkeys.rb +56 -0
  104. data/spec/rspec_spec.rb +35 -0
  105. data/spec/shortcuts_spec.rb +474 -0
  106. data/spec/slice_set_spec.rb +162 -0
  107. data/spec/spec_helper.rb +172 -0
  108. data/spec/stat_spec.rb +214 -0
  109. data/spec/test.pcd +20 -0
  110. data/spec/utm5940.mtx +83844 -0
  111. metadata +295 -0
@@ -0,0 +1,77 @@
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.cpp
25
+ //
26
+ // Code for the STORAGE struct that is common to all storage types.
27
+
28
+ /*
29
+ * Standard Includes
30
+ */
31
+
32
+ /*
33
+ * Project Includes
34
+ */
35
+
36
+ #include "common.h"
37
+
38
+ /*
39
+ * Macros
40
+ */
41
+
42
+ /*
43
+ * Global Variables
44
+ */
45
+
46
+ /*
47
+ * Forward Declarations
48
+ */
49
+
50
+ /*
51
+ * Functions
52
+ */
53
+
54
+ extern "C" {
55
+ /*
56
+ * Calculate the number of elements in the dense storage structure, based on
57
+ * shape and dim.
58
+ */
59
+ size_t nm_storage_count_max_elements(const STORAGE* storage) {
60
+ unsigned int i;
61
+ size_t count = 1;
62
+
63
+ for (i = storage->dim; i-- > 0;) {
64
+ count *= storage->shape[i];
65
+ }
66
+
67
+ return count;
68
+ }
69
+
70
+ // Helper function used only for the RETURN_SIZED_ENUMERATOR macro. Returns the length of
71
+ // the matrix's storage.
72
+ VALUE nm_enumerator_length(VALUE nmatrix) {
73
+ long len = nm_storage_count_max_elements(NM_STORAGE_DENSE(nmatrix));
74
+ return LONG2NUM(len);
75
+ }
76
+
77
+ } // end of extern "C" block
@@ -0,0 +1,183 @@
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 <ruby.h>
36
+ #include <cmath> // pow().
37
+ #include <type_traits>
38
+
39
+ /*
40
+ * Project Includes
41
+ */
42
+ #include "data/data.h"
43
+ #include "nmatrix.h"
44
+
45
+ /*
46
+ * Macros
47
+ */
48
+
49
+ #define u_int8_t static_assert(false, "Please use uint8_t for cross-platform support and consistency."); uint8_t
50
+ #define u_int16_t static_assert(false, "Please use uint16_t for cross-platform support and consistency."); uint16_t
51
+ #define u_int32_t static_assert(false, "Please use uint32_t for cross-platform support and consistency."); uint32_t
52
+ #define u_int64_t static_assert(false, "Please use uint64_t for cross-platform support and consistency."); uint64_t
53
+
54
+ extern "C" {
55
+
56
+ /*
57
+ * Types
58
+ */
59
+
60
+ // For binary operations involving matrices that need to be casted.
61
+ struct STORAGE_PAIR {
62
+ STORAGE* left;
63
+ STORAGE* right;
64
+ };
65
+
66
+ struct SLICE {
67
+ size_t* coords; // Coordinate of first element
68
+ size_t* lengths; // Lengths of slice
69
+ bool single; // true if all lengths equal to 1 (represents single matrix element)
70
+ };
71
+
72
+ /*
73
+ * Data
74
+ */
75
+
76
+ /*
77
+ * Functions
78
+ */
79
+
80
+ size_t nm_storage_count_max_elements(const STORAGE* storage);
81
+ VALUE nm_enumerator_length(VALUE nmatrix);
82
+
83
+ } // end of extern "C" block
84
+
85
+ namespace nm {
86
+
87
+ /*
88
+ * Templated helper function for element-wise operations, used by dense, yale, and list.
89
+ */
90
+ template <ewop_t op, typename LDType, typename RDType>
91
+ inline VALUE ew_op_switch(LDType left, RDType right) {
92
+ switch (op) {
93
+ case EW_ADD:
94
+ return RubyObject(left + right).rval;
95
+
96
+ case EW_SUB:
97
+ return RubyObject(left - right).rval;
98
+
99
+ case EW_MUL:
100
+ return RubyObject(left * right).rval;
101
+
102
+ case EW_DIV:
103
+ return RubyObject(left / right).rval;
104
+
105
+ case EW_POW:
106
+ return RubyObject(pow(left, right)).rval;
107
+
108
+ case EW_MOD:
109
+ rb_raise(rb_eNotImpError, "Element-wise modulo is currently not supported.");
110
+ break;
111
+
112
+ default:
113
+ rb_raise(rb_eStandardError, "This should not happen.");
114
+ }
115
+ return Qnil;
116
+ }
117
+
118
+ #define EWOP_INT_INT_DIV(ltype, rtype) template <> \
119
+ inline VALUE ew_op_switch<EW_DIV>( ltype left, rtype right) { \
120
+ if (right == 0) rb_raise(rb_eZeroDivError, "cannot divide type by 0, would throw SIGFPE"); \
121
+ if ((left > 0 && right > 0) || (left < 0 && right < 0)) \
122
+ return left / right; \
123
+ else \
124
+ return ( ltype )(std::floor((double)(left) / (double)(right))); \
125
+ }
126
+
127
+ #define EWOP_UINT_UINT_DIV(ltype, rtype) template <> \
128
+ inline VALUE ew_op_switch<EW_DIV>( ltype left, rtype right) { \
129
+ if (right == 0) rb_raise(rb_eZeroDivError, "cannot divide type by 0, would throw SIGFPE"); \
130
+ return left / right; \
131
+ }
132
+
133
+ #define EWOP_INT_UINT_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 (left > 0 ) return left / right; \
137
+ else return ( ltype )(std::floor((double)(left) / (double)(right))); \
138
+ }
139
+
140
+ #define EWOP_UINT_INT_DIV(ltype, rtype) template <> \
141
+ inline VALUE ew_op_switch<EW_DIV>( ltype left, rtype right) { \
142
+ if (right == 0) rb_raise(rb_eZeroDivError, "cannot divide type by 0, would throw SIGFPE"); \
143
+ if (right > 0) return left / right; \
144
+ else return ( ltype )(std::floor((double)(left) / (double)(right))); \
145
+ }
146
+
147
+ #define EWOP_FLOAT_INT_DIV(ltype, rtype) template <> \
148
+ inline VALUE ew_op_switch<EW_DIV>( ltype left, rtype right) { \
149
+ return left / (ltype)(right); \
150
+ }
151
+
152
+ // Ensure that divisions are done in the Ruby way, and that (int)x/0 always raises a Ruby error instead
153
+ // of throwing a SIGFPE.
154
+ EWOP_INT_INT_DIV(int64_t, int64_t)
155
+ EWOP_INT_INT_DIV(int32_t, int32_t)
156
+ EWOP_INT_INT_DIV(int32_t, int64_t)
157
+ EWOP_INT_INT_DIV(int16_t, int16_t)
158
+ EWOP_INT_INT_DIV(int16_t, int32_t)
159
+ EWOP_INT_INT_DIV(int16_t, int64_t)
160
+ EWOP_INT_INT_DIV(int8_t, int8_t)
161
+ EWOP_INT_UINT_DIV(int8_t, uint8_t)
162
+ EWOP_INT_INT_DIV(int8_t, int16_t)
163
+ EWOP_INT_INT_DIV(int8_t, int32_t)
164
+ EWOP_INT_INT_DIV(int8_t, int64_t)
165
+ EWOP_UINT_UINT_DIV(uint8_t, uint8_t)
166
+ EWOP_UINT_INT_DIV(uint8_t, int8_t)
167
+ EWOP_UINT_INT_DIV(uint8_t, int16_t)
168
+ EWOP_UINT_INT_DIV(uint8_t, int32_t)
169
+ EWOP_UINT_INT_DIV(uint8_t, int64_t)
170
+ EWOP_FLOAT_INT_DIV(float, int8_t)
171
+ EWOP_FLOAT_INT_DIV(float, uint8_t)
172
+ EWOP_FLOAT_INT_DIV(float, int16_t)
173
+ EWOP_FLOAT_INT_DIV(float, int32_t)
174
+ EWOP_FLOAT_INT_DIV(float, int64_t)
175
+ EWOP_FLOAT_INT_DIV(double, int8_t)
176
+ EWOP_FLOAT_INT_DIV(double, uint8_t)
177
+ EWOP_FLOAT_INT_DIV(double, int16_t)
178
+ EWOP_FLOAT_INT_DIV(double, int32_t)
179
+ EWOP_FLOAT_INT_DIV(double, int64_t)
180
+
181
+ }
182
+
183
+ #endif // STORAGE_COMMON_H