Skip to content

Commit

Permalink
fix stretcher losing the input datatype - #511
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Dec 20, 2024
1 parent 4745752 commit c9d8fcd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/PDL/MatrixOps.pd
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,15 @@ pp_addpm(<<'EOD');
=for ref
Return a diagonal matrix with the specified diagonal elements
Return a diagonal matrix with the specified diagonal elements.
Preserves higher dimensions.
As of 2.096, it will also have the same datatype.
=cut
sub stretcher {
my $in = shift;
my $out = zeroes($in->dim(0),$in->dims);
my $out = zeroes($in->type, $in->dim(0), $in->dims);
$out->diagonal(0,1) += $in;
$out;
}
Expand Down
1 change: 1 addition & 0 deletions t/matrixops.t
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ is_pdl identity(zeroes 2, 3), pdl('1 0; 0 1'), "identity matrix with dimensioned
is_pdl identity(zeroes 2, 3, 4)->shape, indx([2,2,4]), "identity matrix with multi-dimensioned ndarray";
is_pdl stretcher(pdl(2,3)), pdl('2 0;0 3'), "stretcher 2x2";
is_pdl stretcher(pdl('2 3;3 4')), pdl('[2 0;0 3][3 0;0 4]'), "stretcher 2x2x2";
is_pdl stretcher(ldouble('0.14142135623731 0.14142135623731')), ldouble('0.14142135623731 0;0 0.14142135623731'), "stretcher ldouble 2x2";
}
{
Expand Down

0 comments on commit c9d8fcd

Please sign in to comment.