~ubuntu-branches/ubuntu/trusty/pdl/trusty-proposed

« back to all changes in this revision

Viewing changes to .pc/callext_compile_options.patch/t/callext.t

  • Committer: Package Import Robot
  • Author(s): Henning Glawe
  • Date: 2013-11-11 13:34:09 UTC
  • mfrom: (2.1.14 sid)
  • Revision ID: package-import@ubuntu.com-20131111133409-kjib7wtpms3kwusg
Tags: 1:2.007-2
* successfully built with gcc 4.8 (closes: #701335, #713346)
* add build log evalution helpers to source package: extract
  test suite output from buildlog, cross-refernce test/subtest
  failures between architectures
* use shell to join stderr into stdout while running test suite
* fix Dumper.pm on kfreebsd: 'gnukfreebsd' was assumed as a bsd
  userland, which disabled/broke calls to 'uuencode' and 'uudecode'
* fix debian/filter-test.pl, which cut the test log too early
  due to a too-unspecific regex
* prefer F77Conf over ExtUtils::F77 in t/flexraw_fortran.t in order
  to prevent test failures on kfreebsd* and hurd*

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/local/bin/perl
 
2
 
 
3
END { unlink 't/callext.pdb';}; # In case we build a 2nd time,
 
4
                                # but using a different Microsoft compiler
 
5
 
 
6
# Example of how to use callext() - also see callext.c
 
7
 
 
8
use strict;
 
9
use Test;
 
10
use Config;
 
11
 
 
12
BEGIN { plan tests => 1;
 
13
}
 
14
use PDL;
 
15
use PDL::CallExt;
 
16
 
 
17
use PDL::Core ':Internal'; # For topdl()
 
18
use Config;
 
19
use File::Spec;
 
20
 
 
21
kill 'INT',$$ if $ENV{UNDER_DEBUGGER}; # Useful for debugging.
 
22
 
 
23
sub tapprox {
 
24
        my($a,$b) = @_;
 
25
        my $c = abs($a-$b);
 
26
        my $d = max($c);
 
27
        $d < 0.01;
 
28
}
 
29
 
 
30
# Create the filenames
 
31
my $cfile = File::Spec->catfile('t', 'callext.c');
 
32
# include the pdlsimple.h that's in blib.
 
33
my $inc = File::Spec->catdir('blib', 'lib', 'PDL', 'Core');
 
34
my $out   = File::Spec->catfile('t', 'callext.'.$Config{dlext});
 
35
 
 
36
# Compile the code
 
37
 
 
38
callext_cc($cfile, "-I$inc", '', $out);
 
39
 
 
40
my $y = sequence(5,4)+2;  # Create PDL
 
41
my $x = $y*20+100;        # Another
 
42
 
 
43
my $try    = loglog($x,$y);
 
44
my $correct = log(float($x))/log(float($y));
 
45
 
 
46
print "Try = $try\n";
 
47
print "Correct = $correct\n";
 
48
ok( tapprox($try, $correct) );
 
49
 
 
50
# Return log $x to base $y using callext() routine -
 
51
# perl wrapper makes this nice and easy to use.
 
52
 
 
53
sub loglog {
 
54
 
 
55
   die 'Usage: loglog($x,$y)' if scalar(@_)!=2;
 
56
 
 
57
   # Tips:
 
58
   #
 
59
   # (i)  topdl() forces arguments to be pdl vars even
 
60
   #      if ordinary numbers are passed
 
61
   #
 
62
   # (ii) float() forces the pdl vars to be float precision
 
63
   #      thus matching the C routine.
 
64
 
 
65
   my $x = float(topdl(shift));
 
66
   my $y = float(topdl(shift));
 
67
 
 
68
   my $ret = $x->copy; # Make copy of $x to return
 
69
 
 
70
   print "X = $x\n";
 
71
   print "Y = $y\n";
 
72
 
 
73
   my $ldfile =
 
74
   callext($out, "loglog_ext", $ret, $y);
 
75
 
 
76
   return $ret;
 
77
}