nmatrix-gemv 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +29 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +14 -0
  5. data/Gemfile +7 -0
  6. data/README.md +29 -0
  7. data/Rakefile +225 -0
  8. data/ext/nmatrix_gemv/binary_format.txt +53 -0
  9. data/ext/nmatrix_gemv/data/complex.h +399 -0
  10. data/ext/nmatrix_gemv/data/data.cpp +298 -0
  11. data/ext/nmatrix_gemv/data/data.h +771 -0
  12. data/ext/nmatrix_gemv/data/meta.h +70 -0
  13. data/ext/nmatrix_gemv/data/rational.h +436 -0
  14. data/ext/nmatrix_gemv/data/ruby_object.h +471 -0
  15. data/ext/nmatrix_gemv/extconf.rb +254 -0
  16. data/ext/nmatrix_gemv/math.cpp +1639 -0
  17. data/ext/nmatrix_gemv/math/asum.h +143 -0
  18. data/ext/nmatrix_gemv/math/geev.h +82 -0
  19. data/ext/nmatrix_gemv/math/gemm.h +271 -0
  20. data/ext/nmatrix_gemv/math/gemv.h +212 -0
  21. data/ext/nmatrix_gemv/math/ger.h +96 -0
  22. data/ext/nmatrix_gemv/math/gesdd.h +80 -0
  23. data/ext/nmatrix_gemv/math/gesvd.h +78 -0
  24. data/ext/nmatrix_gemv/math/getf2.h +86 -0
  25. data/ext/nmatrix_gemv/math/getrf.h +240 -0
  26. data/ext/nmatrix_gemv/math/getri.h +108 -0
  27. data/ext/nmatrix_gemv/math/getrs.h +129 -0
  28. data/ext/nmatrix_gemv/math/idamax.h +86 -0
  29. data/ext/nmatrix_gemv/math/inc.h +47 -0
  30. data/ext/nmatrix_gemv/math/laswp.h +165 -0
  31. data/ext/nmatrix_gemv/math/long_dtype.h +52 -0
  32. data/ext/nmatrix_gemv/math/math.h +1069 -0
  33. data/ext/nmatrix_gemv/math/nrm2.h +181 -0
  34. data/ext/nmatrix_gemv/math/potrs.h +129 -0
  35. data/ext/nmatrix_gemv/math/rot.h +141 -0
  36. data/ext/nmatrix_gemv/math/rotg.h +115 -0
  37. data/ext/nmatrix_gemv/math/scal.h +73 -0
  38. data/ext/nmatrix_gemv/math/swap.h +73 -0
  39. data/ext/nmatrix_gemv/math/trsm.h +387 -0
  40. data/ext/nmatrix_gemv/nm_memory.h +60 -0
  41. data/ext/nmatrix_gemv/nmatrix_gemv.cpp +90 -0
  42. data/ext/nmatrix_gemv/nmatrix_gemv.h +374 -0
  43. data/ext/nmatrix_gemv/ruby_constants.cpp +153 -0
  44. data/ext/nmatrix_gemv/ruby_constants.h +107 -0
  45. data/ext/nmatrix_gemv/ruby_nmatrix.c +84 -0
  46. data/ext/nmatrix_gemv/ttable_helper.rb +122 -0
  47. data/ext/nmatrix_gemv/types.h +54 -0
  48. data/ext/nmatrix_gemv/util/util.h +78 -0
  49. data/lib/nmatrix-gemv.rb +43 -0
  50. data/lib/nmatrix_gemv/blas.rb +85 -0
  51. data/lib/nmatrix_gemv/nmatrix_gemv.rb +35 -0
  52. data/lib/nmatrix_gemv/rspec.rb +75 -0
  53. data/nmatrix-gemv.gemspec +31 -0
  54. data/spec/blas_spec.rb +154 -0
  55. data/spec/spec_helper.rb +128 -0
  56. metadata +186 -0
