diff --git a/lib/PDL/MatrixOps.pd b/lib/PDL/MatrixOps.pd index 464ea0fbe..337159d88 100644 --- a/lib/PDL/MatrixOps.pd +++ b/lib/PDL/MatrixOps.pd @@ -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; } diff --git a/t/matrixops.t b/t/matrixops.t index d43efc022..94b2f9cc1 100644 --- a/t/matrixops.t +++ b/t/matrixops.t @@ -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"; } {