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

Fix conv2d to allow complex arguments #407

Merged
merged 1 commit into from
Aug 21, 2022

Conversation

wlmb
Copy link
Contributor

@wlmb wlmb commented Aug 15, 2022

No description provided.

@coveralls
Copy link

coveralls commented Aug 15, 2022

Coverage Status

Coverage increased (+1.6%) to 56.508% when pulling 3e1e990 on wlmb:complex-conv2d into ff46905 on PDLPorters:master.

@wlmb
Copy link
Contributor Author

wlmb commented Aug 15, 2022

Program to test complex conv2d

  use v5.36;
  use PDL;
  use PDL::Image2D;
  my $realmask=ones(3,3)/9;
  my $realseq=sequence(3,3);
  my $imagmask=$realmask*i();
  my $imagseq=$realseq*i();
  print "Real matrix real mask ", $realseq->conv2d($realmask);
  print "Imag matrix real mask ", $imagseq->conv2d($realmask);
  print "Real matrix imag mask ", $realseq->conv2d($imagmask);
  print "Imag matrix imag mask ", $imagseq->conv2d($imagmask);

Output:

Real matrix real mask 
[
 [4 4 4]
 [4 4 4]
 [4 4 4]
]
Imag matrix real mask 
[
 [4i 4i 4i]
 [4i 4i 4i]
 [4i 4i 4i]
]
Real matrix imag mask 
[
 [4i 4i 4i]
 [4i 4i 4i]
 [4i 4i 4i]
]
Imag matrix imag mask 
[
 [-4 -4 -4]
 [-4 -4 -4]
 [-4 -4 -4]
]

@mohawk2
Copy link
Member

mohawk2 commented Aug 21, 2022

Thanks for this! For your reference another time, this is what I added to image2d.t:

{
  my $realmask=ones(3,3)/9;
  my $realseq=sequence(3,3);
  my $imagmask=$realmask*i();
  my $imagseq=$realseq*i();
  my $real_exp = <<EOF;
\n[
 [4 4 4]
 [4 4 4]
 [4 4 4]
]
EOF
  my $neg_exp = <<EOF;
\n[
 [-4 -4 -4]
 [-4 -4 -4]
 [-4 -4 -4]
]
EOF
  my $imag_exp = <<EOF;
\n[
 [4i 4i 4i]
 [4i 4i 4i]
 [4i 4i 4i]
]
EOF
  is $realseq->conv2d($realmask).'', $real_exp, "Real matrix real mask";
  is $imagseq->conv2d($realmask).'', $imag_exp, "Imag matrix real mask";
  is $realseq->conv2d($imagmask).'', $imag_exp, "Real matrix imag mask";
  is $imagseq->conv2d($imagmask).'', $neg_exp, "Imag matrix imag mask";
}

@mohawk2
Copy link
Member

mohawk2 commented Aug 21, 2022

I also added the "all types" to the other Image2D functions that were suitable, which wasn't all of them (med2d requires sorting, so no good for complex), and changed "double" to "long double" to avoid loss of precision.

@mohawk2 mohawk2 merged commit 7219e10 into PDLPorters:master Aug 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants