AI-MXNetCAPI
view release on metacpan or search on metacpan
Changes
Makefile.PL
MANIFEST
README
META.json
META.yml
t/AI-MXNetCAPI.t
lib/AI/MXNetCAPI.pm
mxnet.i
mxnet_typemaps.i
AI-MXNetCAPI version 1.0102
=====================
Swig interface to MXNet c api.
INSTALLATION
To install this module type the following:
perl Makefile.PL
make
make test
make install
DEPENDENCIES
This module requires mxnet http://mxnet.io
It's used by AI::MXNet
%module "AI::MXNetCAPI"
%rename("%(strip:[MX])s") "";
%include typemaps.i
%include mxnet_typemaps.i
%inline %{
#include <c_api.h>
// Taken as is from http://cpansearch.perl.org/src/COLEMINOR/Games-EternalLands-Binary-Float16-0.01/Float16.xs
/* This method is faster than the OpenEXR implementation (very often
* used, eg. in Ogre), with the additional benefit of rounding, inspired
* by James Tursa's half-precision code. */
static inline uint16_t _float_to_half(uint32_t x) {
uint16_t bits = (x >> 16) & 0x8000;
uint16_t m = (x >> 12) & 0x07ff;
XPUSHs(SWIG_NewPointerObj(SWIG_as_voidptr(handle), SWIGTYPE_p_MXNDArray, 0));
PUTBACK;
call_sv((SV*)callback, G_DISCARD);
}
}
%}
%init %{
/* These SWIG_TypeClientData() calls might break in the future, but
* %rename should work on these types before that happens. */
SWIG_TypeClientData(SWIGTYPE_p_MXNDArray, (void *)"NDArrayHandle");
SWIG_TypeClientData(SWIGTYPE_p_MXFunction, (void *)"FunctionHandle");
SWIG_TypeClientData(SWIGTYPE_p_MXAtomicSymbolCreator, (void *)"AtomicSymbolCreator");
SWIG_TypeClientData(SWIGTYPE_p_MXSymbol, (void *)"SymbolHandle");
SWIG_TypeClientData(SWIGTYPE_p_MXExecutor, (void *)"ExecutorHandle");
SWIG_TypeClientData(SWIGTYPE_p_MXDataIterCreator, (void *)"DataIterCreator");
SWIG_TypeClientData(SWIGTYPE_p_MXDataIter, (void *)"DataIterHandle");
SWIG_TypeClientData(SWIGTYPE_p_MXKVStore, (void *)"KVStoreHandle");
SWIG_TypeClientData(SWIGTYPE_p_MXRecordIO, (void *)"RecordIOHandle");
SWIG_TypeClientData(SWIGTYPE_p_MXRtc, (void *)"RtcHandle");
SWIG_TypeClientData(SWIGTYPE_p_MXCachedOp, (void *)"CachedOpHandle");
%}
/*! \brief manually define unsigned int */
typedef unsigned int mx_uint;
/*! \brief manually define float */
typedef float mx_float;
// all the handles are simply void *
// will be casted internally to specific pointers types
// these typedefs are mainly used for readablity reasons
/*! \brief handle to NDArray */
typedef MXNDArray *NDArrayHandle;
/*! \brief handle to a mxnet ndarray function that changes NDArray */
typedef MXFunction *FunctionHandle;
/*! \brief handle to a function that takes param and creates symbol */
typedef MXAtomicSymbolCreator *AtomicSymbolCreator;
/*! \brief handle to a symbol that can be bind as operator */
typedef MXSymbol *SymbolHandle;
/*! \brief handle to a AtomicSymbol */
typedef MXAtomicSymbol *AtomicSymbolHandle;
/*! \brief handle to an Executor */
typedef MXExecutor *ExecutorHandle;
/*! \brief handle a dataiter creator */
typedef MXDataIterCreator *DataIterCreator;
/*! \brief handle to a DataIterator */
typedef MXDataIter *DataIterHandle;
/*! \brief handle to KVStore */
typedef MXKVStore *KVStoreHandle;
/*! \brief handle to RecordIO */
typedef MXRecordIO *RecordIOHandle;
/*! \brief handle to MXRtc*/
typedef MXRtc *RtcHandle;
/*! \brief handle to cached operator */
typedef MXCachedOp *CachedOpHandle;
typedef void (*ExecutorMonitorCallback)(const char*,
NDArrayHandle,
void *);
struct NativeOpInfo {
void (*forward)(int, float**, int*, unsigned**, int*, void*);
void (*backward)(int, float**, int*, unsigned**, int*, void*);
void (*infer_shape)(int, int*, unsigned**, void*);
void (*list_outputs)(char***, void*);
void (*list_arguments)(char***, void*);
// all functions also pass a payload void* pointer
void* p_forward;
* can be used to pass in as mutate variables
* to hold the result of NDArray
* \param out the returning handle
* \return 0 when success, -1 when failure happens
*/
int MXNDArrayCreateNone(NDArrayHandle *out);
/*!
* \brief create a NDArray with specified shape
* \param shape the pointer to the shape
* \param ndim the dimension of the shape
* \param dev_type device type, specify device we want to take
* \param dev_id the device id of the specific device
* \param delay_alloc whether to delay allocation until
* the ndarray is first mutated
* \param out the returning handle
* \return 0 when success, -1 when failure happens
*/
int MXNDArrayCreate(const mx_uint *in,
mx_uint ndim,
int dev_type,
int dev_id,
int delay_alloc,
NDArrayHandle *out);
/*!
* \brief create a NDArray with specified shape and data type
* \param shape the pointer to the shape
* \param ndim the dimension of the shape
* \param dev_type device type, specify device we want to take
* \param dev_id the device id of the specific device
* \param delay_alloc whether to delay allocation until
* the ndarray is first mutated
* \param dtype data type of created array
* \param out the returning handle
* \return 0 when success, -1 when failure happens
*/
int MXNDArrayCreateEx(const mx_uint *in,
mx_uint ndim,
int dev_type,
int dev_id,
int delay_alloc,
int dtype,
NDArrayHandle *out);
/*!
* \brief create a NDArray handle that is loaded from raw bytes.
* \param buf the head of the raw bytes
* \param size size of the raw bytes
* \param out the returning handle
* \return 0 when success, -1 when failure happens
*/
int MXNDArrayLoadFromRawBytes(const void *in,
size_t size,
const mx_uint **out_pdata);
/*!
* \brief get the content of the data in NDArray
* \param handle the handle to the ndarray
* \param out_pdata pointer holder to get pointer of data
* \return 0 when success, -1 when failure happens
*/
int MXNDArrayGetData(NDArrayHandle handle,
void **out_pdata);
/*!
* \brief get the type of the data in NDArray
* \param handle the handle to the ndarray
* \param out_dtype pointer holder to get type of data
* \return 0 when success, -1 when failure happens
*/
int MXNDArrayGetDType(NDArrayHandle handle,
int *out);
/*!
* \brief get the context of the NDArray
* \param handle the handle to the ndarray
* \param out_dev_type the output device type
* \param out_dev_id the output device id
* \return 0 when success, -1 when failure happens
*/
int MXNDArrayGetContext(NDArrayHandle handle,
int *out,
int *out);
/*!
* \brief return gradient buffer attached to this NDArray
* \param handle NDArray handle
* \return 0 when success, -1 when failure happens
*/
int MXGetFunction(const char *name,
FunctionHandle *out);
/*!
* \brief Get the information of the function handle.
* \param fun The function handle.
* \param name The returned name of the function.
* \param description The returned description of the function.
* \param num_args Number of arguments.
* \param arg_names Name of the arguments.
* \param arg_type_infos Type information about the arguments.
* \param arg_descriptions Description information about the arguments.
* \param return_type Return type of the function.
* \return 0 when success, -1 when failure happens
*/
int MXFuncGetInfo(FunctionHandle fun,
const char **name,
const char **description,
mx_uint *num_args,
const char ***arg_names,
const char ***arg_type_infos,
const char ***arg_descriptions
);
/*!
* \brief get the argument requirements of the function
* \param fun input function handle
* \param num_use_vars how many NDArrays to be passed in as used_vars
* \param num_scalars scalar variable is needed
* \param num_mutate_vars how many NDArrays to be passed in as mutate_vars
* \param type_mask the type mask of this function
* \return 0 when success, -1 when failure happens
* \sa MXFuncInvoke
*/
int MXFuncDescribe(FunctionHandle fun,
mx_uint *out,
mx_uint *out,
mx_uint *out,
int *out);
/*!
* \brief invoke a function, the array size of passed in arguments
*/
int MXSymbolGetAtomicSymbolName(AtomicSymbolCreator in,
const char **out);
/*!
* \brief Get the detailed information about atomic symbol.
* \param creator the AtomicSymbolCreator.
* \param name The returned name of the creator.
* \param description The returned description of the symbol.
* \param num_args Number of arguments.
* \param arg_names Name of the arguments.
* \param arg_type_infos Type informations about the arguments.
* \param arg_descriptions Description information about the arguments.
* \param key_var_num_args The keyword argument for specifying variable number of arguments.
* When this parameter has non-zero length, the function allows variable number
* of positional arguments, and will need the caller to pass it in in
* MXSymbolCreateAtomicSymbol,
* With key = key_var_num_args, and value = number of positional arguments.
* \param return_type Return type of the function, can be Symbol or Symbol[]
* \return 0 when success, -1 when failure happens
*/
int MXSymbolGetAtomicSymbolInfo(AtomicSymbolCreator in,
const char **name,
const char **description,
mx_uint *num_args,
const char ***arg_names,
const char ***arg_type_infos,
const char ***arg_descriptions,
const char **key_var_num_args
);
/*!
* \brief Create an AtomicSymbol.
* \param creator the AtomicSymbolCreator
* \param num_param the number of parameters
* \param keys the keys to the params
* \param vals the vals of the params
* \param out pointer to the created symbol handle
const mx_uint ***in_shape_data,
mx_uint *out_shape_size,
const mx_uint **out_shape_ndim,
const mx_uint ***out_shape_data,
mx_uint *aux_shape_size,
const mx_uint **aux_shape_ndim,
const mx_uint ***aux_shape_data,
int *out);
/*!
* \brief infer type of unknown input types given the known one.
* The types are packed into a CSR matrix represented by arg_ind_ptr and arg_type_data
* The call will be treated as a kwargs call if key != nullptr or num_args==0, otherwise it is positional.
*
* \param sym symbol handle
* \param num_args numbe of input arguments.
* \param keys the key of keyword args (optional)
* \param arg_type_data the content of the CSR
* \param in_type_size sizeof the returning array of in_types
* \param in_type_data returning array of pointers to head of the input type.
* \param out_type_size sizeof the returning array of out_types
* \param out_type_data returning array of pointers to head of the input type.
* \param aux_type_size sizeof the returning array of aux_types
* \param aux_type_data returning array of pointers to head of the auxiliary type.
* \param complete whether infer type completes or more information is needed.
* \return 0 when success, -1 when failure happens
*/
int MXSymbolInferType(SymbolHandle sym,
mx_uint num_args,
const char** in,
const int *in,
mx_uint *in_type_size,
const int **in_type_data,
mx_uint *out_type_size,
const int **out_type_data,
mx_uint *aux_type_size,
const int **aux_type_data,
int *out);
//--------------------------------------------
// Part 4: Executor interface
//--------------------------------------------
/*!
* \brief Delete the executor
* \param handle the executor.
* \return 0 when success, -1 when failure happens
*/
int MXExecutorFree(ExecutorHandle handle);
* \return 0 when success, -1 when failure happens
*/
int MXExecutorOutputs(ExecutorHandle handle,
mx_uint *out_size,
NDArrayHandle **out_array);
/*!
* \brief Generate Executor from symbol
*
* \param symbol_handle symbol handle
* \param dev_type device type
* \param dev_id device id
* \param len length
* \param in_args in args array
* \param arg_grad_store arg grads handle array
* \param grad_req_type grad req array
* \param aux_states_len length of auxiliary states
* \param aux_states auxiliary states array
* \param out output executor handle
* \return 0 when success, -1 when failure happens
*/
int MXExecutorBind(SymbolHandle symbol_handle,
int dev_type,
int dev_id,
mx_uint len,
NDArrayHandle *in,
NDArrayHandle *in,
mx_uint *in,
mx_uint aux_states_len,
NDArrayHandle *in,
ExecutorHandle *out);
/*!
* \brief Generate Executor from symbol,
* This is advanced function, allow specify group2ctx map.
* The user can annotate "ctx_group" attribute to name each group.
*
* \param symbol_handle symbol handle
* \param dev_type device type of default context
* \param dev_id device id of default context
* \param num_map_keys size of group2ctx map
* \param map_keys keys of group2ctx map
* \param map_dev_types device type of group2ctx map
* \param map_dev_ids device id of group2ctx map
* \param len length
* \param in_args in args array
* \param arg_grad_store arg grads handle array
* \param grad_req_type grad req array
* \param aux_states_len length of auxiliary states
* \param aux_states auxiliary states array
* \param out output executor handle
* \return 0 when success, -1 when failure happens
*/
int MXExecutorBindX(SymbolHandle symbol_handle,
int dev_type,
int dev_id,
mx_uint num_map_keys,
const char** in,
const int* in,
const int* in,
mx_uint len,
NDArrayHandle *in,
NDArrayHandle *in,
mx_uint *in,
mx_uint aux_states_len,
NDArrayHandle *in,
ExecutorHandle *out);
/*!
* \brief Generate Executor from symbol,
* This is advanced function, allow specify group2ctx map.
* The user can annotate "ctx_group" attribute to name each group.
*
* \param symbol_handle symbol handle
* \param dev_type device type of default context
* \param dev_id device id of default context
* \param num_map_keys size of group2ctx map
* \param map_keys keys of group2ctx map
* \param map_dev_types device type of group2ctx map
* \param map_dev_ids device id of group2ctx map
* \param len length
* \param in_args in args array
* \param arg_grad_store arg grads handle array
* \param grad_req_type grad req array
* \param aux_states_len length of auxiliary states
* \param aux_states auxiliary states array
* \param shared_exec input executor handle for memory sharing
* \param out output executor handle
* \return 0 when success, -1 when failure happens
*/
int MXExecutorBindEX(SymbolHandle symbol_handle,
int dev_type,
int dev_id,
mx_uint num_map_keys,
const char** in,
const int* in,
const int* in,
mx_uint len,
NDArrayHandle *in,
NDArrayHandle *in,
mx_uint *in,
mx_uint aux_states_len,
NDArrayHandle *in,
ExecutorHandle shared_exec,
ExecutorHandle *out);
int MXExecutorSimpleBind(SymbolHandle symbol_handle,
int dev_type,
int dev_id,
const mx_uint num_g2c_keys,
const char** in, // g2c_keys,
const int* in, // g2c_dev_types,
const int* in, // g2c_dev_ids,
const mx_uint provided_grad_req_list_len,
const char** in, // provided_grad_req_names,
const char** in, // provided_grad_req_types,
const mx_uint num_provided_arg_shapes,
const char** in, // provided_arg_shape_names,
const mx_uint* in, // provided_arg_shape_data,
const mx_uint* in, // provided_arg_shape_idx,
const mx_uint num_provided_arg_dtypes,
const char** in, // provided_arg_dtype_names,
const int* in, // provided_arg_dtypes,
const mx_uint num_shared_arg_names,
const char** in, // shared_arg_name_list,
//------------
int* shared_buffer_len,
const char** shared_buffer_name_list,
NDArrayHandle* shared_buffer_handle_list,
const char*** updated_shared_buffer_name_list,
NDArrayHandle** updated_shared_buffer_handle_list,
//------------------
const char **keys,
const char **vals,
DataIterHandle *out);
/*!
* \brief Get the detailed information about data iterator.
* \param creator the DataIterCreator.
* \param name The returned name of the creator.
* \param description The returned description of the symbol.
* \param num_args Number of arguments.
* \param arg_names Name of the arguments.
* \param arg_type_infos Type informations about the arguments.
* \param arg_descriptions Description information about the arguments.
* \return 0 when success, -1 when failure happens
*/
int MXDataIterGetIterInfo(DataIterCreator creator,
const char **name,
const char **description,
mx_uint *num_args,
const char ***arg_names,
const char ***arg_type_infos,
const char ***arg_descriptions);
/*!
* \brief Free the handle to the IO module
* \param handle the handle pointer to the data iterator
* \return 0 when success, -1 when failure happens
*/
int MXDataIterFree(DataIterHandle handle);
/*!
* \brief Move iterator to next position
* \param handle the handle to iterator
* \param keys environment keys
* \param vals environment values
*/
int MXInitPSEnv(mx_uint num_vars,
const char **keys,
const char **vals);
/*!
* \brief Create a kvstore
* \param type the type of KVStore
* \param out The output type of KVStore
* \return 0 when success, -1 when failure happens
*/
int MXKVStoreCreate(const char *type,
KVStoreHandle *out);
/*!
* \brief Delete a KVStore handle.
* \param handle handle to the kvstore
* \return 0 when success, -1 when failure happens
*/
int MXKVStoreFree(KVStoreHandle handle);
/*!
* \brief Init a list of (key,value) pairs in kvstore, where each key is a string
NDArrayHandle* in,
int priority);
/*!
* \brief user-defined updater for the kvstore
* It's this updater's responsibility to delete \a recv and \a local
* \param the key
* \param recv the pushed value on this key
* \param local the value stored on local on this key
* \param handle The additional handle to the updater
*/
typedef void (MXKVStoreUpdater)(int key,
NDArrayHandle recv,
NDArrayHandle local,
void *handle);
/*!
* \brief register an push updater
* \param handle handle to the KVStore
* \param updater udpater function
* \param updater_handle The additional handle used to invoke the updater
* \return 0 when success, -1 when failure happens
*/
int MXKVStoreSetUpdater(KVStoreHandle handle,
MXKVStoreUpdater updater,
void *callback_handle);
/*!
* \brief get the type of the kvstore
* \param handle handle to the KVStore
* \param type a string type
* \return 0 when success, -1 when failure happens
*/
int MXKVStoreGetType(KVStoreHandle handle,
const char** out);
//--------------------------------------------
// Part 6: advanced KVStore for multi-machines
//--------------------------------------------
/**
* \brief return The rank of this node in its group, which is in [0, GroupSize).
* \brief whether to do barrier when finalize
*
* \param handle handle to the KVStore
* \param barrier_before_exit whether to do barrier when kvstore finalize
* \return 0 when success, -1 when failure happens
*/
int MXKVStoreSetBarrierBeforeExit(KVStoreHandle handle,
const int barrier_before_exit);
/**
* \brief the prototype of a server controller
* \param head the head of the command
* \param body the body of the command
* \param controller_handle helper handle for implementing controller
*/
typedef void (MXKVStoreServerController)(int head,
const char *body,
void *controller_handle);
/**
* \return Run as server (or scheduler)
*
* \param handle handle to the KVStore
* \param controller the user-defined server controller
* \param controller_handle helper handle for implementing controller
* \return 0 when success, -1 when failure happens
mx_uint gridDimZ,
mx_uint blockDimX,
mx_uint blockDimY,
mx_uint blockDimZ);
/**
* \brief Delete a MXRtc object
*/
int MXRtcFree(RtcHandle handle);
int MXCustomOpRegister(const char* op_type, CustomOpPropCreator creator);
mxnet_typemaps.i view on Meta::CPAN
%typemap(in) (const char** in), (char** in)
{
AV *tempav;
I32 len;
int i;
SV **tv;
STRLEN len2;
if (!SvROK($input))
croak("Argument $argnum is not a reference.");
if (SvTYPE(SvRV($input)) != SVt_PVAV)
croak("Argument $argnum is not an array.");
mxnet_typemaps.i view on Meta::CPAN
for (i = 0; i < len; i++) {
tv = av_fetch(tempav, i, 0);
$1[i] = (char *) SvPV(*tv,len2);
}
}
else
{
$1 = NULL;
}
}
%typemap(freearg) (const char** in), (char** in) {
Safefree($1);
}
%typemap(in) (const char **keys, const char **vals), (char **keys, char **vals)
{
HV *temphv;
char *key;
SV *val;
I32 len;
STRLEN len2;
int hash_len;
int i = 0;
if (!SvROK($input))
croak("Argument $argnum is not a reference.");
mxnet_typemaps.i view on Meta::CPAN
$2[i] = SvPV(val, len2);
++i;
}
}
else
{
$1 = NULL;
$2 = NULL;
}
}
%typemap(freearg) (const char **keys, const char **vals), (char **keys, char **vals)
{
Safefree($1);
Safefree($2);
}
%typemap(in,numinputs=0) (const char **out) (char *temp)
{
temp = NULL;
$1 = &temp;
}
%typemap(argout) (const char **out)
{
if(!result)
{
$result = newSVpv(*$1, 0);
sv_2mortal($result);
argvi++;
}
}
%typemap(in,numinputs=0) (int *out) (int temp)
{
temp = 0;
$1 = &temp;
}
%typemap(argout) (int *out)
{
if(!result)
{
$result = newSViv(*$1);
sv_2mortal($result);
argvi++;
}
}
%typemap(in,numinputs=0) (nn_uint *out_size, const char ***out_array) (nn_uint temp_size, char** temp),
(mx_uint *out_size, const char ***out_array) (mx_uint temp_size, char** temp)
{
$1 = &temp_size;
$2 = &temp;
}
%typemap(argout) (nn_uint *out_size, const char ***out_array),
(mx_uint *out_size, const char ***out_array)
{
if(!result)
{
AV *myav;
SV **svs;
int i = 0;
svs = (SV **)safemalloc(*$1*sizeof(SV *));
for (i = 0; i < *$1 ; i++) {
svs[i] = newSVpv((*$2)[i],0);
sv_2mortal(svs[i]);
};
myav = av_make(*$1,svs);
Safefree(svs);
$result = newRV_noinc((SV*)myav);
sv_2mortal($result);
argvi++;
}
}
%typemap(in,numinputs=0) (mx_uint *out_size, const char ***out_array2) (mx_uint temp_size, char** temp)
{
$1 = &temp_size;
$2 = &temp;
}
%typemap(argout) (mx_uint *out_size, const char ***out_array2)
{
if(!result)
{
AV *myav;
SV **svs;
int i = 0;
svs = (SV **)safemalloc(*$1*sizeof(SV *)*2);
for (i = 0; i < *$1*2 ; i++) {
svs[i] = newSVpv((*$2)[i],0);
sv_2mortal(svs[i]);
};
myav = av_make(*$1*2,svs);
Safefree(svs);
$result = newRV_noinc((SV*)myav);
sv_2mortal($result);
argvi++;
}
}
%typemap(in) (FunctionHandle in)
{
int res;
void **void_ptrptr = const_cast< void** >(&$1);
res = SWIG_ConvertPtr($input,void_ptrptr, 0, 0);
if (!SWIG_IsOK(res)) {
SWIG_exception_fail(SWIG_ArgError(res), "in method '" "$symname" "', argument " "$argnum"" of type '" "FunctionHandle""'");
}
}
%typemap(in) (AtomicSymbolCreator in)
{
int res = SWIG_ConvertPtr($input,&$1, 0, 0);
if (!SWIG_IsOK(res)) {
SWIG_exception_fail(SWIG_ArgError(res), "in method '" "$symname" "', argument " "$argnum"" of type '" "AtomicSymbolCreator""'");
}
}
%typemap(in) (const void *in), (void *in)
{
STRLEN len;
$1 = (void *)SvPV($input, len);
}
%typemap(in) (const char *in)
{
STRLEN len;
$1 = SvPV($input, len);
}
%typemap(in) (const mx_uint *in), (mx_uint *in)
{
AV *tempav;
int i;
SV **tv;
int av_len;
if (!SvROK($input))
croak("Argument $argnum is not a reference.");
if (SvTYPE(SvRV($input)) != SVt_PVAV)
croak("Argument $argnum is not an array.");
tempav = (AV*)SvRV($input);
mxnet_typemaps.i view on Meta::CPAN
tv = av_fetch(tempav, i, 0);
$1[i] = (mx_uint)SvIV(*tv);
}
}
else
{
$1 = NULL;
}
}
%typemap(freearg) (const mx_uint *in), (mx_uint *in) {
Safefree($1);
}
%typemap(in) (const int *in), (int *in)
{
AV *tempav;
int i;
SV **tv;
int av_len;
if (!SvROK($input))
croak("Argument $argnum is not a reference.");
if (SvTYPE(SvRV($input)) != SVt_PVAV)
croak("Argument $argnum is not an array.");
tempav = (AV*)SvRV($input);
mxnet_typemaps.i view on Meta::CPAN
$1[i] = (int)SvIV(*tv);
}
}
else
{
$1 = NULL;
}
}
%typemap(freearg) (const int *in), (int *in) {
Safefree($1);
}
%typemap(in) (NDArrayHandle* in), (SymbolHandle* in)
{
AV *tempav;
int i;
SV **tv;
int res;
int av_len;
if (!SvROK($input))
croak("Argument $argnum is not a reference.");
if (SvTYPE(SvRV($input)) != SVt_PVAV)
croak("Argument $argnum is not an array.");
tempav = (AV*)SvRV($input);
av_len = av_top_index(tempav) + 1;
if(av_len)
{
$1 = ($1_type)safemalloc(av_len*sizeof($*1_type));
for (i = 0; i < av_len; i++) {
tv = av_fetch(tempav, i, 0);
res = SWIG_ConvertPtr(*tv,SWIG_as_voidptrptr(&$1[i]), $*1_descriptor, 0);
if (!SWIG_IsOK(res)) {
SWIG_exception_fail(SWIG_ArgError(res), "in method '" "$symname" "', argument " "$argnum"" of type '" "$*1_type""'");
}
}
}
else
{
$1 = NULL;
}
}
%typemap(freearg) (NDArrayHandle* in), (SymbolHandle* in) {
Safefree($1);
}
%typemap(in) (mx_float *in)
{
AV *tempav;
int i, len;
SV **tv;
if (!SvROK($input))
croak("Argument $argnum is not a reference.");
if (SvTYPE(SvRV($input)) != SVt_PVAV)
croak("Argument $argnum is not an array.");
tempav = (AV*)SvRV($input);
len = av_top_index(tempav) + 1;
mxnet_typemaps.i view on Meta::CPAN
tv = av_fetch(tempav, i, 0);
$1[i] = (mx_float)SvNV(*tv);
}
}
else
{
$1 = NULL;
}
}
%typemap(freearg) (mx_float *in) {
Safefree($1);
}
%typemap(in,numinputs=0) (NDArrayHandle *out) (NDArrayHandle temp),
(FunctionHandle* out) (FunctionHandle temp),
(SymbolHandle *out) (SymbolHandle temp),
(ExecutorHandle *out) (ExecutorHandle temp),
(DataIterHandle *out) (ExecutorHandle temp),
(KVStoreHandle *out) (KVStoreHandle temp),
(RecordIOHandle *out) (RecordIOHandle temp),
(RtcHandle *out) (RtcHandle temp),
(CachedOpHandle *out) (CachedOpHandle temp)
{
$1 = &temp;
}
%typemap(argout) (NDArrayHandle *out), (FunctionHandle* out), (SymbolHandle *out), (ExecutorHandle *out), (DataIterHandle *out),
(KVStoreHandle *out), (RecordIOHandle *out), (RtcHandle *out) (RtcHandle temp), (CachedOpHandle *out) (CachedOpHandle temp)
{
if(!result)
{
$result = SWIG_NewPointerObj(SWIG_as_voidptr(*$1), $*1_descriptor, 0); argvi++;
}
}
%typemap(in) (mx_float **out_pdata) (mx_float *temp_pdata)
{
$1 = &temp_pdata;
}
%typemap(argout) (mx_float **out_pdata)
{
if(!result)
{
AV *myav;
SV **svs;
int len;
int i = 0;
len = SvIV($input);
svs = (SV **)safemalloc(len*sizeof(SV *));
for (i = 0; i < len ; i++) {
mxnet_typemaps.i view on Meta::CPAN
sv_2mortal(svs[i]);
}
myav = av_make(len,svs);
Safefree(svs);
$result = newRV_noinc((SV*)myav);
sv_2mortal($result);
argvi++;
}
}
%typemap(in,numinputs=0) (char const **out_array, size_t *out_size) (char * temp, size_t temp_size)
{
$2 = &temp_size;
$1 = &temp;
}
%typemap(argout) (char const **out_array, size_t *out_size)
{
if(!result)
{
$result = newSVpvn(*$1, *$2);
sv_2mortal($result);
argvi++;
}
}
%typemap(in,numinputs=0) (size_t *out_size, char const **out_array) (size_t temp_size, char *temp)
{
$1 = &temp_size;
$2 = &temp;
}
%typemap(argout) (size_t *out_size, char const **out_array)
{
if(!result)
{
$result = newSVpvn(*$2, *$1);
sv_2mortal($result);
argvi++;
}
}
%typemap(in,numinputs=0) (mx_uint *out_dim, const mx_uint **out_pdata) (mx_uint temp_dim, mx_uint *temp_pdata)
{
$1 = &temp_dim;
$2 = &temp_pdata;
}
%typemap(argout) (mx_uint *out_dim, const mx_uint **out_pdata)
{
if(!result)
{
AV *myav;
SV **svs;
int i = 0;
svs = (SV **)safemalloc(*$1*sizeof(SV *));
for (i = 0; i < *$1 ; i++) {
svs[i] = newSViv((*$2)[i]);
sv_2mortal(svs[i]);
}
myav = av_make(*$1,svs);
Safefree(svs);
$result = newRV_noinc((SV*)myav);
sv_2mortal($result);
argvi++;
}
}
%typemap(in,numinputs=0) (uint64_t **out_index, uint64_t *out_size) (uint64_t *temp1, uint64_t temp2)
{
$1 = &temp1;
$2 = &temp2;
}
%typemap(argout) (uint64_t **out_index, uint64_t *out_size)
{
if(!result)
{
AV *myav;
SV **svs;
int i = 0;
svs = (SV **)safemalloc(*$2*sizeof(SV *));
for (i = 0; i < *$2 ; i++) {
svs[i] = newSViv((*$1)[i]);
sv_2mortal(svs[i]);
}
myav = av_make(*$2,svs);
Safefree(svs);
$result = newRV_noinc((SV*)myav);
sv_2mortal($result);
argvi++;
}
}
%typemap(in,numinputs=0) (mx_uint *out_size, FunctionHandle** out_array) (mx_uint temp_size, FunctionHandle* temp),
(mx_uint *out_size, AtomicSymbolCreator** out_array) (mx_uint temp_size, AtomicSymbolCreator* temp),
(mx_uint *out_size, DataIterCreator **out_array) (mx_uint temp_size, DataIterCreator* temp),
(mx_uint *out_size, NDArrayHandle** out_array) (mx_uint temp_size, NDArrayHandle* temp)
{
$1 = &temp_size;
$2 = &temp;
}
// many argouts needed because SWIG can't $**2_mangle
%typemap(argout) (mx_uint *out_size, AtomicSymbolCreator** out_array)
{
if(!result)
{
AV *myav;
SV **svs;
int i = 0;
svs = (SV **)safemalloc(*$1*sizeof(SV *));
for (i = 0; i < *$1 ; i++) {
svs[i] = SWIG_NewPointerObj(SWIG_as_voidptr((*$2)[i]), SWIGTYPE_p_MXAtomicSymbolCreator, 0);
}
myav = av_make(*$1,svs);
Safefree(svs);
$result = newRV_noinc((SV*)myav);
sv_2mortal($result);
argvi++;
}
}
%typemap(argout) (mx_uint *out_size, FunctionHandle** out_array)
{
if(!result)
{
AV *myav;
SV **svs;
int i = 0;
svs = (SV **)safemalloc(*$1*sizeof(SV *));
for (i = 0; i < *$1 ; i++) {
svs[i] = SWIG_NewPointerObj(SWIG_as_voidptr((*$2)[i]), SWIGTYPE_p_MXFunction, 0);
}
myav = av_make(*$1,svs);
Safefree(svs);
$result = newRV_noinc((SV*)myav);
sv_2mortal($result);
argvi++;
}
}
%typemap(argout) (mx_uint *out_size, DataIterCreator **out_array)
{
if(!result)
{
AV *myav;
SV **svs;
int i = 0;
svs = (SV **)safemalloc(*$1*sizeof(SV *));
for (i = 0; i < *$1 ; i++) {
svs[i] = SWIG_NewPointerObj(SWIG_as_voidptr((*$2)[i]), SWIGTYPE_p_MXDataIterCreator, 0);
}
myav = av_make(*$1,svs);
Safefree(svs);
$result = newRV_noinc((SV*)myav);
sv_2mortal($result);
argvi++;
}
}
%typemap(argout) (mx_uint *out_size, NDArrayHandle** out_array)
{
if(!result)
{
AV *myav;
SV **svs;
int i = 0;
svs = (SV **)safemalloc(*$1*sizeof(SV *));
for (i = 0; i < *$1 ; i++) {
svs[i] = SWIG_NewPointerObj(SWIG_as_voidptr((*$2)[i]), SWIGTYPE_p_MXNDArray, 0);
}
myav = av_make(*$1,svs);
Safefree(svs);
$result = newRV_noinc((SV*)myav);
sv_2mortal($result);
argvi++;
}
}
%typemap(in) (int *out_size, NDArrayHandle** out_array) (int temp, NDArrayHandle* temp_array)
{
AV *tempav;
int i;
SV **tv;
int res;
int av_len;
if (!SvROK($input))
croak("Argument $argnum is not a reference.");
if (SvTYPE(SvRV($input)) != SVt_PVAV)
croak("Argument $argnum is not an array.");
tempav = (AV*)SvRV($input);
av_len = av_top_index(tempav) + 1;
temp_array = NULL;
if(av_len)
{
temp_array = (void**)safemalloc(av_len*sizeof(void*));
for (i = 0; i < av_len; i++) {
tv = av_fetch(tempav, i, 0);
res = SWIG_ConvertPtr(*tv,SWIG_as_voidptrptr(&(temp_array[i])), 0, 0);
if (!SWIG_IsOK(res)) {
SWIG_exception_fail(SWIG_ArgError(res), "in method '" "$symname" "', argument " "$argnum"" of type '" "NDArray""'");
}
}
}
temp = av_len;
$1 = &temp;
$2 = &temp_array;
}
%typemap(freearg) (int *out_size, NDArrayHandle** out_array) {
if(av_top_index((AV*)SvRV(ST(3))) > -1)
{
Safefree(*$2);
}
}
%typemap(argout) (int *out_size, NDArrayHandle** out_array)
{
SV **svs;
int i = 0;
if(av_top_index((AV*)SvRV(ST(3))) == -1)
{
if(!result)
{
AV *container = newAV();
for (i = 0; i < *$1 ; i++) {
av_push(container, SvREFCNT_inc(SWIG_NewPointerObj(SWIG_as_voidptr((*$2)[i]), SWIGTYPE_p_MXNDArray, 0)));
}
$result = newRV_noinc((SV*)container);
sv_2mortal($result);
argvi++;
}
}
}
%typemap(in,numinputs=0) (const char **name,
const char **description,
mx_uint *num_args,
const char ***arg_names,
const char ***arg_type_infos,
const char ***arg_descriptions
)
(char *name_temp,
char *desc_temp,
mx_uint num_args_temp,
char **names_temp,
char **types_temp,
char **descs_temp
)
{
$1 = &name_temp;
$2 = &desc_temp;
$3 = &num_args_temp;
$4 = &names_temp;
$5 = &types_temp;
$6 = &descs_temp;
}
%typemap(argout) (const char **name,
const char **description,
mx_uint *num_args,
const char ***arg_names,
const char ***arg_type_infos,
const char ***arg_descriptions
)
{
if(!result)
{
AV *container, *names, *types, *descs;
int i;
container = newAV();
names = newAV();
types = newAV();
descs = newAV();
if($1) av_push(container, newSVpv(*$1,0));
if($2) av_push(container, newSVpv(*$2,0));
if($3)
{
for (i = 0; i < *$3 ; i++) {
av_push(names, newSVpv((*$4)[i],0));
av_push(types, newSVpv((*$5)[i],0));
av_push(descs, newSVpv((*$6)[i],0));
}
}
av_push(container, newRV_noinc((SV*)names));
av_push(container, newRV_noinc((SV*)types));
av_push(container, newRV_noinc((SV*)descs));
$result = newRV_noinc((SV*)container);
sv_2mortal($result);
argvi++;
}
}
%typemap(in,numinputs=0) (const char **name,
const char **description,
mx_uint *num_args,
const char ***arg_names,
const char ***arg_type_infos,
const char ***arg_descriptions,
const char **key_var_num_args
)
(char *name_temp,
char *desc_temp,
mx_uint num_args_temp,
char **names_temp,
char **types_temp,
char **descs_temp,
char *key_temp
)
{
$1 = &name_temp;
$2 = &desc_temp;
$3 = &num_args_temp;
$4 = &names_temp;
$5 = &types_temp;
$6 = &descs_temp;
$7 = &key_temp;
}
%typemap(argout) (const char **name,
const char **description,
mx_uint *num_args,
const char ***arg_names,
const char ***arg_type_infos,
const char ***arg_descriptions,
const char **key_var_num_args
)
{
if(!result)
{
AV *container, *names, *types, *descs;
int i;
container = newAV();
names = newAV();
types = newAV();
descs = newAV();
if($1) av_push(container, newSVpv(*$1,0));
if($2) av_push(container, newSVpv(*$2,0));
if($3)
{
for (i = 0; i < *$3 ; i++) {
av_push(names, newSVpv((*$4)[i],0));
av_push(types, newSVpv((*$5)[i],0));
av_push(descs, newSVpv((*$6)[i],0));
}
}
av_push(container, newRV_noinc((SV*)names));
av_push(container, newRV_noinc((SV*)types));
av_push(container, newRV_noinc((SV*)descs));
if($7) av_push(container, newSVpv(*$7,0));
$result = newRV_noinc((SV*)container);
sv_2mortal($result);
argvi++;
}
}
%typemap(in,numinputs=0) (mx_uint *out) (mx_uint temp), (size_t *out) (size_t temp)
{
$1 = &temp;
}
%typemap(argout) (mx_uint *out), (size_t *out)
{
if(!result)
{
$result = newSViv(*$1);
sv_2mortal($result);
argvi++;
}
}
%typemap(in,numinputs=0) (mx_uint *in_shape_size, const mx_uint **in_shape_ndim, const mx_uint ***in_shape_data)
(mx_uint temp1, mx_uint *temp2, mx_uint **temp3),
(mx_uint *out_shape_size, const mx_uint **out_shape_ndim, const mx_uint ***out_shape_data)
(mx_uint temp1, mx_uint *temp2, mx_uint **temp3),
(mx_uint *aux_shape_size, const mx_uint **aux_shape_ndim, const mx_uint ***aux_shape_data)
(mx_uint temp1, mx_uint *temp2, mx_uint **temp3)
{
$1 = &temp1;
$2 = &temp2;
$3 = &temp3;
*$1 = 0;
}
%typemap(argout) (mx_uint *in_shape_size, const mx_uint **in_shape_ndim, const mx_uint ***in_shape_data),
(mx_uint *out_shape_size, const mx_uint **out_shape_ndim, const mx_uint ***out_shape_data),
(mx_uint *aux_shape_size, const mx_uint **aux_shape_ndim, const mx_uint ***aux_shape_data)
{
if(!result && *arg15)
{
AV *container;
AV *tmp;
int i, j;
container = newAV();
for (i = 0; i < *$1 ; i++)
mxnet_typemaps.i view on Meta::CPAN
av_push(tmp, newSViv((*$3)[i][j]));
}
av_push(container, newRV((SV*)tmp));
}
$result = newRV_noinc((SV*)container);
sv_2mortal($result);
argvi++;
}
}
%typemap(in,numinputs=0) (mx_uint *in_type_size, const int **in_type_data)
(mx_uint temp1, int *temp2),
(mx_uint *out_type_size, const int **out_type_data)
(mx_uint temp1, int *temp2),
(mx_uint *aux_type_size, const int **aux_type_data)
(mx_uint temp1, int *temp2)
{
$1 = &temp1;
$2 = &temp2;
*$1 = 0;
}
%typemap(argout) (mx_uint *in_type_size, const int **in_type_data),
(mx_uint *out_type_size, const int **out_type_data),
(mx_uint *aux_type_size, const int **aux_type_data)
{
if(!result && *arg11)
{
AV *container;
int i;
container = newAV();
for (i = 0; i < *$1 ; i++)
{
av_push(container, newSViv((*$2)[i]));
}
$result = newRV_noinc((SV*)container);
sv_2mortal($result);
argvi++;
}
}
%typemap(in,numinputs=0) (mx_uint* num_in_args,
NDArrayHandle** in_args,
NDArrayHandle** arg_grads)
(mx_uint temp1,
NDArrayHandle* temp2,
NDArrayHandle* temp3)
{
$1 = &temp1;
$2 = &temp2;
$3 = &temp3;
*$1 = 0;
}
%typemap(argout) (mx_uint* num_in_args,
NDArrayHandle** in_args,
NDArrayHandle** arg_grads)
{
if(!result)
{
AV *container1 = newAV();
AV *container2 = newAV();
for (int i = 0; i < *$1 ; i++)
{
av_push(container1, SvREFCNT_inc(SWIG_NewPointerObj(SWIG_as_voidptr((*$2)[i]), SWIGTYPE_p_MXNDArray, 0)));
mxnet_typemaps.i view on Meta::CPAN
}
$result = newRV_noinc((SV*)container1);
sv_2mortal($result);
argvi++;
$result = newRV_noinc((SV*)container2);
sv_2mortal($result);
argvi++;
}
}
%typemap(in,numinputs=0) (mx_uint* num_aux_states,
NDArrayHandle** aux_states)
(mx_uint temp1,
NDArrayHandle* temp2)
{
$1 = &temp1;
$2 = &temp2;
*$1 = 0;
}
%typemap(argout) (mx_uint* num_aux_states,
NDArrayHandle** aux_states)
{
if(!result)
{
AV *container = newAV();
for (int i = 0; i < *$1 ; i++)
{
av_push(container, SvREFCNT_inc(SWIG_NewPointerObj(SWIG_as_voidptr((*$2)[i]), SWIGTYPE_p_MXNDArray, 0)));
}
$result = newRV_noinc((SV*)container);
sv_2mortal($result);
argvi++;
}
}
%typemap(in) (int* shared_buffer_len,
const char** shared_buffer_name_list,
NDArrayHandle* shared_buffer_handle_list,
const char*** updated_shared_buffer_name_list,
NDArrayHandle** updated_shared_buffer_handle_list)
(int temp1,
char* temp2,
NDArrayHandle temp3,
char** temp4,
NDArrayHandle* temp5)
{
mxnet_typemaps.i view on Meta::CPAN
*$1 = hv_iterinit(temphv);
if(*$1)
{
$2 = (char**)safemalloc((*$1)*sizeof(char*));
$3 = (void**)safemalloc((*$1)*sizeof(void*));
while ((val = hv_iternextsv(temphv, &key, &len)))
{
$2[i] = key;
res = SWIG_ConvertPtr(val,SWIG_as_voidptrptr(&($3[i])), 0, 0);
if (!SWIG_IsOK(res)) {
SWIG_exception_fail(SWIG_ArgError(res), "in method '" "$symname" "', argument " "$argnum"" of type '" "NDArray""'");
}
i++;
}
}
else
{
$2 = NULL;
$3 = NULL;
}
}
}
%typemap(freearg) (int* shared_buffer_len,
const char** shared_buffer_name_list,
NDArrayHandle* shared_buffer_handle_list,
const char*** updated_shared_buffer_name_list,
NDArrayHandle** updated_shared_buffer_handle_list)
{
Safefree($2);
Safefree($3);
}
%typemap(argout) (int* shared_buffer_len,
const char** shared_buffer_name_list,
NDArrayHandle* shared_buffer_handle_list,
const char*** updated_shared_buffer_name_list,
NDArrayHandle** updated_shared_buffer_handle_list)
{
if(!result)
{
HV* hash = newHV();
for(int j = 0; j < *$1; j++)
{
hv_store(hash, (*$4)[j], strlen((*$4)[j]), SvREFCNT_inc(SWIG_NewPointerObj(SWIG_as_voidptr((*$5)[j]), SWIGTYPE_p_MXNDArray, 0)), 0);
}
$result = newRV_noinc((SV*)hash);
sv_2mortal($result);
argvi++;
}
}
%typemap(in) (uint32_t x)
{
union fbits u;
u.f = SvNV($input);
$1 = u.x;
}
%typemap(out) (uint16_t)
{
$result = newSViv($1);
sv_2mortal($result);
argvi++;
}
%typemap(in) (uint16_t x)
{
$1 = SvIV($input);
}
%typemap(out) (uint32_t)
{
union fbits u;
u.x = $1;
$result = newSVnv(u.f);
sv_2mortal($result);
argvi++;
}
%typemap(in,numinputs=0) (MXKVStoreUpdater* updater)
{
$1 = KVStore_callback;
}
%typemap(in,numinputs=0) (MXKVStoreServerController* controller)
{
$1 = KVStoreServer_callback;
}
%typemap(in,numinputs=0) (ExecutorMonitorCallback callback)
{
$1 = ExecutorMonitor_callback;
}
%typemap(in) (void* callback_handle)
{
$1 = (void*)$input;
}
( run in 2.680 seconds using v1.01-cache-2.11-cpan-df04353d9ac )