AI-MXNetCAPI

 view release on metacpan or  search on metacpan

META.json  view on Meta::CPAN

14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
   },
   "name" : "AI-MXNetCAPI",
   "no_index" : {
      "directory" : [
         "t",
         "inc"
      ]
   },
   "prereqs" : {
      "build" : {
         "requires" : {
            "ExtUtils::MakeMaker" : "0"
         }
      },
      "configure" : {
         "requires" : {
            "ExtUtils::MakeMaker" : "0"
         }
      },
      "runtime" : {
         "requires" : {
            "Test::More" : "0"
         }
      }
   },
   "release_status" : "stable",
   "version" : "1.0102"
}

META.yml  view on Meta::CPAN

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
---
abstract: 'Swig interface to mxnet c api'
author:
  - 'Sergey Kolychev <sergeykolychev.github@gmail.com>'
build_requires:
  ExtUtils::MakeMaker: '0'
configure_requires:
  ExtUtils::MakeMaker: '0'
dynamic_config: 0
generated_by: 'ExtUtils::MakeMaker version 7.24, CPAN::Meta::Converter version 2.143240'
license: apache
meta-spec:
  version: '1.4'
name: AI-MXNetCAPI
no_index:
  directory:
    - t
    - inc
requires:
  Test::More: '0'
version: '1.0102'

README  view on Meta::CPAN

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
 
COPYRIGHT AND LICENCE
 
Copyright (C) 2017 by Sergey Kolychev <sergeykolychev.github@gmail.com>
 
This library is licensed under Apache 2.0 license https://www.apache.org/licenses/LICENSE-2.0

mxnet.i  view on Meta::CPAN

239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
/*! \brief Set the number of OMP threads to use */
int MXSetNumOMPThreads(int thread_num);
 
//-------------------------------------
// Part 1: NDArray creation and deletion
//-------------------------------------
/*!
 * \brief create a NDArray handle that is not initialized
 *  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

mxnet.i  view on Meta::CPAN

356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
*  not wrapped by NDArray(thus dependency not being tracked).
 *
 * \param handle the NDArray handle
 * \param data the data source to copy into.
 * \param size the memory size we want to copy into.
 */
int MXNDArraySyncCopyToCPU(NDArrayHandle handle,
                                     void *in,
                                     size_t size);
/*!
 * \brief Wait until all the pending writes with respect NDArray are finished.
 *  Always call this before read data out synchronizely.
 * \param handle the NDArray handle
 * \return 0 when success, -1 when failure happens
 */
int MXNDArrayWaitToRead(NDArrayHandle handle);
/*!
 * \brief Wait until all the pending read/write with respect NDArray are finished.
 *  Always call this before write data into NDArray synchronizely.
 * \param handle the NDArray handle
 * \return 0 when success, -1 when failure happens
 */
int MXNDArrayWaitToWrite(NDArrayHandle handle);
/*!
 * \brief wait until all delayed operations in
 *   the system is completed
 * \return 0 when success, -1 when failure happens
 */

mxnet.i  view on Meta::CPAN

408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
* \return 0 when success, -1 when failure happens
 */
int MXNDArrayAt(NDArrayHandle handle,
                          mx_uint idx,
                          NDArrayHandle *out);
/*!
 * \brief Reshape the NDArray.
 * \param handle the handle to the ndarray
 * \param ndim number of dimensions of new shape
 * \param dims new shape
 * \param out the NDArrayHandle of reshaped NDArray
 * \return 0 when success, -1 when failure happens
 */
int MXNDArrayReshape(NDArrayHandle handle,
                               int ndim,
                               int *in,
                               NDArrayHandle *out);
/*!
 * \brief get the shape of the array
 * \param handle the handle to the ndarray
 * \param out_dim the output dimension

mxnet.i  view on Meta::CPAN

496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
*   most user can use it to list all the needed functions
 * \param out_size the size of returned array
 * \param out_array the output function array
 * \return 0 when success, -1 when failure happens
 */
int MXListFunctions(mx_uint *out_size,
                              FunctionHandle **out_array);
