Operator overloading

ILArray<> objects profit from overloaded operators. This enables one to formulate algorithms much more intuitive in the following way:

// construct 4-dim. array: random numbers betw. 1..10
ILArray<double> A = ILMath.rand(3,2,5,4) * 9.0 + 1.0; 
// subtract exp(A) from A, divide by 2: 
A = (A - ILMath.exp(A)) / 2; 

The principle gets clear. The size of all parameters in an operation must match. This means in an operation like: B + C, B and C must be of the same size. Corresponding elements on B and C will get added and the result is stored into the corresponding element in A.

Alternatively either one of B or C may be scalar! The (same) scalar value will get added to all elements of the non-scalar array and the result is returned then.

The following operators are overloaded (if available in your language). Static functions are available, if you are using languages not supporting operator overloading.

OperationOperator overloadStatic functionreturn typeT/A/B types
Additionplus: '+'ILMath.add(A,B)ILArray<T>all numeric
Subtractionminus: '-'ILMath.subtract(A,B)ILArray<T>all numeric
Negationunary minus: '-'ILMath.invert(A,RetVal)N/Aall signed numeric
Multiplicationmult: '*'ILMath.multiplyElem(A,B)ILArray<T>all numeric
Divisiondivide: '/'ILMath.divide(A,B)ILArray<T>all numeric
Lower than<ILMath.lt(A,B)ILLogicalArrayall numeric
Lower equal<=ILMath.le(A,B)ILLogicalArrayall numeric
Greater than>ILMath.gt(A,B)ILLogicalArrayall numeric
Greater equal>=ILMath.ge(A,B)ILLogicalArrayall numeric
Equals==ILMath.eq(A,B)ILLogicalArrayall numeric
Not equal to!=ILMath.neq(A,B)ILLogicalArrayall numeric

Currently the generic type for both operands (for binary operators) must be the same. If you are using different types, one of the conversion functions (ILMath.convert, ILMath.to?????? ...) may be of interest for you. Those functions can be used to convert between types.

The generic type of the return values will always be the same as the type of the operands.

For all comparison operations the return value will be a ILLogicalArray - a special array which derives from ILArray<byte>, having 1 on corresponding elements where the comparison resulted to true, 0 else.


Valid CSS! Valid XHTML 1.0 Transitional