Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Nov 17, 2023. It is now read-only.
This repository was archived by the owner on Nov 17, 2023. It is now read-only.

Perl Data Language types are hardcoded and need to not be #20851

@mohawk2

Description

@mohawk2

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions