diff --git a/Basic/Core/Core.pm b/Basic/Core/Core.pm index 2d5e93f33..5f31631bf 100644 --- a/Basic/Core/Core.pm +++ b/Basic/Core/Core.pm @@ -1469,18 +1469,10 @@ C<[o]>, C<[oca]>, C<[io]>, or C<[t]> in C). The memory address of the struct. -=item name - -The function name from the vtable. - =item flags List of strings of flags set for this trans. -=item flags_vtable - -List of strings of flags set for this trans's vtable. - =item vaffine Whether the trans is affine. @@ -1501,6 +1493,18 @@ The size of each named dim. The size of the inc for each use of a named dim. +=item vtable + +This trans's vtable. + +=item C<< $vtable->name >> + +The function name from this vtable. + +=item C<< $vtable->flags >> + +List of strings of flags set for this vtable. + =back =head2 trans_children @@ -2217,9 +2221,10 @@ Not exported, and not inserted into the C namespace. sub pdump_trans { my ($trans) = @_; + my $vtable = $trans->vtable; my @lines = ( "State: ${\join '|', $trans->flags}", - "vtable flags: ${\join '|', $trans->flags_vtable}", + "vtable flags: ${\join '|', $vtable->flags}", ); my @ins = $trans->parents; my @outs = $trans->children; @@ -2233,7 +2238,7 @@ sub pdump_trans { "inc_sizes: (@{[$trans->inc_sizes]})", "INPUTS: (@{[map sprintf('0x%x', $_->address), @ins]}) OUTPUTS: (@{[map sprintf('0x%x', $_->address), @outs]})", ; - join '', "PDUMPTRANS 0x${\sprintf '%x', $trans->address} (${\$trans->name})\n", map " $_\n", @lines; + join '', "PDUMPTRANS 0x${\sprintf '%x', $trans->address} (${\$vtable->name})\n", map " $_\n", @lines; } =head2 pdumphash @@ -2262,13 +2267,14 @@ sub pdumphash { my $addr = sprintf '0x%x', $obj->address; # both ndarray and trans return $sofar if $sofar->{$addr}; if ($obj->isa('PDL::Trans')) { + my $vtable = $obj->vtable; my @ins = $obj->parents; my @outs = $obj->children; $sofar->{$addr} = { kind => 'trans', - name => $obj->name, + name => $vtable->name, flags => [$obj->flags], - vtable_flags => [$obj->flags_vtable], + vtable_flags => [$vtable->flags], !($obj->vaffine && !$outs[0]->dimschgd) ? () : ( affine => "o:".$obj->offs." i:(@{[$obj->incs]}) d:(@{[$outs[0]->dims_nophys]})" ), diff --git a/Basic/Core/Core.xs b/Basic/Core/Core.xs index 098dd827c..f7d7c2b1f 100644 --- a/Basic/Core/Core.xs +++ b/Basic/Core/Core.xs @@ -318,27 +318,20 @@ address(self) OUTPUT: RETVAL -char * -name(self) - pdl_trans *self; - CODE: - if (!self->vtable) barf("%p has NULL vtable", self); - RETVAL = self->vtable->name; - OUTPUT: - RETVAL - void flags(x) pdl_trans *x PPCODE: PDL_FLAG_DUMP(PDL_LIST_FLAGS_PDLTRANS, x->flags) -void -flags_vtable(x) +pdl_transvtable * +vtable(x) pdl_trans *x - PPCODE: + CODE: if (!x->vtable) barf("%p has NULL vtable", x); - PDL_FLAG_DUMP(PDL_LIST_FLAGS_PDLVTABLE, x->vtable->flags) + RETVAL = x->vtable; + OUTPUT: + RETVAL int vaffine(x) @@ -381,6 +374,22 @@ inc_sizes(x) EXTEND(sp, max); for(i=0; iinc_sizes[i]); +MODULE = PDL::Core PACKAGE = PDL::Trans::VTable + +char * +name(x) + pdl_transvtable *x; + CODE: + RETVAL = x->name; + OUTPUT: + RETVAL + +void +flags(x) + pdl_transvtable *x + PPCODE: + PDL_FLAG_DUMP(PDL_LIST_FLAGS_PDLVTABLE, x->flags) + MODULE = PDL::Core PACKAGE = PDL::Core IV diff --git a/Basic/Core/typemap b/Basic/Core/typemap index 5fc95b973..4404d7bed 100644 --- a/Basic/Core/typemap +++ b/Basic/Core/typemap @@ -1,6 +1,7 @@ TYPEMAP pdl * T_PDL pdl_trans * T_PDLTRANS +pdl_transvtable * T_PDLTRANSVTABLE PDL_Indx T_IV float T_NV PDL_Anyval T_PDL_ANYVAL @@ -21,6 +22,11 @@ T_PDLTRANS croak(\"$var is not of type PDL::Trans\"); $var = INT2PTR(pdl_trans *,SvIV(SvRV($arg))); +T_PDLTRANSVTABLE + if (!sv_isa($arg,\"PDL::Trans::VTable\")) + croak(\"$var is not of type PDL::Trans::VTable\"); + $var = INT2PTR(pdl_transvtable *,SvIV(SvRV($arg))); + T_PDL_SLICEARGS $var = PDL_CORE_(slice_args_parse_sv)($arg) @@ -41,6 +47,9 @@ T_PDL_ANYVAL T_PDLTRANS sv_setref_pv($arg, \"PDL::Trans\", (void*)$var); +T_PDLTRANSVTABLE + sv_setref_pv($arg, \"PDL::Trans::VTable\", (void*)$var); + T_PDL_LIST if ($var) { $arg = PDL_CORE_(unpackpdls)($var, ${var}_count); diff --git a/Changes b/Changes index 475cca50c..2efd5afbb 100644 --- a/Changes +++ b/Changes @@ -3,6 +3,7 @@ - add datachgd method - add MatrixOps::tritosquare - add gv command to shells +- add PDL::Trans::VTable 2.085 2024-01-30 - switch FFT code to use heap, not VLA (#436) - thanks @HaraldJoerg for report diff --git a/t/core.t b/t/core.t index 190be832e..417095e2f 100644 --- a/t/core.t +++ b/t/core.t @@ -581,9 +581,15 @@ my $slice = $s->slice; isnt +(my $tp=$slice->trans_parent), undef, 'trans_parent with trans defined'; is ${($s->trans_children)[0]}, $$tp, 'correct trans_children'; my @parents = $tp->parents; -is ${$parents[0]}, $$s, 'correct parent ndarray'; +is ${$parents[0]}, $s->address, 'correct parent ndarray'; my @children = $tp->children; -is ${$children[0]}, $$slice, 'correct child ndarray'; +is ${$children[0]}, $slice->address, 'correct child ndarray'; +my $vtable = $tp->vtable; +isnt $vtable->name, undef, 'trans vtable has a name'; +isnt PDL::Core::pdump($slice), undef, 'pdump works'; +isnt PDL::Core::pdump_trans($tp), undef, 'pdump_trans works'; +isnt PDL::Core::pdumphash($slice), undef, 'pdumphash works with ndarray'; +isnt PDL::Core::pdumphash($tp), undef, 'pdumphash works with trans'; my $notouch = sequence(4); $notouch->set_donttouchdata(4 * PDL::Core::howbig($notouch->get_datatype));