/*!
 * \brief get the function handle by name
 * \param name the name of the function
 * \param out the corresponding function 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.

mxnet.i  view on Meta::CPAN

766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
int MXSymbolSaveToJSON(SymbolHandle symbol, const char **out);
/*!
 * \brief Free the symbol handle.
 * \param symbol the symbol
 * \return 0 when success, -1 when failure happens
 */
int MXSymbolFree(SymbolHandle symbol);
/*!
 * \brief Copy the symbol to another handle
 * \param symbol the source symbol
 * \param out used to hold the result of copy
 * \return 0 when success, -1 when failure happens
 */
int MXSymbolCopy(SymbolHandle symbol, SymbolHandle *out);
/*!
 * \brief Print the content of symbol, used for debug.
 * \param symbol the symbol
 * \param out_str pointer to hold the output string of the printing.
 * \return 0 when success, -1 when failure happens
 */
int MXSymbolPrint(SymbolHandle symbol, const char **out);
/*!
 * \brief Get string name from symbol
 * \param symbol the source symbol
 * \param out The result name.
 * \param success Whether the result is contained in out.
 * \return 0 when success, -1 when failure happens
 */
int MXSymbolGetName(SymbolHandle symbol,
                              const char** out,
                              int *out);
/*!
 * \brief Get string attribute from symbol
 * \param symbol the source symbol
 * \param key The key of the symbol.
 * \param out The result attribute, can be NULL if the attribute do not exist.
 * \param success Whether the result is contained in out.
 * \return 0 when success, -1 when failure happens
 */
int MXSymbolGetAttr(SymbolHandle symbol,
                              const char* key,
                              const char** out,
                              int *out);
/*!
 * \brief Set string attribute from symbol.
 *  NOTE: Setting attribute to a symbol can affect the semantics(mutable/immutable) of symbolic graph.
 *

mxnet.i  view on Meta::CPAN

822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
* \param value The value to be saved.
 * \return 0 when success, -1 when failure happens
 */
int MXSymbolSetAttr(SymbolHandle symbol,
                              const char* in,
                              const char* in);
/*!
 * \brief Get all attributes from symbol, including all descendents.
 * \param symbol the source symbol
 * \param out_size The number of output attributes
 * \param out 2*out_size strings representing key value pairs.
 * \return 0 when success, -1 when failure happens
 */
int MXSymbolListAttr(SymbolHandle symbol,
                               mx_uint *out_size,
                               const char*** out_array2);
/*!
 * \brief Get all attributes from symbol, excluding descendents.
 * \param symbol the source symbol
 * \param out_size The number of output attributes
 * \param out 2*out_size strings representing key value pairs.
 * \return 0 when success, -1 when failure happens
 */
int MXSymbolListAttrShallow(SymbolHandle symbol,
                                      mx_uint *out_size,
                                      const char*** out_array2);
/*!
 * \brief List arguments in the symbol.
 * \param symbol the symbol
 * \param out_size output size
 * \param out_str_array pointer to hold the output string array

mxnet.i  view on Meta::CPAN

928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
* \param wrt the name of the arguments to get gradient
 * \param out the returned symbol that has gradient
 * \return 0 when success, -1 when failure happens
 */
int MXSymbolGrad(SymbolHandle sym,
                           mx_uint num_wrt,
                           const char** in,
                           SymbolHandle* out);
/*!
 * \brief infer shape of unknown input shapes given the known one.
 *  The shapes are packed into a CSR matrix represented by arg_ind_ptr and arg_shape_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_ind_ptr the head pointer of the rows in CSR
 * \param arg_shape_data the content of the CSR
 * \param in_shape_size sizeof the returning array of in_shapes
 * \param in_shape_ndim returning array of shape dimensions of eachs input shape.
 * \param in_shape_data returning array of pointers to head of the input shape.

mxnet.i  view on Meta::CPAN

966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
                                 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 partially infer shape of unknown input shapes given the known one.
 *
 *  Return partially inferred results if not all shapes could be inferred.
 *  The shapes are packed into a CSR matrix represented by arg_ind_ptr and arg_shape_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_ind_ptr the head pointer of the rows in CSR
 * \param arg_shape_data the content of the CSR
 * \param in_shape_size sizeof the returning array of in_shapes
 * \param in_shape_ndim returning array of shape dimensions of eachs input shape.
 * \param in_shape_data returning array of pointers to head of the input shape.

mxnet.i  view on Meta::CPAN

1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
                                 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.

mxnet.i  view on Meta::CPAN

1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
*/
int MXListDataIters(mx_uint *out_size,
                              DataIterCreator **out_array);
