Skip to content

Fix det_exact for ruby object #514

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch on this. @cjfuller Just want to check this with you since you wrote the register/unregister functions.

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like you're not testing #det with Ruby objects anymore.

Copy link
Author

@isuruf isuruf May 19, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not testing #det, only #det_exact. Both were disabled in line 949 before

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh! I see now.

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