AI-MXNet
view release on metacpan or search on metacpan
lib/AI/MXNet/Symbol.pm view on Meta::CPAN
);
}
return @res;
}
=head2 infer_shape_partial
Partially infer the shape. The same as infer_shape, except that the partial
results can be returned.
=cut
method infer_shape_partial(Maybe[Str|Shape] @args)
{
$self->_infer_shape_impl(1, @args)
}
# The actual implementation for calling shape inference API.
method _infer_shape_impl(Maybe[Str|Shape] @args)
{
my $partial = shift(@args);
my ($positional_arguments, $kwargs, $kwargs_order) = _parse_arguments("Shape", @args);
my $sdata = [];
my $indptr = [0];
my $keys = [];
if(@{ $positional_arguments })
{
for my $shape (grep { defined } @{ $positional_arguments })
{
push @{ $sdata }, @{ $shape };
push @{ $indptr }, scalar(@{ $sdata });
}
}
{
for my $k (@{ $kwargs_order })
{
push @{ $keys }, $k;
push @{ $sdata }, @{ $kwargs->{ $k } };
push @{ $indptr }, scalar(@{ $sdata });
}
}
my $infer_func = $partial ? \&AI::MXNetCAPI::SymbolInferShapePartial : \&AI::MXNetCAPI::SymbolInferShape;
my ($arg_shapes, $out_shapes, $aux_shapes, $complete) = check_call(
$infer_func->(
$self->handle,
scalar(@{ $indptr }) - 1,
$keys,
$indptr,
$sdata,
)
);
if($complete)
{
return $arg_shapes, $out_shapes, $aux_shapes;
}
else
{
return (undef, undef, undef);
}
}
=head2 debug_str
The debug string.
Returns
-------
debug_str : string
Debug string of the symbol.
=cut
method debug_str()
{
return scalar(check_call(AI::MXNetCAPI::SymbolPrint($self->handle)));
}
=head2 save
Save the symbol into a file.
You can also use Storable to do the job if you only work with Perl.
The advantage of load/save is the file is language agnostic.
This means the file saved using save can be loaded by other language binding of mxnet.
You also get the benefit being able to directly load/save from cloud storage(S3, HDFS)
Parameters
----------
fname : str
The name of the file
- s3://my-bucket/path/my-s3-symbol
- hdfs://my-bucket/path/my-hdfs-symbol
- /path-to/my-local-symbol
See Also
--------
load : Used to load symbol from file.
=cut
method save(Str $fname)
{
check_call(AI::MXNetCAPI::SymbolSaveToFile($self->handle, $fname));
}
=head2 tojson
Save the symbol into a JSON string.
See Also
--------
load_json : Used to load symbol from JSON string.
=cut
method tojson()
{
return scalar(check_call(AI::MXNetCAPI::SymbolSaveToJSON($self->handle)));
}
method _get_ndarray_inputs(
Str $arg_key,
HashRef[AI::MXNet::NDArray]|ArrayRef[AI::MXNet::NDArray] $args,
ArrayRef[Str] $arg_names,
Bool $allow_missing=0
)
{
my ($arg_handles, $arg_arrays) = ([], []);
if(ref $args eq 'ARRAY')
{
confess("Length of $arg_key do not match number of arguments")
unless @$args == @$arg_names;
@{ $arg_handles } = map { $_->handle } @{ $args };
$arg_arrays = $args;
}
( run in 0.517 second using v1.01-cache-2.11-cpan-df04353d9ac )