@@ -0,0 +1,153 @@
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
+ // == ruby_symbols.cpp
25
+ //
26
+ // Ruby symbols used throught the NMatrix project.
27
+
28
+ /*
29
+ * Standard Includes
30
+ */
31
+
32
+ #include <ruby.h>
33
+
34
+ /*
35
+ * Global Variables
36
+ */
37
+
38
+ ID nm_rb_dtype,
39
+ nm_rb_stype,
40
+
41
+ nm_rb_capacity,
42
+ nm_rb_default,
43
+
44
+ nm_rb_real,
45
+ nm_rb_imag,
46
+
47
+ nm_rb_numer,
48
+ nm_rb_denom,
49
+
50
+ nm_rb_complex_conjugate,
51
+ nm_rb_transpose,
52
+ nm_rb_no_transpose,
53
+ nm_rb_left,
54
+ nm_rb_right,
55
+ nm_rb_upper,
56
+ nm_rb_lower,
57
+ nm_rb_unit,
58
+ nm_rb_nonunit,
59
+
60
+ nm_rb_dense,
61
+ nm_rb_list,
62
+ nm_rb_yale,
63
+
64
+ nm_rb_row,
65
+ nm_rb_column,
66
+ nm_rb_add,
67
+ nm_rb_sub,
68
+ nm_rb_mul,
69
+ nm_rb_div,
70
+ nm_rb_both,
71
+ nm_rb_none,
72
+
73
+ nm_rb_negate,
74
+
75
+ nm_rb_percent,
76
+ nm_rb_gt,
77
+ nm_rb_lt,
78
+ nm_rb_eql,
79
+ nm_rb_neql,
80
+ nm_rb_gte,
81
+ nm_rb_lte,
82
+
83
+ nm_rb_hash;
84
+
85
+ VALUE cNMatrix,
86
+ cNMatrix_IO,
87
+ cNMatrix_IO_Matlab,
88
+ cNVector,
89
+ cNMatrix_YaleFunctions,
90
+ cNMatrix_BLAS,
91
+ cNMatrix_LAPACK,
92
+
93
+ cNMatrix_GC_holder,
94
+
95
+ nm_eDataTypeError,
96
+ nm_eConvergenceError,
97
+ nm_eStorageTypeError;
98
+
99
+ /*
100
+ * Functions
101
+ */
102
+
103
+ void nm_init_ruby_constants(void) {
104
+ nm_rb_dtype = rb_intern("dtype");
105
+ nm_rb_stype = rb_intern("stype");
106
+
107
+ nm_rb_capacity = rb_intern("capacity");
108
+ nm_rb_default = rb_intern("default");
109
+
110
+ nm_rb_real = rb_intern("real");
111
+ nm_rb_imag = rb_intern("imag");
112
+
113
+ nm_rb_numer = rb_intern("numerator");
114
+ nm_rb_denom = rb_intern("denominator");
115
+
116
+ nm_rb_complex_conjugate = rb_intern("complex_conjugate");
117
+ nm_rb_transpose = rb_intern("transpose");
118
+ nm_rb_no_transpose = rb_intern("no_transpose");
119
+
120
+ nm_rb_dense = rb_intern("dense");
121
+ nm_rb_list = rb_intern("list");
122
+ nm_rb_yale = rb_intern("yale");
123
+
124
+ nm_rb_add = rb_intern("+");
125
+ nm_rb_sub = rb_intern("-");
126
+ nm_rb_mul = rb_intern("*");
127
+ nm_rb_div = rb_intern("/");
128
+
129
+ nm_rb_negate = rb_intern("-@");
130
+
131
+ nm_rb_percent = rb_intern("%");
132
+ nm_rb_gt = rb_intern(">");
133
+ nm_rb_lt = rb_intern("<");
134
+ nm_rb_eql = rb_intern("==");
135
+ nm_rb_neql = rb_intern("!=");
136
+ nm_rb_gte = rb_intern(">=");
137
+ nm_rb_lte = rb_intern("<=");
138
+
139
+ nm_rb_left = rb_intern("left");
140
+ nm_rb_right = rb_intern("right");
141
+ nm_rb_upper = rb_intern("upper");
142
+ nm_rb_lower = rb_intern("lower");
143
+ nm_rb_unit = rb_intern("unit");
144
+ nm_rb_nonunit = rb_intern("nonunit");
145
+ nm_rb_hash = rb_intern("hash");
146
+
147
+ nm_rb_column = rb_intern("column");
148
+ nm_rb_row = rb_intern("row");
149
+
150
+ //Added by Ryan
151
+ nm_rb_both = rb_intern("both");
152
+ nm_rb_none = rb_intern("none");
153
+ }
@@ -0,0 +1,107 @@
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
+ cNVector,
91
+ cNMatrix_YaleFunctions,
92
+ cNMatrix_BLAS,
93
+ cNMatrix_LAPACK,
94
+
95
+ cNMatrix_GC_holder,
96
+
97
+ nm_eDataTypeError,
98
+ nm_eConvergenceError,
99
+ nm_eStorageTypeError;
100
+
101
+ /*
102
+ * Functions
103
+ */
104
+
105
+ void nm_init_ruby_constants(void);
106
+
107
+ #endif // RUBY_CONSTANTS_H
@@ -0,0 +1,84 @@
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
+ // == ruby_nmatrix.c
25
+ //
26
+ // Ruby-facing NMatrix C functions. Not compiled directly -- included
27
+ // into nmatrix.cpp.
28
+ //
29
+
30
+ /*
31
+ #ifdef BENCHMARK
32
+ static double get_time(void);
33
+ #endif
34
+ */
35
+
36
+ ///////////////////
37
+ // Ruby Bindings //
38
+ ///////////////////
39
+
40
+ void Init_nmatrix_gemv() {
41
+
42
+
43
+ ///////////////////////
44
+ // Class Definitions //
45
+ ///////////////////////
46
+
47
+ cNMatrix = rb_define_class("NMatrix", rb_cObject);
48
+
49
+ // Special exceptions
50
+
51
+ /*
52
+ * Exception raised when there's a problem with data.
53
+ */
54
+ nm_eDataTypeError = rb_define_class("DataTypeError", rb_eStandardError);
55
+
56
+ /*
57
+ * Exception raised when something goes wrong with the storage of a matrix.
58
+ */
59
+ nm_eStorageTypeError = rb_define_class("StorageTypeError", rb_eStandardError);
60
+
61
+ /*
62
+ * Class that holds values in use by the C code.
63
+ */
64
+ cNMatrix_GC_holder = rb_define_class("NMGCHolder", rb_cObject);
65
+
66
+ ///////////////////////
67
+ // Symbol Generation //
68
+ ///////////////////////
69
+
70
+ nm_init_ruby_constants();
71
+
72
+ /////////////////
73
+ // BLAS module //
74
+ /////////////////
75
+
76
+ nm_math_init_blas();
77
+
78
+ /////////////////////////////////////////////////
79
+ // Force compilation of necessary constructors //
80
+ /////////////////////////////////////////////////
81
+ nm_init_data();
82
+ }
83
+
84
+
@@ -0,0 +1,122 @@
1
+ #!/usr/bin/ruby
2
+
3
+ # A helper file for generating and maintaining template tables.
4
+
5
+
6
+ DTYPES = [
7
+ :uint8_t,
8
+ :int8_t,
9
+ :int16_t,
10
+ :int32_t,
11
+ :int64_t,
12
+ :float32_t,
13
+ :float64_t,
14
+ :'nm::Complex64',
15
+ :'nm::Complex128',
16
+ :'nm::Rational32',
17
+ :'nm::Rational64',
18
+ :'nm::Rational128',
19
+ :'nm::RubyObject'
20
+ ]
21
+
22
+ def nullify(disabled = []) #:nodoc:
23
+ DTYPES.map { |t| if disabled.include?(t) then :NULL else t end }
24
+ end
25
+
26
+ ITYPES = [
27
+ :uint8_t,
28
+ :uint16_t,
29
+ :uint32_t,
30
+ :uint64_t
31
+ ]
32
+
33
+ EWOPS = [
34
+ :'nm::EW_ADD',
35
+ :'nm::EW_SUB',
36
+ :'nm::EW_MUL',
37
+ :'nm::EW_DIV',
38
+ :'nm::EW_POW',
39
+ :'nm::EW_MOD',
40
+ :'nm::EW_EQEQ',
41
+ :'nm::EW_NEQ',
42
+ :'nm::EW_LT',
43
+ :'nm::EW_GT',
44
+ :'nm::EW_LEQ',
45
+ :'nm::EW_GEQ'
46
+ ]
47
+
48
+ LR_ALLOWED = {
49
+ :uint8_t => DTYPES,
50
+ :int8_t => DTYPES,
51
+ :int16_t => DTYPES,
52
+ :int32_t => DTYPES,
53
+ :int64_t => DTYPES,
54
+ :float32_t => DTYPES,
55
+ :float64_t => DTYPES,
56
+ :'nm::Complex64' => DTYPES,
57
+ :'nm::Complex128' => DTYPES,
58
+ :'nm::Rational32' => nullify([:float32_t, :float64_t, :'nm::Complex64', :'nm::Complex128']),
59
+ :'nm::Rational64' => nullify([:float32_t, :float64_t, :'nm::Complex64', :'nm::Complex128']),
60
+ :'nm::Rational128' => nullify([:float32_t, :float64_t, :'nm::Complex64', :'nm::Complex128']),
61
+ :'nm::RubyObject' => DTYPES
62
+ }
63
+
64
+ lines =
65
+ case ARGV[0]
66
+ when 'OPLR'
67
+ '{' +
68
+ EWOPS.map do |op|
69
+
70
+ '{' +
71
+ DTYPES.map do |l_dtype|
72
+
73
+ '{' +
74
+ LR_ALLOWED[l_dtype].map do |r_dtype|
75
+ if r_dtype == :NULL
76
+ 'NULL'
77
+ else
78
+ "fun<#{op}, #{l_dtype}, #{r_dtype}>"
79
+ end
80
+ end.join(', ') +
81
+ '}'
82
+
83
+ end.join(",\n") +
84
+ '}'
85
+
86
+ end.join(",\n") +
87
+ '}'
88
+
89
+ when 'OPID'
90
+ '{' +
91
+ EWOPS.map do |op|
92
+ '{' +
93
+ ITYPES.map do |itype|
94
+ '{' +
95
+ DTYPES.map do |dtype|
96
+
97
+ if dtype == :NULL
98
+ 'NULL'
99
+ else
100
+ "fun<#{op}, #{itype}, #{dtype}>"
101
+ end
102
+
103
+ end.join(",") +
104
+ '}'
105
+ end.join(",\\\n") +
106
+ '}'
107
+ end.join(",\\\n") +
108
+ '}'
109
+
110
+ when 'LR'
111
+ '{' + DTYPES.map do |l_dtype|
112
+ '{' + LR_ALLOWED[l_dtype].map do |r_dtype|
113
+ if r_dtype == :NULL
114
+ 'NULL'
115
+ else
116
+ "fun<#{l_dtype}, #{r_dtype}>"
117
+ end
118
+ end.join(', ') + '}'
119
+ end.join(",\n") + '}'
120
+ end
121
+
122
+ puts lines