From 3fdd4310608e4db3c35e35a623ba43410234c06a Mon Sep 17 00:00:00 2001 From: Ed J Date: Mon, 11 Nov 2024 01:29:22 +0000 Subject: [PATCH] add IO::Misc::bswap16 --- Basic/IO-Misc/misc.pd | 102 ++++++++++------------------------------- Basic/IO-Misc/t/misc.t | 6 +-- Changes | 1 + 3 files changed, 29 insertions(+), 80 deletions(-) diff --git a/Basic/IO-Misc/misc.pd b/Basic/IO-Misc/misc.pd index 19b50b911..c0591dda7 100644 --- a/Basic/IO-Misc/misc.pd +++ b/Basic/IO-Misc/misc.pd @@ -14,7 +14,7 @@ PDL::IO::Misc - misc IO routines for PDL =head1 DESCRIPTION -Some basic I/O functionality: FITS, tables, byte-swapping +Some basic I/O functionality: tables, byte-swapping =head1 SYNOPSIS @@ -53,78 +53,36 @@ use PDL::Bad; use Carp; use Symbol qw/ gensym /; use List::Util; -use strict; !NO!SUBS! -defpdl( - 'bswap2', - 'x(); ', - '', - ' - int i; - PDL_Short *aa; PDL_Short bb; - PDL_Byte *a,*b; - - int n = sizeof($x()) / sizeof(PDL_Short); - aa = (PDL_Short*) &$x(); - - for(i=0;i '[io] x()', + Code => < $doc, + ); +} +defswap(2, "Swaps pairs of bytes in argument x()"); +defswap(4, "Swaps quads of bytes in argument x()"); +defswap(8, "Swaps octets of bytes in argument x()"); +defswap(16, "Swaps 16s of bytes in argument x()"); pp_addpm(<<'!NO!SUBS!'); - - # Internal routine to extend PDL array by size $n along last dimension # - Would be nice to have a proper extend function rather than hack # - Is a NO-OP when handed a perl ARRAY ref rather than an ndarray arg @@ -1180,16 +1138,6 @@ pp_add_exported("", "isbigendian"); ################################ XS CODE ###################################### -sub defpdl { - pp_def( - $_[0], - Pars => $_[1], - OtherPars => $_[2], - Code => $_[3], - Doc => $_[4], - ); -} - pp_add_exported('', 'rcube'); pp_addpm(<<'EOPM'); =head2 rcube diff --git a/Basic/IO-Misc/t/misc.t b/Basic/IO-Misc/t/misc.t index 2656fe9c7..f1a54dfa5 100644 --- a/Basic/IO-Misc/t/misc.t +++ b/Basic/IO-Misc/t/misc.t @@ -86,11 +86,11 @@ is( (sum($x)==15 && max($y)==66 && $y->getdim(0)==5), 1, "rgrep" ); $x = short(3); $y = long(3); # $c=long([3,3]); bswap2($x); bswap4($y); -is sum($x)."", 768, "bswap2"; -is sum($y)."", 50331648, "bswap4"; +is_pdl $x, short(768), "bswap2"; +is_pdl $y, long(50331648), "bswap4"; $x = short(3); $x->type->bswap->($x); -is sum($x)."", 768, "bswap Type method"; +is_pdl $x, short(768), "bswap Type method"; ############# Test rasc ############# diff --git a/Changes b/Changes index 285efc2aa..6ca3d2029 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,7 @@ - CallExt removed - use `Inline with => "PDL"; use Inline C => "..."` - Inline::MakePdlppInstallable removed - use Inline::Module - PDL::PP::Dump removed - set $::PP_VERBOSE in .pd instead +- add IO::Misc::bswap16 2.095 2024-11-03 - add PDL_GENTYPE_IS_{REAL,FLOATREAL,COMPLEX,SIGNED,UNSIGNED}_##ppsym (#502)