///////////////////////////////////////////////////////////////////// // = 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 // // == io.h // // Header file for input/output support functions. #ifndef NMATRIX_IO_H #define NMATRIX_IO_H /* * Project Includes */ #include "nmatrix.h" #include "data/data.h" #include "storage/storage.h" /* * Extern Types */ extern const char* const DTYPE_NAMES[nm::NUM_DTYPES]; namespace nm { namespace io { /* * Types */ enum matlab_dtype_t { miINT8 = 1, miUINT8 = 2, miINT16 = 3, miUINT16 = 4, miINT32 = 5, miUINT32 = 6, miSINGLE = 7, miDOUBLE = 9, miINT64 = 12, miUINT64 = 13, miMATRIX = 14 }; /* * Constants */ const size_t NUM_MATLAB_DTYPES = 15; }} // end of namespace nm::io extern "C" { /* * C accessors. */ nm::dtype_t nm_dtype_from_rbsymbol(VALUE sym); nm::dtype_t nm_dtype_from_rbstring(VALUE str); nm::stype_t nm_stype_from_rbsymbol(VALUE sym); nm::stype_t nm_stype_from_rbstring(VALUE str); void nm_init_io(void); /* * Macros. */ /* * Macro for a function pointer table between NMatrix dtypes and MATLAB dtypes. * * You can't convert as freely between these two as you can between NMatrix dtypes, but there's no reason to. MATLAB * stores its complex numbers in two separate arrays, for example, not as a single unit of data. If you want to convert * to a VALUE, convert first to an appropriate integer or float type. * * FIXME: Maybe be a little more selective about which conversions we DO allow. This is really just for loading an * already-constructed MATLAB matrix into memory, and most of these functions will never get called. */ #define NM_MATLAB_DTYPE_TEMPLATE_TABLE(name,fun,ret,...) \ static ret (*(name)[7][nm::io::NUM_MATLAB_DTYPES])(__VA_ARGS__) = { \ { NULL, fun, fun, fun, fun, fun, fun, fun, NULL, fun, NULL, NULL, fun, fun, NULL }, \ { NULL, fun, fun, fun, fun, fun, fun, fun, NULL, fun, NULL, NULL, fun, fun, NULL }, \ { NULL, fun, fun, fun, fun, fun, fun, fun, NULL, fun, NULL, NULL, fun, fun, NULL }, \ { NULL, fun, fun, fun, fun, fun, fun, fun, NULL, fun, NULL, NULL, fun, fun, NULL }, \ { NULL, fun, fun, fun, fun, fun, fun, fun, NULL, fun, NULL, NULL, fun, fun, NULL }, \ { NULL, fun, fun, fun, fun, fun, fun, fun, NULL, fun, NULL, NULL, fun, fun, NULL }, \ { NULL, fun, fun, fun, fun, fun, fun, fun, NULL, fun, NULL, NULL, fun, fun, NULL } \ }; /* * Hash#has_key? for symbols. Arguments are: hash (VALUE), string (char*). */ #define RB_HASH_HAS_SYMBOL_KEY(hash, str) (rb_funcall((hash), rb_intern("has_key?"), 1, ID2SYM(rb_intern(str))) == Qtrue) } #endif