~ubuntu-branches/ubuntu/lucid/pdl/lucid

« back to all changes in this revision

Viewing changes to Basic/Complex/complex.pd

  • Committer: Bazaar Package Importer
  • Author(s): Henning Glawe
  • Date: 2003-12-13 22:25:41 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20031213222541-m2sq55fevk74h93c
Tags: 1:2.4.0-1
* new maintainer (Closes: #215543)
* acknowlege NMU (Closes: #141117, #104630, #140104, #170182)
* new upstream release.
* enable plplot support (Closes: #196185)
* enable gsl support
* enable fftw support
* swap out m51.fits and COPYING, taken from PDL CVS HEAD (Closes: #223793)

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
# pp_setversion $VERSION;  # haven't worked out why it breaks my system (CS)
4
4
pp_beginwrap; # required for overload to work
5
5
 
 
6
# pp_def functions go into the PDL::Complex namespace
 
7
# to avoid clashing with PDL::FFTW funcs of the same name that go
 
8
# into the PDL namespace
 
9
# it should be of no effect to the user of the module but you
 
10
# never know....
 
11
pp_bless('PDL::Complex');
6
12
pp_addpm {At => Top}, <<'EOD';
7
13
=head1 NAME
8
14
 
220
226
if you don't want this.
221
227
 
222
228
 
 
229
=head2 complex real-valued-pdl
 
230
 
 
231
Cast a real-valued piddle to the complex datatype I<without> dataflow
 
232
and I<inplace>. Achieved by merely reblessing a piddle. The first dimension of
 
233
the piddle must be of size 2.
 
234
 
223
235
=head2 real cplx-valued-pdl
224
236
 
225
 
Cast a complex vlaued pdl back to the "normal" pdl datatype. Afterwards
 
237
Cast a complex valued pdl back to the "normal" pdl datatype. Afterwards
226
238
the normal elementwise pdl operators are used in operations. Dataflow
227
239
to the real parent works. Use C<sever> on the result if you don't want this.
228
240
 
229
241
=cut
230
242
 
 
243
use Carp;
231
244
sub cplx($) {
 
245
  return $_[0] if UNIVERSAL::isa($_[0],'PDL::Complex'); # NOOP if just piddle
 
246
  croak "first dimsize must be 2" unless $_[0]->dims > 0 && $_[0]->dim(0) == 2;
232
247
   bless $_[0]->slice('');
233
248
}
234
249
 
 
250
sub complex($) {
 
251
  return $_[0] if UNIVERSAL::isa($_[0],'PDL::Complex'); # NOOP if just piddle
 
252
  croak "first dimsize must be 2" unless $_[0]->dims > 0 && $_[0]->dim(0) == 2;
 
253
  bless $_[0];
 
254
}
 
255
 
235
256
*PDL::cplx = \&cplx;
 
257
*PDL::complex = \&complex;
236
258
 
237
259
sub real($) {
 
260
  return $_[0] unless UNIVERSAL::isa($_[0],'PDL::Complex'); # NOOP unless complex
238
261
   bless $_[0]->slice(''), 'PDL';
239
262
}
240
263
 
243
266
pp_def 'r2C',
244
267
       Pars => 'r(); [o]c(m=2)',
245
268
       Doc => 'convert real to complex, assuming an imaginary part of zero',
246
 
       PMCode => 'sub PDL::r2C($) { my $r = __PACKAGE__->initialize; &PDL::_r2C_int($_[0], $r); $r }',
 
269
       PMCode => << 'EOPM',
 
270
 
 
271
*PDL::r2C = \&PDL::Complex::r2C;
 
272
sub PDL::Complex::r2C($) {
 
273
  return $_[0] if UNIVERSAL::isa($_[0],'PDL::Complex');
 
274
  my $r = __PACKAGE__->initialize;
 
275
  &PDL::Complex::_r2C_int($_[0], $r);
 
276
  $r }
 
277
 
 
278
EOPM
247
279
       Code => q!
248
280
          $c(m=>0) = $r();
249
281
          $c(m=>1) = 0;
253
285
pp_def 'i2C',
254
286
       Pars => 'r(); [o]c(m=2)',
255
287
       Doc => 'convert imaginary to complex, assuming a real part of zero',
256
 
       PMCode => 'sub PDL::i2C($) { my $r = __PACKAGE__->initialize; &PDL::_i2C_int($_[0], $r); $r }',
 
288
       PMCode => '*PDL::i2C = \&PDL::Complex::i2C; sub PDL::Complex::i2C($) { my $r = __PACKAGE__->initialize; &PDL::Complex::_i2C_int($_[0], $r); $r }',
257
289
       Code => q!
258
290
          $c(m=>0) = 0;
259
291
          $c(m=>1) = $r();
357
389
pp_def 'Ccmp',
358
390
        Pars => 'a(m=2); b(m=2); [o]c()',
359
391
        GenericTypes => [F,D],
360
 
        Doc => 'Complex comparison oeprator (spaceship). It orders by real first, then by imaginary.',
 
392
        Doc => 'Complex comparison oeprator (spaceship). It orders by real first, then by imaginary. Hm, but it is mathematical nonsense! Complex numbers cannot be ordered.',
361
393
        Code => q^
362
394
           $GENERIC() a, b;
363
395
           
687
719
        OtherPars => 'int n => n',
688
720
        GenericTypes => [F,D],
689
721
        Doc => 'Compute the C<n> roots of C<a>. C<n> must be a positive integer. The result will always be a complex type!',
690
 
        PMCode => q^sub PDL::Croots($$) {
 
722
        PMCode => q^sub PDL::Complex::Croots($$) {
691
723
           my ($pdl, $n) = @_;
692
724
           my $r = PDL->null;
693
 
           &PDL::_Croots_int($pdl, $r, $n);
 
725
           &PDL::Complex::_Croots_int($pdl, $r, $n);
694
726
           bless $r;
695
727
        }^,
696
728
        Code => q^
723
755
 
724
756
=cut
725
757
 
726
 
sub re($) { bless $_[0]->slice("(0)"), 'PDL' }
727
 
sub im($) { bless $_[0]->slice("(1)"), 'PDL' }
 
758
sub re($) { bless $_[0]->slice("(0)"), 'PDL'; }
 
759
sub im($) { bless $_[0]->slice("(1)"), 'PDL'; }
 
760
 
 
761
*PDL::Complex::re = \&re;
 
762
*PDL::Complex::im = \&im;
728
763
 
729
764
EOD
730
765
 
795
830
   bless PDL->null, $_[0];
796
831
}
797
832
 
 
833
my $i;
798
834
BEGIN { $i = bless pdl 0,1 }
799
835
sub i () { $i->copy };
800
836