Skip to content

Commit

Permalink
log10 handle output arg, use initalize
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Oct 24, 2024
1 parent 14177b7 commit 1c9a7cb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 23 deletions.
24 changes: 8 additions & 16 deletions Basic/Ops/ops.pd
Original file line number Diff line number Diff line change
Expand Up @@ -440,25 +440,17 @@ pp_export_nothing();
ufunc('log10','log10',0,'the base 10 logarithm', GenericTypes => $A,
Exception => '$a() <= 0',
NoTgmath => 1, # glibc for at least GCC 8.3.0 won't tgmath log10 though 7.1.0 did
PMCode =>
'
PMCode => <<'EOF',
sub PDL::log10 {
my $x = shift;
if ( ! UNIVERSAL::isa($x,"PDL") ) { return log($x) / log(10); }
my $y;
if ( $x->is_inplace ) { $x->set_inplace(0); $y = $x; }
elsif( ref($x) eq "PDL"){
#PDL Objects, use nullcreate:
$y = PDL->nullcreate($x);
}else{
#PDL-Derived Object, use copy: (Consistent with
# Auto-creation docs in Objects.pod)
$y = $x->copy;
}
my ($x, $y) = @_;
return log($x) / log(10) if !UNIVERSAL::isa($x,"PDL");
barf "inplace but output given" if $x->is_inplace and defined $y;
if ($x->is_inplace) { $x->set_inplace(0); $y = $x; }
elsif (!defined $y) { $y = $x->initialize; }
&PDL::_log10_int( $x, $y );
return $y;
$y;
};
'
EOF
);

pp_def(
Expand Down
3 changes: 2 additions & 1 deletion t/ops.t
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,14 @@ my $pb = log(pdl(110,23)) / log(10);
note "a: $pa\n";
note "b: $pb\n";
ok(all( approx( $pa, $pb)), 'log10 pdl');
log10(pdl(110,23), my $pc=null);
ok(all( approx( $pc, $pb)), '2-arg log10 pdl');
# check inplace
ok(all( approx( pdl(110,23)->inplace->log10(), $pb)), 'inplace pdl log10');
if ($can_complex_power) {
ok(all( approx( cdouble(110,23)->inplace->log()/log(10), $pb)), 'complex inplace pdl log10');
}
}

}

{
Expand Down
10 changes: 4 additions & 6 deletions t/subclass.t
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,15 @@ sub new {
sub initialize {
my ($class) = @_;
my $self = $class->SUPER::initialize;
$self->{someThingElse} = 42,
# copy the other stuff:
$self->{someThingElse} = ref $class ? $class->{someThingElse} : 42;
$self;
}
###### Derived3 Object Needs to supply its own copy #####
sub copy {
my $self = shift;
my $new = $self->initialize;
$new->{PDL} = $self->{PDL}->SUPER::copy;
# copy the other stuff:
$new->{someThingElse} = $self->{someThingElse};
$new;
}
}
Expand Down Expand Up @@ -173,7 +172,8 @@ sub initialize {
$::INIT_CALLED = 1;
my $class = shift;
my $self = $class->SUPER::initialize;
$self->{someThingElse} = 42,
# copy the other stuff:
$self->{someThingElse} = ref $class ? $class->{someThingElse} : 42;
$self;
}

Expand All @@ -183,8 +183,6 @@ sub copy {
my $self = shift;
my $new = $self->initialize;
$new->{PDL} = $self->{PDL}->SUPER::copy;
# copy the other stuff:
$new->{someThingElse} = $self->{someThingElse};
return $new;
}

Expand Down

0 comments on commit 1c9a7cb

Please sign in to comment.