nmatrix-lapacke 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -32,6 +32,7 @@
32
32
  * Standard Includes
33
33
  */
34
34
 
35
+ #include <ruby.h>
35
36
  #include <cmath> // pow().
36
37
 
37
38
  /*
@@ -57,9 +58,9 @@ struct STORAGE_PAIR {
57
58
  };
58
59
 
59
60
  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)
61
+ size_t* coords; // Coordinate of first element
62
+ size_t* lengths; // Lengths of slice
63
+ bool single; // true if all lengths equal to 1 (represents single matrix element)
63
64
  };
64
65
 
65
66
  /*
@@ -32,7 +32,8 @@
32
32
  * Standard Includes
33
33
  */
34
34
 
35
- #include <stdlib.h>
35
+ #include <ruby.h>
36
+ #include <cstdlib>
36
37
 
37
38
  /*
38
39
  * Project Includes
@@ -69,10 +70,10 @@ extern "C" {
69
70
  // Lifecycle //
70
71
  ///////////////
71
72
 
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*);
73
+ DENSE_STORAGE* nm_dense_storage_create(nm::dtype_t dtype, size_t* shape, size_t dim, void* elements, size_t elements_length);
74
+ void nm_dense_storage_delete(STORAGE* s);
75
+ void nm_dense_storage_delete_ref(STORAGE* s);
76
+ void nm_dense_storage_mark(STORAGE*);
76
77
  void nm_dense_storage_register(const STORAGE* s);
77
78
  void nm_dense_storage_unregister(const STORAGE* s);
78
79
 
@@ -86,8 +87,8 @@ VALUE nm_dense_map_pair(VALUE self, VALUE right);
86
87
  VALUE nm_dense_map(VALUE self);
87
88
  VALUE nm_dense_each(VALUE nmatrix);
88
89
  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);
90
+ void* nm_dense_storage_get(const STORAGE* s, SLICE* slice);
91
+ void* nm_dense_storage_ref(const STORAGE* s, SLICE* slice);
91
92
  void nm_dense_storage_set(VALUE left, SLICE* slice, VALUE right);
92
93
 
93
94
  ///////////
@@ -33,7 +33,8 @@
33
33
  * Standard Includes
34
34
  */
35
35
 
36
- #include <stdlib.h>
36
+ #include <ruby.h>
37
+ #include <cstdlib>
37
38
  #include <list>
38
39
  /*
39
40
  * Project Includes
@@ -69,17 +70,17 @@ extern "C" {
69
70
  // Lifecycle //
70
71
  ///////////////
71
72
 
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*);
73
+ LIST_STORAGE* nm_list_storage_create(nm::dtype_t dtype, size_t* shape, size_t dim, void* init_val);
74
+ void nm_list_storage_delete(STORAGE* s);
75
+ void nm_list_storage_delete_ref(STORAGE* s);
76
+ void nm_list_storage_mark(STORAGE*);
76
77
  void nm_list_storage_register(const STORAGE* s);
77
78
  void nm_list_storage_unregister(const STORAGE* s);
78
79
  void nm_list_storage_register_list(const LIST* l, size_t recursions);
79
80
  void nm_list_storage_unregister_list(const LIST* l, size_t recursions);
80
81
  void nm_list_storage_register_node(const NODE* n);
81
82
  void nm_list_storage_unregister_node(const NODE* n);
82
- void nm_list_storage_completely_unregister_node(const NODE* curr);
83
+ void nm_list_storage_completely_unregister_node(const NODE* curr);
83
84
  ///////////////
84
85
  // Accessors //
85
86
  ///////////////
@@ -34,6 +34,7 @@
34
34
  * Standard Includes
35
35
  */
36
36
 
37
+ #include <ruby.h>
37
38
  #include <cstdlib>
38
39
 
39
40
  /*
@@ -53,10 +54,10 @@
53
54
  * Macros
54
55
  */
55
56
 
