Skip to content

Commit

Permalink
simplify mstack with loop()
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Sep 5, 2024
1 parent f0dc06b commit ae8d223
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 77 deletions.
51 changes: 15 additions & 36 deletions Complex/complex.pd
Original file line number Diff line number Diff line change
Expand Up @@ -4925,46 +4925,25 @@ pp_def(
);

pp_bless('PDL');
pp_def(
'cmstack',
DefaultFlow => 1,
TwoWay => 1,
Pars => 'x(c,n,m);y(c,n,p);[o]out(c,n,q=CALC($SIZE(m)+$SIZE(n)));',
Code => '
loop(m,n,c) %{
$out(q=>m) = $x();
%}
register PDL_Indx i,j=0;
for (i = $SIZE(m); i < $SIZE(q); i++,j++)
{
loop(n,c) %{
$out(q=>i) = $y(p=>j);
%}
}
',

BackCode => '
loop(m,n,c) %{
$x() = $out(q=>m);
%}
register PDL_Indx i,j=0;
for (i = $SIZE(m); i < $SIZE(q) ;i++,j++)
{
loop(n,c)%{
$y(p=>j) = $out(q=>i);
%}
}
',
Doc => <<EOT

pp_def('cmstack',
DefaultFlow => 1,
TwoWay => 1,
Pars => 'x(c,n,m);y(c,n,p);[o]out(c,n,q=CALC($SIZE(m)+$SIZE(p)));',
Code => '
loop (m,n,c) %{ $out(q=>m) = $x(); %}
loop (q=$SIZE(m),n,c) %{ $out() = $y(p=>q-$SIZE(m)); %}
',
BackCode => '
loop (m,n,c) %{ $x() = $out(q=>m); %}
loop (q=$SIZE(m),n,c) %{ $y(p=>q-$SIZE(m)) = $out(); %}
',
Doc => <<EOT
=for ref

Combine two 3D ndarrays into a single ndarray.
Combine two 3D ndarrays into a single ndarray, along the second
("vertical") dim.
This routine does backward and forward dataflow automatically.

=cut
EOT

);

pp_addhdr('
Expand Down
58 changes: 17 additions & 41 deletions Real/real.pd
Original file line number Diff line number Diff line change
Expand Up @@ -10617,57 +10617,33 @@ EOT

);

pp_def(
'mstack',
DefaultFlow => 1,
TwoWay => 1,
Pars => 'x(n,m);y(n,p);[o]out(n,q=CALC($SIZE(m)+$SIZE(p)));',
Code => '
register PDL_Indx i,j;
loop(m,n) %{
$out(q=>m) = $x();
%}
j=0;
for (i = $SIZE(m); i < $SIZE(q) ;i++,j++)
{
loop(n)%{
$out(q=>i) = $y(p=>j);
%}
}
',

BackCode => '
register PDL_Indx i,j;
loop(m,n) %{
$x() = $out(q=>m);
%}
j=0;
for (i = $SIZE(m); i < $SIZE(q) ;i++,j++)
{
loop(n)%{
$y(p=>j) = $out(q=>i);
%}
}
',

Doc => <<EOT
pp_def('mstack',
DefaultFlow => 1,
TwoWay => 1,
Pars => 'x(n,m);y(n,p);[o]out(n,q=CALC($SIZE(m)+$SIZE(p)));',
GenericTypes => [ppdefs_all()],
Code => '
loop (m,n) %{ $out(q=>m) = $x(); %}
loop (q=$SIZE(m),n) %{ $out() = $y(p=>q-$SIZE(m)); %}
',
BackCode => '
loop (m,n) %{ $x() = $out(q=>m); %}
loop (q=$SIZE(m),n) %{ $y(p=>q-$SIZE(m)) = $out(); %}
',
Doc => <<EOT
=for ref

Combine two ndarrays into a single ndarray.
Combine two 3D ndarrays into a single ndarray, along the second
("vertical") dim.
This routine does backward and forward dataflow automatically.

=cut

EOT

);

pp_addhdr('
float ftrace(int n, float *mat);
double dtrace(int n, double *mat);
');
pp_def(
'charpol',
pp_def('charpol',
Pars => 'A(n,n);[o]Y(n,n);[o]out(p=CALC($SIZE(n)+1));',
GenericTypes => [F,D],
Code => '
Expand Down

0 comments on commit ae8d223

Please sign in to comment.