Jump to content

Double values in arrays


konstantin magnus

Recommended Posts

How can I prevent double values in vex arrays? Also is there a way to sort them out afterwards?

int collect[];
int pt_prims[] = pointprims(0, @ptnum);
foreach(int pt_prim; pt_prims) {
    int prim_pts[] = primpoints(0, pt_prim);
    foreach(int prim_pt; prim_pts) {
        append(collect, prim_pt);
    } 
}

 

vex_tree_connect.hipnc

Edited by konstantin magnus
Link to comment
Share on other sites

I'm not in front of a machine right now but could you use removevalue? Inside the second foreach do something like (pseudo code):

Int temp_collect[] = collect

Int has_value = removevalue(prim_pt, temp_collect)

If (has_value == 0) [append(collect, prim_pt)]*

*No curly braces on my phone!

 

Link to comment
Share on other sites

Thank you both! 

1 hour ago, petz said:

for large arrays you might be better off using python/numpy since vex gets slow at some point ...

I intend to use lots of small arrays. Say 500 individual trees with an average of 10 branches (each branch fusing to an array of 8 points). Does this sound more like numpy (never used it so far) or can one keep this responsive using VEX?

Link to comment
Share on other sites

27 minutes ago, konstantin magnus said:

I intend to use lots of small arrays. Say 500 individual trees with an average of 10 branches (each branch fusing to an array of 8 points). Does this sound more like numpy (never used it so far) or can one keep this responsive using VEX?

lots of small arrays are not a problem at all in vex. for searching and sorting arrays with more than 1024 entires (somehow the magical number last time i checked) it might be better to use python/numpy, depending on the situation ...

Link to comment
Share on other sites

  • 2 weeks later...
On 12/10/2016 at 9:50 PM, petz said:

attached is one possibility.
for large arrays you might be better off using python/numpy since vex gets slow at some point ...

vex_tree_connect1.hipnc

I found another vex method, about 10-15% faster than geo2/attribwrangle4 in your file:

int collect[], prims[], points[], i, collectSort[], collectFin[];
prims = pointprims(0, @ptnum);
foreach(int prim; prims)
{
    points = primpoints(0, prim);
    for( i = 0; i < len(points); i++)
    {
        if(points[i] != @ptnum)
            append(collect, points[i]);
    }
}

collectSort = argsort(collect);
for(i = 0; i< len(collect) ; i++)
{
    if(i == 0 || collect[ collectSort[i]] != collect[ collectSort[i-1]])
        append(collectFin, collect[ collectSort[i] ]);
}

i[]@collect = collectFin;

it does output the array in a slightly different order though, and I'm not sure if it will work the same way with a string array, but its an idea :P

Edited by acey195
Link to comment
Share on other sites

3 minutes ago, konstantin magnus said:

Great, thanks! Do you see any way of preventing to store double values right from the start? or would this be even slower?

well that is basically what (one of) petz's method(s) was doing, but the more often you have to search the array, the slower it will be.

In my method, I do prevent putting the processed point itself in the array, but that's it.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...