56
- #define NMATRIX_DTYPE_IS_COMPLEX(s) ((s->dtype == nm::COMPLEX64) or (s->dtype == nm::COMPLEX128))
57
- #define NMATRIX_DTYPE_IS_FLOAT(s) ((s->dtype == nm::FLOAT32) or (s->dtype == nm::FLOAT64))
58
- #define NMATRIX_DTYPE_IS_INTEGER(s) (s->dtype <= nm::INT64)
59
- #define NMATRIX_DTYPE_IS_RUBYOBJ(s) (s->dtype == nm::RUBYOBJ)
57
+ #define NMATRIX_DTYPE_IS_COMPLEX(s) ((s->dtype == nm::COMPLEX64) or (s->dtype == nm::COMPLEX128))
58
+ #define NMATRIX_DTYPE_IS_FLOAT(s) ((s->dtype == nm::FLOAT32) or (s->dtype == nm::FLOAT64))
59
+ #define NMATRIX_DTYPE_IS_INTEGER(s) (s->dtype <= nm::INT64)
60
+ #define NMATRIX_DTYPE_IS_RUBYOBJ(s) (s->dtype == nm::RUBYOBJ)
60
61
 
61
62
 
62
63
  /*
@@ -69,7 +70,7 @@
69
70
  */
70
71
 
71
72
  namespace nm {
72
- const int NUM_STYPES = 3;
73
+ const int NUM_STYPES = 3;
73
74
  }
74
75
 
75
76
  extern "C" {
@@ -85,12 +86,12 @@ extern "C" {
85
86
  // Copying and Casting //
86
87
  /////////////////////////
87
88
 
88
- STORAGE* nm_dense_storage_from_list(const STORAGE* right, nm::dtype_t l_dtype, void*);
89
- STORAGE* nm_dense_storage_from_yale(const STORAGE* right, nm::dtype_t l_dtype, void*);
90
- STORAGE* nm_list_storage_from_dense(const STORAGE* right, nm::dtype_t l_dtype, void*);
91
- STORAGE* nm_list_storage_from_yale(const STORAGE* right, nm::dtype_t l_dtype, void*);
92
- STORAGE* nm_yale_storage_from_list(const STORAGE* right, nm::dtype_t l_dtype, void*);
93
- STORAGE* nm_yale_storage_from_dense(const STORAGE* right, nm::dtype_t l_dtype, void*);
89
+ STORAGE* nm_dense_storage_from_list(const STORAGE* right, nm::dtype_t l_dtype, void*);
90
+ STORAGE* nm_dense_storage_from_yale(const STORAGE* right, nm::dtype_t l_dtype, void*);
91
+ STORAGE* nm_list_storage_from_dense(const STORAGE* right, nm::dtype_t l_dtype, void*);
92
+ STORAGE* nm_list_storage_from_yale(const STORAGE* right, nm::dtype_t l_dtype, void*);
93
+ STORAGE* nm_yale_storage_from_list(const STORAGE* right, nm::dtype_t l_dtype, void*);
94
+ STORAGE* nm_yale_storage_from_dense(const STORAGE* right, nm::dtype_t l_dtype, void*);
94
95
 
95
96
  } // end of extern "C" block
96
97
 
@@ -754,8 +754,8 @@ public:
754
754
  nm_yale_storage_register(lhs);
755
755
  for (size_t m = 0; m < size(); ++m) {
756
756
  if (Yield) {
757
- la[m] = rb_yield(nm::yale_storage::nm_rb_dereference(a(m)));
758
- }
757
+ la[m] = rb_yield(nm::yale_storage::nm_rb_dereference(a(m)));
758
+ }
759
759
  else la[m] = static_cast<E>(a(m));
760
760
  }
761
761
  nm_yale_storage_unregister(lhs);
@@ -29,6 +29,7 @@
29
29
  #ifndef YALE_ITERATORS_BASE_H
30
30
  # define YALE_ITERATORS_BASE_H
31
31
 
32
+ #include <ruby.h>
32
33
  #include <type_traits>
33
34
  #include <typeinfo>
34
35
  #include <stdexcept>
@@ -139,4 +140,4 @@ public:
139
140
 
140
141
  } } // end of namespace nm::yale_storage
141
142
 
142
- #endif // YALE_ITERATORS_BASE_H
143
+ #endif // YALE_ITERATORS_BASE_H
@@ -29,6 +29,7 @@
29
29
  #ifndef YALE_ITERATORS_ITERATOR_H
30
30
  # define YALE_ITERATORS_ITERATOR_H
31
31
 
32
+ #include <ruby.h>
32
33
  #include <type_traits>
33
34
  #include <typeinfo>
34
35
 
@@ -127,4 +128,4 @@ public:
127
128
 
128
129
  } } // end of namespace nm::yale_storage
129
130
 
