in reply to Re^4: Can I speed this up? (repetitively scanning ranges in a large array)
in thread Can I speed this up? (repetitively scanning ranges in a large array)

does have coordinate 100.

Wait, are your suggesting to use the 2nd to 101st index for coordinates 1 to 100? And here I thought the alternative would have been to to use the 1st index to the 100th index for coordinates 1 to 100. That's even worse. You can't use the mod at all even though the situation calls for it.

not all genomes are circular. What would you do about those?

It's not relevant, but I'd use the first index of the array for the first element of the genome. I'd personally use that for circular genomes too. What I did was propose a compromise.

(if the genome is circular scalar(@arr) == genome size, but if it's linear scalar(@arr) == genome size + 1). Confusing...

Exactly. The size of the genome (@genome) should be the size of the genome.

Anyway, I must admit I'm not sure why are we focusing on this.

To point out how silly it is to be focusing on such.

But it is pertinent, as choosing a bad coordinate system will just add operations, slowing things down.

  • Comment on Re^5: Can I speed this up? (repetitively scanning ranges in a large array)

Replies are listed 'Best First'.
Re^6: Can I speed this up? (repetitively scanning ranges in a large array)
by daverave (Scribe) on Nov 03, 2010 at 06:43 UTC
    Of course I can use the modulo operator (and I sure do). Anyway, this is a matter of taste. I originally used something like you suggested but later found it more convenient to have $genome$i always refer to genomic position $i, regardless if the genome is linear or circular (I have both kinds).

    I don't think I pay any performance price and it's more straightforward for me to be consistent with the biological conventions.

      Of course I can use the modulo operator (and I sure do).

      I suppose you're right. It'll just look like

      (x - 1) % size + 1
      instead of
      x % size

      I don't think I pay any performance price

      Well, there are more ops, but the real cost is the complexity and clarity due to working with off-by-one numbers (first element of genome in second element of array).