Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^2: PDL vs C speed question

by glwtta (Hermit)
on May 07, 2005 at 23:58 UTC ( [id://454943]=note: print w/replies, xml ) Need Help??


in reply to Re: PDL vs C speed question
in thread PDL vs C speed question

I don't think I understand your code - is @data the same as my @data?

I think what's confusing people here is the PDL notation - my fault, I should've given the pure Perl version - since $data[$i] and $data[$j] are PDL vectors, the '*' operator is overloaded to return a vector of the same length as its arguments, with every component being the product of the corresponding components of the input vectors. The sum() function simply returns the sum of the vector components.

The Perl version of my C example would look like this, assuming @data is an array of arrayrefs, rather than an array of PDL vectors:

for ($i = 0; i < @data; $i++) { for($j = $i + 1; $j < @data; $j++) { my $sum = 0; $sum += $data[$i][$_] * $data[$j][$_] for(0..@{$data[$i]}-1); my $pears = $sum / @{$data[$i]}; } }
I really don't think the math here can be simplified any more; or else I need to brush up on basic arithmetic :)

minor edit: forgot that square brackets get interpreted

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://454943]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2024-04-26 03:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found