///////////////////////////////////////////////////////////////////// // = 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 - 2013, Ruby Science Foundation // NMatrix is Copyright (c) 2013, 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 // // == data.h // // Header file for dealing with data types. #ifndef DATA_H #define DATA_H /* * Standard Includes */ #include /* * Project Includes */ #include "nmatrix.h" #include "types.h" #include "complex.h" #include "rational.h" #include "ruby_object.h" namespace nm { /* * Constants */ const int NUM_DTYPES = 13; const int NUM_ITYPES = 4; const int NUM_EWOPS = 12; const int NUM_NONCOMP_EWOPS = 6; enum ewop_t { EW_ADD, EW_SUB, EW_MUL, EW_DIV, EW_POW, EW_MOD, EW_EQEQ, EW_NEQ, EW_LT, EW_GT, EW_LEQ, EW_GEQ }; // element-wise and scalar operators extern const char* const EWOP_OPS[nm::NUM_EWOPS]; extern const std::string EWOP_NAMES[nm::NUM_EWOPS]; } // end of namespace nm /* * Macros */ #define STYPE_MARK_TABLE(name) \ static void (*(name)[nm::NUM_STYPES])(void*) = { \ nm_dense_storage_mark, \ nm_list_storage_mark, \ nm_yale_storage_mark \ }; #define CAST_TABLE(name) \ static STORAGE* (*(name)[nm::NUM_STYPES][nm::NUM_STYPES])(const STORAGE*, nm::dtype_t, void*) = { \ { nm_dense_storage_cast_copy, nm_dense_storage_from_list, nm_dense_storage_from_yale }, \ { nm_list_storage_from_dense, nm_list_storage_cast_copy, nm_list_storage_from_yale }, \ { nm_yale_storage_from_dense, nm_yale_storage_from_list, nm_yale_storage_cast_copy } \ }; /* * Defines a static array that hold function pointers to dtype templated * versions of the specified function. */ #define DTYPE_TEMPLATE_TABLE(fun, ret, ...) NAMED_DTYPE_TEMPLATE_TABLE(ttable, fun, ret, __VA_ARGS__) #define NAMED_DTYPE_TEMPLATE_TABLE(name, fun, ret, ...) \ static ret (*(name)[nm::NUM_DTYPES])(__VA_ARGS__) = { \ fun, \ fun, \ fun, \ fun, \ fun, \ fun, \ fun, \ fun, \ fun, \ fun, \ fun, \ fun, \ fun \ }; #define NAMED_DTYPE_TEMPLATE_TABLE_NO_ROBJ(name, fun, ret, ...) \ static ret (*(name)[nm::NUM_DTYPES])(__VA_ARGS__) = { \ fun, \ fun, \ fun, \ fun, \ fun, \ fun, \ fun, \ fun, \ fun, \ fun, \ fun, \ fun \ }; /* * Defines a static array that holds function pointers to itype templated * versions of the specified function. */ #define ITYPE_TEMPLATE_TABLE(fun, ret, ...) NAMED_ITYPE_TEMPLATE_TABLE(ttable, fun, ret, __VA_ARGS__) #define NAMED_ITYPE_TEMPLATE_TABLE(name, fun, ret, ...) \ static ret (*(name)[nm::NUM_ITYPES])(__VA_ARGS__) = { \ fun, \ fun, \ fun, \ fun \ }; #define ITYPE_TEMPLATE_TABLE(fun, ret, ...) NAMED_ITYPE_TEMPLATE_TABLE(ttable, fun, ret, __VA_ARGS__) #define NAMED_LR_ITYPE_TEMPLATE_TABLE(name, fun, ret, ...) \ static ret (*(name)[nm::NUM_ITYPES][nm::NUM_ITYPES])(__VA_ARGS__) = { \ { fun, fun, fun, fun }, \ { fun, fun, fun, fun }, \ { fun, fun, fun, fun }, \ { fun, fun, fun, fun } \ }; /* * Same as DTYPE_TEMPLATE_TABLE but for functions that have two template * parameters. * * The left-hand DType is used as the first index, and the right-hand side is * the second index. Not all left- and right-hand side combinations are valid, * and an invalid combination will result in a NULL pointer. */ #define LR_DTYPE_TEMPLATE_TABLE(fun, ret, ...) NAMED_LR_DTYPE_TEMPLATE_TABLE(ttable, fun, ret, __VA_ARGS__) #define NAMED_LR_DTYPE_TEMPLATE_TABLE(name, fun, ret, ...) \ static ret (*(name)[nm::NUM_DTYPES][nm::NUM_DTYPES])(__VA_ARGS__) = { \ {fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun}, \ {fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun}, \ {fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun}, \ {fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun}, \ {fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun}, \ {fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun}, \ {fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun}, \ {fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun}, \ {fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun}, \ {fun, fun, fun, fun, fun, NULL, NULL, NULL, NULL, fun, fun, fun, fun}, \ {fun, fun, fun, fun, fun, NULL, NULL, NULL, NULL, fun, fun, fun, fun}, \ {fun, fun, fun, fun, fun, NULL, NULL, NULL, NULL, fun, fun, fun, fun}, \ {fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun} \ }; /* * Defines a static array that holds function pointers to operation, and left- * and right-side dtype templated version sof the specified function. */ #define OP_LR_DTYPE_TEMPLATE_TABLE(fun, ret, ...) NAMED_OP_LR_DTYPE_TEMPLATE_TABLE(ttable, fun, ret, __VA_ARGS__) #define NAMED_OP_LR_DTYPE_TEMPLATE_TABLE(name, fun, ret, ...) \ static ret (*(name)[nm::NUM_EWOPS][nm::NUM_DTYPES][nm::NUM_DTYPES])(__VA_ARGS__) = { \ { \ {fun, fun, fun, fun, fun, \ fun, fun, fun, fun, \ fun, fun, fun, NULL}, \ \ {fun, fun, fun, fun, fun, \ fun, fun, fun, fun, \ fun, fun, fun, NULL}, \ \ {fun, fun, fun, fun, fun, \ fun, fun, fun, fun, \ fun, fun, fun, NULL}, \ \ {fun, fun, fun, fun, fun, \ fun, fun, fun, fun, \ fun, fun, fun, NULL}, \ \ {fun, fun, fun, fun, fun, \ fun, fun, fun, fun, \ fun, fun, fun, NULL}, \ \ {fun, fun, fun, fun, fun, \ fun, fun, fun, fun, \ fun, fun, fun, NULL}, \ \ {fun, fun, fun, fun, fun, \ fun, fun, fun, fun, \ fun, fun, fun, NULL}, \ \ {fun, fun, fun, fun, \ fun, fun, fun, fun, \ fun, fun, fun, \ fun, NULL}, \ \ {fun, fun, fun, fun, \ fun, fun, fun, fun, \ fun, fun, fun, \ fun, NULL}, \ \ {fun, fun, fun, fun, \ fun, NULL, NULL, NULL, NULL, fun, fun, \ fun, NULL}, \ \ {fun, fun, fun, fun, \ fun, NULL, NULL, NULL, NULL, fun, fun, \ fun, NULL}, \ \ {fun, fun, fun, fun, \ fun, NULL, NULL, NULL, NULL, fun, fun, \ fun, NULL}, \ \ {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, fun} \ }, \ \ { \ {fun, fun, fun, fun, fun, \ fun, fun, fun, fun, \ fun, fun, fun, NULL}, \ \ {fun, fun, fun, fun, fun, \ fun, fun, fun, fun, \ fun, fun, fun, NULL}, \ \ {fun, fun, fun, fun, fun, \ fun, fun, fun, fun, \ fun, fun, fun, NULL}, \ \ {fun, fun, fun, fun, fun, \ fun, fun, fun, fun, \ fun, fun, fun, NULL}, \ \ {fun, fun, fun, fun, fun, \ fun, fun, fun, fun, \ fun, fun, fun, NULL}, \ \ {fun, fun, fun, fun, fun, \ fun, fun, fun, fun, \ fun, fun, fun, NULL}, \ \ {fun, fun, fun, fun, fun, \ fun, fun, fun, fun, \ fun, fun, fun, NULL}, \ \ {fun, fun, fun, fun, \ fun, fun, fun, fun, \ fun, fun, fun, \ fun, NULL}, \ \ {fun, fun, fun, fun, \ fun, fun, fun, fun, \ fun, fun, fun, \ fun, NULL}, \ \ {fun, fun, fun, fun, \ fun, NULL, NULL, NULL, NULL, fun, fun, \ fun, NULL}, \ \ {fun, fun, fun, fun, \ fun, NULL, NULL, NULL, NULL, fun, fun, \ fun, NULL}, \ \ {fun, fun, fun, fun, \ fun, NULL, NULL, NULL, NULL, fun, fun, \ fun, NULL}, \ \ {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, fun} \ }, \ \ { \ {fun, fun, fun, fun, fun, \ fun, fun, fun, fun, \ fun, fun, fun, NULL}, \ \ {fun, fun, fun, fun, fun, \ fun, fun, fun, fun, \ fun, fun, fun, NULL}, \ \ {fun, fun, fun, fun, fun, \ fun, fun, fun, fun, \ fun, fun, fun, NULL}, \ \ {fun, fun, fun, fun, fun, \ fun, fun, fun, fun, \ fun, fun, fun, NULL}, \ \ {fun, fun, fun, fun, fun, \ fun, fun, fun, fun, \ fun, fun, fun, NULL}, \ \ {fun, fun, fun, fun, fun, \ fun, fun, fun, fun, \ fun, fun, fun, NULL}, \ \ {fun, fun, fun, fun, fun, \ fun, fun, fun, fun, \ fun, fun, fun, NULL}, \ \ {fun, fun, fun, fun, \ fun, fun, fun, fun, \ fun, fun, fun, \ fun, NULL}, \ \ {fun, fun, fun, fun, \ fun, fun, fun, fun, \ fun, fun, fun, \ fun, NULL}, \ \ {fun, fun, fun, fun, \ fun, NULL, NULL, NULL, NULL, fun, fun, \ fun, NULL}, \ \ {fun, fun, fun, fun, \ fun, NULL, NULL, NULL, NULL, fun, fun, \ fun, NULL}, \ \ {fun, fun, fun, fun, \ fun, NULL, NULL, NULL, NULL, fun, fun, \ fun, NULL}, \ \ {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, fun} \ }, \ \ { \ {fun, fun, fun, fun, fun, \ fun, fun, fun, fun, \ fun, fun, fun, NULL}, \ \ {fun, fun, fun, fun, fun, \ fun, fun, fun, fun, \ fun, fun, fun, NULL}, \ \ {fun, fun, fun, fun, fun, \ fun, fun, fun, fun, \ fun, fun, fun, NULL}, \ \ {fun, fun, fun, fun, fun, \ fun, fun, fun, fun, \ fun, fun, fun, NULL}, \ \ {fun, fun, fun, fun, fun, \ fun, fun, fun, fun, \ fun, fun, fun, NULL}, \ \ {fun, fun, fun, fun, fun, \ fun, fun, fun, fun, \ fun, fun, fun, NULL}, \ \ {fun, fun, fun, fun, fun, \ fun, fun, fun, fun, \ fun, fun, fun, NULL}, \ \ {fun, fun, fun, fun, \ fun, fun, fun, fun, \ fun, fun, fun, \ fun, NULL}, \ \ {fun, fun, fun, fun, \ fun, fun, fun, fun, \ fun, fun, fun, \ fun, NULL}, \ \ {fun, fun, fun, fun, \ fun, NULL, NULL, NULL, NULL, fun, fun, \ fun, NULL}, \ \ {fun, fun, fun, fun, \ fun, NULL, NULL, NULL, NULL, fun, fun, \ fun, NULL}, \ \ {fun, fun, fun, fun, \ fun, NULL, NULL, NULL, NULL, fun, fun, \ fun, NULL}, \ \ {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, fun} \ }, \ \ { \ {fun, fun, fun, fun, fun, \ fun, fun, fun, fun, \ fun, fun, fun, NULL}, \ \ {fun, fun, fun, fun, fun, \ fun, fun, fun, fun, \ fun, fun, fun, NULL}, \ \ {fun, fun, fun, fun, fun, \ fun, fun, fun, fun, \ fun, fun, fun, NULL}, \ \ {fun, fun, fun, fun, fun, \ fun, fun, fun, fun, \ fun, fun, fun, NULL}, \ \ {fun, fun, fun, fun, fun, \ fun, fun, fun, fun, \ fun, fun, fun, NULL}, \ \ {fun, fun, fun, fun, fun, \ fun, fun, fun, fun, \ fun, fun, fun, NULL}, \ \ {fun, fun, fun, fun, fun, \ fun, fun, fun, fun, \ fun, fun, fun, NULL}, \ \ {fun, fun, fun, fun, \ fun, fun, fun, fun, \ fun, fun, fun, \ fun, NULL}, \ \ {fun, fun, fun, fun, \ fun, fun, fun, fun, \ fun, fun, fun, \ fun, NULL}, \ \ {fun, fun, fun, fun, \ fun, NULL, NULL, NULL, NULL, fun, fun, \ fun, NULL}, \ \ {fun, fun, fun, fun, \ fun, NULL, NULL, NULL, NULL, fun, fun, \ fun, NULL}, \ \ {fun, fun, fun, fun, \ fun, NULL, NULL, NULL, NULL, fun, fun, \ fun, NULL}, \ \ {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, fun} \ }, \ \ { \ {fun, fun, fun, fun, fun, \ fun, fun, fun, fun, \ fun, fun, fun, NULL}, \ \ {fun, fun, fun, fun, fun, \ fun, fun, fun, fun, \ fun, fun, fun, NULL}, \ \ {fun, fun, fun, fun, fun, \ fun, fun, fun, fun, \ fun, fun, fun, NULL}, \ \ {fun, fun, fun, fun, fun, \ fun, fun, fun, fun, \ fun, fun, fun, NULL}, \ \ {fun, fun, fun, fun, fun, \ fun, fun, fun, fun, \ fun, fun, fun, NULL}, \ \ {fun, fun, fun, fun, fun, \ fun, fun, fun, fun, \ fun, fun, fun, NULL}, \ \ {fun, fun, fun, fun, fun, \ fun, fun, fun, fun, \ fun, fun, fun, NULL}, \ \ {fun, fun, fun, fun, \ fun, fun, fun, fun, \ fun, fun, fun, \ fun, NULL}, \ \ {fun, fun, fun, fun, \ fun, fun, fun, fun, \ fun, fun, fun, \ fun, NULL}, \ \ {fun, fun, fun, fun, \ fun, NULL, NULL, NULL, NULL, fun, fun, \ fun, NULL}, \ \ {fun, fun, fun, fun, \ fun, NULL, NULL, NULL, NULL, fun, fun, \ fun, NULL}, \ \ {fun, fun, fun, fun, \ fun, NULL, NULL, NULL, NULL, fun, fun, \ fun, NULL}, \ \ {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, fun} \ }, \ \ { \ {fun, fun, fun, fun, \ fun, fun, fun, fun, \ fun, fun, fun, \ fun, NULL}, \ {fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, NULL, NULL, NULL, NULL, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, NULL, NULL, NULL, NULL, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, NULL, NULL, NULL, NULL, fun, fun, fun, NULL}, \ {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, fun} \ }, \ {{fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, NULL, NULL, NULL, NULL, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, NULL, NULL, NULL, NULL, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, NULL, NULL, NULL, NULL, fun, fun, fun, NULL}, \ {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, fun}}, \ {{fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, NULL, NULL, NULL, NULL, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, NULL, NULL, NULL, NULL, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, NULL, NULL, NULL, NULL, fun, fun, fun, NULL}, \ {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, fun}}, \ {{fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, NULL, NULL, NULL, NULL, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, NULL, NULL, NULL, NULL, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, NULL, NULL, NULL, NULL, fun, fun, fun, NULL}, \ {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, fun}}, \ {{fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, NULL, NULL, NULL, NULL, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, NULL, NULL, NULL, NULL, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, NULL, NULL, NULL, NULL, fun, fun, fun, NULL}, \ {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, fun}}, \ {{fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, NULL, NULL, NULL, NULL, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, NULL, NULL, NULL, NULL, fun, fun, fun, NULL}, \ {fun, fun, fun, fun, fun, NULL, NULL, NULL, NULL, fun, fun, fun, NULL}, \ {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, fun} \ } \ }; /* * Defines a static array that holds function pointers to an elementwise op, * itype, dtype templated versions of the specified function. */ #define OP_ITYPE_DTYPE_TEMPLATE_TABLE(fun, ret, ...) NAMED_OP_ITYPE_DTYPE_TEMPLATE_TABLE(ttable, fun, ret, __VA_ARGS__) #define NAMED_OP_ITYPE_DTYPE_TEMPLATE_TABLE(name, fun, ret, ...) \ static ret (*(name)[nm::NUM_EWOPS][nm::NUM_ITYPES][nm::NUM_DTYPES])(__VA_ARGS__) = \ {{{fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun},\ {fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun},\ {fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun},\ {fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun}},\ {{fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun},\ {fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun},\ {fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun},\ {fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun}},\ {{fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun},\ {fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun},\ {fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun},\ {fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun}},\ {{fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun},\ {fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun},\ {fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun},\ {fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun}},\ {{fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun},\ {fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun},\ {fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun},\ {fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun}},\ {{fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun},\ {fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun},\ {fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun},\ {fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun}},\ {{fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun},\ {fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun},\ {fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun},\ {fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun}},\ {{fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun},\ {fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun},\ {fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun},\ {fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun}},\ {{fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun},\ {fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun},\ {fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun},\ {fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun}},\ {{fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun},\ {fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun},\ {fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun},\ {fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun}},\ {{fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun},\ {fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun},\ {fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun},\ {fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun,fun}}}; /* * Defines a static array that holds function pointers to left dtype, right * dtype, and itype templated versions of the specified function. */ #define LRI_DTYPE_TEMPLATE_TABLE(fun, ret, ...) NAMED_LRI_DTYPE_TEMPLATE_TABLE(ttable, fun, ret, __VA_ARGS__) #define NAMED_LRI_DTYPE_TEMPLATE_TABLE(name, fun, ret, ...) \ static ret (*(name)[nm::NUM_DTYPES][nm::NUM_DTYPES][nm::NUM_ITYPES])(__VA_ARGS__) = { \ { \ {fun, fun, fun, fun }, \ {fun, fun, fun, fun }, \ {fun, fun, fun, fun }, \ {fun, fun, fun, fun }, \ {fun, fun, fun, fun }, \ {fun, fun, fun, fun }, \ {fun, fun, fun, fun }, \ {fun, fun, fun, fun }, \ {fun, fun, fun, fun }, \ {fun, fun, fun, fun }, \ {fun, fun, fun, fun }, \ {fun, fun, fun, fun }, \ {fun, fun, fun, fun } \ }, \ { \ {fun, fun, fun, fun }, \ {fun, fun, fun, fun }, \ {fun, fun, fun, fun }, \ {fun, fun, fun, fun }, \ {fun, fun, fun, fun }, \ {fun, fun, fun, fun }, \ {fun, fun, fun, fun }, \ {fun, fun, fun, fun }, \ {fun, fun, fun, fun }, \ {fun, fun, fun, fun }, \ {fun, fun, fun, fun }, \ {fun, fun, fun, fun }, \ {fun, fun, fun, fun } \ }, \ {{fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }}, \ {{fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }}, \ {{fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }}, \ {{fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }}, \ {{fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }}, \ {{fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }}, \ {{fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }}, \ {{fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {NULL, NULL, NULL, NULL }, {NULL, NULL, NULL, NULL }, {NULL, NULL, NULL, NULL }, {NULL, NULL, NULL, NULL }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun}}, \ {{fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {NULL, NULL, NULL, NULL }, {NULL, NULL, NULL, NULL }, {NULL, NULL, NULL, NULL }, {NULL, NULL, NULL, NULL }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun}}, \ {{fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {NULL, NULL, NULL, NULL }, {NULL, NULL, NULL, NULL }, {NULL, NULL, NULL, NULL }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun}}, \ {{fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun }, {fun, fun, fun, fun}} \ }; /* * Defines a static array that holds function pointers to left dtype and itype * templated versions of the specified function. */ #define LI_DTYPE_TEMPLATE_TABLE(fun, ret, ...) NAMED_LI_DTYPE_TEMPLATE_TABLE(ttable, fun, ret, __VA_ARGS__) #define NAMED_LI_DTYPE_TEMPLATE_TABLE(name, fun, ret, ...) \ static ret (*(name)[nm::NUM_DTYPES][nm::NUM_ITYPES])(__VA_ARGS__) = { \ { fun,fun,fun,fun }, \ { fun,fun,fun,fun }, \ { fun,fun,fun,fun }, \ { fun,fun,fun,fun }, \ { fun,fun,fun,fun }, \ { fun,fun,fun,fun }, \ { fun,fun,fun,fun }, \ { fun,fun,fun,fun }, \ { fun,fun,fun,fun }, \ { fun,fun,fun,fun }, \ { fun,fun,fun,fun }, \ { fun,fun,fun,fun }, \ { fun,fun,fun,fun} \ }; #define NAMED_LI_DTYPE_TEMPLATE_TABLE_NO_ROBJ(name, fun, ret, ...) \ static ret (*(name)[nm::NUM_DTYPES][nm::NUM_ITYPES])(__VA_ARGS__) = { \ { fun,fun,fun,fun }, \ { fun,fun,fun,fun }, \ { fun,fun,fun,fun }, \ { fun,fun,fun,fun }, \ { fun,fun,fun,fun }, \ { fun,fun,fun,fun }, \ { fun,fun,fun,fun }, \ { fun,fun,fun,fun }, \ { fun,fun,fun,fun }, \ { fun,fun,fun,fun }, \ { fun,fun,fun,fun }, \ { fun,fun,fun,fun } \ }; extern "C" { /* * Data */ // regular data types extern const char* const DTYPE_NAMES[nm::NUM_DTYPES]; extern const size_t DTYPE_SIZES[nm::NUM_DTYPES]; // index data types extern const char* const ITYPE_NAMES[nm::NUM_ITYPES]; extern const size_t ITYPE_SIZES[nm::NUM_ITYPES]; extern const nm::dtype_t Upcast[nm::NUM_DTYPES][nm::NUM_DTYPES]; /* * Functions */ void* rubyobj_to_cval(VALUE val, nm::dtype_t dtype); void rubyval_to_cval(VALUE val, nm::dtype_t dtype, void* loc); nm::RubyObject rubyobj_from_cval(void* val, nm::dtype_t dtype); nm::RubyObject rubyobj_from_cval_by_itype(void* val, nm::itype_t itype); void nm_init_data(); } // end of extern "C" block #endif // DATA_H