Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make parameter 'uplo' optional for [c]tricpy #24

Merged
merged 8 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 16 additions & 20 deletions Complex/complex.pd
Original file line number Diff line number Diff line change
Expand Up @@ -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 => <<EOT

=for ref

Copy triangular part to another matrix. If uplo == 0 copy upper triangular part.

=cut

EOT

Doc => undef
);

pp_bless('PDL');
Expand Down
42 changes: 31 additions & 11 deletions Real/real.pd
Original file line number Diff line number Diff line change
Expand Up @@ -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
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.
Expand All @@ -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)',
Expand Down
11 changes: 11 additions & 0 deletions t/1.t
Original file line number Diff line number Diff line change
Expand Up @@ -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;
8 changes: 8 additions & 0 deletions t/legacy.t
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Loading