Table of Contents

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:

  1. 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.
  2. All methods can accept either a scalar, an array, or SiteData object as an input argument.
  3. Operators can only accept a scalar or SiteData object as the second operand.
  4. When the input is a SiteData object it must match the same underlying type, T, as the SiteData object being operated on.
  5. When both operands are scaler, they must have identical data types, and that data type must be supported by the desired method.
  6. 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.
  7. When the underlying data, T, of the SiteData<T> object is an array type, if the second operand is:
    1. 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.
    2. Scalar type, the scalar type must match the array element type of the underlining data within the SiteData<T> object.
    3. SiteData<T> object, both operand objects must be of identical data types, T.
  8. The Bitwise methods are only supported when the underlying data type of the SiteData object, T, is an integer type, either a scalar integer, array of integers, or another SiteData object of the same integer type.
  9. 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 the SiteData<T> object, T, and be of equal or lesser dimensions (i.e. TOther cannot be 2D when T is 1D).
  10. The Divide method returns a scalar double value per site by default. When the underlying data type T of the SiteData<T> object is an array, the TResult type must be explicitly specified as a double array with the same dimensions as T. Otherwise, a NISemiconductorTestException exception is thrown with exception message matching the exception scenarios of Mismatched Array Dimensions. Refer to the Divide<TOther, TResult>(TOther) and Divide<TOther, TResult>(SiteData<TOther>) method signatures in the API Reference documentation.
  11. The Compare method returns a boolean value per site by default. When the underlying data type T of the SiteData<T> object is an array, the TResult type must be explicitly specified as a boolean array with the same dimensions as T. Otherwise, a NISemiconductorTestException exception is thrown with exception message matching the exception scenarios of Mismatched Array Dimensions. Refer to the Compare<TOther, TResult>(ComparisonType, TOther) and Compare<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:

  1. The Invert, Log10, and SquareRoot methods return a scalar double value per site by default. When the underlying data type T of the SiteData<T> object is an array, the TResult type must be explicitly specified as a double array with the same dimensions as T. Otherwise, a NISemiconductorTestException exception is thrown with exception message matching the exception scenarios of Mismatched Array Dimensions.
  2. The count input value passed to the ShiftLeft and ShiftRight operators must be positive, otherwise an exception NISemiconductorTestException 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".