/usr/lib/perl5/PDL/FFTW.pm is in pdl 1:2.4.7+dfsg-2ubuntu5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 | #
# GENERATED WITH PDL::PP! Don't modify!
#
package PDL::FFTW;
@EXPORT_OK = qw( PDL::PP Cmul PDL::PP Cscale PDL::PP Cdiv PDL::PP Cbmul PDL::PP Cbscale PDL::PP Cconj PDL::PP Cbconj PDL::PP Cexp PDL::PP Cbexp PDL::PP Cmod PDL::PP Carg PDL::PP Cmod2 load_wisdom save_wisdom rfftw irfftw fftw ifftw
nfftw infftw nrfftw inrfftw fftwconv rfftwconv kernctr );
%EXPORT_TAGS = (Func=>[@EXPORT_OK]);
use PDL::Core;
use PDL::Exporter;
use DynaLoader;
@ISA = ( 'PDL::Exporter','DynaLoader' );
push @PDL::Core::PP, __PACKAGE__;
bootstrap PDL::FFTW ;
=head1 NAME
PDL::FFTW - PDL interface to the Fastest Fourier Transform in the West v2.x
=head1 DESCRIPTION
This is a means to interface PDL with the FFTW library. It's similar to
the standard FFT routine but it's usually faster and has support for
real transforms. It works well for the types of PDLs for
which was the library was compiled (otherwise it must do conversions).
=head1 SYNOPSIS
use PDL::FFTW
load_wisdom("file_name");
out_cplx_pdl = fftw(in_cplx_pdl);
out_cplx_pdl = ifftw(in_cplx_pdl);
out_cplx_pdl = rfftw(in_real_pdl);
out_real_pdl = irfftw(in_cplx_pdl);
cplx_pdl = nfftw(cplx_pdl);
cplx_pdl = infftw(cplx_pdl);
cplx_pdl = Cmul(a_cplx_pdl, b_cplx_pdl);
cplx_pdl = Cconj(a_cplx_pdl);
real_pdl = Cmod(a_cplx_pdl);
real_pdl = Cmod2(a_cplx_pdl);
=head1 FFTW documentation
Please refer to the FFTW documentation for a better understanding of
these functions.
Note that complex numbers are represented as piddles with leading
dimension size 2 (real/imaginary pairs).
=cut
=head1 FUNCTIONS
=cut
=head2 load_wisdom
=for ref
Loads the wisdom from a file for better FFTW performance.
The wisdom
is automatically saved when the program ends. It will be automagically
called when the variable C<$PDL::FFT::wisdom> is set to a file name.
For example, the following is a useful idiom to have in your F<.perldlrc>
file:
$PDL::FFT::wisdom = "$ENV{HOME}/.fftwisdom"; # save fftw wisdom in this file
Explicit usage:
=for usage
load_wisdom($fname);
=head2 fftw
=for ref
calculate the complex FFT of a real piddle (complex input, complex output)
=for usage
$pdl_cplx = fftw $pdl_cplx;
=head2 ifftw
=for ref
Complex inverse FFT (complex input, complex output).
=for usage
$pdl_cplx = ifftw $pdl_cplx;
=head2 nfftw
=for ref
Complex inplace FFT (complex input, complex output).
=for usage
$pdl_cplx = nfftw $pdl_cplx;
=head2 infftw
=for ref
Complex inplace inverse FFT (complex input, complex output).
=for usage
$pdl_cplx = infftw $pdl_cplx;
=head2 rfftw
=for ref
Real FFT. For an input piddle of dimensions [n1,n2,...] the
output is [2,(n1/2)+1,n2,...] (real input, complex output).
=for usage
$pdl_cplx = fftw $pdl_real;
=head2 irfftw
=for ref
Real inverse FFT. Have a look at rfftw to understand the format. USE
ONLY an even n1! (complex input, real output)
=for usage
$pdl_real = ifftw $pdl_cplx;
=head2 nrfftw
=for ref
Real inplace FFT. If you want a transformation on a piddle
with dimensions [n1,n2,....] you MUST pass in a piddle
with dimensions [2*(n1/2+1),n2,...] (real input, complex output).
Use with care due to dimension restrictions mentioned below.
For details check the html docs that come with the fftw library.
=for usage
$pdl_cplx = nrfftw $pdl_real;
=head2 inrfftw
=for ref
Real inplace inverse FFT. Have a look at nrfftw to understand the format. USE
ONLY an even first dimension size! (complex input, real output)
=for usage
$pdl_real = infftw $pdl_cplx;
=cut
use PDL;
use PDL::ImageND qw/kernctr/;
use strict;
my ($wisdom_fname, $wisdom_loaded, %plan_cache, $datatype, $warn_conv);
#
# package vriables: $wisdom_fname, $wisdom_loaded, %plan_cache, $datatype, $warn_conv,
# $COMPILED_TYPE: (Type "double" or "float") that PDL::FFTW was compiled/linked to
#
$wisdom_loaded = 0;
$PDL::FFTW::COMPILED_TYPE = "double";
sub load_wisdom {
$wisdom_fname = shift;
if (!$wisdom_loaded) {
my ($wisdom, $ok);
$wisdom_loaded = 1;
if (!open(TMPFILE,$wisdom_fname)) {
print STDERR "Warning: couldn't find wisdom file\n";
return;
}
$wisdom = <TMPFILE>;
close(TMPFILE);
$ok = PDL_fftw_import_wisdom_from_string($wisdom);
if (!$ok) {
print STDERR "Warning: couldn't import wisdom\n";
}
}
}
sub save_wisdom {
if ($wisdom_loaded) {
my $wisdom = PDL_fftw_export_wisdom_to_string();
if (!open(TMPFILE,">$wisdom_fname")) {
print STDERR "Warning: couldn't write wisdom file\n";
return;
}
print TMPFILE $wisdom;
close(TMPFILE);
}
}
sub BEGIN {
my $HOME=$ENV{HOME};
my $test_type = double 1;
$datatype = $test_type->get_datatype;
$warn_conv = 0;
# if ( -e "$HOME/.wisdom" ) {
# print STDERR "Autoloading wisdom\n";
# load_wisdom("$HOME/.wisdom");
# }
}
sub END {
save_wisdom();
}
if (defined $PDL::FFT::wisdom) {
load_wisdom($PDL::FFT::wisdom);
print "loading wisdom from $PDL::FFT::wisdom\n" if $PDL::debug;
}
# real fftw
*PDL::rfftw = \&rfftw;
sub rfftw {
my $in = PDL::Core::topdl(shift);
my @dims = $in->dims;
my @newdims;
my ($out,$name,$i);
if ($datatype != $in->get_datatype) {
$in = convert $in, double;
if ($warn_conv != 1) {
print STDERR "PDL::FFTW Warning! doing conversion.\n";
$warn_conv = 1;
}
}
foreach $i (@dims) {
unshift @newdims, $i;
}
$name="r_@{newdims}_f";
if ( !defined($plan_cache{$name}) ) {
my $pdldims = long [@newdims];
$plan_cache{$name} = PDL_rfftwnd_create_plan($pdldims,0,$wisdom_loaded);
}
$dims[0]= int($dims[0]/2)+1;
unshift @dims, 2;
$out = zeroes double,@dims;
$in->make_physical;
PDL_rfftwnd_one_real_to_complex($plan_cache{$name},$in,$out);
return $out;
}
# this assumes even last input dimension!
*PDL::irfftw = \&irfftw;
sub irfftw {
my $in = PDL::Core::topdl(shift);
my @dims = $in->dims;
my @newdims;
my ($out,$name,$i);
$i = shift @dims;
if ($i != 2) {
barf("Working only on complex numbers!");
}
if ($datatype != $in->get_datatype) {
$in = convert $in, double;
if ($warn_conv != 1) {
print STDERR "PDL::FFTW Warning! doing conversion.\n";
$warn_conv = 1;
}
}
$i= shift @dims;
unshift @newdims, 2*($i-1);
foreach $i (@dims) {
unshift @newdims, $i;
}
$name="r_@{newdims}_b";
if ( !defined($plan_cache{$name}) ) {
my $pdldims = long [@newdims];
$plan_cache{$name} = PDL_rfftwnd_create_plan($pdldims,1,$wisdom_loaded);
}
unshift @dims, 2*($i-1);
$out = zeroes double,@dims;
$in->make_physical;
PDL_rfftwnd_one_complex_to_real($plan_cache{$name},$in,$out);
return $out;
}
# real inplace fftw
*PDL::nrfftw = \&nrfftw;
sub nrfftw {
my ($in)=@_;
my @dims = $in->dims;
my @newdims;
my ($out,$name,$i,$ndim);
if ($datatype != $in->get_datatype) {
barf("Cannot do inplace fftw: compiled for double !");
}
foreach $i (@dims) {
unshift @newdims, $i;
}
$ndim = $newdims[$#newdims] = 2*(int($newdims[$#newdims]/2) - 1);
$name="nr_@{newdims}_f";
if ( !defined($plan_cache{$name}) ) {
my $pdldims = long [@newdims];
$plan_cache{$name} = PDL_rfftwnd_create_plan($pdldims,0,$wisdom_loaded+2);
}
$dims[0]= int($ndim/2)+1;
unshift @dims, 2;
$in->make_physical;
PDL_inplace_rfftwnd_one_real_to_complex($plan_cache{$name},$in);
$in->reshape(@dims);
return $in;
}
# this assumes even last input dimension!
*PDL::inrfftw = \&inrfftw;
sub inrfftw {
my ($in)=@_;
my @dims = $in->dims;
my @newdims;
my ($out,$name,$i,$ndim);
$i = shift @dims;
if ($i != 2) {
barf("Working only on complex numbers!");
}
if ($datatype != $in->get_datatype) {
barf("Cannot do inplace fftw: compiled for double !");
}
$i= shift @dims;
$ndim = 2*($i-1);
unshift @newdims, $ndim;
foreach $i (@dims) {
unshift @newdims, $i;
}
$name="nr_@{newdims}_b";
if ( !defined($plan_cache{$name}) ) {
my $pdldims = long [@newdims];
$plan_cache{$name} = PDL_rfftwnd_create_plan($pdldims,1,$wisdom_loaded+2);
}
unshift @dims, 2*(int($ndim/2)+1);
$in->make_physical;
PDL_inplace_rfftwnd_one_complex_to_real($plan_cache{$name},$in);
$in->reshape(@dims);
return $in;
}
# complex fftw
*PDL::fftw = \&fftw;
sub fftw {
my $in = PDL::Core::topdl(shift);
my @dims = $in->dims;
my @newdims;
my ($out,$name,$i);
if ($datatype != $in->get_datatype) {
$in = convert $in, double;
if ($warn_conv != 1) {
print STDERR "PDL::FFTW Warning! doing conversion.\n";
$warn_conv = 1;
}
}
$i=shift @dims;
if ($i!=2) {
barf("It works only on complex!");
}
foreach $i (@dims) {
unshift @newdims, $i;
}
$name="c_@{newdims}_f";
if ( !defined($plan_cache{$name}) ) {
my $pdldims = long [@newdims];
$plan_cache{$name} = PDL_fftwnd_create_plan($pdldims,0,$wisdom_loaded);
}
unshift @dims, 2;
$out = zeroes double,@dims;
$in->make_physical;
PDL_fftwnd_one($plan_cache{$name},$in,$out);
return $out;
}
*PDL::ifftw = \&ifftw;
sub ifftw {
my $in = PDL::Core::topdl(shift);
my @dims = $in->dims;
my @newdims;
my ($out,$name,$i);
if ($datatype != $in->get_datatype) {
$in = convert $in, double;
if ($warn_conv != 1) {
print STDERR "PDL::FFTW Warning! doing conversion.\n";
$warn_conv = 1;
}
}
$i = shift @dims;
if ($i != 2) {
barf("Working only on complex numbers!");
}
foreach $i (@dims) {
unshift @newdims, $i;
}
$name="c_@{newdims}_b";
if ( !defined($plan_cache{$name}) ) {
my $pdldims = long [@newdims];
$plan_cache{$name} = PDL_fftwnd_create_plan($pdldims,1,$wisdom_loaded);
}
unshift @dims, 2;
$out = zeroes double,@dims;
$in->make_physical;
PDL_fftwnd_one($plan_cache{$name},$in,$out);
return $out;
}
# complex inplace fftw
*PDL::nfftw = \&nfftw;
sub nfftw {
my ($in)=@_;
my @dims = $in->dims;
my @newdims;
my ($name,$i);
if ($datatype != $in->get_datatype) {
barf("Cannot do inplace fftw: compiled for double !");
}
$i=shift @dims;
if ($i!=2) {
barf("It works only on complex!");
}
foreach $i (@dims) {
unshift @newdims, $i;
}
$name="n_@{newdims}_f";
if ( !defined($plan_cache{$name}) ) {
my $pdldims = long [@newdims];
$plan_cache{$name} = PDL_fftwnd_create_plan($pdldims,0,$wisdom_loaded+2);
}
$in->make_physical;
PDL_inplace_fftwnd_one($plan_cache{$name},$in);
return $in;
}
*PDL::infftw = \&infftw;
sub infftw {
my ($in)=@_;
my @dims = $in->dims;
my @newdims;
my ($out,$name,$i);
if ($datatype != $in->get_datatype) {
barf("Cannot do inplace fftw: compiled for double !");
}
$i = shift @dims;
if ($i != 2) {
barf("Working only on complex numbers!");
}
foreach $i (@dims) {
unshift @newdims, $i;
}
$name="n_@{newdims}_b";
if ( !defined($plan_cache{$name}) ) {
my $pdldims = long [@newdims];
$plan_cache{$name} = PDL_fftwnd_create_plan($pdldims,1,$wisdom_loaded+2);
}
$in->make_physical;
PDL_inplace_fftwnd_one($plan_cache{$name},$in);
return $in;
}
=head2 rfftwconv
=for ref
ND convolution using real ffts from the FFTW library
=for example
$conv = rfftwconv $im, kernctr $im, $k; # kernctr is from PDL::FFT
=cut
*PDL::rfftwconv = \&rfftwconv;
sub rfftwconv {
my ($a,$b) = @_;
my ($ca,$cb) = (rfftw($a), rfftw($b));
my $cmul = Cmul($ca,$cb);
my $ret = irfftw($cmul);
my $mul = 1; for (0..$a->getndims-1) {$mul *= $a->getdim($_)}
$ret /= $mul;
return $ret;
}
=head2 fftwconv
=for ref
ND convolution using complex ffts from the FFTW library
Assumes real input!
=for example
$conv = fftwconv $im, kernctr $im, $k; # kernctr is from PDL::FFT
=cut
*PDL::fftwconv = \&fftconv;
sub fftwconv {
my ($a,$b) = @_;
my ($ca,$cb) = (PDL->zeroes(2,$a->dims),PDL->zeroes(2,$b->dims));
$ca->slice('(0)') .= $a;
$cb->slice('(0)') .= $b;
nfftw($ca); nfftw($cb);
my $cmul = Cmul($ca,$cb);
infftw $cmul; # transfer back inplace
# and return real part only
my $ret = $cmul->slice('(0)')->sever;
my $mul = 1; for (0..$a->getndims-1) {$mul *= $a->getdim($_)}
$ret /= $mul;
return $ret;
}
=head2 Cmul
=for sig
Signature: (a(n); b(n); [o]c(n))
=for ref
Complex multiplication
=for usage
$out_pdl_cplx = Cmul($a_pdl_cplx,$b_pdl_cplx);
=for bad
Cmul does not process bad values.
It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles.
=cut
*Cmul = \&PDL::Cmul;
=head2 Cscale
=for sig
Signature: (a(n); b(); [o]c(n))
=for ref
Complex by real multiplation.
=for usage
Cscale($a_pdl_cplx,$b_pdl_real);
=for bad
Cscale does not process bad values.
It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles.
=cut
*Cscale = \&PDL::Cscale;
=head2 Cdiv
=for sig
Signature: (a(n); b(n); [o]c(n))
=for ref
Complex division.
=for usage
$out_pdl_cplx = Cdiv($a_pdl_cplx,$b_pdl_cplx);
=for bad
Cdiv does not process bad values.
It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles.
=cut
*Cdiv = \&PDL::Cdiv;
=head2 Cbmul
=for sig
Signature: (a(n); b(n))
=for ref
Complex inplace multiplication.
=for usage
Cbmul($a_pdl_cplx,$b_pdl_cplx);
=for bad
Cbmul does not process bad values.
It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles.
=cut
*Cbmul = \&PDL::Cbmul;
=head2 Cbscale
=for sig
Signature: (a(n); b())
=for ref
Complex inplace multiplaction by real.
=for usage
Cbscale($a_pdl_cplx,$b_pdl_real);
=for bad
Cbscale does not process bad values.
It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles.
=cut
*Cbscale = \&PDL::Cbscale;
=head2 Cconj
=for sig
Signature: (a(n); [o]c(n))
=for ref
Complex conjugate.
=for usage
$out_pdl_cplx = Cconj($a_pdl_cplx);
=for bad
Cconj does not process bad values.
It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles.
=cut
*Cconj = \&PDL::Cconj;
=head2 Cbconj
=for sig
Signature: (a(n))
=for ref
Complex inplace conjugate.
=for usage
Cbconj($a_pdl_cplx);
=for bad
Cbconj does not process bad values.
It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles.
=cut
*Cbconj = \&PDL::Cbconj;
=head2 Cexp
=for sig
Signature: (a(n); [o]c(n))
=for ref
Complex exponentation.
=for usage
$out_pdl_cplx = Cexp($a_pdl_cplx);
=for bad
Cexp does not process bad values.
It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles.
=cut
*Cexp = \&PDL::Cexp;
=head2 Cbexp
=for sig
Signature: (a(n))
=for ref
Complex inplace exponentation.
=for usage
$out_pdl_cplx = Cexp($a_pdl_cplx);
=for bad
Cbexp does not process bad values.
It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles.
=cut
*Cbexp = \&PDL::Cbexp;
=head2 Cmod
=for sig
Signature: (a(n); [o]c())
=for ref
modulus of a complex piddle.
=for usage
$out_pdl_real = Cmod($a_pdl_cplx);
=for bad
Cmod does not process bad values.
It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles.
=cut
*Cmod = \&PDL::Cmod;
=head2 Carg
=for sig
Signature: (a(n); [o]c())
=for ref
argument of a complex number.
=for usage
$out_pdl_real = Carg($a_pdl_cplx);
=for bad
Carg does not process bad values.
It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles.
=cut
*Carg = \&PDL::Carg;
=head2 Cmod2
=for sig
Signature: (a(n); [o]c())
=for ref
Returns squared modulus of a complex number.
=for usage
$out_pdl_real = Cmod2($a_pdl_cplx);
=for bad
Cmod2 does not process bad values.
It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles.
=cut
*Cmod2 = \&PDL::Cmod2;
;
=head1 AUTHOR
Copyright (C) 1999 Christian Pellegrin, 2000 Christian Soeller.
All rights reserved. There is no warranty. You are allowed
to redistribute this software / documentation under certain
conditions. For details, see the file COPYING in the PDL
distribution. If this file is separated from the PDL distribution,
the copyright notice should be included in the file.
=cut
# Exit with OK status
1;
|