Math Operations with SiteData
The SiteData
type supports various math operations which include both binary and unary math operations.
Binary Math Operations with SiteData
The following table outlines the binary operator-based mathematical operations available for SiteData<T>
and specifies the permitted data types for T
for each operation.
Table of Binary Math Operations for SiteData:
Methods | Operator | Description | Supported Data Types |
---|---|---|---|
Add | + | Performs an add operation between every element in current SiteData object and the given value. |
double , decimal , float , int , unint ,long , ulong , byte , sbyte , short , ushort |
BitwiseAnd | & | Performs a bitwise AND operation with another SiteData object, for each element across each site. |
int , unint , long , ulong , byte , sbyte , short , ushort |
BitwiseOr | | | Performs a bitwise OR operation with another SiteData object, for each element across each site. |
int , unint , long , ulong , byte , sbyte , short , ushort |
BitwiseXor | ^ | Performs a bitwise XOR operation with another SiteData object |
int , unint , long , ulong , byte , sbyte , short , ushort |
Compare | Performs a compare operation between every element in current SiteData object and the given value. |
double , decimal , float , int , unint ,long , ulong , byte , sbyte , short , ushort |
|
Divide | / | Performs a divide operation between every element in current SiteData object and the given value. |
double , decimal , float , int , unint ,long , ulong , byte , sbyte , short , ushort |
Maximum | Returns the larger of the element in current SiteData object and the given value. |
double , decimal , float , int , unint ,long , ulong , byte , sbyte , short , ushort |
|
Minimum | Returns the smaller of the element in current SiteData object and the given value. |
double , decimal , float , int , unint ,long , ulong , byte , sbyte , short , ushort |
|
Multiply | * | Performs a multiply operation between every element in current SiteData object and the given value. |
double , decimal , float , int , unint ,long , ulong , byte , sbyte , short , ushort |
Power | Raises every element in current SiteData to the power of the given value. |
double , decimal , float , int , unint ,long , ulong , byte , sbyte , short , ushort |
|
Subtract | - | Subtracts the given value from every element in current SiteData object. |
double , decimal , float , int , unint ,long , ulong , byte , sbyte , short , ushort |
Usage Considerations for Binary Math Operations with SiteData
When performing binary math operations on SiteData
objects you should consider the following:
- The
SiteData
object on which the method operates, and the input argument provided to the method serve as the two operands in the binary math operation being performed. - All methods can accept either a scalar, an array, or
SiteData
object as an input argument. - Operators can only accept a scalar or
SiteData
object as the second operand. - When the input is a
SiteData
object it must match the same underlying type,T
, as theSiteData
object being operated on. - When both operands are scaler, they must have identical data types, and that data type must be supported by the desired method.
- When one of the operand is
SiteData<T>
and other operand is scaler, then both operand must be of identical data type,T
, and that data type must be supported by the desired method. - When the underlying data,
T
, of theSiteData<T>
object is an array type, if the second operand is:- Also an array type, the second operand must have the same length, dimensions, and underlying type as the array contained within the
SiteData<T>
object. - Scalar type, the scalar type must match the array element type of the underlining data within the
SiteData<T>
object. SiteData<T>
object, both operand objects must be of identical data types,T
.
- Also an array type, the second operand must have the same length, dimensions, and underlying type as the array contained within the
- The Bitwise methods are only supported when the underlying data type of the
SiteData
object,T
, is aninteger
type, either a scalar integer, array of integers, or anotherSiteData
object of the same integer type. - When the input argument is an array or a
SiteData
object of an array type, the array element data type must match the underlying type of theSiteData<T>
object,T
, and be of equal or lesser dimensions (i.e.TOther
cannot be 2D whenT
is 1D). - The
Divide
method returns a scalar double value per site by default. When the underlying data typeT
of theSiteData<T>
object is an array, theTResult
type must be explicitly specified as adouble
array with the same dimensions asT
. Otherwise, aNISemiconductorTestException
exception is thrown with exception message matching the exception scenarios of Mismatched Array Dimensions. Refer to theDivide<TOther, TResult>(TOther)
andDivide<TOther, TResult>(SiteData<TOther>)
method signatures in the API Reference documentation. - The
Compare
method returns aboolean
value per site by default. When the underlying data typeT
of theSiteData<T>
object is an array, the TResult type must be explicitly specified as aboolean
array with the same dimensions asT
. Otherwise, aNISemiconductorTestException
exception is thrown with exception message matching the exception scenarios of Mismatched Array Dimensions. Refer to theCompare<TOther, TResult>(ComparisonType, TOther)
andCompare<TOther, TResult>(ComparisonType, SiteData<TOther>)
method signatures in the API Reference documentation.
Note
For more information on specific exception conditions when preforming math operations refer to Exception Conditions For Math Operations.
Examples for Binary Math Operations with SiteData
Example of binary math operations ✔️ ALLOWED with SiteData
:
var siteData1 = new SiteData<int>(new int[] { 1, 2, 3 });
var siteData2 = new SiteData<int>(new int[] { 4, 5, 6 });
var operatorOverloadResult = siteData1 + siteData2;
// The operatorOverloadResult will be a SiteData<int> object containing three sites worth of scalar data equivalent to:
// { [0] = 5, [1] = 7, [2] = 9} }
var siteData3 = new SiteData<long[]>(new long[][] { new long [] { 1, 2, 3 }, new long [] { 4, 5, 6 } });
var siteData4 = new SiteData<long>(new long [] { 4, -5 });
var result = siteData3.Add(siteData4);
// The result will be a SiteData<long[]> object containing two sites worth of array data equivalent to:
// { [0] = {5, 6, 7}, [1] = {-1, 0, 1} }
Example of a binary math operation ❌ NOT ALLOWED with SiteData
:
var siteData1 = new SiteData<int>(new int[] { 1, 2, 3 });
var siteData2 = new SiteData<long>(new long[] { 4, -5, 6 });
var result = siteData1.Add(siteData2);
// The above operation will throw an NISemiconductorTestException with the following message:
// "For Add operation, the inner data type of the first operand (System.Double) and that of the second operand (System.Int64) must match."
Unary Math Operations with SiteData
The following table outlines the unary operator-based mathematical operations available for SiteData<T>
and specifies the permitted data types for T
for each operation.
Table of Unary Math Operations for SiteData:
Methods | Operator | Description | Supported Data Types |
---|---|---|---|
Abs | Performs Math.Abs operation on every element in current SiteData object. |
double , decimal , float , int , unint ,long , ulong , byte , sbyte , short , ushort |
|
BitwiseComplement | ~ | Gets the bitwise complement of the original SiteData object. |
int , unint , long , ulong , byte , sbyte , short , ushort |
Invert | Performs invert operation on every element in current SiteData object. |
double , decimal , float , int , unint ,long , ulong , byte , sbyte , short , ushort |
|
Log10 | Performs Math.Log10 operation on every element in current SiteData object. |
double , decimal , float , int , unint ,long , ulong , byte , sbyte , short , ushort |
|
Max | Calculates the maximum value across sites. | double , decimal , float , int , unint ,long , ulong , byte , sbyte , short , ushort |
|
Mean | Calculates the mean value across sites. | double , decimal , float , int , unint ,long , ulong , byte , sbyte , short , ushort |
|
Min | Calculates the minimum value across sites. | double , decimal , float , int , unint ,long , ulong , byte , sbyte , short , ushort |
|
Negate | Returns the negative value of every element in current SiteData object. |
int , long , sbyte , short , double , decimnal , float |
|
ShiftLeft | << | Shifts the value to the left by the specified bit count, for each element, per site. | int , unint , long , ulong , byte , sbyte , short , ushort |
ShiftRight | >> | Shifts the value to the right by the specified bit count, for each element, per site. | int , unint , long , ulong , byte , sbyte , short , ushort |
SquareRoot | Returns the square root of every element in current SiteData object. |
double , decimal , float , int , unint ,long , ulong , byte , sbyte , short , ushort |
|
Truncate | Returns integer portion of every element in current SiteData object. |
double , decimnal , float |
Usage Considerations for Unary Math Operations with SiteData
When performing unary math operations on SiteData
objects you should consider the following:
- The
Invert
,Log10
, andSquareRoot
methods return a scalar double value per site by default. When the underlying data typeT
of theSiteData<T>
object is an array, theTResult
type must be explicitly specified as adouble
array with the same dimensions asT
. Otherwise, aNISemiconductorTestException
exception is thrown with exception message matching the exception scenarios of Mismatched Array Dimensions. - The
count
input value passed to theShiftLeft
andShiftRight
operators must be positive, otherwise an exceptionNISemiconductorTestException
is thrown with exception message matching the exception scenarios of Shift Count Must Be Positive.
Note
For more information on specific exception conditions when preforming math operations refer to Exception Conditions For Math Operations.
Examples for Unary Math Operations with SiteData
Example of a unary math operation ✔️ ALLOWED with SiteData
:
var siteData = new SiteData<double>(new double[] { -1, 2, -3 });
var result = siteData.Abs();
// The result will be { [0] =1, [1] = 2, [2] = 3 }
Example of a unary math operation ❌ NOT ALLOWED with SiteData
:
var siteData = new SiteData<string>(new string[] { "A", "B", "C" });
var result= siteData.Abs();
// The above operation will throw an NISemiconductorTestException with the following message:
// "Math operations not supported on the System.String type data".