130
- #endif // YALE_ITERATORS_ITERATOR_H
131
+ #endif // YALE_ITERATORS_ITERATOR_H
@@ -31,6 +31,7 @@
31
31
  #ifndef YALE_ITERATORS_ROW_H
32
32
  # define YALE_ITERATORS_ROW_H
33
33
 
34
+ #include <ruby.h>
34
35
  #include <stdexcept>
35
36
 
36
37
  namespace nm { namespace yale_storage {
@@ -446,4 +447,4 @@ public:
446
447
 
447
448
  } } // end of nm::yale_storage namespace
448
449
 
449
- #endif // YALE_ITERATORS_ROW_H
450
+ #endif // YALE_ITERATORS_ROW_H
@@ -34,6 +34,7 @@
34
34
  #ifndef YALE_ITERATORS_ROW_STORED_H
35
35
  # define YALE_ITERATORS_ROW_STORED_H
36
36
 
37
+ #include <ruby.h>
37
38
  #include <stdexcept>
38
39
 
39
40
  namespace nm { namespace yale_storage {
@@ -136,4 +137,4 @@ public:
136
137
 
137
138
  }} // end of namespace nm::yale_storage
138
139
 
139
- #endif // YALE_ITERATORS_ROW_STORED_H
140
+ #endif // YALE_ITERATORS_ROW_STORED_H
@@ -29,6 +29,7 @@
29
29
  #ifndef YALE_ITERATORS_ROW_STORED_ND_H
30
30
  # define YALE_ITERATORS_ROW_STORED_ND_H
31
31
 
32
+ #include <ruby.h>
32
33
  #include <type_traits>
33
34
  #include <typeinfo>
34
35
  #include <stdexcept>
@@ -29,6 +29,7 @@
29
29
  #ifndef YALE_ITERATORS_STORED_DIAGONAL_H
30
30
  # define YALE_ITERATORS_STORED_DIAGONAL_H
31
31
 
32
+ #include <ruby.h>
32
33
  #include <type_traits>
33
34
  #include <typeinfo>
34
35
 
@@ -120,4 +121,4 @@ public:
120
121
 
121
122
  } } // end of namespace nm::yale_storage
122
123
 
123
- #endif // YALE_ITERATORS_STORED_DIAGONAL_H
124
+ #endif // YALE_ITERATORS_STORED_DIAGONAL_H
@@ -42,6 +42,7 @@
42
42
  * Standard Includes
43
43
  */
44
44
 
45
+ #include <ruby.h>
45
46
  #include <limits> // for std::numeric_limits<T>::max()
46
47
  #include <stdexcept>
47
48
 
@@ -84,15 +85,15 @@ extern "C" {
84
85
 
85
86
  YALE_STORAGE* nm_yale_storage_create(nm::dtype_t dtype, size_t* shape, size_t dim, size_t init_capacity);
86
87
  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
+ YALE_STORAGE* nm_yale_storage_create_merged(const YALE_STORAGE* merge_template, const YALE_STORAGE* other);
88
89
  void nm_yale_storage_delete(STORAGE* s);
89
90
  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*);
91
+ void nm_yale_storage_init(YALE_STORAGE* s, void* default_val);
92
+ void nm_yale_storage_mark(STORAGE*);
92
93
  void nm_yale_storage_register(const STORAGE* s);
93
94
  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);
95
+ void nm_yale_storage_register_a(void* a, size_t size);
96
+ void nm_yale_storage_unregister_a(void* a, size_t size);
96
97
 
97
98
  ///////////////
98
99
  // Accessors //
