NMatrix.load_matlab_file raises exception
alyssais opened this issue · 1 comments
alyssais commented
From the root of the repository:
ruby -Ilib -r nmatrix -e "NMatrix.load_matlab_file(ARGV[0])" /path/to/file.mat
/Users/alyssa/.gem/ruby/2.4.0/gems/backports-3.6.8/lib/backports/1.8.7/fixnum/div.rb:1: warning: constant ::Fixnum is deprecated /Users/alyssa/.gem/ruby/2.4.0/gems/backports-3.6.8/lib/backports/1.8.7/fixnum/fdiv.rb:1: warning: constant ::Fixnum is deprecated /Users/alyssa/.gem/ruby/2.4.0/gems/backports-3.6.8/lib/backports/2.1.0/bignum/bit_length.rb:1: warning: constant ::Bignum is deprecated /Users/alyssa/.gem/ruby/2.4.0/gems/backports-3.6.8/lib/backports/2.1.0/fixnum/bit_length.rb:1: warning: constant ::Fixnum is deprecated /private/tmp/nmatrix/lib/nmatrix/monkeys.rb:121:in `gsub': stack level too deep (SystemStackError) from /private/tmp/nmatrix/lib/nmatrix/monkeys.rb:121:in `underscore' from /private/tmp/nmatrix/lib/nmatrix/monkeys.rb:132:in `const_missing' from /private/tmp/nmatrix/lib/nmatrix/monkeys.rb:134:in `const_get' from /private/tmp/nmatrix/lib/nmatrix/monkeys.rb:134:in `const_missing' from /private/tmp/nmatrix/lib/nmatrix/monkeys.rb:134:in `const_get' from /private/tmp/nmatrix/lib/nmatrix/monkeys.rb:134:in `const_missing' from /private/tmp/nmatrix/lib/nmatrix/monkeys.rb:134:in `const_get' from /private/tmp/nmatrix/lib/nmatrix/monkeys.rb:134:in `const_missing' ... 9776 levels... from /private/tmp/nmatrix/lib/nmatrix/monkeys.rb:134:in `const_get' from /private/tmp/nmatrix/lib/nmatrix/monkeys.rb:134:in `const_missing' from /private/tmp/nmatrix/lib/nmatrix/nmatrix.rb:100:in `load_matlab_file' from -e:1:in `'
This error occurs because that method looks up Mat5Reader
in the wrong namespace.
This patch fixes it:
From 476a898c40b15a8889ea5b6d8ce395eab3cc00ba Mon Sep 17 00:00:00 2001
From: Alyssa Ross <hi@alyssa.is>
Date: Wed, 22 Mar 2017 10:58:01 +0000
Subject: [PATCH] Fix incorrect reference in .load_matlab_file
---
lib/nmatrix/nmatrix.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/nmatrix/nmatrix.rb b/lib/nmatrix/nmatrix.rb
index 6898cc1..06d731b 100644
--- a/lib/nmatrix/nmatrix.rb
+++ b/lib/nmatrix/nmatrix.rb
@@ -97,7 +97,7 @@ class NMatrix
# * *Returns* :
# - A Mat5Reader object.
def load_matlab_file(file_path)
- NMatrix::IO::Mat5Reader.new(File.open(file_path, 'rb')).to_ruby
+ NMatrix::IO::Matlab::Mat5Reader.new(File.open(file_path, 'rb')).to_ruby
end
# call-seq:
As a workaround in the meantime, one can use NMatrix::IO::Matlab.load_mat
instead.
Even though I have a fix, I'm submitting this as an issue instead of a PR because as far as I can see there's currently no infrastructure to test Matlab files, and I don't have the time to set one up for this trivial fix, so I can't provide a spec.
translunar commented
Hi @alyssais, would you mind submitting as a PR anyway, please? I'll open an issue for creating a spec for Matlab IO.