Hi January,

Something like the following might work and should be faster:

$score = sequence 2,2; # some random scores
$p = pdl [0,1,1,1];
$q = pdl [0,0,1,1];

$matrix = $score->index2d($p->dummy(1),$q->dummy(0));

The key is to use vectorized operations instead of individual  
assignments. Perhaps you can try to work out how the above example  
works by experimenting a bit and looking up some of the functions  
that are called.

Hope this works,

Christian

On 11/02/2008, at 12:03 AM, January Weiner wrote:

> Dear Karl,
>
>> If you write things in the same element by element way as regular  
>> Perl
>> then PDL will be even slower. set() and at() are functions of last
>> resort.
>
> Thanks for the explanation.
>
>> The idea of PDL is  to use fast internal functions for vector ops.
>> What you want can be accomplished in one line with PDL's
>> Image2D::conv2d(...) and will be a bazillion times faster than  
>> regular
>> perl
>
> I imagined so much (although I just considered adding up slices of the
> matrix which would have the same effect). But this is not even the
> step that takes the most time. The initial filling up of the matrix
> with scores is what really takes a lot time.
>
> I have one scoring matrix, 20x20 (call it $scoring), containing a
> score for each pair of the amino acids. I have two sequences, which
> constitute the matrix that I am calculating. For each two amino acids
> from the two sequences, I look up the scoring matrix and enter the
> respective value into my main matrix ($matrix). I can't imagine of a
> way of doing it fast if set() and at() is slow. Is an assignement
> between elements of two piddles faster? Like that:
>
>


_______________________________________________
Perldl mailing list
[email protected]
http://mailman.jach.hawaii.edu/mailman/listinfo/perldl

Reply via email to