diff --git a/Complex/complex.pd b/Complex/complex.pd index 02bdfa2..7538ca1 100644 --- a/Complex/complex.pd +++ b/Complex/complex.pd @@ -4947,35 +4947,31 @@ EOF ################################################################################ pp_def( 'ctricpy', - Pars => 'A(c=2,m,n);int uplo();[o] C(c=2,m,n)', + Pars => 'A(c=2,m,n);[o] C(c=2,m,n)', + OtherPars => 'int uplo', + OtherParsDefaults => {uplo => 0}, + ArgOrder => [qw(A uplo C)], Code => ' - if ($uplo()) + if ($COMP(uplo)) { - loop (n,m) %{ - loop(c) %{ $C() = $A(); %} - if (m >= n) break; + broadcastloop %{ + loop (n,m) %{ + loop(c) %{ $C() = $A(); %} + if (m >= n) break; + %} %} } else { - loop (m,n) %{ - loop(c) %{ $C() = $A(); %} - if (n >= m) break; + broadcastloop %{ + loop (m,n) %{ + loop(c) %{ $C() = $A(); %} + if (n >= m) break; + %} %} } - - ', - Doc => < undef ); pp_bless('PDL'); diff --git a/Real/real.pd b/Real/real.pd index 1ba5edf..bae8d86 100644 --- a/Real/real.pd +++ b/Real/real.pd @@ -10473,28 +10473,49 @@ the exponent range, as is found on a Cray. # OTHER AUXILIARY ROUTINES # ################################################################################ - pp_def( 'tricpy', - Pars => 'A(m,n);int uplo();[o] C(m,n)', + Pars => 'A(m,n);[o] C(m,n)', + OtherPars => 'int uplo', + OtherParsDefaults => {uplo => 0}, + ArgOrder => [qw(A uplo C)], GenericTypes => [ppdefs_all()], Code => ' - if ($uplo()) + if ($COMP(uplo)) { - loop(n,m) %{ - $C() = $A(); - if (m >= n) break; + broadcastloop %{ + loop(n,m) %{ + $C() = $A(); + if (m >= n) break; + %} %} } else { - loop(m,n) %{ - $C() = $A(); - if (n >= m) break; + broadcastloop %{ + loop(m,n) %{ + $C() = $A(); + if (n >= m) break; + %} %} } ', - Doc => < <<'EOT' +=for usage + +tricpy(PDL(A), int(uplo), PDL(C)) + +=for example + + use PDL::LinearAlgebra; + + $c = $a->tricpy($uplo); # explicit uplo + $c = $a->tricpy; # default upper +or + use PDL::LinearAlgebra::Real; + + tricpy($a, $uplo, $c); # modify c + =for ref Copy triangular part to another matrix. If uplo == 0 copy upper triangular part. @@ -10505,7 +10526,6 @@ EOT ); - pp_def( 'cplx_eigen', Pars => 'eigreval(n);eigimval(n); eigvec(n,p);int fortran();[o]cplx_val(c=2,n);[o]cplx_vec(c=2,n,p)', diff --git a/t/1.t b/t/1.t index b1475c7..a8643d9 100644 --- a/t/1.t +++ b/t/1.t @@ -81,4 +81,15 @@ $B = identity(2); ok fapprox($got = $A x $B, $A), 'complex first' or diag "got: $got"; ok fapprox($got = $B x $A, $A), 'complex second' or diag "got: $got"; +$A = pdl '[[1 2 3] [4 5 6] [7 8 9]]'; +my $up = pdl '[[1 2 3] [0 5 6] [0 0 9]]'; +my $lo = pdl '[[1 0 0] [4 5 0] [7 8 9]]'; +ok fapprox($got = $A->tricpy(0), $up), 'upper triangle #1' or diag "got: $got"; +tricpy($A, 0, $got = null); +ok fapprox($got, $up), 'upper triangle #2' or diag "got: $got"; +ok fapprox($got = $A->tricpy, $up), 'upper triangle #3' or diag "got: $got"; +ok fapprox($got = $A->tricpy(1), $lo), 'lower triangle #1' or diag "got: $got"; +tricpy($A, 1, $got = null); +ok fapprox($got, $lo), 'lower triangle #2' or diag "got: $got"; + done_testing; diff --git a/t/legacy.t b/t/legacy.t index 6dc89d6..87ba8db 100644 --- a/t/legacy.t +++ b/t/legacy.t @@ -37,6 +37,14 @@ EOF runtest($aa, '_norm', $aa_exp->abs, [1]); runtest($aa, '_norm', $aa_exp->t, [0,1]); +$aa = pdl('[[[0 1] [2 3] [4 5]] [[6 7] [8 9] [10 11]] [[12 13] [14 15] [16 17]]] ')->cplx; +my $up = pdl('[[[0 1] [2 3] [4 5]] [[0 0] [8 9] [10 11]] [[0 0] [0 0] [16 17]]]')->cplx; +my $lo = pdl('[[[0 1] [0 0] [0 0]] [[6 7] [8 9] [0 0]] [[12 13] [14 15] [16 17]]]')->cplx; + +runtest($aa, 'ctricpy', $up, [0]); +runtest($aa, 'ctricpy', $up); +runtest($aa, 'ctricpy', $lo, [1]); + do './t/common.pl'; die if $@; done_testing;