I have a large byte array that I want to convert to a number array. I want
to use _ to indicate a bad value, but blank should be treated as 0
$ c
4862343 10
Instead of this:
asnumber =: _&".
asnumber (>' ';'bad';'10')
_ _ 10
I want this:
asnumber (>' ';'bad';'10')
0 _ 10
This works, but is much slower than I'd like -- nearly 3x slower than just
_ ".
asnumber =: _ ". '0' ,~^:([: */ ' '&=@])"1 ]
asnumber (>' ';'bad';'10')
0 _ 10
(6!:2) 'asnumber c'
3.32579
(6!:2) '_&". c'
1.35091
I have an isblank function that is fast
isblank =. ([: ({. -:"1 }.) ' '&,)
(6!:2) 'isblank c'
0.033164
I can't seem to combine the two into something that performs well without
doing things at the atom/row level instead of the entire array. I suspect
I'm getting tripped up by rank
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm