From e5d169b27345d28d6d87411501833a1a7c6acab3 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Mon, 23 May 2016 19:16:48 +0530 Subject: [PATCH] Fix det_exact for object dtype (#514) * Fix NMatrix#det_exact for ruby objects * Add tests for NMatrix#det_exact dtype=:object --- ext/nmatrix/ruby_nmatrix.c | 10 +++++----- spec/math_spec.rb | 13 +++++++++---- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/ext/nmatrix/ruby_nmatrix.c b/ext/nmatrix/ruby_nmatrix.c index 975e0561..066c1c3f 100644 --- a/ext/nmatrix/ruby_nmatrix.c +++ b/ext/nmatrix/ruby_nmatrix.c @@ -3006,12 +3006,12 @@ static VALUE nm_det_exact(VALUE self) { nm::dtype_t dtype = NM_DTYPE(self); nm_math_det_exact(NM_SHAPE0(self), NM_STORAGE_DENSE(self)->elements, NM_SHAPE0(self), NM_DTYPE(self), result); + VALUE to_return; if (dtype == nm::RUBYOBJ) { - nm_register_values(reinterpret_cast(result), 1); - } - VALUE to_return = nm::rubyobj_from_cval(result, NM_DTYPE(self)).rval; - if (dtype == nm::RUBYOBJ) { - nm_unregister_values(reinterpret_cast(result), 1); + to_return = *reinterpret_cast(result); + + } else { + to_return = nm::rubyobj_from_cval(result, NM_DTYPE(self)).rval; } NM_CONSERVATIVE(nm_unregister_value(&self)); diff --git a/spec/math_spec.rb b/spec/math_spec.rb index eff8fdfb..a0656beb 100644 --- a/spec/math_spec.rb +++ b/spec/math_spec.rb @@ -946,7 +946,6 @@ context "determinants" do ALL_DTYPES.each do |dtype| - next if dtype == :object context dtype do before do @a = NMatrix.new([2,2], [1,2, @@ -968,13 +967,19 @@ end end it "computes the determinant of 2x2 matrix" do - expect(@a.det).to be_within(@err).of(-2) + if dtype != :object + expect(@a.det).to be_within(@err).of(-2) + end end it "computes the determinant of 3x3 matrix" do - expect(@b.det).to be_within(@err).of(-8) + if dtype != :object + expect(@b.det).to be_within(@err).of(-8) + end end it "computes the determinant of 4x4 matrix" do - expect(@c.det).to be_within(@err).of(-18) + if dtype != :object + expect(@c.det).to be_within(@err).of(-18) + end end it "computes the exact determinant of 2x2 matrix" do if dtype == :byte