nmatrix-lapacke 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (185) 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_lapacke/extconf.rb +200 -0
  44. data/ext/nmatrix_lapacke/lapacke.cpp +100 -0
  45. data/ext/nmatrix_lapacke/lapacke/include/lapacke.h +16445 -0
  46. data/ext/nmatrix_lapacke/lapacke/include/lapacke_config.h +119 -0
  47. data/ext/nmatrix_lapacke/lapacke/include/lapacke_mangling.h +17 -0
  48. data/ext/nmatrix_lapacke/lapacke/include/lapacke_mangling_with_flags.h +17 -0
  49. data/ext/nmatrix_lapacke/lapacke/include/lapacke_utils.h +579 -0
  50. data/ext/nmatrix_lapacke/lapacke/src/lapacke_cgeev.c +89 -0
  51. data/ext/nmatrix_lapacke/lapacke/src/lapacke_cgeev_work.c +141 -0
  52. data/ext/nmatrix_lapacke/lapacke/src/lapacke_cgesdd.c +106 -0
  53. data/ext/nmatrix_lapacke/lapacke/src/lapacke_cgesdd_work.c +158 -0
  54. data/ext/nmatrix_lapacke/lapacke/src/lapacke_cgesvd.c +94 -0
  55. data/ext/nmatrix_lapacke/lapacke/src/lapacke_cgesvd_work.c +149 -0
  56. data/ext/nmatrix_lapacke/lapacke/src/lapacke_cgetrf.c +51 -0
  57. data/ext/nmatrix_lapacke/lapacke/src/lapacke_cgetrf_work.c +83 -0
  58. data/ext/nmatrix_lapacke/lapacke/src/lapacke_cgetri.c +77 -0
  59. data/ext/nmatrix_lapacke/lapacke/src/lapacke_cgetri_work.c +89 -0
  60. data/ext/nmatrix_lapacke/lapacke/src/lapacke_cgetrs.c +56 -0
  61. data/ext/nmatrix_lapacke/lapacke/src/lapacke_cgetrs_work.c +102 -0
  62. data/ext/nmatrix_lapacke/lapacke/src/lapacke_cpotrf.c +50 -0
  63. data/ext/nmatrix_lapacke/lapacke/src/lapacke_cpotrf_work.c +82 -0
  64. data/ext/nmatrix_lapacke/lapacke/src/lapacke_cpotri.c +50 -0
  65. data/ext/nmatrix_lapacke/lapacke/src/lapacke_cpotri_work.c +82 -0
  66. data/ext/nmatrix_lapacke/lapacke/src/lapacke_cpotrs.c +55 -0
  67. data/ext/nmatrix_lapacke/lapacke/src/lapacke_cpotrs_work.c +101 -0
  68. data/ext/nmatrix_lapacke/lapacke/src/lapacke_dgeev.c +78 -0
  69. data/ext/nmatrix_lapacke/lapacke/src/lapacke_dgeev_work.c +136 -0
  70. data/ext/nmatrix_lapacke/lapacke/src/lapacke_dgesdd.c +88 -0
  71. data/ext/nmatrix_lapacke/lapacke/src/lapacke_dgesdd_work.c +153 -0
  72. data/ext/nmatrix_lapacke/lapacke/src/lapacke_dgesvd.c +83 -0
  73. data/ext/nmatrix_lapacke/lapacke/src/lapacke_dgesvd_work.c +144 -0
  74. data/ext/nmatrix_lapacke/lapacke/src/lapacke_dgetrf.c +50 -0
  75. data/ext/nmatrix_lapacke/lapacke/src/lapacke_dgetrf_work.c +81 -0
  76. data/ext/nmatrix_lapacke/lapacke/src/lapacke_dgetri.c +75 -0
  77. data/ext/nmatrix_lapacke/lapacke/src/lapacke_dgetri_work.c +87 -0
  78. data/ext/nmatrix_lapacke/lapacke/src/lapacke_dgetrs.c +55 -0
  79. data/ext/nmatrix_lapacke/lapacke/src/lapacke_dgetrs_work.c +99 -0
  80. data/ext/nmatrix_lapacke/lapacke/src/lapacke_dpotrf.c +50 -0
  81. data/ext/nmatrix_lapacke/lapacke/src/lapacke_dpotrf_work.c +81 -0
  82. data/ext/nmatrix_lapacke/lapacke/src/lapacke_dpotri.c +50 -0
  83. data/ext/nmatrix_lapacke/lapacke/src/lapacke_dpotri_work.c +81 -0
  84. data/ext/nmatrix_lapacke/lapacke/src/lapacke_dpotrs.c +54 -0
  85. data/ext/nmatrix_lapacke/lapacke/src/lapacke_dpotrs_work.c +97 -0
  86. data/ext/nmatrix_lapacke/lapacke/src/lapacke_sgeev.c +78 -0
  87. data/ext/nmatrix_lapacke/lapacke/src/lapacke_sgeev_work.c +134 -0
  88. data/ext/nmatrix_lapacke/lapacke/src/lapacke_sgesdd.c +88 -0
  89. data/ext/nmatrix_lapacke/lapacke/src/lapacke_sgesdd_work.c +152 -0
  90. data/ext/nmatrix_lapacke/lapacke/src/lapacke_sgesvd.c +83 -0
  91. data/ext/nmatrix_lapacke/lapacke/src/lapacke_sgesvd_work.c +143 -0
  92. data/ext/nmatrix_lapacke/lapacke/src/lapacke_sgetrf.c +50 -0
  93. data/ext/nmatrix_lapacke/lapacke/src/lapacke_sgetrf_work.c +81 -0
  94. data/ext/nmatrix_lapacke/lapacke/src/lapacke_sgetri.c +75 -0
  95. data/ext/nmatrix_lapacke/lapacke/src/lapacke_sgetri_work.c +87 -0
  96. data/ext/nmatrix_lapacke/lapacke/src/lapacke_sgetrs.c +55 -0
  97. data/ext/nmatrix_lapacke/lapacke/src/lapacke_sgetrs_work.c +99 -0
  98. data/ext/nmatrix_lapacke/lapacke/src/lapacke_spotrf.c +50 -0
  99. data/ext/nmatrix_lapacke/lapacke/src/lapacke_spotrf_work.c +81 -0
  100. data/ext/nmatrix_lapacke/lapacke/src/lapacke_spotri.c +50 -0
  101. data/ext/nmatrix_lapacke/lapacke/src/lapacke_spotri_work.c +81 -0
  102. data/ext/nmatrix_lapacke/lapacke/src/lapacke_spotrs.c +54 -0
  103. data/ext/nmatrix_lapacke/lapacke/src/lapacke_spotrs_work.c +97 -0
  104. data/ext/nmatrix_lapacke/lapacke/src/lapacke_zgeev.c +89 -0
  105. data/ext/nmatrix_lapacke/lapacke/src/lapacke_zgeev_work.c +141 -0
  106. data/ext/nmatrix_lapacke/lapacke/src/lapacke_zgesdd.c +106 -0
  107. data/ext/nmatrix_lapacke/lapacke/src/lapacke_zgesdd_work.c +158 -0
  108. data/ext/nmatrix_lapacke/lapacke/src/lapacke_zgesvd.c +94 -0
  109. data/ext/nmatrix_lapacke/lapacke/src/lapacke_zgesvd_work.c +149 -0
  110. data/ext/nmatrix_lapacke/lapacke/src/lapacke_zgetrf.c +51 -0
  111. data/ext/nmatrix_lapacke/lapacke/src/lapacke_zgetrf_work.c +83 -0
  112. data/ext/nmatrix_lapacke/lapacke/src/lapacke_zgetri.c +77 -0
  113. data/ext/nmatrix_lapacke/lapacke/src/lapacke_zgetri_work.c +89 -0
  114. data/ext/nmatrix_lapacke/lapacke/src/lapacke_zgetrs.c +56 -0
  115. data/ext/nmatrix_lapacke/lapacke/src/lapacke_zgetrs_work.c +102 -0
  116. data/ext/nmatrix_lapacke/lapacke/src/lapacke_zpotrf.c +50 -0
  117. data/ext/nmatrix_lapacke/lapacke/src/lapacke_zpotrf_work.c +82 -0
  118. data/ext/nmatrix_lapacke/lapacke/src/lapacke_zpotri.c +50 -0
  119. data/ext/nmatrix_lapacke/lapacke/src/lapacke_zpotri_work.c +82 -0
  120. data/ext/nmatrix_lapacke/lapacke/src/lapacke_zpotrs.c +55 -0
  121. data/ext/nmatrix_lapacke/lapacke/src/lapacke_zpotrs_work.c +101 -0
  122. data/ext/nmatrix_lapacke/lapacke/utils/lapacke_cge_nancheck.c +62 -0
  123. data/ext/nmatrix_lapacke/lapacke/utils/lapacke_cge_trans.c +65 -0
  124. data/ext/nmatrix_lapacke/lapacke/utils/lapacke_cpo_nancheck.c +43 -0
  125. data/ext/nmatrix_lapacke/lapacke/utils/lapacke_cpo_trans.c +45 -0
  126. data/ext/nmatrix_lapacke/lapacke/utils/lapacke_ctr_nancheck.c +85 -0
  127. data/ext/nmatrix_lapacke/lapacke/utils/lapacke_ctr_trans.c +85 -0
  128. data/ext/nmatrix_lapacke/lapacke/utils/lapacke_dge_nancheck.c +62 -0
  129. data/ext/nmatrix_lapacke/lapacke/utils/lapacke_dge_trans.c +65 -0
  130. data/ext/nmatrix_lapacke/lapacke/utils/lapacke_dpo_nancheck.c +43 -0
  131. data/ext/nmatrix_lapacke/lapacke/utils/lapacke_dpo_trans.c +45 -0
  132. data/ext/nmatrix_lapacke/lapacke/utils/lapacke_dtr_nancheck.c +85 -0
  133. data/ext/nmatrix_lapacke/lapacke/utils/lapacke_dtr_trans.c +85 -0
  134. data/ext/nmatrix_lapacke/lapacke/utils/lapacke_lsame.c +41 -0
  135. data/ext/nmatrix_lapacke/lapacke/utils/lapacke_sge_nancheck.c +62 -0
  136. data/ext/nmatrix_lapacke/lapacke/utils/lapacke_sge_trans.c +65 -0
  137. data/ext/nmatrix_lapacke/lapacke/utils/lapacke_spo_nancheck.c +43 -0
  138. data/ext/nmatrix_lapacke/lapacke/utils/lapacke_spo_trans.c +45 -0
  139. data/ext/nmatrix_lapacke/lapacke/utils/lapacke_str_nancheck.c +85 -0
  140. data/ext/nmatrix_lapacke/lapacke/utils/lapacke_str_trans.c +85 -0
  141. data/ext/nmatrix_lapacke/lapacke/utils/lapacke_xerbla.c +46 -0
  142. data/ext/nmatrix_lapacke/lapacke/utils/lapacke_zge_nancheck.c +62 -0
  143. data/ext/nmatrix_lapacke/lapacke/utils/lapacke_zge_trans.c +65 -0
  144. data/ext/nmatrix_lapacke/lapacke/utils/lapacke_zpo_nancheck.c +43 -0
  145. data/ext/nmatrix_lapacke/lapacke/utils/lapacke_zpo_trans.c +45 -0
  146. data/ext/nmatrix_lapacke/lapacke/utils/lapacke_ztr_nancheck.c +85 -0
  147. data/ext/nmatrix_lapacke/lapacke/utils/lapacke_ztr_trans.c +85 -0
  148. data/ext/nmatrix_lapacke/lapacke_nmatrix.h +16 -0
  149. data/ext/nmatrix_lapacke/make_lapacke_cpp.rb +9 -0
  150. data/ext/nmatrix_lapacke/math_lapacke.cpp +967 -0
  151. data/ext/nmatrix_lapacke/math_lapacke/cblas_local.h +576 -0
  152. data/ext/nmatrix_lapacke/math_lapacke/cblas_templates_lapacke.h +51 -0
  153. data/ext/nmatrix_lapacke/math_lapacke/lapacke_templates.h +356 -0
  154. data/ext/nmatrix_lapacke/nmatrix_lapacke.cpp +42 -0
  155. data/lib/nmatrix/lapack_ext_common.rb +69 -0
  156. data/lib/nmatrix/lapacke.rb +213 -0
  157. data/spec/00_nmatrix_spec.rb +730 -0
  158. data/spec/01_enum_spec.rb +190 -0
  159. data/spec/02_slice_spec.rb +389 -0
  160. data/spec/03_nmatrix_monkeys_spec.rb +78 -0
  161. data/spec/2x2_dense_double.mat +0 -0
  162. data/spec/4x4_sparse.mat +0 -0
  163. data/spec/4x5_dense.mat +0 -0
  164. data/spec/blas_spec.rb +193 -0
  165. data/spec/elementwise_spec.rb +303 -0
  166. data/spec/homogeneous_spec.rb +99 -0
  167. data/spec/io/fortran_format_spec.rb +88 -0
  168. data/spec/io/harwell_boeing_spec.rb +98 -0
  169. data/spec/io/test.rua +9 -0
  170. data/spec/io_spec.rb +149 -0
  171. data/spec/lapack_core_spec.rb +482 -0
  172. data/spec/leakcheck.rb +16 -0
  173. data/spec/math_spec.rb +730 -0
  174. data/spec/nmatrix_yale_resize_test_associations.yaml +2802 -0
  175. data/spec/nmatrix_yale_spec.rb +286 -0
  176. data/spec/plugins/lapacke/lapacke_spec.rb +303 -0
  177. data/spec/rspec_monkeys.rb +56 -0
  178. data/spec/rspec_spec.rb +34 -0
  179. data/spec/shortcuts_spec.rb +310 -0
  180. data/spec/slice_set_spec.rb +157 -0
  181. data/spec/spec_helper.rb +140 -0
  182. data/spec/stat_spec.rb +203 -0
  183. data/spec/test.pcd +20 -0
  184. data/spec/utm5940.mtx +83844 -0
  185. metadata +262 -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