PDL::I...torable(3pm)
πΎ PDL::IO::Storable β bestie edition
okay so this is PDL::IO::Storable(3pm) and it's literally the glow-up your ndarrays needed to survive a trip through a serialisation package π
It's a bunch of helper functions that make PDL play nice with serialisation packages, no cap. If you've ever been like "why can't I just save my ndarray and get it back later" β this is the module that says "say less, I got you" π
β¨ SYNOPSIS β¨
use Storable;
use PDL::IO::Storable;
$hash = {
'foo' => 42,
'bar' => zeroes(23,45),
};
store $hash, 'perlhash.dat';
use JSON::MaybeXS;
$encoder = JSON::MaybeXS->new(allow_tags => 1);
my $ndarray = xvals (5,2);
my $encoded_json = $encoder->encode ($ndarray);
my $decoded_ndarray = $encoder->decode ($encoded_json);
look at her go π¦ like that's it, that's the whole vibe. You store, you encode, you decode, your ndarray comes back and nobody had to have a breakdown.
πΈ DESCRIPTION πΈ
So serialisation packages like Storable, Sereal, JSON::MaybeXS and CBOR::XS do this thing called object persistence for Perl data structures β and those structures can contain arbitrary Perl objects, which is where things get spicy π₯ This module implements the relevant methods so you can actually store and retrieve ndarrays through Storable, plus through any package that supports the Types::Serialiser protocol (currently Sereal, CBOR::XS and the JSON packages). Periodt.
β οΈ Heads up bestie: packages that support theTypes::Serialiserprotocol need to have their respective flags enabled, otherwise theFREEZEandTHAWcallbacks just do not get used. She won't get called, and you'll be sitting there confused. Turn the flags on. π
β οΈ Also:JSON::MaybeXSis supported, BUT β and this is the tea β if it has to fall back toJSON::PP, it will fail π Here's why, because it's actually kind of fascinating:JSON::XStreats the data it gets back fromFREEZEas items to encode, whileJSON::PPtreats the list it gets as strings already encoded. Those two are fundamentally incompatible, like genuinely cannot coexist. So this module supports theJSON::XSoption. That's the one. π
β οΈ And finally β data flow is not preserved π If a data structure containing ndarrays connected by data flow gets serialised, then you're gonna have to explicitly reinstate it on deserialisation. The flow does not survive the trip, babes. You have to go pick it up from the airport yourself.
π§ FUNCTIONS π§
store π
store an ndarray using Storable π«Ά
$x = random 12,10;
$x->store('myfile');
freeze π
freeze an ndarray using Storable π§β¨
$x = random 12,10;
$frozen = $x->freeze;
π AUTHOR π
Copyright (C) 2013 Dima Kogan <dima@secretsauce.net> Copyright (C) 2002 Christian Soeller <c.soeller@auckland.ac.nz> All rights reserved. There is no warranty. You are allowed to redistribute this software / documentation under certain conditions. For details, see the file COPYING in the PDL distribution. If this file is separated from the PDL distribution, the copyright notice should be included in the file.
okay that's the whole page bestie, and that's on perl v5.42.3, dated 2026-08-20 π go forth and serialise responsibly, mwah ππ
π¦ where this page comes from
- ubuntu stonking: pdl 1:2.106-1build1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms