Skip to content

Commit ab44869

Browse files
committed
can now do pdl(cplx(1,2)) - fix #543
1 parent 9642e24 commit ab44869

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

Changes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
- pptemplate improvements (#538 #539) - thanks @HaraldJoerg
2+
- pdldoc database now reproducible (#542) - thanks @daym
3+
- can now do pdl(cplx(1,2)) (#543) - thanks @gladilin for report
24

35
2.100 2025-03-27
46
- fix Math function prototypes for GCC 15 (#528) - thanks @jplesnik for report

lib/PDL/Core.pm

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,7 +1232,7 @@ sub _establish_type {
12321232
}
12331233

12341234
sub PDL::new {
1235-
return $_[0]->copy if ref($_[0]);
1235+
return $_[0]->copy if ref($_[0]) and UNIVERSAL::isa($_[0], 'PDL');
12361236
my $this = shift;
12371237
my $type = ref($_[0]) eq 'PDL::Type' ? shift->enum : undef;
12381238
my $value = (@_ > 1 ? [@_] : shift);
@@ -1283,13 +1283,17 @@ sub PDL::new {
12831283
}
12841284
}
12851285
}
1286+
elsif (blessed($value) and UNIVERSAL::isa($value, 'Math::Complex')) {
1287+
$new->setdims([]);
1288+
set_c($new, [], $value);
1289+
}
12861290
elsif (blessed($value)) { # Object
1287-
$new = $value->copy;
1291+
$new = $value->copy;
12881292
}
12891293
else {
1290-
barf("Can not interpret argument $value of type ".ref($value) );
1294+
barf("Can not interpret argument $value of type ".ref($value) );
12911295
}
1292-
return $new;
1296+
$new;
12931297
}
12941298

12951299

t/core.t

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,8 @@ $y = pdl(5,$x);
446446
is_pdl $y, pdl([[[5,0]]],[[[0,0]]]), "concatenating an empty and a scalar on the left gives the right answer";
447447
}
448448

449+
is_pdl pdl(Math::Complex->make(1,2)), pdl('1+2i'), 'pdl(Math::Complex obj)';
450+
449451
# cat problems
450452
eval {cat(1, pdl(1,2,3), {}, 6)};
451453
isnt $@, '', 'cat barfs on non-ndarray arguments';

0 commit comments

Comments
 (0)