LDAC(3pm)

πŸ“¦
version 1.24.1 Β· 5 versions
, in debian trixie, ubuntu resolute

✨ NAME ✨

PDL::CCS::IO::LDAC β€” LDA-C format text I/O for PDL::CCS::Nd

ok so bestie, you've landed on the LDAC(3pm) page, which lives in the User Contributed Perl Documentation section of the manual. it's giving "sparse matrix girlies, this one's for you" πŸ’… if you've got a PDL::CCS::Nd object and you wanna yeet it to/from LDA-C text files, you are SO in the right place.


πŸŽ€ SYNOPSIS πŸŽ€

use PDL;
use PDL::CCS::Nd;
use PDL::CCS::IO::LDAC;

##-- (Document x Term) matrix
$dtm = PDL::CCS::Nd->newFromWhich($which,$nzvals);

ccs_writeldac($dtm,"dtm.ldac");   # write a sparse LDA-C text file
$dtm2 = ccs_readldac("dtm.ldac"); # read a sparse LDA-C text file

###-- (Term x Document) matrix in document-primary format
$tdm = $dtm->xchg(0,1)->make_physically_indexed();

ccs_writeldac($tdm,"tdm.ldac",   {transpose=>1});
$dtm2 = ccs_readldac("tdm.ldac", {transpose=>1});

like, look at her. write, read, and if your matrix is vibing in the other orientation, just transpose=>1 and move on. no cap. πŸ”₯


πŸ¦‹ I/O Utilities πŸ¦‹

ccs_writeldac

write a 2d PDL::CCS::Nd (Document x Term) matrix out as an LDA-C text file. that's the whole assignment, bestie.

now here's the ✨plot twist✨: if the transpose option is specified and true, your input matrix $ccs gets treated as a (Term x Document) matrix, and the output lines correspond to logical dimension 1 of $ccs. otherwise? output lines correspond to logical dimension 0 of $ccs, which is expected to be a (Document x Term) matrix. so like, know which way your matrix is facing before you commit, fr fr 🫢

ccs_writeldac($ccs,$filename_or_fh)
ccs_writeldac($ccs,$filename_or_fh,\%opts)

Options %opts:

header => $bool,     ##-- do/don't write a header to the output file (default=do)
transpose => $bool,  ##-- treat input $ccs as (Term x Document) matrix (default=don't)
  • header => $bool β€” do you want a header written to the output file or not? default is do (write that header, queen) πŸ‘‘
  • transpose => $bool β€” treat the input $ccs as a (Term x Document) matrix. default is don't. no transposing unless you ask for it 🌸

ccs_readldac

read a 2d (Document x Term) matrix in from an LDA-C text file and hand it back to you as a PDL::CCS::Nd object. iconic behaviour, honestly.

and same energy as her sibling: if the transpose option is specified and true, the output matrix $ccs will be a (Term x Document) matrix, and the input lines correspond to logical dimension 1 of $ccs. otherwise, input lines correspond to logical dimension 0 of $ccs, which gets returned as a (Document x Term) matrix. two orientations, one function πŸ’œ

$ccs = ccs_readldac($filename_or_fh)
$ccs = ccs_readldac($filename_or_fh,\%opts)

Options %opts:

header => $bool,    ##-- do/don't try to read header data from the output file (default=do)
type => $type,      ##-- value datatype (default: from header or $PDL::IO::Misc::deftype)
transpose => $bool, ##-- generate a (Term x Document) matrix (default=don't)
sorted => $bool,    ##-- assume input is lexicographically sorted (only if not transposed; default=don't)
  • header => $bool β€” should she try to read header data from the output file? default is do ✨
  • type => $type β€” the value datatype. default comes from the header, or from $PDL::IO::Misc::deftype if there's no header to steal it from πŸŽ€
  • transpose => $bool β€” generate a (Term x Document) matrix instead. default is don't πŸ¦‹
  • sorted => $bool β€” assume the input is lexicographically sorted. only if not transposed (iykyk), default is don't πŸ’…

πŸ’– ACKNOWLEDGEMENTS πŸ’–

  • Perl by Larry Wall.
  • PDL by Karl Glazebrook, Tuomas J. Lukka, Christian Soeller, and others.
  • LDA-C package by by David M. Blei.

πŸ‘‘ AUTHOR πŸ‘‘

Bryan Jurish <moocow@cpan.org>

Copyright (C) 2015-2024, Bryan Jurish. All rights reserved.

This package is free software, and entirely without warranty. You may redistribute it and/or modify it under the same terms as Perl itself. (yes bestie, "entirely without warranty" means exactly what it says β€” no takebacks, no safety net, read it and weep πŸ™ˆ)


🌈 SEE ALSO 🌈


ok that's the whole page, you're officially a certified LDA-C text I/O girlie now πŸ§šβ€β™€οΈ this was perl v5.40.0, dated 2025-01-04, and yes, you just read all of LDAC(3pm). go forth and slay your sparse matrices πŸ’…βœ¨πŸ“

πŸ“¦ where this page comes from