diff --git a/Basic/Ops/ops.pd b/Basic/Ops/ops.pd index e25d2d8ce..b7da73749 100644 --- a/Basic/Ops/ops.pd +++ b/Basic/Ops/ops.pd @@ -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( diff --git a/t/ops.t b/t/ops.t index 0ae20f28c..b0ab47fec 100644 --- a/t/ops.t +++ b/t/ops.t @@ -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'); } } - } { diff --git a/t/subclass.t b/t/subclass.t index 44ad96d74..747b2f3ce 100644 --- a/t/subclass.t +++ b/t/subclass.t @@ -84,7 +84,8 @@ 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 ##### @@ -92,8 +93,6 @@ sub copy { my $self = shift; my $new = $self->initialize; $new->{PDL} = $self->{PDL}->SUPER::copy; - # copy the other stuff: - $new->{someThingElse} = $self->{someThingElse}; $new; } } @@ -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; } @@ -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; }