Skip to content

Commit

Permalink
fix 'Runtime error: Tried to convert(null)' when multiplying all-miss…
Browse files Browse the repository at this point in the history
…ing CCS::Nd
  • Loading branch information
moocow-the-bovine committed Dec 20, 2024
1 parent 017d1c9 commit 6972a9f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
6 changes: 3 additions & 3 deletions CCS/Nd.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions CCS/t/06_matops.t
Original file line number Diff line number Diff line change
Expand Up @@ -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;
17 changes: 16 additions & 1 deletion testme.perl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6972a9f

Please sign in to comment.