Skip to content

Commit

Permalink
Fix det_exact for object dtype (#514)
Browse files Browse the repository at this point in the history
* Fix NMatrix#det_exact for ruby objects

* Add tests for NMatrix#det_exact dtype=:object
  • Loading branch information
isuruf authored and translunar committed May 23, 2016
1 parent a3e489b commit e5d169b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
10 changes: 5 additions & 5 deletions ext/nmatrix/ruby_nmatrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -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<VALUE*>(result), 1);
}
VALUE to_return = nm::rubyobj_from_cval(result, NM_DTYPE(self)).rval;
if (dtype == nm::RUBYOBJ) {
nm_unregister_values(reinterpret_cast<VALUE*>(result), 1);
to_return = *reinterpret_cast<VALUE*>(result);

} else {
to_return = nm::rubyobj_from_cval(result, NM_DTYPE(self)).rval;
}
NM_CONSERVATIVE(nm_unregister_value(&self));

Expand Down
13 changes: 9 additions & 4 deletions spec/math_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down

0 comments on commit e5d169b

Please sign in to comment.