MXNet/Symbol/Random.pm untested

filter: Statementstmt 0.0% 0 / 30 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 62 CC 7 SCAR 36.8
CC
7
Cov
0%
AUTOLOAD
56.0
BEGIN
2.0
BEGIN
2.0
CRAP 39.8
1 # Licensed to the Apache Software Foundation (ASF) under one
2 # or more contributor license agreements. See the NOTICE file
3 # distributed with this work for additional information
4 # regarding copyright ownership. The ASF licenses this file
5 # to you under the Apache License, Version 2.0 (the
6 # "License"); you may not use this file except in compliance
7 # with the License. You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing,
12 # software distributed under the License is distributed on an
13 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 # KIND, either express or implied. See the License for the
15 # specific language governing permissions and limitations
16 # under the License.
17  
18 package AI::MXNet::Symbol::Random;
19 use strict;
20 use warnings;
21 use Scalar::Util qw/blessed/;
22  
23 sub AUTOLOAD {
24 my $sub = $AI::MXNet::Symbol::Random::AUTOLOAD;
25 $sub =~ s/.*:://;
26 shift;
27 my @args = @_;
28 if($sub eq 'exponential')
29 {
30 my $changed = 0;
31 for my $i (0..@args-1)
32 {
33 if(not ref $args[$i] and $args[$i] eq 'scale')
34 {
35 $args[$i] = 'lam';
36 $args[$i+1] = 1/$args[$i+1];
37 $changed = 1;
38 }
39 }
40 $args[0] = 1/$args[0] unless $changed;
41 }
42 if(grep { blessed($_) and $_->isa('AI::MXNet::Symbol') } @args)
43 {
44 if($sub eq 'normal')
45 {
46 my %mapping = qw/loc mu scale sigma/;
47 @args = map { (not ref $_ and exists $mapping{$_}) ? $mapping{$_} : $_ } @args
48 }
49 $sub = "_sample_$sub";
50 }
51 else
52 {
53 $sub = "_random_$sub";
54 }
55 return AI::MXNet::Symbol->$sub(@args);
56 }
57  
58 1;