Message Boards Message Boards

0
|
3087 Views
|
1 Reply
|
0 Total Likes
View groups...
Share
Share this post:

How to convert the ListVector into PackedArray in FunctionCompile?

Posted 2 years ago

Cross post here


I have a compile function cf to calculate the mean for a ragged list:

groups = N[{{40, 23, 213, 79, 18, 152, 105, 191, 119, 243}, {86, 3, 152, 89, 
     52, 36, 132, 196, 159, 108, 200}, {253, 223, 167, 197, 147, 112, 
     225, 98, 159, 163, 245, 240, 267}, {89, 164, 156, 124, 15, 253, 
     41, 171, 209, 132}}];

cf = FunctionCompile[
  Function[Typed[groups, "ListVector"::["ListVector"::["Real64"]]], 
   Mean[Cast[Catenate[groups], "PackedArray"::["Real64", 1]]]]]

cf[groups]

141.955

It works indeed. But I have to use a highly in-efficient "ListVector"::["ListVector"::[*]] for the following Catenate. Then I have to use a very time-consuming Cast for the following Mean in the code. This leads to disastrous efficiency:

lis = DeleteCases[Table[ResourceFunction["RandomSplit"][RandomReal[255, 1000], 10],100000], {}, {2}];

Timing[Mean@*Catenate /@ lis;]
Timing[cf /@ lis;]

{2.70313, Null}

{9.92188, Null}

This is obviously a bit unbearably slow. I note the documentation of "ListVector": enter image description here So I think there must be a more efficient way to replace Cast, but the documentation is not perfect at the moment and I can't find any relevant examples to do this. Can anyone help me?


It would be nice to get an official response

POSTED BY: Yode Japhe
Posted 1 year ago

And then hopefully this problem will be solved

POSTED BY: Yode Japhe
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract