-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Perl Data Language types are hardcoded and need to not be #20851
Description
Description
@sergeykolychev This code shows hardcoded type-numbers (https://github.com/apache/incubator-mxnet/blob/v1.x/perl-package/AI-MXNet/lib/AI/MXNet/Base.pm#L62-L84):
use constant DTYPE_MX_TO_PDL => {
0 => 6,
1 => 7,
2 => 6,
3 => 0,
4 => 3,
5 => 0,
6 => 5,
float32 => 6,
float64 => 7,
float16 => 6,
uint8 => 0,
int32 => 3,
int8 => 0,
int64 => 5
};but PDL since 2.064 has changed these numbers due to an increased number of integer types, and the floating-point types needing to all be above all the integer types.
This is the same problem as #20850 which can be closed.
Error Message
Code below prints [5,0] instead of [5, 9].
To Reproduce
From PDLPorters/pdl#377:
use strict;
use warnings;
use AI::MXNet qw(mx);
use AI::MXNet qw(nd);
my $x = mx->nd->array([5, 9]);
print $x->aspdl;Steps to reproduce
Run the above Perl code.
What have you tried to solve it?
Instead the code (one way only) should be something like this in order to work on all recent-ish version of PDL (both before and after the added types, though sbyte is new and would need to be either adjusted for lower-versioned PDL, or simply a dependency on PDL 2.064 added):
use constant DTYPE_MX_TO_PDL => {
0 => PDL::Type->new('float')->enum,
1 => PDL::Type->new('double')->enum,
# half-precision is not supported by PDL and this would cause chaos
# 2 => ,
3 => PDL::Type->new('byte')->enum,
4 => PDL::Type->new('long')->enum,
5 => PDL::Type->new('sbyte')->enum,
6 => PDL::Type->new('longlong')->enum,
float32 => PDL::Type->new('float')->enum,
float64 => PDL::Type->new('double')->enum,
# half-precision is not supported by PDL and this would cause chaos
# float16 => ,
uint8 => PDL::Type->new('byte')->enum,
int32 => PDL::Type->new('long')->enum,
int8 => PDL::Type->new('sbyte')->enum,
int64 => PDL::Type->new('longlong')->enum,
};Environment
Perl 5.32, CPAN AI::MXNet 1.5, PDL 2.068.