AI-MXNet
view release on metacpan or search on metacpan
lib/AI/MXNet/Symbol/Base.pm view on Meta::CPAN
package AI::MXNet::Symbol::Base;
use strict;
use warnings;
use AI::MXNet::Base;
use AI::MXNet::Symbol::AttrScope;
use AI::MXNet::Symbol::Doc;
use AI::MXNet::Symbol::NameManager;
use Mouse;
use AI::MXNet::Function::Parameters;
=head1 NAME
AI::MXNet::Symbol::Base
=cut
=head1 DESCRIPTION
A convenience class that loads all C++m symbol related functions at runtime.
=cut
my %function_meta;
method function_meta($code)
{
return $function_meta{$code};
}
method function_meta_hash()
{
return \%function_meta;
}
sub _compose
{
my $self = shift;
my (@args, %kwargs);
while(ref $_[0])
{
push @args, shift(@_);
}
%kwargs = @_;
my $name = delete $kwargs{'name'};
if(@args and %kwargs)
{
confess("_compose only accept input Symbols \
either as positional or keyword arguments, not both");
}
if(grep { not blessed($_) or not $_->isa(__PACKAGE__) } (@args, values %kwargs))
{
confess("_compose expect 'Symbol' as arguments");
}
my $num_args = scalar(@args) + scalar(keys %kwargs);
my $keys = [];
my $args = [];
for my $key (keys %kwargs)
{
push @$keys, $key;
push @$args, $kwargs{ $key }->handle;
}
@$args = map { $_->handle } @args if @args;
check_call(
AI::NNVMCAPI::SymbolCompose(
$self->handle, $name, $num_args, $keys, $args
)
);
}
# Create an atomic symbol function by handle and funciton name
func _make_atomic_symbol_function($handle, $name)
{
my ($real_name, $desc, $arg_names,
$arg_types, $arg_descs, $key_var_num_args,
$ret_type) = @{ check_call(AI::MXNetCAPI::SymbolGetAtomicSymbolInfo($handle)) };
$ret_type //= '';
my $func_name = $name;
my $doc_str = build_doc($func_name,
$desc,
$arg_names,
$arg_types,
$arg_descs,
$key_var_num_args,
$ret_type
);
my $creator = sub {
my $class = shift;
my (@args, %kwargs);
if(
@_
and
ref $_[-1] eq 'HASH'
and
not (@_ >= 2 and not blessed $_[-2] and $_[-2] eq 'attr')
)
{
%kwargs = %{ pop(@_) };
@args = @_;
}
elsif(blessed $_[0] and $_[0]->isa(__PACKAGE__))
{
while(blessed $_[0] and $_[0]->isa(__PACKAGE__))
{
push @args, shift(@_);
}
%kwargs = @_;
}
else
{
%kwargs = @_;
}
my $params = {};
my $symbol_kwargs = {};
my $attr = delete $kwargs{ 'attr' };
%kwargs = (%kwargs, % { AI::MXNet::Symbol::AttrScope->current->get($attr) });
$name = delete $kwargs{ 'name' };
if($key_var_num_args and not exists $kwargs { $key_var_num_args })
{
$params->{ $key_var_num_args } = scalar(@args);
}
for my $key (keys %kwargs)
{
( run in 0.916 second using v1.01-cache-2.11-cpan-39bf76dae61 )