/*!
 * \brief Init an iterator, init with parameters
 * the array size of passed in arguments
 * \param handle of the iterator creator
 * \param num_param number of parameter
 * \param keys parameter keys
 * \param vals parameter values
 * \param out resulting iterator
 * \return 0 when success, -1 when failure happens
 */
int MXDataIterCreateIter(DataIterCreator handle,
                                   mx_uint num_param,
                                   const char **keys,
                                   const char **vals,
                                   DataIterHandle *out);
/*!
 * \brief Get the detailed information about data iterator.
 * \param creator the DataIterCreator.

mxnet.i  view on Meta::CPAN

1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
* \param priority the priority of the action
 * \return 0 when success, -1 when failure happens
 */
int MXKVStorePullEx(KVStoreHandle handle,
                              mx_uint num,
                              const char** in,
                              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);
/*!

mxnet.i  view on Meta::CPAN

1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
                                             const char* cmd_body);
 
/**
 * \brief Get the number of ps dead node(s) specified by {node_id}
 *
 * \param handle handle to the KVStore
 * \param node_id Can be a node group or a single node.
 *                kScheduler = 1, kServerGroup = 2, kWorkerGroup = 4
 * \param number Ouptut number of dead nodes
 * \param timeout_sec A node fails to send heartbeart in {timeout_sec} seconds
 *                    will be presumed as 'dead'
 */
int MXKVStoreGetNumDeadNode(KVStoreHandle handle,
                                      const int node_id,
                                      int *out,
                                      const int timeout_sec = 60);
 
/**
 * \brief Create a RecordIO writer object
 * \param uri path to file
 * \param out handle pointer to the created object

mxnet_typemaps.i  view on Meta::CPAN

67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
}
 
%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)

mxnet_typemaps.i  view on Meta::CPAN

241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
%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);

mxnet_typemaps.i  view on Meta::CPAN

313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
                         (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++) {
            svs[i] = newSVnv((*$1)[i]);
            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)

mxnet_typemaps.i  view on Meta::CPAN

558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
        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,

mxnet_typemaps.i  view on Meta::CPAN

602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
}
 
%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,

mxnet_typemaps.i  view on Meta::CPAN

664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
%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)

mxnet_typemaps.i  view on Meta::CPAN

686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
            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)

mxnet_typemaps.i  view on Meta::CPAN

724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
    $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++)
        {
            tmp = newAV();
            int len = (*$2)[i];
            for (j = 0; j < len ; j++)
            {
                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)

mxnet_typemaps.i  view on Meta::CPAN

763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
    $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)

mxnet_typemaps.i  view on Meta::CPAN

795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
    $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)));
            av_push(container2, (*$3)[i] ? SvREFCNT_inc(SWIG_NewPointerObj(SWIG_as_voidptr((*$3)[i]), SWIGTYPE_p_MXNDArray, 0)) : newSV(0));
        }
        $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)
{
    HV *temphv;
    char *key;
    SV *val;
    I32 len;
    int res;
    int i = 0;
    int hash_len;
    $1 = &temp1;
    $2 = &temp2;
    $3 = &temp3;
    $4 = &temp4;
    $5 = &temp5;
    if (!SvROK($input))
    {
        *$1 = -1;

mxnet_typemaps.i  view on Meta::CPAN

881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
        croak("Argument $argnum is not a hash.");
    temphv = (HV*)SvRV($input);
    *$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;
    }
}

mxnet_typemaps.i  view on Meta::CPAN

913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
    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)
{



( run in 0.814 second using v1.01-cache-2.11-cpan-3cd7ad12f66 )