Skip to content

Commit

Permalink
reduce allocating big zeroes ndarray in mapflex - #501
Browse files Browse the repository at this point in the history
  • Loading branch information
vitstradal authored and mohawk2 committed Oct 9, 2024
1 parent 2f0d069 commit 72d707b
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions IO/FlexRaw/FlexRaw.pm
Original file line number Diff line number Diff line change
Expand Up @@ -598,9 +598,7 @@ sub mapflex {
} else {
barf "Bad typename '$type' in mapflex" if !defined $flextypes{$type};
$type = $flextypes{$type};
my $si = 1;
$si *= $_ for ref $hdr->{Dims} ? @{$hdr->{Dims}} : $hdr->{Dims};
$size += $si * PDL::Core::howbig ($type);
$size += _data_size_in_bytes($type, $hdr->{Dims});
}
}
# $s now contains estimated size of data in header --
Expand Down Expand Up @@ -671,6 +669,13 @@ sub mapflex {
wantarray ? @out : $out[0];
}

sub _data_size_in_bytes {
my ($type, $dims) = @_;
my $si = 1;
$si *= $_ for ref $dims ? @$dims : $dims;
$si * PDL::Core::howbig($type);
}

=head2 writeflex
=for ref
Expand Down

0 comments on commit 72d707b

Please sign in to comment.