From 43bc7c7815ef7a1c70d0217c536eac56be7ce6b6 Mon Sep 17 00:00:00 2001 From: Zakariyya Mughal Date: Wed, 26 Jan 2022 19:18:46 -0500 Subject: [PATCH 1/2] [Perl] Updates mapping between PDL and MX types This removes the hardcoded values and uses PDL::Type instead. Upgrades minimum PDL dependency to PDL v2.064 which provides the int8 (PDL: sbyte) type. Fix tests by allowing some PDL data alongside Perl scalars. Fixes . --- ci/docker/install/ubuntu_perl.sh | 2 +- docker/install/perl.sh | 2 +- perl-package/AI-MXNet/Changes | 4 ++ perl-package/AI-MXNet/META.json | 2 +- perl-package/AI-MXNet/META.yml | 2 +- perl-package/AI-MXNet/Makefile.PL | 4 +- perl-package/AI-MXNet/lib/AI/MXNet/Base.pm | 39 ++++++++++---------- perl-package/AI-MXNet/lib/AI/MXNet/Metric.pm | 10 ++--- 8 files changed, 35 insertions(+), 30 deletions(-) diff --git a/ci/docker/install/ubuntu_perl.sh b/ci/docker/install/ubuntu_perl.sh index 1f4a983c35af..31dc294725b8 100755 --- a/ci/docker/install/ubuntu_perl.sh +++ b/ci/docker/install/ubuntu_perl.sh @@ -24,4 +24,4 @@ set -ex # install libraries for mxnet's perl package on ubuntu apt-get update || true apt-get install -y libmouse-perl pdl cpanminus swig libgraphviz-perl -cpanm -q Function::Parameters Hash::Ordered CHM/PDL-2.019.tar.gz PDL::CCS +cpanm -q Function::Parameters Hash::Ordered PDL~2.064 PDL::CCS diff --git a/docker/install/perl.sh b/docker/install/perl.sh index 29313c7bfa6e..47f32e1209b5 100755 --- a/docker/install/perl.sh +++ b/docker/install/perl.sh @@ -19,4 +19,4 @@ # install libraries for mxnet's perl package on ubuntu apt-get update && apt-get install -y libmouse-perl pdl cpanminus swig libgraphviz-perl -cpanm -q Function::Parameters Hash::Ordered PDL::CCS +cpanm -q Function::Parameters Hash::Ordered PDL~2.064 PDL::CCS diff --git a/perl-package/AI-MXNet/Changes b/perl-package/AI-MXNet/Changes index 6807d79d088a..3d5ba8a85556 100644 --- a/perl-package/AI-MXNet/Changes +++ b/perl-package/AI-MXNet/Changes @@ -1,4 +1,8 @@ Revision history for Perl extension AI::MXNet + - Update mapping between PDL and MX types - Zakariyya Mughal + - Upgrade minimum PDL dependency to PDL v2.064 for + int8 (PDL: sbyte) type - Zakariyya Mughal + 1.5 Sun Feb 16 19:56:17 PST 2020 - Runtime features - INT64 Tensor support diff --git a/perl-package/AI-MXNet/META.json b/perl-package/AI-MXNet/META.json index 02357d478095..ed4fd68536c5 100644 --- a/perl-package/AI-MXNet/META.json +++ b/perl-package/AI-MXNet/META.json @@ -36,7 +36,7 @@ "Hash::Ordered" : "0.012", "GraphViz" : "2.14", "Mouse" : "v2.1.0", - "PDL" : "2.007", + "PDL" : "2.064", "PDL::CCS" : "1.23.4", "Archive::Tar": "0", "Digest::SHA": "0", diff --git a/perl-package/AI-MXNet/META.yml b/perl-package/AI-MXNet/META.yml index b06b331ec4ae..ee3f8a61408b 100644 --- a/perl-package/AI-MXNet/META.yml +++ b/perl-package/AI-MXNet/META.yml @@ -40,7 +40,7 @@ requires: Hash::Ordered: '0.012' GraphViz: '2.14' Mouse: v2.1.0 - PDL: '2.007' + PDL: '2.064' PDL::CCS: '1.23.4' Archive::Tar: '0' Digest::SHA: '0' diff --git a/perl-package/AI-MXNet/Makefile.PL b/perl-package/AI-MXNet/Makefile.PL index 4a9016234ad6..17cfc01396d7 100644 --- a/perl-package/AI-MXNet/Makefile.PL +++ b/perl-package/AI-MXNet/Makefile.PL @@ -41,7 +41,7 @@ my %WriteMakefileArgs = ( "Function::Parameters" => "1.0705", "Hash::Ordered" => "0.012", "Mouse" => "v2.1.0", - "PDL" => "2.007", + "PDL" => "2.064", "PDL::CCS" => "1.23.4", "GraphViz" => "2.14" }, @@ -59,7 +59,7 @@ my %FallbackPrereqs = ( "Function::Parameters" => "1.0705", "Hash::Ordered" => "0.012", "Mouse" => "v2.1.0", - "PDL" => "2.007", + "PDL" => "2.064", "PDL::CCS" => "1.23.4", "GraphViz" => "2.14" ); diff --git a/perl-package/AI-MXNet/lib/AI/MXNet/Base.pm b/perl-package/AI-MXNet/lib/AI/MXNet/Base.pm index 9ac917b57b41..d0a1aacae511 100644 --- a/perl-package/AI-MXNet/lib/AI/MXNet/Base.pm +++ b/perl-package/AI-MXNet/lib/AI/MXNet/Base.pm @@ -60,27 +60,28 @@ use constant DTYPE_MX_TO_STR => { 6 => 'int64' }; 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 + 0 => PDL::Type->new('float')->enum, + 1 => PDL::Type->new('double')->enum, + 2 => PDL::Type->new('float')->enum, + 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, + float16 => PDL::Type->new('float')->enum, + uint8 => PDL::Type->new('byte')->enum, + int32 => PDL::Type->new('long')->enum, + int8 => PDL::Type->new('sbyte')->enum, + int64 => PDL::Type->new('longlong')->enum, }; use constant DTYPE_PDL_TO_MX => { - 6 => 0, - 7 => 1, - 0 => 3, - 3 => 4, - 5 => 6 + PDL::Type->new('float')->enum => 0, + PDL::Type->new('double')->enum => 1, + PDL::Type->new('byte')->enum => 3, + PDL::Type->new('long')->enum => 4, + PDL::Type->new('sbyte')->enum => 5, + PDL::Type->new('longlong')->enum => 6, }; use constant DTYPE_MX_TO_PERL => { 0 => 'f', diff --git a/perl-package/AI-MXNet/lib/AI/MXNet/Metric.pm b/perl-package/AI-MXNet/lib/AI/MXNet/Metric.pm index cf98458d61ab..52b44507a5cc 100644 --- a/perl-package/AI-MXNet/lib/AI/MXNet/Metric.pm +++ b/perl-package/AI-MXNet/lib/AI/MXNet/Metric.pm @@ -79,7 +79,7 @@ use overload '""' => sub { has 'name' => (is => 'rw', isa => 'Str'); has 'num' => (is => 'rw', isa => 'Int'); has 'num_inst' => (is => 'rw', isa => 'Maybe[Int|ArrayRef[Int]]'); -has 'sum_metric' => (is => 'rw', isa => 'Maybe[Num|ArrayRef[Num]]'); +has 'sum_metric' => (is => 'rw', isa => 'Maybe[Num|ArrayRef[Num]|PDL]'); has '_kwargs' => (is => 'rw', init_arg => undef); around BUILDARGS => \&AI::MXNet::Base::process_arguments; @@ -168,8 +168,8 @@ method get() method get_name_value() { my ($name, $value) = $self->get; - $name = [$name] unless ref $name; - $value = [$value] unless ref $value; + $name = [$name] unless ref $name eq 'ARRAY'; + $value = [$value] unless ref $value eq 'ARRAY'; my %ret; @ret{ @$name } = @$value; return \%ret; @@ -221,8 +221,8 @@ method get() for my $metric (@{ $self->metrics }) { my ($name, $result) = $metric->get; - $name = [$name] unless ref $name; - $result = [$result] unless ref $result; + $name = [$name] unless ref $name eq 'ARRAY'; + $result = [$result] unless ref $result eq 'ARRAY'; push @$names, @$name; push @$results, @$result; } From 2d8964e99f15c3dee0daa16a9dd4145244716225 Mon Sep 17 00:00:00 2001 From: Zakariyya Mughal Date: Fri, 28 Jan 2022 15:51:25 -0500 Subject: [PATCH 2/2] [Perl] Release AI-MXNet v1.6 --- perl-package/AI-MXNet/Changes | 1 + perl-package/AI-MXNet/META.json | 2 +- perl-package/AI-MXNet/META.yml | 2 +- perl-package/AI-MXNet/Makefile.PL | 2 +- perl-package/AI-MXNet/README | 2 +- perl-package/AI-MXNet/lib/AI/MXNet.pm | 2 +- 6 files changed, 6 insertions(+), 5 deletions(-) diff --git a/perl-package/AI-MXNet/Changes b/perl-package/AI-MXNet/Changes index 3d5ba8a85556..49d5216e77c7 100644 --- a/perl-package/AI-MXNet/Changes +++ b/perl-package/AI-MXNet/Changes @@ -1,4 +1,5 @@ Revision history for Perl extension AI::MXNet +1.6 Fri Jan 28 15:50:00 EST 2022 - Update mapping between PDL and MX types - Zakariyya Mughal - Upgrade minimum PDL dependency to PDL v2.064 for int8 (PDL: sbyte) type - Zakariyya Mughal diff --git a/perl-package/AI-MXNet/META.json b/perl-package/AI-MXNet/META.json index ed4fd68536c5..4ece2200c606 100644 --- a/perl-package/AI-MXNet/META.json +++ b/perl-package/AI-MXNet/META.json @@ -51,5 +51,5 @@ } }, "release_status" : "stable", - "version" : "1.5" + "version" : "1.6" } diff --git a/perl-package/AI-MXNet/META.yml b/perl-package/AI-MXNet/META.yml index ee3f8a61408b..c79929a1a829 100644 --- a/perl-package/AI-MXNet/META.yml +++ b/perl-package/AI-MXNet/META.yml @@ -48,4 +48,4 @@ requires: IO::Zlib: '0' JSON::PP: '0' parent: '0' -version: '1.5' +version: '1.6' diff --git a/perl-package/AI-MXNet/Makefile.PL b/perl-package/AI-MXNet/Makefile.PL index 17cfc01396d7..54ce774ad836 100644 --- a/perl-package/AI-MXNet/Makefile.PL +++ b/perl-package/AI-MXNet/Makefile.PL @@ -46,7 +46,7 @@ my %WriteMakefileArgs = ( "GraphViz" => "2.14" }, "TEST_REQUIRES" => {}, - "VERSION" => "1.5", + "VERSION" => "1.6", "test" => { "TESTS" => "t/*.t" } diff --git a/perl-package/AI-MXNet/README b/perl-package/AI-MXNet/README index 57d9e4a7b7e8..d2c5b772d369 100644 --- a/perl-package/AI-MXNet/README +++ b/perl-package/AI-MXNet/README @@ -1,5 +1,5 @@ This archive contains the distribution AI-MXNet, -version 1.5: +version 1.6: Perl interface to MXNet machine learning library diff --git a/perl-package/AI-MXNet/lib/AI/MXNet.pm b/perl-package/AI-MXNet/lib/AI/MXNet.pm index 0778da8440a8..23282fd90c0b 100644 --- a/perl-package/AI-MXNet/lib/AI/MXNet.pm +++ b/perl-package/AI-MXNet/lib/AI/MXNet.pm @@ -54,7 +54,7 @@ use AI::MXNet::Gluon 'gluon'; use AI::MXNet::NDArray::Sparse; use AI::MXNet::Symbol::Sparse; use AI::MXNet::Engine 'engine'; -our $VERSION = '1.5'; +our $VERSION = '1.6'; sub cpu { AI::MXNet::Context->cpu($_[1]//0) } sub cpu_pinned { AI::MXNet::Context->cpu_pinned($_[1]//0) }