@@ -5,13 +5,7 @@ use PDL::Core::Dev;
5
5
use PDL::Types qw( ppdefs ppdefs_complex ppdefs_all) ;
6
6
7
7
use Test::More;
8
-
9
- sub tapprox {
10
- my ($x ,$y ) = @_ ;
11
- my $c = abs($x -$y );
12
- my $d = max($c );
13
- $d < 0.0001;
14
- }
8
+ use Test::PDL;
15
9
16
10
is_deeply [ ppdefs() ], [qw( A B S U L K N P Q F D E) ];
17
11
is_deeply [ ppdefs_complex() ], [qw( G C H) ];
@@ -22,7 +16,7 @@ my $ref2 = squeeze(czip($ref->slice("0,"), $ref->slice("1,")));
22
16
my $x = i() -pdl (-2, -3);
23
17
24
18
is($x -> type, ' cdouble' , ' type promotion i - ndarray' );
25
- ok(tapprox( $x -> im,$ref -> slice(" 1 ,:" )) , ' value from i - ndarray' ) ;
19
+ is_pdl $x -> im, $ref -> slice(" (1) ,:" ), ' value from i - ndarray' ;
26
20
ok !$x -> type-> real, ' complex type not real' ;
27
21
ok double-> real, ' real type is real' ;
28
22
ok !$x -> sumover-> type-> real, ' sumover type=complex' ;
@@ -34,7 +28,7 @@ is $x->re->type, 'double', 'real real part';
34
28
my $y =cfloat($x );
35
29
is type($y ), ' cfloat' , ' type conversion to cfloat' ;
36
30
is $y -> re-> type, ' float' , ' real real part' ;
37
- ok(tapprox( $x -> im,$ref -> slice(" 0,1 " )) , ' value from ndarray - i' ) or diag ' got: ' , $x -> im ;
31
+ is_pdl $x -> im, $ref -> slice(" (0),(1),*2 " ) , ' value from ndarray - i' ;
38
32
is zeroes($_ -> [0], 2)-> r2C-> type, $_ -> [1], " r2C $_ ->[0] -> $_ ->[1]"
39
33
for [byte, ' cdouble' ], [long, ' cdouble' ],
40
34
[float, ' cfloat' ], [cfloat, ' cfloat' ],
@@ -69,64 +63,45 @@ for (float, double, ldouble, cfloat, cdouble, cldouble) {
69
63
# dataflow from complex to real
70
64
my $ar = $x -> re;
71
65
$ar ++;
72
- ok(tapprox( $x -> re, -$ref -> slice(" 0," )-> squeeze + 1) , ' complex to real dataflow' ) or diag " got= " . $x -> re, " expected= " .(- $ref -> slice( " 0, " ) -> squeeze + 1) ;
66
+ is_pdl $x -> re, -$ref -> slice(" 0," )-> squeeze + 1, ' complex to real dataflow' ;
73
67
my $ai = $x -> im;
74
68
$x +=i;
75
69
my $expected = pdl(-2, -2);
76
- ok(tapprox($x -> im, $expected ), ' dataflow after conversion' )
77
- or diag " got=" .$x -> im, " \n expected=$expected " ;
70
+ is_pdl $x -> im, $expected , ' dataflow after conversion' ;
78
71
$ai ++;
79
- $expected ++;
80
- ok(tapprox($x -> im, $expected ), ' dataflow after change ->im' )
81
- or diag " got=" .$x -> im, " \n expected=$expected " ;
72
+ is_pdl $x -> im, $expected +1, ' dataflow after change ->im' ;
82
73
}
83
74
84
75
# Check that converting from re/im to mag/ang and
85
76
# back we get the same thing
86
77
$x = $ref2 -> copy;
87
78
my $a =abs($x );
88
79
my $p =carg($x )-> double; # force to double to avoid glibc bug 18594
89
-
90
- $y = czip($a *cos ($p ), $a *sin ($p ));
91
- ok(tapprox($x -$y , 0.), ' check re/im and mag/ang equivalence' )
92
- or diag " For ($x ), got: ($y ) from a=($a ) p=($p ) cos(p)=(" , cos ($p ), " ) sin(p)=(" , sin ($p ), " )" ;
80
+ is_pdl czip($a *cos ($p ), $a *sin ($p )), $x , ' check re/im and mag/ang equivalence' ;
93
81
94
82
# Catan, Csinh, Ccosh, Catanh, Croots
95
83
96
84
my $cabs = sqrt ($x -> re**2+$x -> im**2);
97
85
98
86
ok(abs($x )-> type-> real, ' Cabs type real' );
99
- ok(tapprox( abs $x , $cabs ) , ' Cabs value' ) or diag " got: (@{[abs $x ]}), expected ( $cabs ) " ;
100
- ok(tapprox( abs2($x ), $cabs **2) , ' Cabs2 value' ) or diag " got: (@{[abs2 $x ]}), expected ( " , $cabs **2, " ) " ;
87
+ is_pdl abs $x , $cabs , ' Cabs value' ;
88
+ is_pdl abs2($x ), $cabs **2, ' Cabs2 value' ;
101
89
ok abs2(cdouble(5))-> type-> real, ' abs2 always real' ;
102
90
ok(carg($x )-> type-> real, ' Carg type real' );
103
- ok(tapprox( carg($x ), atan2 ($x -> im, $x -> re)) , ' Carg value' ) ;
91
+ is_pdl carg($x ), atan2 ($x -> im, $x -> re), ' Carg value' ;
104
92
105
- {
106
- # Check cat'ing
107
- $y = $x -> re-> copy + 1;
108
- my $bigArray = $x -> cat($y );
109
- my $sum = $bigArray -> sum;
110
- my $cz = czip(8, -2);
111
- my $abs = abs($sum + $cz );
112
- ok(all($abs < .0001), ' check cat for complex' ) or diag " got:$abs from cat(x=$x y=$y ): $bigArray " ;
113
- }
93
+ is_pdl $x -> cat($x -> re-> copy + 1), pdl(' -2+i -3+i; -1 -2' ), ' cat for complex' ;
114
94
115
95
if (PDL::Core::Dev::got_complex_version(' pow' , 2)) {
116
- ok(tapprox($x **2, $x * $x ), ' ** op complex' )
117
- or diag " For ($x ), got: " , $x **2, " , expected: " , $x * $x ;
118
- ok(tapprox($x -> pow(2), $x * $x ), ' complex pow' )
119
- or diag " Got: " , $x -> pow(2), " , expected: " , $x * $x ;
120
- ok(tapprox($x -> power(2, 0), $x * $x ), ' complex power' )
121
- or diag " Got: " , $x -> power(2, 0), " , expected: " , $x * $x ;
96
+ is_pdl $x **2, $x * $x , ' ** op complex' ;
97
+ is_pdl $x -> pow(2), $x * $x , ' complex pow' ;
98
+ is_pdl $x -> power(2, 0), $x * $x , ' complex power' ;
122
99
my $z = pdl(0) + i()*pdl(0);
123
100
$z **= 2;
124
- ok(tapprox( $z , i2C(0)) , ' check that 0 +0i exponentiates correctly' ) ; # Wasn't always so.
101
+ is_pdl $z , i2C(0), ' check that 0 +0i exponentiates correctly' ; # Wasn't always so.
125
102
my $r = r2C(-10);
126
103
$r **= 2;
127
- ok(tapprox($r , r2C(100)),
128
- ' check that imaginary part is exactly zero' ) # Wasn't always so
129
- or diag " got: " , $r ;
104
+ is_pdl $r , r2C(100), ' check imaginary part exactly zero' ; # Wasn't always so
130
105
}
131
106
132
107
my $asin_2 = PDL::asin(2)." " ;
0 commit comments