Performing string operations in Dyalog
I have 2 questions related to matching character vectors in APL Dyalog. The following code will compare character vectors in turn:
a←'ATCG'
b←'GTCA'
a=b
- To speed up ( in the case of 2 vectors, and also in the case of comparing many vectors with one vector ), should one convert the character vector to a numeric vector or win 'doesn't matter in APL (similar to comparing characters in C)?
- I am comparing DNA sequences (which can only consist of the letter from
ATCG
). Is there something I can do to speed up various operations on such vectors?
+3
source to share
1 answer
Interestingly, on my (old) version of Dyalog APL, converting characters to small integers is actually 25% faster. It may have sped up in later versions.
Try
a <- []av iota 'ATCG' // sorry, no apl characters
b <- []av iota 'GTCA'
a = b
Make sure the largest value is less than 128.
To check that you have the smallest possible representation of integers, use the [] dr function. [] dr a should return 82 for integer -128 <= x <= 127.
Dyalog APL automatically converts to the largest possible maximum width.
+1
source to share