@@ -104,7 +105,7 @@ extern "C" {
104
105
  VALUE nm_yale_stored_nondiagonal_each_with_indices(VALUE nmatrix);
105
106
  VALUE nm_yale_each_ordered_stored_with_indices(VALUE nmatrix);
106
107
  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_ref(const STORAGE* s, SLICE* slice);
108
109
  void nm_yale_storage_set(VALUE left, SLICE* slice, VALUE right);
109
110
 
110
111
  //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);
@@ -32,6 +32,7 @@
32
32
  * Standard Includes
33
33
  */
34
34
 
35
+ #include <ruby.h>
35
36
  #include <cstdint>
36
37
 
37
38
  /*
@@ -46,8 +47,8 @@
46
47
  * Types
47
48
  */
48
49
 
49
- typedef float float32_t;
50
- typedef double float64_t;
50
+ typedef float float32_t;
51
+ typedef double float64_t;
51
52
 
52
53
  typedef size_t IType;
53
54
 
@@ -33,6 +33,7 @@
33
33
  * Standard Includes
34
34
  */
35
35
 
36
+ #include <ruby.h>
36
37
  #include <type_traits>
37
38
  #include <cstdlib>
38
39
 
@@ -69,9 +70,9 @@ namespace nm { namespace list {
69
70
  // Lifecycle //
70
71
  ///////////////
71
72
 
72
- LIST* create(void);
73
- void del(LIST* list, size_t recursions);
74
- void mark(LIST* list, size_t recursions);
73
+ LIST* create(void);
74
+ void del(LIST* list, size_t recursions);
75
+ void mark(LIST* list, size_t recursions);
75
76
 
76
77
  ///////////////
77
78
  // Accessors //
@@ -90,25 +91,25 @@ bool node_is_within_slice(NODE* n, size_t coord, size_t len);
90
91
 
91
92
  template <typename Type>
92
93
  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
- }
94
+ Type* val_mem = NM_ALLOC(Type);
95
+ *val_mem = val;
96
+
97
+ if (node == NULL) {
98
+ return insert(list, false, key, val_mem);
99
+
100
+ } else {
101
+ return insert_after(node, key, val_mem);
102
+ }
102
103
  }
103
104
 
104
105
  template <typename Type>
105
106
  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
- }
107
+ if (node == NULL) {
108
+ return insert(list, false, key, ptr);
109
+
110
+ } else {
111
+ return insert_after(node, key, ptr);
112
+ }
112
113
  }
113
114
 
114
115
  ///////////
@@ -107,9 +107,6 @@ basenames = %w{nmatrix_lapacke math_lapacke lapacke}
107
107
  $objs = basenames.map { |b| "#{b}.o" }
108
108
  $srcs = basenames.map { |b| "#{b}.cpp" }
109
109
 
110
- #CONFIG['CXX'] = 'clang++'
111
- CONFIG['CXX'] = 'g++'
112
-
113
110
  def find_newer_gplusplus #:nodoc:
114
111
  print "checking for apparent GNU g++ binary with C++0x/C++11 support... "
115
112
  [9,8,7,6,5,4,3].each do |minor|
@@ -137,7 +134,7 @@ end
137
134
 
138
135
 
139
136
  if CONFIG['CXX'] == 'clang++'
140
- $CPP_STANDARD = 'c++11'
137
+ $CXX_STANDARD = 'c++11'
141
138
 
142
139
  else
143
140
  version = gplusplus_version
@@ -149,11 +146,11 @@ else
149
146
  end
150
147
 
151
148
  if version < '4.7.0'
152
- $CPP_STANDARD = 'c++0x'
149
+ $CXX_STANDARD = 'c++0x'
153
150
  else
154
- $CPP_STANDARD = 'c++11'
151
+ $CXX_STANDARD = 'c++11'
155
152
  end
156
- puts "using C++ standard... #{$CPP_STANDARD}"
153
+ puts "using C++ standard... #{$CXX_STANDARD}"
157
154
  puts "g++ reports version... " + `#{CONFIG['CXX']} --version|head -n 1|cut -f 3 -d " "`
158
155
  end
159
156
 
@@ -165,6 +162,10 @@ end
165
162
  # that Dir.exists?(d) for each.
166
163
  ldefaults = {lapack: ["/usr/local/lib"].delete_if { |d| !Dir.exists?(d) } }
167
164
 
165
+ # It is not clear how this variable should be defined, or if it is necessary at all.
166
+ # See issue https://github.com/SciRuby/nmatrix/issues/403
167
+ idefaults = {lapack: [] }
168
+
168
169
  unless have_library("lapack")
169
170
  dir_config("lapack", idefaults[:lapack], ldefaults[:lapack])
170
171
  end
@@ -183,13 +184,18 @@ $libs += " -llapack "
183
184
  # For release, these next two should both be changed to -O3.
184
185
  $CFLAGS += " -O3" #" -O0 -g "
185
186
  #$CFLAGS += " -static -O0 -g "
