From a4a687a71e28fcc87a53a52352c3b96c014b43d2 Mon Sep 17 00:00:00 2001 From: Ed J Date: Mon, 2 Dec 2024 06:44:20 +0000 Subject: [PATCH] pdl() to only get_dataref/upd_data for non-zero values --- Basic/lib/PDL/Core.pm | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Basic/lib/PDL/Core.pm b/Basic/lib/PDL/Core.pm index b5d8324fe..b708a8554 100644 --- a/Basic/lib/PDL/Core.pm +++ b/Basic/lib/PDL/Core.pm @@ -1210,8 +1210,12 @@ sub PDL::new { set_c($new, [0], $value); } else { $new->setdims([]); - ${$new->get_dataref} = pack( $pack[$new->get_datatype], $value ); - $new->upd_data; + if ($value) { + ${$new->get_dataref} = pack( $pack[$new->get_datatype], $value ); + $new->upd_data; + } else { # do nothing if 0 - allocdata already memsets to 0 + $new->make_physical; + } } } elsif (blessed($value)) { # Object