09-11-2010 12:56 AM
I have a cluster with all U16 and U16 Enum. When I use the cluster to array funciton, there was an error. I believe that the error was due to the U16 enum in the cluster. How do I fix that?
Yik
09-11-2010 01:41 AM
An Enum is not an integer data type. Thus probably the source of your error.
09-11-2010 09:38 AM
@PJS wrote:
An Enum is not an integer data type. Thus probably the source of your error.
Whoops... Paul, the value of an enum is passed as a integer on every wire and every node! (it has a unique display format for the number that looks up an array of strings)
Cluster to array requires the cluster members to all be of the same data type. An array can only contain elements with identical properties. So if you have a cluster of strings you can convert to an array of strings. If you have an cluster of String, U32, DBL, Varient, Array[EXT] you will get an error. A cluster of {str-type-defA enum of U16,and U16} cast to an array would require a type cast (coersion) of one element since the display properties are dissimillar on the cluster contents.
09-11-2010 10:44 AM
Really? if so, using an enum of type (U32 for example) should be able to be in an cluster of other U32 elements and the cluster to array function should work (but in actuality does not). It is a special data type, and as you said it below, MUST be coerced to the desired data type... before a the primitive mentioned originally will work. You can not and should not think of an enum as an integer.... If that is what you want, use a ring.
It is closely related to being an integer, but then again... only a half step closer than a boolean datatype.
@Jeff Bohrer wrote:
@PJS wrote:
An Enum is not an integer data type. Thus probably the source of your error.
Whoops... Paul, the value of an enum is passed as a integer on every wire and every node! (it has a unique display format for the number that looks up an array of strings)
Cluster to array requires the cluster members to all be of the same data type. An array can only contain elements with identical properties. So if you have a cluster of strings you can convert to an array of strings. If you have an cluster of String, U32, DBL, Varient, Array[EXT] you will get an error. A cluster of {str-type-defA enum of U16,and U16} cast to an array would require a type cast (coersion) of one element since the display properties are dissimillar on the cluster contents.
09-11-2010 11:28 AM - edited 09-11-2010 11:29 AM
Others have already explained why this will not work, but I am curious why you would want to do that? At a minimum, you'll lose all associated item names of the enum. So what good is that???
You can convert an cluster with all U32 numeric to an array of numerics or a cluster or all identical enums (differing only in value!) to an array of such enums. If even one enum had different items, things will again break.
If you only want to retain the value of the enum, you can use typecast, but this seems quite useless and dangerous.
Here's an example for "all U32". But why????
09-11-2010 02:24 PM
so as long as the enum is U16 like the other numeric, the type case won't become dangerous, right?
I have to convert to cluster to cluster because my function requires an array. I made the input a cluster, so that it would be more descriptive. Not sure is that the best way or not.
Yik
09-11-2010 03:35 PM
@jyang72211 wrote:
so as long as the enum is U16 like the other numeric, the type case won't become dangerous, right?
No, it's still dangerous because typecasting such as this is a fragile process. You create a house of cards where (inevitable) programming mistakes manifest themselves as run-time errors rather than design-time compile errors.
One step closer to a robust system would involve a type-covert prior to the typecast (see the bottom example). The middle example is dangerous because the output is sensitive to the enum representation.
Ultimately, I am skeptical of designs that rely upon the Cluster to Array prim, which often points to an underlying problem in data structure design (or the necessity to interface with a function over which you do not have control).
09-13-2010 09:19 AM
@PJS wrote:
Really? if so, using an enum of type (U32 for example) should be able to be in an cluster of other U32 elements and the cluster to array function should work (but in actuality does not).
The U32 and an Enum U32 have different properties. Specifically, the Strings[] and Strings and values[] properties of the enum do not exist in a U32 so they cannot be contained in the same array since elemtnets of an array must have identical properties.