Jump to content

casting to string in vex?


Aearon

Recommended Posts

is there anyway to cast an integer to string in vex?

i'm trying to do an equivalent of the partition sop in vex using something like:

string grpname = "grp" + (string) ptnum;

addgroup(grpname,ptnum)

(this is just a simple example that would create a group per point named grp$PT in expression speak)

is this possible? casting to string like that doesn't seem to work.

Edited by Aearon
Link to comment
Share on other sites

is there anyway to cast an integer to string in vex?

take a look at the sprintf function:

string mystring = sprintf("grp%d", pnum);

it should do what you want.

Looking forward to see what you're up to ...

Link to comment
Share on other sites

hm... weird stuff happening now.

i have this code:

printf("grp%d\n",ptnum);
addgroup(sprintf("grp%d", ptnum),ptnum);

the printf generates the expected output (grp0,grp1,...,grp1042)

i have 1043 points so everything seems correct

but the groups created look like this:

256 points in grp0
256 points in grp256
256 points in grp768
19 points in grp1024

Link to comment
Share on other sites

hm possible. maybe it executes blocks of 256 points at a time? interesting!

ptnum is just the global var. the two lines are all the code there is.

Looks like the optimizer thinks some part of your code is not worthy of inclusion :)

Anyway, this hack seems to work (tried it in an InLine VOP inside a VopSop):

if(!ptnum) {
   int i;
   for(i=0;i<Npt;i++) {
	  addgroup(sprintf("grp%d",i),i);
   }
}

Link to comment
Share on other sites

why:

if(!ptnum) {

Is ptnum set later to execute it just once?

Not sure I understand the question. My thought behind it was that even if a bunch of threads (or "virtual processors" in SIMD) were spawned, one per point, that conditional would still only be true for just one of them. And ptnum is only referenced that one time (the local variable "i" takes over after that).

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...