PDA

View Full Version : Perl --> Timing a Matrix Inversion



danbaron
29-06-2010, 07:35
[font=courier new][size=8pt]I ran the following Perl program.

On my computer, it took 288.103 seconds, to fill a 1000 x 1000 matrix with random doubles,
and then to invert it.

Perl 5.10.1
PDL 2.4.6

http://www.perl.org/

You have to install "PDL" (Perl Data Language), separately. It is not included in the Perl distribution.

http://pdl.perl.org/


use PDL;

my $t = times();
$a = zeroes(double, 1000, 1000);
$a = random($a);
$a = inv($a);
$t = times() - $t;
print $t;
my $dump = <STDIN>;

# Output = 288.103 (seconds)


[font=courier new][size=8pt]PDL, in Perl, corresponds to, NumPy, in Python.

Look at the link below, to see the results of a similar program, written in Python.
According to this test, PDL, is amazingly slow, compared to, NumPy.
(I feel bad for PDL, but, what can I do?)

:oops: :x :grrrr:
Dan

http://community.thinbasic.com/index.php?topic=3485.msg25776;topicseen#msg25776

zak
29-06-2010, 09:13
i have tried your program, it gives me 305.75 seconds, i was about to close it because it heats my cpu.
we can ask perlmonks.com may be someone have more efficient way.
regards

ErosOlmi
29-06-2010, 13:31
Didn't check results if they are ok or not but here a possible thinBasic example.
On my machine it takes about 35 seconds



Uses "console"
Uses "math"
Uses "stat"

Dim T1 As Double = Timer
Dim T2 As Double = T1

Dim MaxX As Long = 1000
Dim MaxY As Long = 1000

PrintL "Defining matrix a and b:", MaxX, "by", MaxY
Dim a(MaxX, MaxY) As Double
Dim b(MaxX, MaxY) As Double

PrintL "Filling matrix a with", Format$(MaxX * MaxY), "numbers"
Stat_Random(a, 1, MaxX * MaxY, Timer)

PrintL "Inverting matrix a to b"
MAT b() = INV(a())

T2 = Timer

PrintL Format$(T2 - T1)
WaitKey

zak
29-06-2010, 14:35
it takes 78.58 seconds running Eros example, even my desktop pc is a dual core 3 Ghz, 2MB cache, BUT Old version cpu, winxp 32 bit, the modern cpu 2.2 Ghz are much speedier.

Michael Clease
29-06-2010, 15:29
Eros your example took 41.5 seconds on my work pc.

Petr Schreiber
29-06-2010, 16:42
Interesting problem,


on PC in my signature (Sempron 3400+, WinXP 32bit): 96.1s
on my notebook (Intel Core 2 Duo T6600, Win7 64bit): 43.1s


Matrix inversion is quite intensive algorithm.


Petr