Category
Function
Evaluates an expression on each data point in a specified field or value list.
Syntax
output = Compute(expression, input, ...);
Inputs
Name | Type | Default | Description |
---|---|---|---|
expression | string | none | expression to be computed |
input | field or value list | no default | input value |
... | ... | ... | more input values |
Outputs
Name | Type | Description |
---|---|---|
output | field, value, or value list | output values |
Functional Details
This module applies an expression to every data value in a field.
expression | is the mathematical expression to be applied to input. Table 1 lists the operators. |
input | is the field or value list to which expression is to be applied. If there are more than one, the input fields must be isomorphic (i.e., their hierarchies must match exactly). |
In the user interface, variables have names and expression does not require quotation marks. If the vector variable is "sample," the vector elements are "sample.x," "sample.y," ... or "sample.0," "sample.1," ....
In the scripting language, the parameters of an expression are indicated by $n, where n is the index of the parameter, and counting begins at 0. The first three components of a vector can be expressed by ".x," ".y," and ".z," or by ".0," ".1," and ".2." The syntax for creating a vector from multiple inputs is [$0, $1, $2, ... ], where the commas separators are required.
Thus, in the user interface the expression used to add the value 3 to every data value of the input field would be "a + 3.," while in the scripting language it would be "$0 + 3."
Multiple expressions can be entered if they are separated by semicolons; the final expression is used as the output. For example, "temp=a.x; sin(temp)" is equivalent to "sin(a.x)".
Compute uses C-language-style order of precedence for mathematical operations.
Operations applied to invalid elements of fields typically result in invalid elements. (For more information, see "Invalid Positions and Invalid Connections Components" in the IBM Visualization Data Explorer User's Guide.) For example, if at a particular element field "a" and "c" are valid, but field "b" is not, "a+b" is invalid, and "a? b: c" is valid only if "a" is 0; otherwise, it is invalid. An exception is the "invalid" function, which returns the integer 1 if the entry is invalid and 0 otherwise.
Operations such as multiplying a vector by a scalar have the expected effect: each element of the vector is multiplied by the scalar. Likewise, the addition of two equal-length vectors or equal-size matrices results in an element-by-element sum. The Compute module defines the multiplication (*) of two equal-length vectors as an element-by-element multiplication (as opposed to the dot product). Other operations, such as the sine of a vector, are defined similarly.
Constants may be specified as double precision by using scientific notation with "d" indicating the exponent (e.g., 1d0 is double-precision 1).
Note that you can convert a "ref" type invalid component (see "Invalid Positions and Invalid Connections Components" in IBM Visualization Data Explorer User's Guide) using the expression "byte (invalid (a))". Then use Replace to substitute this new array into the original field as the "invalid positions" or "invalid connections" component.
Table 1. Operators for
the Compute Module
Functions | Types of Operands | |
---|---|---|
Trigonometric Functions (argument in radians) | ||
sin(a), cos(a), tan(a), asin(a), acos(a), atan(a), atan2(a, b) | float, double
| |
Hyperbolic Functions | ||
sinh(a), cosh(a), tanh(a) | float, double
| |
Logarithmic Functions | ||
log(a), In(a) (natural logarithm), log10(a) | ||
(log base 10--see
Note 1), exp(a)
| float, double | |
IEEE inquiry functions | ||
isnan(a), finite(a) | float, double
| |
Unary Functions | ||
+a, -a (negation) | any type
| |
Binary Functions | ||
a+b, a-b, a*b, a/b, a%b (modulus--see Note 1), | ||
a^b or a**b
(exponentiation--see Note 4)
| any type | |
Vector Functions (see Note 1) | ||
a dot b or dot(a, b) | float vector | |
a cross b or cross(a,b) | float 3-vector | |
mag(a) | double, float vector | |
norm(a) | float vector
| |
Miscellaneous Functions | ||
sqrt(a) | float, double, complex | |
pow(a, b) (see Note 4) | float, double, complex | |
abs(a) (see Note 2) | double, float, integer, complex | |
arg(a) | complex only | |
sign(a) | all real types | |
min(a, b, ...), max(a, b, ...) | scalar | |
invalid(a) (see Note 5) | any type | |
random(a,seed) (see note 8) | produces random
values in the range
0<=r<1 for each item in a.
| |
Type Manipulation Functions | ||
int(a), float(a), byte(a), char(a), double(a), short(a), | float, integer, byte, | |
sbyte, ubyte, ushort, uint (see Note 6) | short, double | |
trunc(a), floor(a), ceil(a), rint(a) | float, double | |
complex(a,b) or complex(a), | float, integer, byte, short, double | |
real(a) | complex only | |
imag(a) | complex only
| |
Vector Construction | ||
[a, b, ...] | any type
| |
Vector Selection Functions | ||
a.x or a.0, a.y or a.1, and so on | vector | |
select(a,b) (selects bth element of a, | ||
where element is of rank r-1) | a is a vector, b is
an integer
| |
Conditional Functions | ||
a?b:c
if a != 0, then b, else c. (b and c must be of the same type.) Expressions b and c are always evaluated, and the output value depends on the value of a.
| a is an integer | |
Logical Operations | ||
binary: <, >, <=, >= (true = 1; false = 0) | any scalar type | |
binary: ==, != | any type | |
Unary: ! (not), binary: && (and), || (or) | integer
| |
Bitwise Operations | ||
and(a,b), xor(a,b), or(a,b), not(a) (one's complement) | byte, int
| |
String functions (see Note 7) | ||
strcmp(a,b)
compares strings a and b and returns 0 if a==b, a negative integer if a<b, and a positive integer if a>b stricmp is identical to strcmp except that it ignores case | strings | |
strlen(a)
returns the length of string a | string | |
strstr(a,b)
finds substring b in string a and returns 1-based offset of b in a. Thus strstr('artist','art') = 1 strstr('artist','picasso') = 0 strstr('monet','one') = 2 stristr(a,b) is identical to strstr except that it ignores case | strings
| |
Notes:
|
A single Compute module can operate on a maximum of 21 ...Input values. The default number of enabled input tabs is two. (Tabs can be added to the module icon and removed with the appropriate ...Input Tab options in the Edit pull-down menu of the VPE.)
Note: | Other than a divide by zero, Compute operations are unchecked. |
Components
Modifies the "data" and "invalid positions" or "invalid connections" components. All other components are propagated to the output.
Script Language Examples
tempf = Compute("$0*(9.0/5.0) + 32", tempc); ·
new_field = Compute("$0.5",field);
new_field = Compute("[2*$0.x, $0.y, $0.z]", field);or
new_field = Compute("[2, 1, 1]*$0", field);
new_field = Compute("mag($0) + $1/($2*4.5)", field1, field2, field3);
· slice = Slice(electrondensity, "z", 5); // Mark the positions so that they can be computed on // The original x positions go from -1 to 2.9 // The original y positions go from -3 to 2.9 markedslice = Mark(slice,"positions"); // Warp the positions onto the shape of a cylinder pi = 3.14159; exp = "[sin(2*$1*($0.x+1)/3.9), $0.y, -cos(2*$1*($0.x+1)/3.9)]"; warped = Compute(exp, markedslice, pi); // Unmark the warped positions, returning them to the positions // component warped = Unmark(warped, "positions"); ·
· // Now warp the positions onto the shape of a doubled cone // by multiplying the x and z positions by the original // y value, which goes from -3 to 2.9 exp = "[$0.y*sin(2*$1*($0.x+1)/3.9),$0.y, -$0.y*cos(2*$1*($0.x+1)/3.9)]"; warped = Compute(exp, markedslice, pi); // Unmark the warped positions, returning them to the positions // component warped = Unmark(warped, "positions"); ·
Example Visual Programs
Many of the example visual programs use Compute, including:
ComputeOnData.net DataDrivenInteractors.net PlotTwoLines.net WarpingPositions.net
See Also
[ OpenDX Home at IBM | OpenDX.org ]