First question,How to Compile this?
gather[data_]:=Gather[data, Mod[#1, 3] == Mod[#2, 3] &]
I dont know why this is wrong.
cf = Compile[{{data, _Integer, 1}}, Gather[data, Mod[#1, 3] == Mod[#2, 3] &]]
cf[Range[9]]
cf[Range[10]]
Second question,How to Compile this?
gather[data_] := Gather[data, Count[#1, 0] == Count[#2, 0] &]
gather[RandomInteger[{0, 5}, {10, 5}]]
Gatheris compilable. You can see a list of compilable functions in the answers to this question. – Mark McClure Mar 20 '14 at 13:59Gathercannot be compiled. The reason whyGatheris not compilable is that it returns a ragged array and compiled code doesn't support ragged arrays. – Szabolcs Mar 20 '14 at 13:59dataof the same length? This is necessary to make it compilable. Vectorization may be better though.Tally@Total[1-Unitize[data],{2}]should do it if I didn't make a mistake (untested). – Szabolcs Mar 20 '14 at 14:27