@@ -134,7 +134,7 @@ my $b_dbl = $a_dbl->slice('5');
134
134
my $c_long = $a_long -> slice(' 4:7' );
135
135
my $c_dbl = $a_dbl -> slice(' 4:7' );
136
136
is $b_long -> sclr, 5, " sclr test of 1-elem pdl (long)" ;
137
- ok approx( $b_dbl -> sclr, 5 ) , " sclr test of 1-elem pdl (dbl)" ;
137
+ is $b_dbl -> sclr, 5, " sclr test of 1-elem pdl (dbl)" ;
138
138
eval { $c_long -> sclr };
139
139
like $@ , qr / multielement ndarray in 'sclr' call/ , " sclr failed on multi-element ndarray (long)" ;
140
140
eval { $c_dbl -> sclr };
@@ -162,18 +162,18 @@ ok eq_array( [ $y->dims ], [3,4] ), "reshape()";
162
162
my $x = ones 3,1,4;
163
163
my $y = $x -> reshape(-1);
164
164
my $c = $x -> squeeze;
165
- ok eq_array( [ $y -> dims ], [3,4] ), " reshape(-1)" ;
166
- ok all( $y == $c ) , " squeeze" ;
165
+ is_pdl $y -> shape, indx( [3,4]), " reshape(-1)" ;
166
+ is_pdl $y , $c , " squeeze" ;
167
167
$c ++; # check dataflow in reshaped PDL
168
- ok all( $y == $c ) , " dataflow" ; # should flow back to y
169
- ok all( $x == 2 ), " dataflow" ;
168
+ is_pdl $y , $c , " dataflow" ; # should flow back to y
169
+ is_pdl $x , pdl(2) -> slice( ' *3,*1,*4 ' ), " dataflow" ;
170
170
}
171
171
172
172
{
173
173
my $d = pdl(5); # zero dim ndarray and reshape/squeeze
174
- ok $d -> reshape(-1)-> ndims==0 , " reshape(-1) on 0-dim PDL gives 0-dim PDL" ;
175
- ok $d -> reshape(1)-> ndims==1 , " reshape(1) on 0-dim PDL gives 1-dim PDL" ;
176
- ok $d -> reshape(1)-> reshape(-1)-> ndims==0 , " reshape(-1) on 1-dim, 1-element PDL gives 0-dim PDL" ;
174
+ is_pdl $d -> reshape(-1)-> shape, empty(indx) , " reshape(-1) on 0-dim PDL gives 0-dim PDL" ;
175
+ is_pdl $d -> reshape(1)-> shape, indx([1]) , " reshape(1) on 0-dim PDL gives 1-dim PDL" ;
176
+ is_pdl $d -> reshape(1)-> reshape(-1)-> shape, empty(indx) , " reshape(-1) on 1-dim, 1-element PDL gives 0-dim PDL" ;
177
177
}
178
178
179
179
{
@@ -260,11 +260,10 @@ my $subobj = PDL::Trivial->new(6);
260
260
isa_ok $subobj , ' PDL::Trivial' ;
261
261
isa_ok +PDL-> topdl($subobj ), ' PDL::Trivial' ;
262
262
isa_ok $subobj -> inplace, ' PDL::Trivial' ;
263
- isa_ok( PDL-> topdl(1), " PDL" , " topdl(1) returns an ndarray" );
264
- isa_ok( PDL-> topdl([1,2,3]), " PDL" , " topdl([1,2,3]) returns an ndarray" );
265
- isa_ok( PDL-> topdl(1,2,3), " PDL" , " topdl(1,2,3) returns an ndarray" );
266
- my $x =PDL-> topdl(1,2,3);
267
- ok (($x -> nelem == 3 and all($x == pdl(1,2,3))), " topdl(1,2,3) returns a 3-ndarray containing (1,2,3)" );
263
+ isa_ok +PDL-> topdl(1), " PDL" , " topdl(1) returns an ndarray" ;
264
+ isa_ok +PDL-> topdl([1,2,3]), " PDL" , " topdl([1,2,3]) returns an ndarray" ;
265
+ isa_ok +PDL-> topdl(1,2,3), " PDL" , " topdl(1,2,3) returns an ndarray" ;
266
+ is_pdl +PDL-> topdl(1,2,3), pdl(1,2,3), " topdl(1,2,3) returns a 3-ndarray containing (1,2,3)" ;
268
267
eval {PDL-> topdl({})};
269
268
isnt $@ , ' ' , ' topdl({}) no segfault' ;
270
269
}
@@ -331,63 +330,52 @@ is $PDL::undefval, 0, "default value of \$PDL::undefval is 0";
331
330
332
331
{
333
332
my $x = [ [ 2, undef ], [3, 4 ] ];
334
- my $y = pdl( $x );
335
- my $c = pdl( [ 2, 0, 3, 4 ] )-> reshape(2,2);
336
- ok all( $y == $c ), " undef converted to 0 (dbl)" ;
337
- ok eq_array( $x , [[2,undef ],[3,4]] ), " pdl() has not changed input array" ;
338
- $y = pdl( long, $x );
339
- $c = pdl( long, [ 2, 0, 3, 4 ] )-> reshape(2,2);
340
- ok all( $y == $c ), " undef converted to 0 (long)" ;
341
- }
342
-
343
- {
344
- local ($PDL::undefval ) = -999;
345
- my $x = [ [ 2, undef ], [3, 4 ] ];
346
- my $y = pdl( $x );
347
- my $c = pdl( [ 2, -999, 3, 4 ] )-> reshape(2,2);
348
- ok all( $y == $c ), " undef converted to -999 (dbl)" ;
349
- $y = pdl( long, $x );
350
- $c = pdl( long, [ 2, -999, 3, 4 ] )-> reshape(2,2);
351
- ok all( $y == $c ), " undef converted to -999 (long)" ;
333
+ my $y = pdl($x );
334
+ my $c = pdl([[2, 0],[3, 4]]);
335
+ is_pdl $y , $c , " undef converted to 0 (dbl)" ;
336
+ is_deeply $x , [[2,undef ],[3,4]], " pdl() has not changed input array" ;
337
+ is_pdl long($x ), long($c ), " undef converted to 0 (long)" ;
338
+ }
339
+
340
+ {
341
+ local ($PDL::undefval ) = -999;
342
+ my $x = [ [ 2, undef ], [3, 4 ] ];
343
+ my $y = pdl($x );
344
+ my $c = pdl(' 2 -999; 3 4' );
345
+ is_pdl $y , $c , " undef converted to -999 (dbl)" ;
346
+ is_pdl long($x ), long($c ), " undef converted to -999 (long)" ;
352
347
};
353
348
354
349
{
355
350
# Funky constructor cases
356
351
# pdl of a pdl
357
- my $x = pdl(pdl(5));
358
- ok all( $x == pdl(5)), " pdl() can piddlify an ndarray" ;
359
- $x = pdl(null);
360
- ok $x -> isnull, ' pdl(null) gives null' or diag " x(" , $x -> info, " )" ;
352
+ is_pdl pdl(pdl(5)), pdl(5), " pdl() can piddlify an ndarray" ;
353
+ is_pdl pdl(null), null, ' pdl(null) gives null' ;
361
354
362
- $x = pdl(null, null);
363
- is_deeply [$x -> dims], [0,2], ' pdl(null, null) gives empty' or diag " x(" , $x -> info, " )" ;
364
- ok !$x -> isnull, ' pdl(null, null) gives non-null' or diag " x(" , $x -> info, " )" ;
355
+ is_pdl pdl(null, null), zeroes(0,2), ' pdl(null, null) gives empty' ;
365
356
366
357
# pdl of mixed-dim pdls: pad within a dimension
367
- $x = pdl( zeroes(5), ones(3) );
368
- ok all($x == pdl([0,0,0,0,0],[1,1,1,0,0]))," Piddlifying two ndarrays concatenates them and pads to length" or diag(" x=$x \n " );
358
+ is_pdl pdl( zeroes(5), ones(3) ), pdl([0,0,0,0,0],[1,1,1,0,0])," Piddlifying two ndarrays concatenates them and pads to length" ;
369
359
370
360
# pdl of mixed-dim pdls: pad a whole dimension
371
- $x = pdl( [[9,9],[8,8]], xvals(3)+1 );
372
- ok all($x == pdl([[[9,9],[8,8],[0,0]] , [[1,0],[2,0],[3,0]] ]))," can concatenate mixed-dim ndarrays" or diag(" x=$x \n " );
361
+ is_pdl pdl( [[9,9],[8,8]], xvals(3)+1 ), pdl([[[9,9],[8,8],[0,0]] , [[1,0],[2,0],[3,0]] ])," can concatenate mixed-dim ndarrays" ;
373
362
374
363
# pdl of mixed-dim pdls: a hairier case
375
- my $c = pdl [1], pdl[2,3,4], pdl[5];
376
- ok all($c == pdl([[[1,0,0],[0,0,0]],[[2,3,4],[5,0,0]]]))," Can concatenate mixed-dim ndarrays: hairy case" or diag(" c=$c \n " );
364
+ is_pdl pdl([1], pdl[2,3,4], pdl[5]), pdl([[[1,0,0],[0,0,0]],[[2,3,4],[5,0,0]]])," Can concatenate mixed-dim ndarrays: hairy case" ;
377
365
}
378
366
379
367
# same thing, with undefval set differently
380
368
{
381
369
local ($PDL::undefval ) = 99;
382
370
my $c = pdl undef ;
383
- ok all( $c == pdl(99)) , " explicit, undefval of 99 works" or diag( " c= $c \n " ) ;
371
+ is_pdl $c , pdl(99), " explicit, undefval of 99 works" ;
384
372
$c = pdl [1], pdl[2,3,4], pdl[5];
385
- ok all( $c == pdl([[[1,99,99],[99,99,99]],[[2,3,4],[5,99,99]]])) , " implicit, undefval works for padding" or diag( " c= $c \n " ) ;
373
+ is_pdl $c , pdl([[[1,99,99],[99,99,99]],[[2,3,4],[5,99,99]]]), " implicit, undefval works for padding" ;
386
374
$PDL::undefval = undef ;
387
375
$c = pdl undef ;
388
- ok all( $c == pdl(0)) , " explicit, undefval of undef falls back to 0" or diag( " c= $c \n " ) ;
376
+ is_pdl $c , pdl(0), " explicit, undefval of undef falls back to 0" ;
389
377
$c = pdl [1], [2,3,4];
390
- ok all( $c == pdl([1,0,0],[2,3,4])) , " implicit, undefval of undef falls back to 0" or diag( " c= $c \n " ) ;
378
+ is_pdl $c , pdl([1,0,0],[2,3,4]), " implicit, undefval of undef falls back to 0" ;
391
379
$PDL::undefval = inf;
392
380
$c = pdl undef ;
393
381
ok all($c == inf), " explicit, undefval of PDL scalar works" or diag(" c=$c \n " );
@@ -400,22 +388,17 @@ ok all($c == pdl([[[1,0,0],[0,0,0]],[[2,3,4],[5,0,0]]])),"Can concatenate mixed-
400
388
my $x = eval {zeroes(2,0,1);};
401
389
is($@ , ' ' , " zeroes accepts empty PDL specification" );
402
390
403
- my $y = eval { pdl($x ,sequence(2,0,1)); };
404
- is $@ , ' ' ;
405
- ok all(pdl($y -> dims) == pdl(2,0,1,2)), " concatenating two empties gives an empty" ;
391
+ my $y = pdl($x ,sequence(2,0,1));
392
+ is_pdl $y -> shape, indx(2,0,1,2), " concatenating two empties gives an empty" ;
406
393
407
- eval { $y = pdl($x ,sequence(2,1,1)); };
408
- is $@ , ' ' ;
409
- ok all(pdl($y -> dims) == pdl(2,1,1,2)), " concatenating an empty and a nonempty treats the empty as a filler" ;
394
+ $y = pdl($x ,sequence(2,1,1));
395
+ is_pdl $y -> shape, indx(2,1,1,2), " concatenating an empty and a nonempty treats the empty as a filler" ;
410
396
411
- eval { $y = pdl($x ,5) };
412
- is $@ , ' ' ;
413
- ok all(pdl($y -> dims)==pdl(2,1,1,2)), " concatenating an empty and a scalar on the right works" ;
397
+ $y = pdl($x ,5);
398
+ is_pdl $y -> shape, indx(2,1,1,2), " concatenating an empty and a scalar on the right works" ;
414
399
415
- eval { $y = pdl(5,$x ) };
416
- is $@ , ' ' ;
417
- ok all(pdl($y -> dims)==pdl(2,1,1,2)), " concatenating an empty and a scalar on the left works" ;
418
- ok( all($y ==pdl([[[5,0]]],[[[0,0]]])), " concatenating an empty and a scalar on the left gives the right answer" );
400
+ $y = pdl(5,$x );
401
+ is_pdl $y , pdl([[[5,0]]],[[[0,0]]]), " concatenating an empty and a scalar on the left gives the right answer" ;
419
402
}
420
403
421
404
# cat problems
@@ -445,12 +428,7 @@ like($@, qr/\(argument 1\)/,
445
428
' cat properly identifies the first actual ndarray in combined screw-ups' );
446
429
}
447
430
448
- {
449
- my $x = eval {cat(pdl(1),pdl(2,3));};
450
- is($@ , ' ' , ' cat(pdl(1),pdl(2,3)) succeeds' );
451
- is_deeply [$x -> dims], [2,2], ' weird cat case has the right shape' ;
452
- ok( all( $x == pdl([1,1],[2,3]) ), " cat does the right thing with catting a 0-pdl and 2-pdl together" );
453
- }
431
+ is_pdl cat(pdl(1),pdl(2,3)), pdl([1,1],[2,3]), " cat does the right thing with catting a 0-pdl and 2-pdl together" ;
454
432
455
433
{
456
434
my $lo =sequence(long,5)+32766;
@@ -460,13 +438,13 @@ my $by=sequence(byte,5)+253;
460
438
my @list = ($lo ,$so ,$fl ,$by );
461
439
my $c2 = cat(@list );
462
440
is($c2 -> type,' float' ,' concatenating different datatypes returns the highest type' );
463
- ok(all( $_ == shift @list ), " cat/dog symmetry for values" ) for $c2 -> dog;
441
+ is_pdl $_ , shift @list , { require_equal_types => 0, test_name => " cat/dog symmetry for values" } for $c2 -> dog;
464
442
my ($dogcopy ) = $c2 -> dog({Break => 1});
465
443
$dogcopy ++;
466
- ok all( $dogcopy != $c2 -> slice(' :,(0)' )) , ' Break means copy' ; # not lo as cat no flow
444
+ is_pdl $dogcopy , $c2 -> slice(' :,(0)' )+1 , ' Break means copy' ; # not lo as cat no flow
467
445
my ($dogslice ) = $c2 -> dog;
468
446
$dogslice ++;
469
- ok all( $dogslice == $c2 -> slice(' :,(0)' )) , ' no Break means dataflow' or diag " got= $dogslice \n expected= $lo " ;
447
+ is_pdl $dogslice , $c2 -> slice(' :,(0)' ), ' no Break means dataflow' ;
470
448
eval {pdl([3])-> dog(5)};
471
449
like $@ , qr / Usage/ , " error if excess args" ;
472
450
for ([[], qr / at least/ ], [[5]], [[4,5]]) {
@@ -489,36 +467,36 @@ my $y = $x->copy;
489
467
ok $x -> is_inplace," original item true inplace flag after copy" ;
490
468
ok !$y -> is_inplace," copy has false inplace flag" ;
491
469
$y ++;
492
- ok all( $y != sequence(byte,5)) ," copy returns severed copy of the original thing if inplace is set" ;
470
+ is_pdl $y , sequence(byte,5)+1 ," copy returns severed copy of the original thing if inplace is set" ;
493
471
ok $x -> is_inplace," original item still true inplace flag" ;
494
472
ok !$y -> is_inplace," copy still false inplace flag" ;
495
- ok all( $x == sequence(byte,5) )," copy really is severed" ;
473
+ is_pdl $x , sequence(byte,5)," copy really is severed" ;
496
474
}
497
475
498
476
{
499
477
# new_or_inplace
500
478
my $x = sequence(byte,5);
501
479
my $y = $x -> new_or_inplace;
502
- ok( all( $y == $x ) && ( $y -> get_datatype == $x -> get_datatype) , " new_or_inplace with no pref returns something like the orig." ) ;
480
+ is_pdl $y , $x , " new_or_inplace with no pref returns something like the orig." ;
503
481
$y ++;
504
- ok(all( $y != $x ), " new_or_inplace with no inplace flag returns something disconnected from the orig." ) ;
482
+ is_pdl $y , $x +1, " new_or_inplace with no inplace flag returns something disconnected from the orig." ;
505
483
506
484
$y = $x -> new_or_inplace(" float,long" );
507
- ok( $y -> type eq ' float' ," new_or_inplace returns the first type in case of no match" ) ;
485
+ is $y -> type, ' float' ," new_or_inplace returns first type in case of no match" ;
508
486
509
487
$y = $x -> inplace-> new_or_inplace;
510
488
$y ++;
511
- ok(all( $y == $x ), " new_or_inplace returns the original thing if inplace is set" ) ;
512
- ok(!( $y -> is_inplace) ," new_or_inplace clears the inplace flag" ) ;
489
+ is_pdl $y , $x , " new_or_inplace returns the original thing if inplace is set" ;
490
+ ok ! $y -> is_inplace," new_or_inplace clears the inplace flag" ;
513
491
}
514
492
515
493
{
516
494
# check reshape and dims. While we're at it, check null & empty creation too.
517
495
my $empty = empty();
518
496
is $empty -> type-> enum, 0, ' empty() gives lowest-numbered type' ;
519
497
is empty(float)-> type, ' float' , ' empty(float) works' ;
520
- ok( $empty -> nelem==0, " you can make an empty PDL with zeroes(0)" ) ;
521
- ok( " $empty " =~ m / Empty/ , " an empty PDL prints 'Empty'" ) ;
498
+ is $empty -> nelem, 0, " you can make an empty PDL with zeroes(0)" ;
499
+ like " $empty " , qr / Empty/ , " an empty PDL prints 'Empty'" ;
522
500
}
523
501
524
502
{
@@ -545,11 +523,10 @@ like $@, qr/null/, 'null->long gives right error';
545
523
}
546
524
547
525
{
548
- my $x = short pdl (3,4,5,6);
526
+ my $x = short(3,4,5,6);
549
527
eval { $x -> reshape(2,2);};
550
528
is($@ , ' ' , " reshape succeeded in the normal case" );
551
- ok( ( $x -> ndims==2 and $x -> dim(0)==2 and $x -> dim(1)==2 ), " reshape did the right thing" );
552
- ok(all($x == short pdl([[3,4],[5,6]])), " reshape moved the elements to the right place" );
529
+ is_pdl $x , short([[3,4],[5,6]]), " reshape moved the elements to the right place" ;
553
530
my $y = $x -> slice(" :,:" );
554
531
eval { $y -> reshape(4); };
555
532
unlike $@ , qr / Can't/ , " reshape doesn't fail on a PDL with a parent" ;
@@ -584,9 +561,8 @@ SKIP: {
584
561
my $neg = -684394069604;
585
562
my $straight_pdl = pdl($neg );
586
563
my $multed = pdl(1) * $neg ;
587
- ok $straight_pdl == $multed , ' upgrade of large negative SV to ndarray'
588
- or diag " straight=$straight_pdl mult=$multed \n " ,
589
- " straight:" , $straight_pdl -> info, " mult:" , $multed -> info;
564
+ is $straight_pdl , $multed , ' upgrade of large negative SV to ndarray'
565
+ or diag " straight:" , $straight_pdl -> info, " mult:" , $multed -> info;
590
566
}
591
567
{
592
568
my $fromuv_r = pdl(' 10223372036854775507' );
0 commit comments