186
- $CPPFLAGS += " -O3 -std=#{$CPP_STANDARD}" #" -O0 -g -std=#{$CPP_STANDARD} " #-fmax-errors=10 -save-temps
187
- #$CPPFLAGS += " -static -O0 -g -std=#{$CPP_STANDARD} "
187
+ $CXXFLAGS += " -O3 -std=#{$CXX_STANDARD}" #" -O0 -g -std=#{$CXX_STANDARD} " #-fmax-errors=10 -save-temps
188
+ #$CPPFLAGS += " -static -O0 -g -std=#{$CXX_STANDARD} "
188
189
 
189
190
  CONFIG['warnflags'].gsub!('-Wshorten-64-to-32', '') # doesn't work except in Mac-patched gcc (4.2)
190
191
  CONFIG['warnflags'].gsub!('-Wdeclaration-after-statement', '')
191
192
  CONFIG['warnflags'].gsub!('-Wimplicit-function-declaration', '')
192
193
 
194
+ have_func("rb_array_const_ptr", "ruby.h")
195
+ have_macro("FIX_CONST_VALUE_PTR", "ruby.h")
196
+ have_macro("RARRAY_CONST_PTR", "ruby.h")
197
+ have_macro("RARRAY_AREF", "ruby.h")
198
+
193
199
  create_conf_h("nmatrix_lapacke_config.h")
194
200
  create_makefile("nmatrix_lapacke")
195
201
 
@@ -213,8 +213,8 @@ static VALUE nm_lapacke_cblas_rotg(VALUE self, VALUE ab) {
213
213
  rb_ary_store(result, 0, *reinterpret_cast<VALUE*>(pC));
214
214
  rb_ary_store(result, 1, *reinterpret_cast<VALUE*>(pS));
215
215
  } else {
216
- rb_ary_store(result, 0, rubyobj_from_cval(pC, dtype).rval);
217
- rb_ary_store(result, 1, rubyobj_from_cval(pS, dtype).rval);
216
+ rb_ary_store(result, 0, nm::rubyobj_from_cval(pC, dtype).rval);
217
+ rb_ary_store(result, 1, nm::rubyobj_from_cval(pS, dtype).rval);
218
218
  }
219
219
  NM_CONSERVATIVE(nm_unregister_value(&ab));
220
220
  NM_CONSERVATIVE(nm_unregister_value(&self));
@@ -334,7 +334,7 @@ static VALUE nm_lapacke_cblas_nrm2(VALUE self, VALUE n, VALUE x, VALUE incx) {
334
334
 
335
335
  ttable[dtype](FIX2INT(n), NM_STORAGE_DENSE(x)->elements, FIX2INT(incx), Result);
336
336
 
337
- return rubyobj_from_cval(Result, rdtype).rval;
337
+ return nm::rubyobj_from_cval(Result, rdtype).rval;
338
338
  }
339
339
  }
340
340
 
@@ -383,7 +383,7 @@ static VALUE nm_lapacke_cblas_asum(VALUE self, VALUE n, VALUE x, VALUE incx) {
383
383
 
384
384
  ttable[dtype](FIX2INT(n), NM_STORAGE_DENSE(x)->elements, FIX2INT(incx), Result);
385
385
 
386
- return rubyobj_from_cval(Result, rdtype).rval;
386
+ return nm::rubyobj_from_cval(Result, rdtype).rval;
387
387
  }
388
388
 
389
389
  /*
@@ -652,7 +652,7 @@ static VALUE nm_lapacke_lapacke_getri(VALUE self, VALUE order, VALUE n, VALUE a,
652
652
  } else {
653
653
  ipiv_ = NM_ALLOCA_N(int, RARRAY_LEN(ipiv));
654
654
  for (int index = 0; index < RARRAY_LEN(ipiv); ++index) {
655
- ipiv_[index] = FIX2INT( RARRAY_PTR(ipiv)[index] );
655
+ ipiv_[index] = FIX2INT( RARRAY_AREF(ipiv, index) );
656
656
  }
657
657
  }
658
658
 
@@ -744,7 +744,7 @@ static VALUE nm_lapacke_lapacke_getrs(VALUE self, VALUE order, VALUE trans, VALU
744
744
  } else {
745
745
  ipiv_ = NM_ALLOCA_N(int, RARRAY_LEN(ipiv));
746
746
  for (int index = 0; index < RARRAY_LEN(ipiv); ++index) {
747
- ipiv_[index] = FIX2INT( RARRAY_PTR(ipiv)[index] );
747
+ ipiv_[index] = FIX2INT( RARRAY_AREF(ipiv, index) );
748
748
  }
749
749
  }
750
750