forked from translunar/nmatrix
-
Notifications
You must be signed in to change notification settings - Fork 133
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
Added NMatrix::IO::Matlab IO features with checking metadata about .m… #620
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
PATH | ||
remote: . | ||
specs: | ||
nmatrix (0.2.4) | ||
packable (~> 1.3, >= 1.3.5) | ||
nmatrix-atlas (0.2.4) | ||
nmatrix (= 0.2.4) | ||
nmatrix-fftw (0.2.4) | ||
nmatrix (= 0.2.4) | ||
nmatrix-lapacke (0.2.4) | ||
nmatrix (= 0.2.4) | ||
|
||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
backports (3.11.1) | ||
coderay (1.1.2) | ||
diff-lcs (1.3) | ||
method_source (0.9.0) | ||
packable (1.3.9) | ||
backports | ||
pry (0.11.3) | ||
coderay (~> 1.1.0) | ||
method_source (~> 0.9.0) | ||
rake (10.5.0) | ||
rake-compiler (0.9.9) | ||
rake | ||
rdoc (4.3.0) | ||
rspec (2.99.0) | ||
rspec-core (~> 2.99.0) | ||
rspec-expectations (~> 2.99.0) | ||
rspec-mocks (~> 2.99.0) | ||
rspec-core (2.99.2) | ||
rspec-expectations (2.99.2) | ||
diff-lcs (>= 1.1.3, < 2.0) | ||
rspec-longrun (1.0.1) | ||
rspec-core (>= 2.10.0) | ||
rspec-mocks (2.99.4) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
bundler (~> 1.6) | ||
nmatrix! | ||
nmatrix-atlas! | ||
nmatrix-fftw! | ||
nmatrix-lapacke! | ||
pry (~> 0.10) | ||
rake (~> 10.3) | ||
rake-compiler (~> 0.8) | ||
rdoc (~> 4.0, >= 4.0.1) | ||
rspec (~> 2.14) | ||
rspec-longrun (~> 1.0) | ||
|
||
BUNDLED WITH | ||
1.16.1 |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
# = NMatrix | ||
# | ||
# A linear algebra library for scientific computation in Ruby. | ||
# NMatrix is part of SciRuby. | ||
# | ||
# NMatrix was originally inspired by and derived from NArray, by | ||
# Masahiro Tanaka: http://narray.rubyforge.org | ||
# | ||
# == Copyright Information | ||
# | ||
# SciRuby is Copyright (c) 2010 - 2014, Ruby Science Foundation | ||
# NMatrix is Copyright (c) 2012 - 2014, John Woods and the Ruby Science Foundation | ||
# | ||
# Please see LICENSE.txt for additional copyright notices. | ||
# | ||
# == Contributing | ||
# | ||
# By contributing source code to SciRuby, you agree to be bound by | ||
# our Contributor Agreement: | ||
# | ||
# * https://github.com/SciRuby/sciruby/wiki/Contributor-Agreement | ||
# | ||
# == fortran_format_spec.rb | ||
# | ||
# Basic tests for NMatrix::IO::Matlab | ||
# | ||
|
||
require_relative '../../lib/nmatrix' | ||
|
||
describe NMatrix::IO::Matlab do | ||
def check_matrix_data_sparse arr | ||
expect(arr[0][:nonzero_max]).to eq(11) | ||
expect(arr[0][:matlab_class]).to eq(:mxSPARSE) | ||
expect(arr[0][:dimensions]).to eq([4,4]) | ||
expect(arr[0][:matlab_name]).to eq("x") | ||
expect(arr[0][:real_part][:tag][:data_type]).to eq(:miDOUBLE) | ||
expect(arr[0][:real_part][:tag][:raw_data_type]).to eq(9) | ||
expect(arr[0][:real_part][:tag][:bytes]).to eq(32) | ||
expect(arr[0][:row_index][:tag][:data_type]).to eq(:miINT32) | ||
expect(arr[0][:row_index][:tag][:raw_data_type]).to eq(5) | ||
expect(arr[0][:row_index][:tag][:bytes]).to eq(20) | ||
expect(arr[0][:column_index][:tag][:data_type]).to eq(:miINT32) | ||
expect(arr[0][:column_index][:tag][:raw_data_type]).to eq(5) | ||
expect(arr[0][:column_index][:tag][:bytes]).to eq(44) | ||
end | ||
def check_matrix_data_dense arr | ||
expect(arr[0][:nonzero_max]).to eq(0) | ||
expect(arr[0][:matlab_class]).to eq(:mxDOUBLE) | ||
expect(arr[0][:dimensions]).to eq([4,5]) | ||
expect(arr[0][:matlab_name]).to eq("x") | ||
expect(arr[0][:real_part][:tag][:data_type]).to eq(:miUINT8) | ||
expect(arr[0][:real_part][:tag][:raw_data_type]).to eq(2) | ||
expect(arr[0][:real_part][:tag][:bytes]).to eq(20) | ||
end | ||
it "reads MATLAB .mat file containing a single square sparse matrix" do | ||
pending("not yet implemented for NMatrix-JRuby") if jruby? | ||
n = NMatrix::IO::Matlab.load_mat("spec/4x4_sparse.mat") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have seen that you are using let(:my_file) { "spec/4x4_sparse.mat" }
let(:n) { NMatrix::IO::Matlab.load_mat(my_file) }
it "reads MATLAB .mat file containing a single square sparse matrix" do
expect(n[0,0]).to eq(2)
...
end
... what do you think? 🤔 |
||
expect(n[0,0]).to eq(2) | ||
expect(n[1,1]).to eq(3) | ||
expect(n[1,3]).to eq(5) | ||
expect(n[3,0]).to eq(4) | ||
expect(n[2,2]).to eq(0) | ||
expect(n[3,3]).to eq(0) | ||
end | ||
|
||
it "reads MATLAB .mat file containing a single dense integer matrix" do | ||
n = NMatrix::IO::Matlab.load_mat("spec/4x5_dense.mat") | ||
m = NMatrix.new([4,5], [16,17,18,19,20,15,14,13,12,11,6,7,8,9,10,5,4,3,2,1]) | ||
expect(n).to eq(m) | ||
end | ||
|
||
it "reads MATLAB .mat file containing a single dense double matrix" do | ||
n = NMatrix::IO::Matlab.load_mat("spec/2x2_dense_double.mat") | ||
m = NMatrix.new(2, [1.1, 2.0, 3.0, 4.0], dtype: :float64) | ||
expect(n).to eq(m) | ||
end | ||
it "reads MATLAB .mat file containing a single square sparse matrix111" do | ||
m = NMatrix::IO::Matlab::Mat5Reader.new(File.open("spec/4x4_sparse.mat", "rb+")) | ||
n = m.to_ruby | ||
expect(m.byte_order).to eq(:little) | ||
expect(m.file_header.version).to eq(256) | ||
expect(m.file_header.endian).to eq("IM") | ||
expect(m.file_header.desc).to eq("MATLAB 5.0 MAT-file, Platform: GLNX86, Created on: Wed Apr 18 13:43:38 2012") | ||
expect(n[0,0]).to eq(2) | ||
expect(n[1,1]).to eq(3) | ||
expect(n[1,3]).to eq(5) | ||
expect(n[2,2]).to eq(0) | ||
expect(n[3,3]).to eq(0) | ||
check_matrix_data_sparse(m.to_a) | ||
end | ||
it "reads MATLAB .mat file containing a single dense double matrix123" do | ||
m = NMatrix::IO::Matlab::Mat5Reader.new(File.open("spec/4x5_dense.mat", "rb+")) | ||
n = m.to_ruby | ||
expect(m.byte_order).to eq(:little) | ||
expect(m.file_header.version).to eq(256) | ||
expect(m.file_header.endian).to eq("IM") | ||
expect(m.file_header.desc).to eq("MATLAB 5.0 MAT-file, Platform: GLNX86, Created on: Wed Apr 18 19:17:17 2012") | ||
p = NMatrix.new([4,5], [16,17,18,19,20,15,14,13,12,11,6,7,8,9,10,5,4,3,2,1]) | ||
expect(n).to eq(p) | ||
check_matrix_data_dense(m.to_a) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you could use
shared_examples
instead of define a method. what do you think? 🤔