ext/nmatrix/storage/dense/dense.cpp in nmatrix-0.1.0.rc4 vs ext/nmatrix/storage/dense/dense.cpp in nmatrix-0.1.0.rc5
- old
+ new
@@ -121,12 +121,12 @@
/*
* Dense storage set/slice-set function, templated version.
*/
template <typename D>
void set(VALUE left, SLICE* slice, VALUE right) {
- NM_CONSERVATIVE(nm_register_value(left));
- NM_CONSERVATIVE(nm_register_value(right));
+ NM_CONSERVATIVE(nm_register_value(&left));
+ NM_CONSERVATIVE(nm_register_value(&right));
DENSE_STORAGE* s = NM_STORAGE_DENSE(left);
std::pair<NMATRIX*,bool> nm_and_free =
interpret_arg_as_dense_nmatrix(right, s->dtype);
@@ -172,12 +172,12 @@
} else {
if (s->dtype == nm::RUBYOBJ)
nm_unregister_values(reinterpret_cast<VALUE*>(v), v_size);
NM_FREE(v);
}
- NM_CONSERVATIVE(nm_unregister_value(left));
- NM_CONSERVATIVE(nm_unregister_value(right));
+ NM_CONSERVATIVE(nm_unregister_value(&left));
+ NM_CONSERVATIVE(nm_unregister_value(&right));
}
}} // end of namespace nm::dense_storage
@@ -359,16 +359,16 @@
/*
* map_pair iterator for dense matrices (for element-wise operations)
*/
VALUE nm_dense_map_pair(VALUE self, VALUE right) {
- NM_CONSERVATIVE(nm_register_value(self));
- NM_CONSERVATIVE(nm_register_value(right));
+ NM_CONSERVATIVE(nm_register_value(&self));
+ NM_CONSERVATIVE(nm_register_value(&right));
RETURN_SIZED_ENUMERATOR_PRE
- NM_CONSERVATIVE(nm_unregister_value(right));
- NM_CONSERVATIVE(nm_unregister_value(self));
+ NM_CONSERVATIVE(nm_unregister_value(&right));
+ NM_CONSERVATIVE(nm_unregister_value(&self));
RETURN_SIZED_ENUMERATOR(self, 0, 0, nm_enumerator_length);
DENSE_STORAGE *s = NM_STORAGE_DENSE(self),
*t = NM_STORAGE_DENSE(right);
@@ -389,39 +389,39 @@
nm_dense_storage_coords(result, k, coords);
size_t s_index = nm_dense_storage_pos(s, coords),
t_index = nm_dense_storage_pos(t, coords);
VALUE sval = NM_DTYPE(self) == nm::RUBYOBJ ? reinterpret_cast<VALUE*>(s->elements)[s_index] : rubyobj_from_cval((char*)(s->elements) + s_index*DTYPE_SIZES[NM_DTYPE(self)], NM_DTYPE(self)).rval;
- nm_register_value(sval);
+ nm_register_value(&sval);
VALUE tval = NM_DTYPE(right) == nm::RUBYOBJ ? reinterpret_cast<VALUE*>(t->elements)[t_index] : rubyobj_from_cval((char*)(t->elements) + t_index*DTYPE_SIZES[NM_DTYPE(right)], NM_DTYPE(right)).rval;
result_elem[k] = rb_yield_values(2, sval, tval);
- nm_unregister_value(sval);
+ nm_unregister_value(&sval);
}
VALUE klass = CLASS_OF(self);
NMATRIX* m = nm_create(nm::DENSE_STORE, reinterpret_cast<STORAGE*>(result));
nm_register_nmatrix(m);
VALUE to_return = Data_Wrap_Struct(klass, nm_mark, nm_delete, m);
nm_unregister_nmatrix(m);
nm_dense_storage_unregister(result);
- NM_CONSERVATIVE(nm_unregister_value(self));
- NM_CONSERVATIVE(nm_unregister_value(right));
+ NM_CONSERVATIVE(nm_unregister_value(&self));
+ NM_CONSERVATIVE(nm_unregister_value(&right));
return to_return;
}
/*
* map enumerator for dense matrices.
*/
VALUE nm_dense_map(VALUE self) {
- NM_CONSERVATIVE(nm_register_value(self));
+ NM_CONSERVATIVE(nm_register_value(&self));
RETURN_SIZED_ENUMERATOR_PRE
- NM_CONSERVATIVE(nm_unregister_value(self));
+ NM_CONSERVATIVE(nm_unregister_value(&self));
RETURN_SIZED_ENUMERATOR(self, 0, 0, nm_enumerator_length);
DENSE_STORAGE *s = NM_STORAGE_DENSE(self);
size_t* coords = NM_ALLOCA_N(size_t, s->dim);
@@ -452,25 +452,25 @@
VALUE to_return = Data_Wrap_Struct(klass, nm_mark, nm_delete, m);
nm_unregister_nmatrix(m);
nm_dense_storage_unregister(result);
- NM_CONSERVATIVE(nm_unregister_value(self));
+ NM_CONSERVATIVE(nm_unregister_value(&self));
return to_return;
}
/*
* each_with_indices iterator for dense matrices.
*/
VALUE nm_dense_each_with_indices(VALUE nmatrix) {
- NM_CONSERVATIVE(nm_register_value(nmatrix));
+ NM_CONSERVATIVE(nm_register_value(&nmatrix));
RETURN_SIZED_ENUMERATOR_PRE
- NM_CONSERVATIVE(nm_unregister_value(nmatrix));
+ NM_CONSERVATIVE(nm_unregister_value(&nmatrix));
RETURN_SIZED_ENUMERATOR(nmatrix, 0, 0, nm_enumerator_length); // fourth argument only used by Ruby2+
DENSE_STORAGE* s = NM_STORAGE_DENSE(nmatrix);
// Create indices and initialize them to zero
size_t* coords = NM_ALLOCA_N(size_t, s->dim);
@@ -484,26 +484,26 @@
for (size_t k = 0; k < nm_storage_count_max_elements(s); ++k) {
nm_dense_storage_coords(sliced_dummy, k, coords);
slice_index = nm_dense_storage_pos(s, coords);
VALUE ary = rb_ary_new();
- nm_register_value(ary);
+ nm_register_value(&ary);
if (NM_DTYPE(nmatrix) == nm::RUBYOBJ) rb_ary_push(ary, reinterpret_cast<VALUE*>(s->elements)[slice_index]);
else rb_ary_push(ary, rubyobj_from_cval((char*)(s->elements) + slice_index*DTYPE_SIZES[NM_DTYPE(nmatrix)], NM_DTYPE(nmatrix)).rval);
for (size_t p = 0; p < s->dim; ++p) {
rb_ary_push(ary, INT2FIX(coords[p]));
}
// yield the array which now consists of the value and the indices
rb_yield(ary);
- nm_unregister_value(ary);
+ nm_unregister_value(&ary);
}
nm_dense_storage_delete(sliced_dummy);
- NM_CONSERVATIVE(nm_unregister_value(nmatrix));
+ NM_CONSERVATIVE(nm_unregister_value(&nmatrix));
return nmatrix;
}
@@ -515,14 +515,14 @@
* Additionally, handles separately matrices containing VALUEs and matrices
* containing other types of data.
*/
VALUE nm_dense_each(VALUE nmatrix) {
- NM_CONSERVATIVE(nm_register_value(nmatrix));
+ NM_CONSERVATIVE(nm_register_value(&nmatrix));
RETURN_SIZED_ENUMERATOR_PRE
- NM_CONSERVATIVE(nm_unregister_value(nmatrix));
+ NM_CONSERVATIVE(nm_unregister_value(&nmatrix));
RETURN_SIZED_ENUMERATOR(nmatrix, 0, 0, nm_enumerator_length);
DENSE_STORAGE* s = NM_STORAGE_DENSE(nmatrix);
size_t* temp_coords = NM_ALLOCA_N(size_t, s->dim);
@@ -551,11 +551,11 @@
rb_yield( v ); // yield to the copy we made
}
}
nm_dense_storage_delete(sliced_dummy);
- NM_CONSERVATIVE(nm_unregister_value(nmatrix));
+ NM_CONSERVATIVE(nm_unregister_value(&nmatrix));
return nmatrix;
}
@@ -872,29 +872,29 @@
* it into the correct form if it's not already there (dtype, non-ref, dense). Returns a pair of the NMATRIX* and a
* boolean. If the boolean is true, the calling function is responsible for calling nm_delete on the NMATRIX*.
* Otherwise, the NMATRIX* still belongs to Ruby and Ruby will free it.
*/
std::pair<NMATRIX*,bool> interpret_arg_as_dense_nmatrix(VALUE right, nm::dtype_t dtype) {
- NM_CONSERVATIVE(nm_register_value(right));
+ NM_CONSERVATIVE(nm_register_value(&right));
if (TYPE(right) == T_DATA && (RDATA(right)->dfree == (RUBY_DATA_FUNC)nm_delete || RDATA(right)->dfree == (RUBY_DATA_FUNC)nm_delete_ref)) {
NMATRIX *r;
if (NM_STYPE(right) != DENSE_STORE || NM_DTYPE(right) != dtype || NM_SRC(right) != NM_STORAGE(right)) {
UnwrapNMatrix( right, r );
NMATRIX* ldtype_r = nm_cast_with_ctype_args(r, nm::DENSE_STORE, dtype, NULL);
- NM_CONSERVATIVE(nm_unregister_value(right));
+ NM_CONSERVATIVE(nm_unregister_value(&right));
return std::make_pair(ldtype_r,true);
} else { // simple case -- right-hand matrix is dense and is not a reference and has same dtype
UnwrapNMatrix( right, r );
- NM_CONSERVATIVE(nm_unregister_value(right));
+ NM_CONSERVATIVE(nm_unregister_value(&right));
return std::make_pair(r, false);
}
// Do not set v_alloc = true for either of these. It is the responsibility of r/ldtype_r
} else if (TYPE(right) == T_DATA) {
- NM_CONSERVATIVE(nm_unregister_value(right));
+ NM_CONSERVATIVE(nm_unregister_value(&right));
rb_raise(rb_eTypeError, "unrecognized type for slice assignment");
}
- NM_CONSERVATIVE(nm_unregister_value(right));
+ NM_CONSERVATIVE(nm_unregister_value(&right));
return std::make_pair<NMATRIX*,bool>(NULL, false);
}
namespace dense_storage {