Skip to content

Conversation

@spacewander
Copy link

Hope this can fix #189

@translunar
Copy link
Member

@cjfuller What do you think, particularly given the discussion in #189? Is it worth it to automatically cast small list and yale matrices to dense in order to calculate the determinant, or is it that we really need these functionalities separately for Yale matrices?

I'm leaning towards saying we really need the functionality for Yale matrices. When I opened the issue initially, I envisioned that it would not be cast. I feel like the user won't expect an automatic cast to be happening, so it's not the best design choice.

@spacewander
Copy link
Author

Actually, I have almost finished a separate implementation for Yale matrices...
Once I have totally completed it, I will do some benchmark to prove whether a separate way is better than casting.

It may be released next week, because I have to go outside and get little time to work in this weekend.

@translunar
Copy link
Member

@spacewander That's excellent! I look forward to seeing the patch. =) Let's discuss more at that point.

@cjfuller
Copy link
Member

Sorry, late to the party here, but:

I agree that the casting may be a bit surprising. I'd expect inverse_exact to preserve stype. It might still be fast enough to cast, compute the inverse and cast back, though, for some definition of "fast enough".

I wholeheartedly support @spacewander's appraoch of benchmarking it so that we can talk in more concrete terms!

@spacewander
Copy link
Author

Here is the benchmark:

The casting implementation can be checkout from there:
https://github.com/spacewander/nmatrix/tree/cast

Casting VS. Separate Yale implementation:

require 'benchmark'
require_relative 'lib/nmatrix'

m = NMatrix.new(2, [1,2,3,4], stype: :yale, dtype: :int64)
Benchmark.bm do |x|
  x.report {50000.times do ; m.det_exact; end}
end
Without casting
   user     system      total        real
   0.010000   0.000000   0.010000 (  0.007864)

With casting
   user     system      total        real
   0.010000   0.000000   0.010000 (  0.008056)
n = m.clone
Benchmark.bm do |x|
  x.report {50000.times do; n = m.clone;  m.method(:__inverse_exact__).call(n, 2,2); end}
end
Without casting
   user     system      total        real
   0.140000   0.000000   0.140000 (  0.144625)

With casting
   user     system      total        real
   0.420000   0.000000   0.420000 (  0.421520) 

@spacewander
Copy link
Author

Cast list matrix to yale matrix VS. cast list matrix to dense matrix:

det_exact:

Cast to yale:
   // 2 x 2
   user     system      total        real
   0.120000   0.000000   0.120000 (  0.123943)
   // 3 x 3
   user     system      total        real
   0.100000   0.020000   0.120000 (  0.119550)

Cast to dense:
   // 2 x 2
   user     system      total        real
   0.110000   0.000000   0.110000 (  0.112930)
   // 3 x 3
   user     system      total        real
   0.120000   0.010000   0.130000 (  0.124914)

Almost the same.

inverse_exact

Cast to dense: // 2 x 2
   user     system      total        real
   0.700000   0.000000   0.700000 (  0.701193)

Cast to yale: // 2 x 2
   user     system      total        real
   0.630000   0.010000   0.640000 (  0.645875)

Cast to yale is faster than cast to dense.

@translunar
Copy link
Member

I'm happy to see my code for casting list to yale is working so well. =) @spacewander Can you give me a link to the Yale exact determinant code you wrote?

@spacewander
Copy link
Author

My code can be reviewed from there

Simply, it is a Yale specific version of det_exact and inverse_exact

@translunar
Copy link
Member

Could you submit that code as a pull request, along with a spec, and tag it with this issue? I want to make sure the code actually does what we think it does. Yale can be tricky.

@translunar
Copy link
Member

Overcome by #582, I think.

@translunar translunar closed this Mar 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Exact determinant and inverse calculations for yale and list 2x2 and 3x3

3 participants