AI-NNVMCAPI
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
Revision history for Perl extension AI::NNVMCAPI.
1.4 Sun Feb 16 19:56:17 PST 2020
- use strict
1.3 Tue Jun 26 20:57:40 PDT 2018
- Major update, Gluon interface updated to parity with Python's API
1.2 Sun Mar 4 16:29:19 PST 2018
- Support for sparse tensors
1.1 Sun Sep 24 10:26:54 PDT 2017
- support for perl 5.14
1.01 Sat Jun 10 23:57:27 PDT 2017
- sync with python.
0.95 Sun Mar 26 17:42:02 PDT 2017
- visible on https://mxnet.io
0.03 Sat Feb 25 13:21:07 PST 2017
- sync up with the Python interface.
0.02 Tue Feb 14 07:28:11 PST 2017
- prepared for inclusion to the mxnet code repository.
0.01 Fri Jan 6 19:40:53 2017
- original version
Changes
Makefile.PL
MANIFEST
META.json
META.yml
README
t/AI-NNVMCAPI.t
lib/AI/NNVMCAPI.pm
nnvm.i
nnvm_typemaps.i
{
"abstract" : "Swig interface to nnvm c api",
"author" : [
"Sergey Kolychev <sergeykolychev.github@gmail.com>"
],
"dynamic_config" : 0,
"generated_by" : "ExtUtils::MakeMaker version 7.24, CPAN::Meta::Converter version 2.143240",
"license" : [
"apache_2_0"
],
"meta-spec" : {
"url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
"version" : "2"
},
"name" : "AI-NNVMCAPI",
"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.4"
}
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
---
abstract: 'Swig interface to nnvm 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:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
version: '1.4'
name: AI-NNVMCAPI
no_index:
directory:
- t
- inc
requires:
Test::More: '0'
version: '1.4'
Makefile.PL view on Meta::CPAN
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
use ExtUtils::MakeMaker;
`swig -noproxy -c++ -perl nnvm.i`;
unlink "NNVMCAPI.pm";
my @tmp = split(/ /, $ExtUtils::MakeMaker::Config{lddlflags});
my @lddlflags;
while(my $flag = shift(@tmp))
{
if($flag eq '-arch')
{
my $arch = shift(@tmp);
if($arch eq 'i386')
{
next;
}
else
{
push @lddlflags, ($flag, $arch);
}
}
else
{
push @lddlflags, $flag;
}
}
WriteMakefile(
NAME => 'AI::NNVMCAPI',
LICENSE => 'apache_2_0',
AUTHOR => 'Sergey Kolychev <sergeykolychev.github@gmail.com>',
VERSION_FROM => 'lib/AI/NNVMCAPI.pm',
ABSTRACT_FROM => 'lib/AI/NNVMCAPI.pm',
LIBS => ['-L../../lib -lmxnet'],
INC => '-I../../3rdparty/tvm/nnvm/include/nnvm',
OBJECT => 'nnvm_wrap.o',
LDDLFLAGS => join(' ', @lddlflags),
PREREQ_PM => {
# prereqs
# build/test prereqs
'Test::More' => 0,
},
PL_FILES => {},
);
AI-NNVMCAPI version 1.4
=====================
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 https://mxnet.io
It's used by AI::MXNet.
COPYRIGHT AND LICENCE
This library is licensed under Apache 2.0 license https://www.apache.org/licenses/LICENSE-2.0
lib/AI/NNVMCAPI.pm view on Meta::CPAN
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
package AI::NNVMCAPI;
use strict;
use base qw(DynaLoader);
bootstrap AI::NNVMCAPI;
our $VERSION = '1.4';
1;
__END__
=head1 NAME
AI::NNVMCAPI - Swig interface to nnvm c api
=head1 SYNOPSIS
use AI::NNVMCAPI;
=head1 DESCRIPTION
This module provides interface to nnvm
via its api.
=head1 SEE ALSO
L<AI::MXNet>
=head1 AUTHOR
Sergey Kolychev, <sergeykolychev.github@gmail.com>
=head1 COPYRIGHT & LICENSE
This library is licensed under Apache 2.0 license.
See https://www.apache.org/licenses/LICENSE-2.0 for more information.
=cut
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
%module "AI::NNVMCAPI"
%include typemaps.i
%rename("%(strip:[NN])s") "";
%init %{
/* These SWIG_TypeClientData() calls might break in the future, but
* %rename should work on these types before that happens. */
SWIG_TypeClientData(SWIGTYPE_p_NNOp, (void *)"OpHandle");
SWIG_TypeClientData(SWIGTYPE_p_NNSymbol, (void *)"SymbolHandle");
SWIG_TypeClientData(SWIGTYPE_p_NNGraph, (void *)"GraphHandle");
%}
%inline %{
#include <c_api.h>
%}
%include nnvm_typemaps.i
/*! \brief manually define unsigned int */
typedef unsigned int nn_uint;
/*! \brief handle to a function that takes param and creates symbol */
typedef NNOp *OpHandle;
/*! \brief handle to a symbol that can be bind as operator */
typedef NNSymbol *SymbolHandle;
/*! \brief handle to Graph */
typedef NNGraph *GraphHandle;
/*!
* \brief Set the last error message needed by C API
* \param msg The error message to set.
*/
void NNAPISetLastError(const char* msg);
/*!
* \brief return str message of the last error
* all function in this file will return 0 when success
* and -1 when an error occured,
* NNGetLastError can be called to retrieve the error
*
* this function is threadsafe and can be called by different thread
* \return error info
*/
const char *NNGetLastError(void);
/*!
* \brief list all the available operator names, include entries.
* \param out_size the size of returned array
* \param out_array the output operator name array.
* \return 0 when success, -1 when failure happens
*/
int NNListAllOpNames(nn_uint *out_size, const char*** out_array);
/*!
* \brief Get operator handle given name.
* \param op_name The name of the operator.
* \param op_out The returnning op handle.
*/
int NNGetOpHandle(const char* op_name,
OpHandle* out);
/*!
* \brief list all the available operators.
* This won't include the alias, use ListAllNames
* instead to get all alias names.
*
* \param out_size the size of returned array
* \param out_array the output AtomicSymbolCreator array
* \return 0 when success, -1 when failure happens
*/
int NNListUniqueOps(nn_uint *out_size,
OpHandle **out_array);
/*!
* \brief Get the detailed information about atomic symbol.
* \param op The operator handle.
* \param real_name The returned name of the creator.
* This name is not the alias name of the atomic symbol.
* \param description The returned description of the symbol.
* \param num_doc_args Number of arguments that contain documents.
* \param arg_names Name of the arguments of doc args
* \param arg_type_infos Type informations about the arguments.
* \param arg_descriptions Description information about the arguments.
* \param return_type Return type of the function, if any.
* \return 0 when success, -1 when failure happens
*/
int NNGetOpInfo(OpHandle op,
const char **real_name,
const char **description,
nn_uint *num_doc_args,
const char ***arg_names,
const char ***arg_type_infos,
const char ***arg_descriptions,
const char **return_type);
/*!
* \brief Create an AtomicSymbol functor.
* \param op The operator handle
* \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
* \return 0 when success, -1 when failure happens
*/
int NNSymbolCreateAtomicSymbol(OpHandle op,
nn_uint num_param,
const char **keys,
const char **vals,
SymbolHandle *out);
/*!
* \brief Create a Variable Symbol.
* \param name name of the variable
* \param out pointer to the created symbol handle
* \return 0 when success, -1 when failure happens
*/
int NNSymbolCreateVariable(const char *name, SymbolHandle *out);
/*!
* \brief Create a Symbol by grouping list of symbols together
* \param num_symbols number of symbols to be grouped
* \param symbols array of symbol handles
* \param out pointer to the created symbol handle
* \return 0 when success, -1 when failure happens
*/
int NNSymbolCreateGroup(nn_uint num_symbols,
SymbolHandle *in,
SymbolHandle *out);
/*!
* \brief Add src_dep to the handle as control dep.
* \param handle The symbol to add dependency edges on.
* \param src_dep the source handles.
*/
int NNAddControlDeps(SymbolHandle in,
SymbolHandle in);
/*!
* \brief Free the symbol handle.
* \param symbol the symbol
* \return 0 when success, -1 when failure happens
*/
int NNSymbolFree(SymbolHandle in);
/*!
* \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 NNSymbolCopy(SymbolHandle in, 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 NNSymbolPrint(SymbolHandle in, const char **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 NNSymbolGetAttr(SymbolHandle in,
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.
*
* Safe recommendaton: use immutable graph
* - Only allow set attributes during creation of new symbol as optional parameter
*
* Mutable graph (be careful about the semantics):
* - Allow set attr at any point.
* - Mutating an attribute of some common node of two graphs can cause confusion from user.
*
* \param symbol the source symbol
* \param num_param Number of parameters to set.
* \param keys The keys of the attribute
* \param values The value to be set
* \return 0 when success, -1 when failure happens
*/
int NNSymbolSetAttrs(SymbolHandle in,
nn_uint num_param,
const char** keys,
const char** vals);
/*!
* \brief Get all attributes from symbol, including all descendents.
* \param symbol the source symbol
* \param recursive_option 0 for recursive, 1 for shallow.
* \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 NNSymbolListAttrs(SymbolHandle in,
int recursive_option,
nn_uint *half_of_out_size,
const char*** out_array);
/*!
* \brief List inputs variables in the symbol.
* \param symbol the symbol
* \param option The option to list the inputs
* option=0 means list all arguments.
* option=1 means list arguments that are readed only by the graph.
* option=2 means list arguments that are mutated by the graph.
* \param out_size output size
* \param out_sym_array the output array.
* \return 0 when success, -1 when failure happens
*/
int NNSymbolListInputVariables(SymbolHandle in,
int option,
nn_uint *out_size,
SymbolHandle** out_array);
/*!
* \brief List input names in the symbol.
* \param symbol the symbol
* \param option The option to list the inputs
* option=0 means list all arguments.
* option=1 means list arguments that are readed only by the graph.
* option=2 means list arguments that are mutated by the graph.
* \param out_size output size
* \param out_str_array pointer to hold the output string array
* \return 0 when success, -1 when failure happens
*/
int NNSymbolListInputNames(SymbolHandle in,
int option,
nn_uint *out_size,
const char ***out_array);
/*!
* \brief List returns names in the symbol.
* \param symbol the symbol
* \param out_size output size
* \param out_str_array pointer to hold the output string array
* \return 0 when success, -1 when failure happens
*/
int NNSymbolListOutputNames(SymbolHandle in,
nn_uint *out_size,
const char ***out_array);
/*!
* \brief Get a symbol that contains all the internals.
* \param symbol The symbol
* \param out The output symbol whose outputs are all the internals.
* \return 0 when success, -1 when failure happens
*/
int NNSymbolGetInternals(SymbolHandle in,
SymbolHandle *out);
/*!
* \brief Get index-th outputs of the symbol.
* \param symbol The symbol
* \param index the Index of the output.
* \param out The output symbol whose outputs are the index-th symbol.
* \return 0 when success, -1 when failure happens
*/
int NNSymbolGetOutput(SymbolHandle in,
nn_uint index,
SymbolHandle *out);
/*!
* \brief Compose the symbol on other symbols.
*
* This function will change the sym hanlde.
* To achieve function apply behavior, copy the symbol first
* before apply.
*
* \param sym the symbol to apply
* \param name the name of symbol
* \param num_args number of arguments
* \param keys the key of keyword args (optional)
* \param symbols arguments to sym
* \return 0 when success, -1 when failure happens
*/
int NNSymbolCompose(SymbolHandle in,
const char* name,
nn_uint num_args,
const char** in,
SymbolHandle* in);
// Graph IR API
/*!
* \brief create a graph handle from symbol
* \param symbol The symbol representing the graph.
* \param graph The graph handle created.
* \return 0 when success, -1 when failure happens
*/
int NNGraphCreate(SymbolHandle in, GraphHandle *out);
/*!
* \brief free the graph handle
* \param handle The handle to be freed.
*/
int NNGraphFree(GraphHandle handle);
/*!
* \brief Get a new symbol from the graph.
* \param graph The graph handle.
* \param symbol The corresponding symbol
* \return 0 when success, -1 when failure happens
*/
int NNGraphGetSymbol(GraphHandle graph, SymbolHandle *out);
/*!
* \brief Get Set a attribute in json format.
* This feature allows pass graph attributes back and forth in reasonable speed.
*
* \param handle The graph handle.
* \param key The key to the attribute.
* \param json_value The value need to be in format [type_name, value],
* Where type_name is a registered type string in C++ side via DMLC_JSON_ENABLE_ANY.
* \return 0 when success, -1 when failure happens
*/
int NNGraphSetJSONAttr(GraphHandle handle,
const char* key,
const char* json_value);
/*!
* \brief Get a serialized attrirbute from graph.
* This feature allows pass graph attributes back and forth in reasonable speed.
*
* \param handle The graph handle.
* \param key The key to the attribute.
* \param json_out The result attribute, can be NULL if the attribute do not exist.
* The json_out is an array of [type_name, value].
* Where the type_name is a registered type string in C++ side via DMLC_JSON_ENABLE_ANY.
* \param success Whether the result is contained in out.
* \return 0 when success, -1 when failure happens
*/
int NNGraphGetJSONAttr(SymbolHandle in,
const char* key,
const char** out,
int *out);
/*!
* \brief Set a attribute whose type is std::vector<NodeEntry> in c++
* This feature allows pass List of symbolic variables for gradient request.
*
* \note This is beta feature only used for test purpos
*
* \param handle The graph handle.
* \param key The key to the attribute.
* \param list The symbol whose outputs represents the list of NodeEntry to be passed.
* \return 0 when success, -1 when failure happens
*/
int NNGraphSetNodeEntryListAttr_(GraphHandle handle,
const char* key,
SymbolHandle in);
/*!
* \brief Apply passes on the src graph.
* \param src The source graph handle.
* \param num_pass The number of pass to be applied.
* \param pass_names The names of the pass.
* \param dst The result graph.
* \return 0 when success, -1 when failure happens
*/
int NNGraphApplyPasses(GraphHandle src,
nn_uint num_pass,
const char** in,
GraphHandle *out);
nnvm_typemaps.i view on Meta::CPAN
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
%typemap(in) (const char** in), (char** in)
{
AV *tempav;
I32 len;
int i;
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_len(tempav) + 1;
if(len!=0)
{
$1 = (char **) safemalloc((len)*sizeof(char *));
for (i = 0; i < len; i++) {
tv = av_fetch(tempav, i, 0);
$1[i] = (char *) SvPV_nolen(*tv);
}
}
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;
int hash_len;
int i = 0;
if (!SvROK($input))
croak("Argument $argnum is not a reference.");
if (SvTYPE(SvRV($input)) != SVt_PVHV)
croak("Argument $argnum is not a hash.");
temphv = (HV*)SvRV($input);
hash_len = hv_iterinit(temphv);
if(hash_len)
{
$1 = (char **)safemalloc(hash_len*sizeof(char *));
$2 = (char **)safemalloc(hash_len*sizeof(char *));
while ((val = hv_iternextsv(temphv, &key, &len)))
{
$1[i] = key;
$2[i] = SvPV_nolen(val);
++i;
}
}
}
%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)
{
$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)
{
$1 = &temp;
*$1 = 0;
}
%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;
*$1 = 0;
$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) (nn_uint *half_of_out_size, const char ***out_array) (nn_uint temp_size, char **temp)
{
$1 = &temp_size;
*$1 = 0;
$2 = &temp;
}
%typemap(argout) (nn_uint *half_of_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)*2 ; 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) (SymbolHandle *in)
{
AV *tempav;
int i;
SV **tv;
int res;
int 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);
len = av_len(tempav) + 1;
if(len)
{
$1 = ($1_type)safemalloc(len*sizeof($*1_type));
for (i = 0; i < len; i++) {
tv = av_fetch(tempav, i, 0);
res = SWIG_ConvertPtr(*tv,SWIG_as_voidptrptr(&$1[i]), 0, 0);
if (!SWIG_IsOK(res)) {
SWIG_exception_fail(SWIG_ArgError(res), "in method '" "$symname" "', argument " "$argnum"" of type '" "$*1_type""'");
}
}
}
}
%typemap(freearg) (SymbolHandle *in) {
Safefree($1);
}
%typemap(in,numinputs=0) (const char **real_name,
const char **description,
nn_uint *num_doc_args,
const char ***arg_names,
const char ***arg_type_infos,
const char ***arg_descriptions,
const char **return_type
)
(char *name_temp,
char *desc_temp,
nn_uint num_args_temp,
char **names_temp,
char **types_temp,
char **descs_temp,
char *return_temp
)
{
$1 = &name_temp;
$2 = &desc_temp;
$3 = &num_args_temp;
$4 = &names_temp;
$5 = &types_temp;
$6 = &descs_temp;
$7 = &return_temp;
}
%typemap(argout) (const char **real_name,
const char **description,
nn_uint *num_doc_args,
const char ***arg_names,
const char ***arg_type_infos,
const char ***arg_descriptions,
const char **return_type
)
{
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) (OpHandle *out) (OpHandle temp),
(SymbolHandle *out) (SymbolHandle temp),
(GraphHandle *out) (GraphHandle temp)
{
$1 = &temp;
}
%typemap(argout) (OpHandle *out)
{
if(!result)
{
$result = SWIG_NewPointerObj(SWIG_as_voidptr(*$1), $*1_descriptor, 0); argvi++;
}
}
%typemap(argout) (SymbolHandle *out), (GraphHandle *out)
{
if(!result)
{
$result = SWIG_NewPointerObj(SWIG_as_voidptr(*$1), $*1_descriptor, 0); argvi++;
}
}
%typemap(in,numinputs=0) (nn_uint *out_size, OpHandle** out_array) (nn_uint temp_num, OpHandle* temp)
{
$1 = &temp_num;
*$1 = 0;
$2 = &temp;
}
%typemap(argout) (nn_uint *out_size, OpHandle** 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_NNOp, 0);
}
myav = av_make(*$1,svs);
Safefree(svs);
$result = newRV_noinc((SV*)myav);
sv_2mortal($result);
argvi++;
}
}
%typemap(in,numinputs=0) (nn_uint *out_size, SymbolHandle** out_array) (nn_uint temp_num, SymbolHandle* temp)
{
$1 = &temp_num;
*$1 = 0;
$2 = &temp;
}
%typemap(argout) (nn_uint *out_size, SymbolHandle** 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_NNSymbol, 0);
}
myav = av_make(*$1,svs);
Safefree(svs);
$result = newRV_noinc((SV*)myav);
sv_2mortal($result);
argvi++;
}
}
%typemap(in) (SymbolHandle 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 '" "SymbolHandle""'");
}
}
t/AI-NNVMCAPI.t view on Meta::CPAN
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
use strict;
use warnings;
use Test::More tests => 1;
BEGIN { use_ok('AI::NNVMCAPI') };
view all matches for this distributionview release on metacpan - search on metacpan
( run in 2.752 seconds using v1.00-cache-2.02-grep-82fe00e-cpan-cec75d87357c )