From 6972a9f945b57851178a014ae4382d229bf5ab8b Mon Sep 17 00:00:00 2001 From: Bryan Jurish Date: Fri, 20 Dec 2024 16:36:34 +0100 Subject: [PATCH] fix 'Runtime error: Tried to convert(null)' when multiplying all-missing CCS::Nd --- CCS/Nd.pm | 6 +++--- CCS/t/06_matops.t | 5 +++++ testme.perl | 17 ++++++++++++++++- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/CCS/Nd.pm b/CCS/Nd.pm index cf877c4..7555a57 100644 --- a/CCS/Nd.pm +++ b/CCS/Nd.pm @@ -164,7 +164,7 @@ sub fromWhich :lvalue { if (!$opts{steal}) { ##-- not stolen: copy or sever if (!$opts{sorted}) { - my $wi = $wnd->isempty ? PDL->null->ccs_indx() : $wnd->vv_qsortveci; + my $wi = $wnd->qsortveci; $wnd = $wnd->dice_axis(1,$wi); $nzvals = $nzvals->index($wi); } @@ -1407,7 +1407,7 @@ sub _ccsnd_binary_op_mia { $avalsr = $avals; } else { $ixar = $ixa->dice_axis(0,$ra); - my $ixar_sorti = $ixar->isempty ? PDL->null->ccs_indx() : $ixar->vv_qsortveci; + my $ixar_sorti = $ixar->qsortveci; $ixa = $ixa->dice_axis(1,$ixar_sorti); $ixar = $ixar->dice_axis(1,$ixar_sorti); $avalsr = $avals->index($ixar_sorti); @@ -1428,7 +1428,7 @@ sub _ccsnd_binary_op_mia { $bvalsr = $bvals; } else { $ixbr = $ixb->dice_axis(0,$rb); - my $ixbr_sorti = $ixbr->isempty ? PDL->null->ccs_indx() : $ixbr->vv_qsortveci; + my $ixbr_sorti = $ixbr->qsortveci; $ixb = $ixb->dice_axis(1,$ixbr_sorti); $ixbr = $ixbr->dice_axis(1,$ixbr_sorti); $bvalsr = $bvals->index($ixbr_sorti); diff --git a/CCS/t/06_matops.t b/CCS/t/06_matops.t index 2e88d0d..472be7d 100644 --- a/CCS/t/06_matops.t +++ b/CCS/t/06_matops.t @@ -245,5 +245,10 @@ my $m = identity(3)->set(2,2,0); # [[1,0,0],[0,1,0],[0,0,0]] my $v = zeroes(1,3)->set(0,2,1); # [[0],[0],[1]] pdlok('matmult with empty row', ($m->toccs x $v)->decode, ($m x $v)); +##-- no more type conversion support for null PDLs -- https://github.com/moocow-the-bovine/PDL-CCS/issues/14#issuecomment-2556862635 +my $u = zeroes(1, 3); +my $z = ones(1, 3); +pdlok('u*z all missing', ($u->toccs * $z->toccs)->decode, ($u * $z)); +pdlok('z*u all missing', ($z->toccs * $u->toccs)->decode, ($z * $u)); done_testing; diff --git a/testme.perl b/testme.perl index 3fe017a..62b7eb5 100755 --- a/testme.perl +++ b/testme.perl @@ -922,7 +922,22 @@ sub test_matmult_gh14 { print STDERR "what now?\n" } -test_matmult_gh14(); +#test_matmult_gh14(); + +##--------------------------------------------------------------------- +## test_matmult_gh14 +## + debug https://github.com/moocow-the-bovine/PDL-CCS/issues/14#issuecomment-2556862635 +sub test_matmult_gh14b { + my $u = zeroes(1, 3); + my $v = ones(1, 3); + + my ($uc, $vc) = ($u->toccs, $v->toccs); + my $uvc = $uc * $vc; # Tried to convert(null) at /usr/lib/x86_64-linux-gnu/perl5/5.36/PDL/Core.pm line 2722. + pdlok('empty mult', $uvc->decode, ($u * $v)); + + print STDERR "what now?\n" +} +test_matmult_gh14b(); ##--------------------------------------------------------------------- ## DUMMY