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 the Types::Serialiser protocol need to have their respective flags enabled, otherwise the FREEZE and THAW callbacks just do not get used. She won't get called, and you'll be sitting there confused. Turn the flags on. πŸ™ˆ
⚠️ Also: JSON::MaybeXS is supported, BUT β€” and this is the tea β€” if it has to fall back to JSON::PP, it will fail πŸ’€ Here's why, because it's actually kind of fascinating: JSON::XS treats the data it gets back from FREEZE as items to encode, while JSON::PP treats the list it gets as strings already encoded. Those two are fundamentally incompatible, like genuinely cannot coexist. So this module supports the JSON::XS option. 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