Most likely it is something very easy I am missing but searched carefully the manual and couldn’t find a function to “de-vectorize” a vector of strings
Starting let’s say with
a = ["X", "Y", "Z"] b = [a]
now b == [["X", "Y", "Z"]]. I would like to find a function f(.) such that
These are two different operations, which one do you want?
The second one is just splatting f(a) = (a...) should do it, though the function would not be type stable and it is not something you should do a lot if you care about performance.
b[1] will be equal to a so f(a) = 1 works for the first one. Not sure how do you want it to depend on a…
Actually I guess you mean [f(a)] instead of b[f(a)]? That’ll match slightly better with the other version. If this is true, then no it’s impossible, [f(a)] will always return a single element array, no exceptions (unless you break the internal implementation since this behavior is implemented in julia after all), so you cannot make it equal to a multiple element array. [a...] would be the closest to what you are asking for but is strongly recomented against if you want to do this many times. [a;] is also equivalent in this case and should be much faster. Of course neither of them are useful since these are just fancy/inefficient ways to spell copy(a). You need to be more specific about your actual problem.
I wouldn’t care about the splatting penalty here. It would give performance problems if you were doing really fast operations in a loop, but here you’re just pulling out a column. Splat and call it a day. Of you need something more, come back to this later and just loop.
Thank you both very much. Indeed this is the case. I’ll be splatting around just a few times. But although I can cope with the lack of elegance, the lack of performance is conceptually somewhat annoying.
Could your vector a perhaps be replaced with a tuple instead? I’m not sure of all the details, but I think splatting with tuples is likely to be more efficient because their size is known at compile-time. Here’s a really simple example: