nmatrix 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. data/.gitignore +3 -0
  2. data/CONTRIBUTING.md +66 -0
  3. data/Gemfile +1 -1
  4. data/History.txt +68 -10
  5. data/LICENSE.txt +2 -2
  6. data/Manifest.txt +2 -0
  7. data/README.rdoc +90 -69
  8. data/Rakefile +18 -9
  9. data/ext/nmatrix/data/complex.h +7 -7
  10. data/ext/nmatrix/data/data.cpp +2 -7
  11. data/ext/nmatrix/data/data.h +7 -4
  12. data/ext/nmatrix/data/rational.h +2 -2
  13. data/ext/nmatrix/data/ruby_object.h +3 -10
  14. data/ext/nmatrix/extconf.rb +79 -54
  15. data/ext/nmatrix/new_extconf.rb +11 -12
  16. data/ext/nmatrix/nmatrix.cpp +94 -125
  17. data/ext/nmatrix/nmatrix.h +38 -17
  18. data/ext/nmatrix/ruby_constants.cpp +2 -15
  19. data/ext/nmatrix/ruby_constants.h +2 -14
  20. data/ext/nmatrix/storage/common.cpp +2 -2
  21. data/ext/nmatrix/storage/common.h +2 -2
  22. data/ext/nmatrix/storage/dense.cpp +206 -31
  23. data/ext/nmatrix/storage/dense.h +5 -2
  24. data/ext/nmatrix/storage/list.cpp +52 -4
  25. data/ext/nmatrix/storage/list.h +3 -2
  26. data/ext/nmatrix/storage/storage.cpp +6 -6
  27. data/ext/nmatrix/storage/storage.h +2 -2
  28. data/ext/nmatrix/storage/yale.cpp +202 -49
  29. data/ext/nmatrix/storage/yale.h +5 -4
  30. data/ext/nmatrix/ttable_helper.rb +108 -108
  31. data/ext/nmatrix/types.h +2 -15
  32. data/ext/nmatrix/util/io.cpp +2 -2
  33. data/ext/nmatrix/util/io.h +2 -2
  34. data/ext/nmatrix/util/lapack.h +2 -2
  35. data/ext/nmatrix/util/math.cpp +14 -14
  36. data/ext/nmatrix/util/math.h +2 -2
  37. data/ext/nmatrix/util/sl_list.cpp +2 -2
  38. data/ext/nmatrix/util/sl_list.h +2 -2
  39. data/ext/nmatrix/util/util.h +2 -2
  40. data/lib/nmatrix.rb +13 -35
  41. data/lib/nmatrix/blas.rb +182 -56
  42. data/lib/nmatrix/io/market.rb +38 -14
  43. data/lib/nmatrix/io/mat5_reader.rb +393 -278
  44. data/lib/nmatrix/io/mat_reader.rb +121 -107
  45. data/lib/nmatrix/lapack.rb +59 -14
  46. data/lib/nmatrix/monkeys.rb +32 -30
  47. data/lib/nmatrix/nmatrix.rb +204 -100
  48. data/lib/nmatrix/nvector.rb +166 -57
  49. data/lib/nmatrix/shortcuts.rb +364 -231
  50. data/lib/nmatrix/version.rb +8 -4
  51. data/nmatrix.gemspec +5 -3
  52. data/scripts/mac-brew-gcc.sh +1 -1
  53. data/spec/blas_spec.rb +80 -2
  54. data/spec/math_spec.rb +78 -32
  55. data/spec/nmatrix_list_spec.rb +55 -55
  56. data/spec/nmatrix_spec.rb +60 -117
  57. data/spec/nmatrix_yale_resize_test_associations.yaml +2802 -0
  58. data/spec/nmatrix_yale_spec.rb +214 -198
  59. data/spec/nvector_spec.rb +58 -2
  60. data/spec/shortcuts_spec.rb +156 -32
  61. data/spec/slice_spec.rb +229 -178
  62. data/spec/spec_helper.rb +2 -2
  63. metadata +71 -21
@@ -9,8 +9,8 @@
9
9
  //
10
10
  // == Copyright Information
11
11
  //
12
- // SciRuby is Copyright (c) 2010 - 2012, Ruby Science Foundation
13
- // NMatrix is Copyright (c) 2012, Ruby Science Foundation
12
+ // SciRuby is Copyright (c) 2010 - 2013, Ruby Science Foundation
13
+ // NMatrix is Copyright (c) 2013, Ruby Science Foundation
14
14
  //
15
15
  // Please see LICENSE.txt for additional copyright notices.
16
16
  //
@@ -86,7 +86,7 @@ extern "C" {
86
86
  // Lifecycle //
87
87
  ///////////////
88
88
 
89
- YALE_STORAGE* nm_yale_storage_create(nm::dtype_t dtype, size_t* shape, size_t dim, size_t init_capacity);
89
+ YALE_STORAGE* nm_yale_storage_create(nm::dtype_t dtype, size_t* shape, size_t dim, size_t init_capacity, nm::itype_t itype);
90
90
  YALE_STORAGE* nm_yale_storage_create_from_old_yale(nm::dtype_t dtype, size_t* shape, void* ia, void* ja, void* a, nm::dtype_t from_dtype);
91
91
  YALE_STORAGE* nm_yale_storage_create_merged(const YALE_STORAGE* merge_template, const YALE_STORAGE* other);
92
92
  void nm_yale_storage_delete(STORAGE* s);
@@ -97,6 +97,7 @@ extern "C" {
97
97
  // Accessors //
98
98
  ///////////////
99
99
 
100
+ VALUE nm_yale_each_stored_with_indices(VALUE nmatrix);
100
101
  void* nm_yale_storage_get(STORAGE* s, SLICE* slice);
101
102
  void* nm_yale_storage_ref(STORAGE* s, SLICE* slice);
102
103
  char nm_yale_storage_set(STORAGE* storage, SLICE* slice, void* v);
@@ -150,7 +151,7 @@ extern "C" {
150
151
  * because UINTX_MAX and UINTX_MAX-1 are both reserved for sparse matrix
151
152
  * multiplication.
152
153
  */
153
- inline nm::itype_t nm_yale_storage_itype(const YALE_STORAGE* s) {
154
+ inline nm::itype_t nm_yale_storage_default_itype(const YALE_STORAGE* s) {
154
155
  return nm_yale_storage_itype_by_shape(s->shape);
155
156
  }
156
157
 
@@ -2,125 +2,125 @@
2
2
 
3
3
  # A helper file for generating and maintaining template tables.
4
4
 
5
- def nullify(disabled)
6
- DTYPES.map { |t| if disabled.include?(t) then :NULL else t end }
5
+ def nullify(disabled) #:nodoc:
6
+ DTYPES.map { |t| if disabled.include?(t) then :NULL else t end }
7
7
  end
8
8
 
9
9
  DTYPES = [
10
- :uint8_t,
11
- :int8_t,
12
- :int16_t,
13
- :int32_t,
14
- :int64_t,
15
- :float32_t,
16
- :float64_t,
17
- :'nm::Complex64',
18
- :'nm::Complex128',
19
- :'nm::Rational32',
20
- :'nm::Rational64',
21
- :'nm::Rational128',
22
- :'nm::RubyObject'
23
- ]
10
+ :uint8_t,
11
+ :int8_t,
12
+ :int16_t,
13
+ :int32_t,
14
+ :int64_t,
15
+ :float32_t,
16
+ :float64_t,
17
+ :'nm::Complex64',
18
+ :'nm::Complex128',
19
+ :'nm::Rational32',
20
+ :'nm::Rational64',
21
+ :'nm::Rational128',
22
+ :'nm::RubyObject'
23
+ ]
24
24
 
25
25
  ITYPES = [
26
- :uint8_t,
27
- :uint16_t,
28
- :uint32_t,
29
- :uint64_t
30
- ]
26
+ :uint8_t,
27
+ :uint16_t,
28
+ :uint32_t,
29
+ :uint64_t
30
+ ]
31
31
 
32
32
  EWOPS = [
33
- :'nm::EW_ADD',
34
- :'nm::EW_SUB',
35
- :'nm::EW_MUL',
36
- :'nm::EW_DIV',
37
- :'nm::EW_MOD',
38
- :'nm::EW_EQEQ',
39
- :'nm::EW_NEQ',
40
- :'nm::EW_LT',
41
- :'nm::EW_GT',
42
- :'nm::EW_LEQ',
43
- :'nm::EW_GEQ'
44
- ]
33
+ :'nm::EW_ADD',
34
+ :'nm::EW_SUB',
35
+ :'nm::EW_MUL',
36
+ :'nm::EW_DIV',
37
+ :'nm::EW_MOD',
38
+ :'nm::EW_EQEQ',
39
+ :'nm::EW_NEQ',
40
+ :'nm::EW_LT',
41
+ :'nm::EW_GT',
42
+ :'nm::EW_LEQ',
43
+ :'nm::EW_GEQ'
44
+ ]
45
45
 
46
46
  LR_ALLOWED = {
47
- :uint8_t => nullify([:RubyObject]),
48
- :int8_t => nullify([:RubyObject]),
49
- :int16_t => nullify([:RubyObject]),
50
- :int32_t => nullify([:RubyObject]),
51
- :int64_t => nullify([:RubyObject]),
52
- :float32_t => nullify([:RubyObject]),
53
- :float64_t => nullify([:RubyObject]),
54
- :Complex64 => nullify([:RubyObject]),
55
- :Complex128 => nullify([:RubyObject]),
56
- :Rational32 => nullify([:float32_t, :float64_t, :'nm::Complex64', :'nm::Complex128', :'nm::RubyObject']),
57
- :Rational64 => nullify([:float32_t, :float64_t, :'nm::Complex64', :'nm::Complex128', :'nm::RubyObject']),
58
- :Rational128 => nullify([:float32_t, :float64_t, :'nm::Complex64', :'nm::Complex128', :'nm::RubyObject']),
59
- :RubyObject => nullify(DTYPES - [:RubyObject])
47
+ :uint8_t => nullify([:RubyObject]),
48
+ :int8_t => nullify([:RubyObject]),
49
+ :int16_t => nullify([:RubyObject]),
50
+ :int32_t => nullify([:RubyObject]),
51
+ :int64_t => nullify([:RubyObject]),
52
+ :float32_t => nullify([:RubyObject]),
53
+ :float64_t => nullify([:RubyObject]),
54
+ :Complex64 => nullify([:RubyObject]),
55
+ :Complex128 => nullify([:RubyObject]),
56
+ :Rational32 => nullify([:float32_t, :float64_t, :'nm::Complex64', :'nm::Complex128', :'nm::RubyObject']),
57
+ :Rational64 => nullify([:float32_t, :float64_t, :'nm::Complex64', :'nm::Complex128', :'nm::RubyObject']),
58
+ :Rational128 => nullify([:float32_t, :float64_t, :'nm::Complex64', :'nm::Complex128', :'nm::RubyObject']),
59
+ :RubyObject => nullify(DTYPES - [:RubyObject])
60
60
  }
61
61
 
62
62
  lines =
63
- case ARGV[0]
64
- when 'OPLR'
65
- '{' +
66
- EWOPS.map do |op|
67
-
68
- '{' +
69
- DTYPES.map do |l_dtype|
70
-
71
- '{' +
72
- LR_ALLOWED[l_dtype].map do |r_dtype|
73
- if r_dtype == :NULL
74
- 'NULL'
75
- else
76
- "fun<#{op}, #{l_dtype}, #{r_dtype}>"
77
- end
78
- end.join(', ') +
79
- '}'
80
-
81
- end.join(",\n") +
82
- '}'
83
-
84
- end.join(",\n") +
85
- '}'
86
-
87
- when 'OPID'
88
- '{' +
89
- EWOPS.map do |op|
90
- '{' +
91
- ITYPES.map do |itype|
92
- '{' +
93
- DTYPES.map do |dtype|
94
-
95
- if dtype == :NULL
96
- 'NULL'
97
- else
98
- "fun<#{op}, #{itype}, #{dtype}>"
99
- end
100
-
101
- end.join(",") +
102
- '}'
103
- end.join(",\\\n") +
104
- '}'
105
- end.join(",\\\n") +
106
- '}'
107
-
108
- when 'LR'
109
- '{' +
110
- DTYPES.map do |l_dtype|
111
-
112
- '{' +
113
- LR_ALLOWED[l_dtype].map do |r_dtype|
114
- if r_dtype == :NULL
115
- 'NULL'
116
- else
117
- "fun<#{l_dtype}, #{r_dtype}>"
118
- end
119
- end.join(', ') +
120
- '}'
121
-
122
- end.join(",\n") +
123
- '}'
124
- end
63
+ case ARGV[0]
64
+ when 'OPLR'
65
+ '{' +
66
+ EWOPS.map do |op|
67
+
68
+ '{' +
69
+ DTYPES.map do |l_dtype|
70
+
71
+ '{' +
72
+ LR_ALLOWED[l_dtype].map do |r_dtype|
73
+ if r_dtype == :NULL
74
+ 'NULL'
75
+ else
76
+ "fun<#{op}, #{l_dtype}, #{r_dtype}>"
77
+ end
78
+ end.join(', ') +
79
+ '}'
80
+
81
+ end.join(",\n") +
82
+ '}'
83
+
84
+ end.join(",\n") +
85
+ '}'
86
+
87
+ when 'OPID'
88
+ '{' +
89
+ EWOPS.map do |op|
90
+ '{' +
91
+ ITYPES.map do |itype|
92
+ '{' +
93
+ DTYPES.map do |dtype|
94
+
95
+ if dtype == :NULL
96
+ 'NULL'
97
+ else
98
+ "fun<#{op}, #{itype}, #{dtype}>"
99
+ end
100
+
101
+ end.join(",") +
102
+ '}'
103
+ end.join(",\\\n") +
104
+ '}'
105
+ end.join(",\\\n") +
106
+ '}'
107
+
108
+ when 'LR'
109
+ '{' +
110
+ DTYPES.map do |l_dtype|
111
+
112
+ '{' +
113
+ LR_ALLOWED[l_dtype].map do |r_dtype|
114
+ if r_dtype == :NULL
115
+ 'NULL'
116
+ else
117
+ "fun<#{l_dtype}, #{r_dtype}>"
118
+ end
119
+ end.join(', ') +
120
+ '}'
121
+
122
+ end.join(",\n") +
123
+ '}'
124
+ end
125
125
 
126
126
  puts lines
@@ -9,8 +9,8 @@
9
9
  //
10
10
  // == Copyright Information
11
11
  //
12
- // SciRuby is Copyright (c) 2010 - 2012, Ruby Science Foundation
13
- // NMatrix is Copyright (c) 2012, Ruby Science Foundation
12
+ // SciRuby is Copyright (c) 2010 - 2013, Ruby Science Foundation
13
+ // NMatrix is Copyright (c) 2013, Ruby Science Foundation
14
14
  //
15
15
  // Please see LICENSE.txt for additional copyright notices.
16
16
  //
@@ -34,10 +34,6 @@
34
34
 
35
35
  #include <stdint.h>
36
36
 
37
- /*
38
- * Project Includes
39
- */
40
-
41
37
  /*
42
38
  * Macros
43
39
  */
@@ -53,13 +49,4 @@
53
49
  typedef float float32_t;
54
50
  typedef double float64_t;
55
51
 
56
-
57
- /*
58
- * Data
59
- */
60
-
61
- /*
62
- * Functions
63
- */
64
-
65
52
  #endif
@@ -9,8 +9,8 @@
9
9
  //
10
10
  // == Copyright Information
11
11
  //
12
- // SciRuby is Copyright (c) 2010 - 2012, Ruby Science Foundation
13
- // NMatrix is Copyright (c) 2012, Ruby Science Foundation
12
+ // SciRuby is Copyright (c) 2010 - 2013, Ruby Science Foundation
13
+ // NMatrix is Copyright (c) 2013, Ruby Science Foundation
14
14
  //
15
15
  // Please see LICENSE.txt for additional copyright notices.
16
16
  //
@@ -9,8 +9,8 @@
9
9
  //
10
10
  // == Copyright Information
11
11
  //
12
- // SciRuby is Copyright (c) 2010 - 2012, Ruby Science Foundation
13
- // NMatrix is Copyright (c) 2012, Ruby Science Foundation
12
+ // SciRuby is Copyright (c) 2010 - 2013, Ruby Science Foundation
13
+ // NMatrix is Copyright (c) 2013, Ruby Science Foundation
14
14
  //
15
15
  // Please see LICENSE.txt for additional copyright notices.
16
16
  //
@@ -9,8 +9,8 @@
9
9
  //
10
10
  // == Copyright Information
11
11
  //
12
- // SciRuby is Copyright (c) 2010 - 2012, Ruby Science Foundation
13
- // NMatrix is Copyright (c) 2012, Ruby Science Foundation
12
+ // SciRuby is Copyright (c) 2010 - 2013, Ruby Science Foundation
13
+ // NMatrix is Copyright (c) 2013, Ruby Science Foundation
14
14
  //
15
15
  // Please see LICENSE.txt for additional copyright notices.
16
16
  //
@@ -9,8 +9,8 @@
9
9
  //
10
10
  // == Copyright Information
11
11
  //
12
- // SciRuby is Copyright (c) 2010 - 2012, Ruby Science Foundation
13
- // NMatrix is Copyright (c) 2012, Ruby Science Foundation
12
+ // SciRuby is Copyright (c) 2010 - 2013, Ruby Science Foundation
13
+ // NMatrix is Copyright (c) 2013, Ruby Science Foundation
14
14
  //
15
15
  // Please see LICENSE.txt for additional copyright notices.
16
16
  //
@@ -219,18 +219,18 @@ inline static void cblas_gemm(const enum CBLAS_ORDER order,
219
219
  * For documentation: http://www.netlib.org/lapack/double/dgetrf.f
220
220
  */
221
221
  template <typename DType>
222
- inline static bool cblas_gemv(const enum CBLAS_TRANSPOSE trans_a,
223
- int m, int n,
224
- void* alpha,
225
- void* a, int lda,
226
- void* x, int incx,
227
- void* beta,
228
- void* y, int incy)
222
+ inline static bool cblas_gemv(const enum CBLAS_TRANSPOSE trans,
223
+ const int m, const int n,
224
+ const void* alpha,
225
+ const void* a, const int lda,
226
+ const void* x, const int incx,
227
+ const void* beta,
228
+ void* y, const int incy)
229
229
  {
230
- return gemv<DType>(trans_a,
231
- m, n, reinterpret_cast<DType*>(alpha),
232
- reinterpret_cast<DType*>(a), lda,
233
- reinterpret_cast<DType*>(x), incx, reinterpret_cast<DType*>(beta),
230
+ return gemv<DType>(trans,
231
+ m, n, reinterpret_cast<const DType*>(alpha),
232
+ reinterpret_cast<const DType*>(a), lda,
233
+ reinterpret_cast<const DType*>(x), incx, reinterpret_cast<const DType*>(beta),
234
234
  reinterpret_cast<DType*>(y), incy);
235
235
  }
236
236
 
@@ -591,7 +591,7 @@ static VALUE nm_cblas_gemv(VALUE self,
591
591
  VALUE beta,
592
592
  VALUE y, VALUE incy)
593
593
  {
594
- NAMED_DTYPE_TEMPLATE_TABLE(ttable, nm::math::cblas_gemv, bool, const enum CBLAS_TRANSPOSE trans_a, int m, int n, void* alpha, void* a, int lda, void* x, int incx, void* beta, void* y, int incy);
594
+ NAMED_DTYPE_TEMPLATE_TABLE(ttable, nm::math::cblas_gemv, bool, const enum CBLAS_TRANSPOSE, const int, const int, const void*, const void*, const int, const void*, const int, const void*, void*, const int)
595
595
 
596
596
  nm::dtype_t dtype = NM_DTYPE(a);
597
597
 
@@ -9,8 +9,8 @@
9
9
  //
10
10
  // == Copyright Information
11
11
  //
12
- // SciRuby is Copyright (c) 2010 - 2012, Ruby Science Foundation
13
- // NMatrix is Copyright (c) 2012, Ruby Science Foundation
12
+ // SciRuby is Copyright (c) 2010 - 2013, Ruby Science Foundation
13
+ // NMatrix is Copyright (c) 2013, Ruby Science Foundation
14
14
  //
15
15
  // Please see LICENSE.txt for additional copyright notices.
16
16
  //
@@ -1,6 +1,6 @@
1
1
  //
2
- // SciRuby is Copyright (c) 2010 - 2012, Ruby Science Foundation
3
- // NMatrix is Copyright (c) 2012, Ruby Science Foundation
2
+ // SciRuby is Copyright (c) 2010 - 2013, Ruby Science Foundation
3
+ // NMatrix is Copyright (c) 2013, Ruby Science Foundation
4
4
  //
5
5
  // Please see LICENSE.txt for additional copyright notices.
6
6
  //
@@ -9,8 +9,8 @@
9
9
  //
10
10
  // == Copyright Information
11
11
  //
12
- // SciRuby is Copyright (c) 2010 - 2012, Ruby Science Foundation
13
- // NMatrix is Copyright (c) 2012, Ruby Science Foundation
12
+ // SciRuby is Copyright (c) 2010 - 2013, Ruby Science Foundation
13
+ // NMatrix is Copyright (c) 2013, Ruby Science Foundation
14
14
  //
15
15
  // Please see LICENSE.txt for additional copyright notices.
16
16
  //
@@ -9,8 +9,8 @@
9
9
  //
10
10
  // == Copyright Information
11
11
  //
12
- // SciRuby is Copyright (c) 2010 - 2012, Ruby Science Foundation
13
- // NMatrix is Copyright (c) 2012, Ruby Science Foundation
12
+ // SciRuby is Copyright (c) 2010 - 2013, Ruby Science Foundation
13
+ // NMatrix is Copyright (c) 2013, Ruby Science Foundation
14
14
  //
15
15
  // Please see LICENSE.txt for additional copyright notices.
16
16
  //
@@ -8,8 +8,8 @@
8
8
  #
9
9
  # == Copyright Information
10
10
  #
11
- # SciRuby is Copyright (c) 2010 - 2012, Ruby Science Foundation
12
- # NMatrix is Copyright (c) 2012, Ruby Science Foundation
11
+ # SciRuby is Copyright (c) 2010 - 2013, Ruby Science Foundation
12
+ # NMatrix is Copyright (c) 2013, Ruby Science Foundation
13
13
  #
14
14
  # Please see LICENSE.txt for additional copyright notices.
15
15
  #
@@ -22,43 +22,21 @@
22
22
  #
23
23
  # == nmatrix.rb
24
24
  #
25
- # This file loads the C extension for NMatrix and adds an autoload for the
26
- # NMatrix and NVector classes.
27
-
28
-
29
- #############
30
- # Autoloads #
31
- #############
32
-
33
-
34
- ############
35
- # Requires #
36
- ############
25
+ # This file loads the C extension for NMatrix and all the ruby files.
26
+ #
37
27
 
38
- # NMatrix
28
+ # For some reason nmatrix.so ends up in a different place during gem build.
29
+ if File.exist? "lib/nmatrix/nmatrix.so"
30
+ # Development
31
+ require "nmatrix/nmatrix.so"
32
+ else
33
+ # Gem
34
+ require "nmatrix.so"
35
+ end
39
36
 
40
37
  require 'nmatrix/nmatrix.rb'
41
38
  require 'nmatrix/version.rb'
42
39
  require 'nmatrix/nvector.rb'
43
40
  require 'nmatrix/blas.rb'
44
-
45
- # For some reason nmatrix.so ends up in a different place during gem build.
46
- if File.exist? 'lib/nmatrix/nmatrix.so'
47
- # Development
48
- require 'nmatrix/nmatrix.so'
49
- else
50
- # Gem
51
- require 'nmatrix.so'
52
- end
53
-
54
- # Monkey patches.
55
41
  require 'nmatrix/monkeys'
56
-
57
- #############
58
- # Autoloads #
59
- #############
60
-
61
- autoload :NMatrix, 'nmatrix/nmatrix'
62
- autoload :NVector, 'nmatrix/nvector'
63
-
64
- require "nmatrix/shortcuts.rb"
42
+ require "nmatrix/shortcuts.rb"