Topic: Expressions

Online Help


High performance vectors and matrices


High performance (hp) vectors and matrices were introduced in Calcpad version 7.3.0 with the purpose of solving larger engineering problems faster and with less memory consumption. But this comes with a trade-off: all elements of an hp vector or matrix must have the same units. This allows Calcpad to store and process the units only once for the whole vector/matrix and perform a lot of additional optimizations like SIMD vectorization of operations, application of more cache-friendly algorithms, etc. All this results in dozens of times improvement in speed and reduces the required memory size more than twice, even if there are no units at all.

Hp vectors and matrices are initially created by special functions, similar to standard creational functions, but ending with “_hp”, as follows:

Functions for creating hp vectors:
  vector_hp(n) - creates an empty hp vector with length n;
  range_hp(x1; xn; s) - creates an hp vector from a range of values.
Functions for creating hp matrices:
  matrix_hp(m; n) - creates an hp empty matrix with dimensions mn;
  identity_hp(n) - creates an hp identity matrix with dimensions nn;
  diagonal_hp(n; d) - creates an nn hp diagonal matrix filled with value d;
  column_hp(m; c) - creates an m⨯1 hp column matrix filled with value c;
  utriang_hp(n) - creates an nn hp upper triangular matrix;
  ltriang_hp(n) - creates an nn hp lower triangular matrix;
  symmetric_hp(n) - creates an nn hp symmetric matrix.

The function hp(x) converts any argument x to its high-performance equivalent. It can be used together with the square brackets operator [] for initialization of vectors and matrices from a list of values. For example:
  a = hp([1; 2; 4]) will create a high-performance vector and …
  A = hp([1; 2; 3|4; 5; 6]) will create a high-performance matrix.

The conversion includes coping the values from the standard array to the hp one, so it must be used only for small arrays. If the standard array contains different, but consistent units, they will be converted to the units of the first element. If the units are not consistent, the conversion is not possible and error is returned instead. For example:
  a = hp([1m; 20dm; 30cm])‘ = [1 m 2 m 0.3 m]
  a = hp([1m; 20s; 30kg])’ = Inconsistent units: "m, kg".

Any expression that contains only hp vectors/arrays will return also an hp type. If the expression contains only standard vectors/arrays or mixed standard and hp, it will return a standard type. To check if the type of x is a high-performance (hp) vector or matrix you can use the function ishp(x).