Skip to content

Commit

Permalink
provide access to default info format
Browse files Browse the repository at this point in the history
  • Loading branch information
jo-37 committed Aug 15, 2024
1 parent d338127 commit e38d133
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
15 changes: 14 additions & 1 deletion Basic/Core/Core.pm
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ $PDL::doubleformat = "%10.8g";
$PDL::indxformat = "%12d"; # Default print format for PDL_Indx values
$PDL::undefval = 0; # Value to use instead of undef when creating PDLs
$PDL::toolongtoprint = 10000; # maximum pdl size to stringify for printing
$PDL::infoformat = "%C: %T %D";

################ Exportable functions of the Core ######################

Expand Down Expand Up @@ -249,6 +250,16 @@ respectively. The default default values are:
=back
=head3 C<$PDL::infoformat>
=over 4
The default format for C<info>. The default value is:
$PDL::infoformat = "%C: %T %D";
=back
=head3 C<$PDL::undefval>
=over 4
Expand Down Expand Up @@ -2116,11 +2127,13 @@ Calculated memory consumption of this ndarray's data area
=back
The default format is C<"%C: %T %D">.
This can be modified by assigning to C<$PDL::infoformat>.
=cut

sub PDL::info {
my ($this,$str) = @_;
$str = "%C: %T %D" unless defined $str;
$str = $PDL::infoformat unless defined $str;
return ref($this)."->null" if $this->isnull;
my @hash = split /(%[-,0-9]*[.]?[0-9]*\w)/, $str;
my @args = ();
Expand Down
6 changes: 6 additions & 0 deletions t/core.t
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,12 @@ my $mt_info = $empty->info;
$mt_info =~m/\[([\d,]+)\]/;
my $mt_info_dims = pdl("$1");
ok(any($mt_info_dims==0), "empty ndarray's info contains a 0 dimension");
{
is($PDL::infoformat, "%C: %T %D", "check default info format");
local $PDL::infoformat = "default info format for %C";
is(pdl(2, 3)->info, "default info format for PDL",
"use default info format");
}
ok($null->isnull, "a null ndarray is null");
ok($null->isempty, "a null ndarray is empty") or diag $null->info;
ok(!$empty->isnull, "an empty ndarray is not null");
Expand Down

0 comments on commit e38d133

Please sign in to comment.