Permalink
Browse files

Naive addition of SciRuby Mat file reader stuff. Doesn't work, but wa…

…nted to establish a baseline before modifying it.
  • Loading branch information...
1 parent 53da083 commit fd1a3748a30f194d4bca38e627d9ed03c4848487 @mohawkjohn mohawkjohn committed Apr 17, 2012
Showing with 506 additions and 3 deletions.
  1. +5 −3 lib/nmatrix.rb
  2. +45 −0 lib/nmatrix/io/matlab.rb
  3. +382 −0 lib/nmatrix/io/matlab/mat5_reader.rb
  4. +74 −0 lib/nmatrix/io/matlab/mat_reader.rb
View
@@ -39,9 +39,10 @@
class NMatrix
VERSION = '0.0.1'
- #def inspect
- #
- #end
+ # Read and write extensions for NMatrix. These are only loaded when needed.
+ module IO
+ autoload(:Matlab, File.join(File.dirname(__FILE__), 'nmatrix', 'io', 'matlab.rb'))
+ end
# TODO: Make this actually pretty.
def pretty_print
@@ -55,6 +56,7 @@ def pretty_print
end
nil
end
+ alias :pp :pretty_print
def inspect
View
@@ -0,0 +1,45 @@
+# = 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 - 2012, Ruby Science Foundation
+# NMatrix is Copyright (c) 2012, 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
+#
+# == io/matlab.rb
+#
+# Code for reading and writing Matlab matrix files.
+#
+
+require_relative "./matlab/mat5_reader"
+
+class NMatrix
+ module IO
+ # IO components for Matlab.
+ module Matlab
+ class << self
+ # Attempt to convert a Matlab .mat file's contents to a Ruby object.
+ #
+ # EXPERIMENTAL. At this time, only supports version 5.
+ #
+ def load_mat file_path
+ NMatrix::IO::Matlab::Mat5Reader.new(File.open(file_path, "rb+")).to_ruby
+ end
+ end
+ end
+ end
+end
Oops, something went wrong.

0 comments on commit fd1a374

Please sign in to comment.