stdlib.sc

stdlib.sc

Module with standard general functions.

Functions:

abs

erf

exp

ln

sin

all

any

max

min

sum

abs

Function for finding the absolute value of the input.

Detailed Description

Supported types - int8 / int16 / int32 / int / float32 / float64

Parameters

x

- input of supported type

returns the absolute value of the input if it’s a scalar or a vector where every element of the input vector is replaced with its absolute value

Function Overloads

int8 abs(int8[[N]] x)

int16 abs(int16[[N]] x)

int32 abs(int32[[N]] x)

int64 abs(int64[[N]] x)

float32 abs(float32[[N]] x)

float64 abs(float64[[N]] x)

argument

Function for accessing the named program arguments of public types.

Detailed Description

T - any data type

Parameters

name

- the name of the argument

the value associated with the argument specified by parameter name

Function Overloads

string argument(string name)

An argument of string type.

An argument of scalar type.

arrayToString

Function for converting an array to a string.

Detailed Description

D - all protection domains

T - any data type

returns a string representation of the input array

Function Overloads

string arrayToString(T scalar)

Parameters

scalar

- a scalar of any type

string arrayToString(T[[1]] vec)

Parameters

vec

- a 1-dimension array of any type

string arrayToString(T[[N]] arr)

Parameters

arr

- any dimension array of any type

erf

Error function.

Detailed Description

Supported types - float32 / float64

Parameters

x

- input array

error function applied to elements of the input array

Function Overloads

float32 erf(float32[[N]] x)

float64 erf(float64[[N]] x)

exp

Exponential function.

Detailed Description

N - any dimensionality

Supported types - float32 / float64

Parameters

x

- input array

exponential function applied to elements of the input array

Function Overloads

float32 exp(float32[[N]] x)

float64 exp(float64[[N]] x)

flatten

Function for converting arrays to 1 dimensional.

Detailed Description

D - all protection domains

N - any array size of any dimension

T - any data type

Parameters

arr

- input array

a 1-dimensional flattened version of the input array with the same type

For example: {{1,2,3}{4,5,6}} → {1,2,3,4,5,6}

Function Overloads

D T flatten(D T[[N]] arr)

iota

Function for generating a vector of consecutive integers.

Detailed Description

Parameters

n

length of the vector

returns a length n vector of consecutive integers.

Function Overloads

D uint iota(uint n)

isNegligible

Function for finding if the error is small enough to neglect.

Detailed Description

D - any protection domain

Supported types - float32 / float64

Parameters

a

- input

true if the error is small enough to neglect

false if the error is not small enough

isNegligible checks up to the 5th place after the comma

None

Function Overloads

D bool isNegligible(D float32 a)

D bool isNegligible(D float64 a)

D bool isNegligible(D float32[[1]] a)

D bool isNegligible(D float64[[1]] a)

isPrefixOf

Function for checking if a string is a prefix of another string.

Detailed Description

Parameters

a

prefix string

b

other string

returns true if a is a prefix of b and false otherwise

Function Overloads

bool isPrefixOf(string a, string b)

isSuffixOf

Function for checking if a string is a suffix of another string.

Detailed Description

Parameters

a

suffix string

b

other string

returns true if a is a suffix of b and false otherwise

Function Overloads

bool isSuffixOf(string a, string b)

ln

Natural logarthim.

Detailed Description

N - any dimensionality

Supported types - float32 / float64

Parameters

x

- input array

the natural logarithms of the input array

Function Overloads

float32 ln(float32[[N]] x)

float64 ln(float64[[N]] x)

print3dArray

Function for printing out 3-dimensional arrays.

Detailed Description

T - any data type

Parameters

arr

- a 3-dimensional array

prints out a string representation of the input array.

see also printArray

Function Overloads

void print3dArray(T[[3]] arr)

printArray

Function for printing out any dimension arrays.

Detailed Description

T - any data type

Parameters

arr

- any dimension array

prints out a string representation of the input array.

Function Overloads

void printArray(T[[N]] arr)

printMatrix

Function for printing out matrices.

Detailed Description

T - any data type

Parameters

mat

- a 2-dimensional matrix

prints out a string representation of the input matrix.

see also printArray

Function Overloads

void printMatrix(T[[2]] mat)

printVector

Function for printing out vectors.

Detailed Description

T - any data type

Parameters

vec

- a 1-dimensional array

prints out a string representation of the input vector

see also printArray

Function Overloads

void printVector(T[[1]] vec)

publish

Function for publishing the named values of public types.

Detailed Description

An argument of 1-dimensional array type.

N - any array size of any dimension

T - any data type

Parameters

name

The name of the argument.

val

the value to publish under the given name. Accepts scalars as well as arrays.

str

the string value to publish under the given name.

Function Overloads

void publish(string name, T[[N]] val)

void publish(string name, string str)

round

Function for rounding values.

Detailed Description

Supported types - float32 / float64

Parameters

x

- input scalar of supported type

returns the rounded value of the input scalar

Function Overloads

int round(float32 x)

int round(float64 x)

shapesAreEqual

Function for checking the shape equality of two arrays.

Detailed Description

D1 - all protection domains

D2 - all protection domains

D3 - all protection domains

N - any array size of any dimension

T1 - any data type

T2 - any data type

T3 - any data type

Parameters

first

- first input

second

- second input

returns a bool type value, whether the input arrays are of equal shape (true) or are not of equal shape (false)

Function Overloads

bool shapesAreEqual(D1 T1[[N]] first, D2 T2[[N]] second)

bool shapesAreEqual(D1 T1[[N]] first, D2 T2[[N]] second, D3 T3[[N]] third)

sin

Function for finding sine.

Detailed Description

Supported types - float32 / float64

Parameters

x

- input

the sines of the input array

Function Overloads

float32 sin(float32[[N]] x)

float64 sin(float64[[N]] x)

sizeof

Function for getting the size of a public value in bytes based on its type.

Detailed Description

Parameters

x

the value of public type.

returns the size of a public value in bytes.

Function Overloads

uint sizeof(bool x)

uint sizeof(uint8 x)

uint sizeof(uint16 x)

uint sizeof(uint32 x)

uint sizeof(uint64 x)

uint sizeof(int8 x)

uint sizeof(int16 x)

uint sizeof(int32 x)

uint sizeof(int64 x)

uint sizeof(float32 x)

uint sizeof(float64 x)

sqrt

Function for finding square roots.

Detailed Description

Supported types - float32 / float64

Parameters

x

- input

the square roots of the input array

Function Overloads

float32 sqrt(float32[[N]] x)

float64 sqrt(float64[[N]] x)

substring

Function for getting a substring of a string.

Detailed Description

Parameters

x

input string

s

start position

e

end position

returns the substring spanning the indices [s, e)

Function Overloads

string substring(string x, uint s, uint e)

all

Function for checking if all elements in a boolean vector are true.

Functions:

all

D - all protection domains

all

Function for checking if all elements in a boolean vector are true.

Detailed Description

D - all protection domains

Supported types - bool

true if all of the input bits are set

false if any input bit is not set

iteratively checks all elements in input vector and returns false when the first 0-bit is found.

None

Function Overloads

D bool all(D bool b)

Parameters

b

- boolean scalar

D bool all(D bool[[1]] vec)

Parameters

vec

- boolean 1-dimensional vector

D bool all(D bool[[N]] arr)

Parameters

arr

- boolean any dimension array

all(parts)

Function for checking if all elements in a boolean vector are true in specified parts.

Detailed Description

D - all protection domains

Supported types - bool

Parameters

vec

- a vector of supported type

k

- an uint type value for specifying from how many subarrays all must be found

returns a boolean vector that evaluates every subarray seperately for all

iteratively checks all elements in input vector and returns false when the first 0-bit is found.

None

Function Overloads

D bool all(D bool[[1]] vec, uint k)

any

Function for checking if any element in a boolean vector is true.

Functions:

any

D - all protection domains

any

Function for checking if any element in a boolean vector is true.

Detailed Description

D - all protection domains

Supported types - bool

true if any of the input bits are set

false if all input bits are not set

iteratively checks all elements in input vector and returns true when the first 1-bit is found.

None

Function Overloads

D bool any(D bool b)

Parameters

b

- boolean scalar

D bool any(D bool[[1]] vec)

Parameters

vec

- boolean 1-dimensional vector

D bool any(D bool[[N]] arr)

Parameters

arr

- boolean any dimension array

any(parts)

Function for checking if any element in a boolean vector is true in specified parts.

Detailed Description

D - all protection domains

Supported types - bool

Parameters

vec

- a vector of supported type

k

- an uint type value for specifying from how many subarrays any must be found

returns a boolean vector that evaluates every subarray seperately for any

iteratively checks all elements in input vector and returns true when the first 1-bit is found.

None

Function Overloads

D bool any(D bool[[1]] vec, uint k)

max

Function for finding the maximum value of the input.

Functions:

max

max

Function for finding the maximum value of the input.

Detailed Description

Supported types - bool / uint8 / uint16 / uint32 / uint / int8 / int16 / int32 / int

return the maximum value of the input

Function Overloads

D T max(D T scalar)

D - all protection domains

T - any data type

Parameters

scalar

- a scalar value

returns the scalar value

None

T max(T[[1]] vec)

Parameters

vec

- a 1-dimensional vector

T - any data type

returns the largest value in the vector

D T max(D T[[1]] vec)

D - all protection domains

T - any data type

Parameters

vec

- a 1-dimensional vector

returns the largest value in the vector

None

T max(T[[N]] arr)

T - any data type

Parameters

arr

- an array of any dimension

returns the largest value in the array

max(parts)

Function for finding the maximum value of the input in specified parts.

Detailed Description

Supported types - bool / uint8 / uint16 / uint32 / uint / int8 / int16 / int32 / int

Parameters

vec

- a vector of supported type

k

- an uint type value for specifying from how many subarrays max must be found

returns the maximum value of every subarray in the input

None

Function Overloads

D T max(D T[[1]] vec, uint k)

max(pointwise)

Function for finding the pointwise maximum of two input vectors.

Detailed Description

D - all protection domains

Supported types - bool / uint8 / uint16 / uint32 / uint / int8 / int16 / int32 / int

Parameters

x, y

- input vectors of supported type

return the pointwise maximum of the two input vectors

None

Function Overloads

D T max(D T[[1]] x, D T[[1]] y)

min

Function for finding the minimum values.

Functions:

min

min

Function for finding the minimum value of the input.

Detailed Description

Supported types - bool / uint8 / uint16 / uint32 / uint / int8 / int16 / int32 / int

returns the minimum value of the input

Function Overloads

D T min(D T scalar)

D - all protection domains

Parameters

scalar

- a scalar value

returns the scalar value

None

T min(T[[1]] vec)

Parameters

vec

- a 1-dimensional vector

returns the smallest value in the vector

D T min(D T[[1]] vec)

does not work for floats, xor_uints

D - all protection domains

Parameters

vec

- a 1-dimensional vector

returns the smallest value in the vector

None

T min(T[[N]] arr)

Parameters

arr

- an array of any dimension

returns the smallest value in the array

min(parts)

Function for finding the minimum value of the input in specified parts.

Detailed Description

D - all protection domains

Supported types - bool / uint8 / uint16 / uint32 / uint / int8 / int16 / int32 / int

Parameters

vec

- input vector on supported type

k

- an uint type value for specifying from how many subarrays min must be found

returns the minimum value of every subarray in the input

None

Function Overloads

D T min(D T[[1]] vec, uint k)

min(pointwise)

Function for finding the pointwise minimum value of the two input vectors.

Detailed Description

D - all protection domains

Supported types - bool / uint8 / uint16 / uint32 / uint / int8 / int16 / int32 / int

Parameters

x, y

- input vector of supported type

returns the pointwise minimum of the two input vectors

None

Function Overloads

D T min(D T[[1]] x, D T[[1]] y)

product

Function for finding the product of all elements in the input vector.

Functions:

D - all protection domains

Supported types - bool / uint8 / uint16 / uint32 / uint / int8 / int16 / int32 / int / float32 / float64

product

Function for finding the product of the input vector.

Detailed Description

D - all protection domains

Supported types - bool / uint8 / uint16 / uint32 / uint / int8 / int16 / int32 / int / float32 / float64

Parameters

x

- input

the product of the input vector

None

Function Overloads

D T product(D T x)

D uint8 product(D uint8[[1]] x)

D uint16 product(D uint16[[1]] x)

D uint32 product(D uint32[[1]] x)

D uint product(D uint[[1]] x)

D int8 product(D int8[[1]] x)

D int16 product(D int16[[1]] x)

D int32 product(D int32[[1]] x)

D int product(D int[[1]] x)

D float32 product(D float32[[1]] x)

D float64 product(D float64[[1]] x)

product(parts)

Function for finding the product of the input vector in parts.

Detailed Description

D - all protection domains

Supported types - bool / uint8 / uint16 / uint32 / uint / int8 / int16 / int32 / int / float32 / float64

Parameters

vec

- input vector

k

- an uint type scalar which specifies in how many parts the product is found.

For example if k = 2 then the input vector is split into two parts and the products of those parts are found seperately.

a vector with the product of the specified number of parts in the input vector

None

Function Overloads

D uint8 product(D uint8[[1]] vec, uint k)

D uint16 product(D uint16[[1]] vec, uint k)

D uint32 product(D uint32[[1]] vec, uint k)

D uint product(D uint[[1]] vec, uint k)

D int8 product(D int8[[1]] vec, uint k)

D int16 product(D int16[[1]] vec, uint k)

D int32 product(D int32[[1]] vec, uint k)

D int product(D int[[1]] vec, uint k)

D float32 product(D float32[[1]] vec, uint k)

D float64 product(D float64[[1]] vec, uint k)

sort

Public sorting functions.

Functions:

Supported types - bool / uint8 / uint16 / uint32 / uint / int8 / int16 / int32 / int / float32 / float64

sort

Sort a public vector.

Detailed Description

Supported types - bool / uint8 / uint16 / uint32 / uint / int8 / int16 / int32 / int / float32 / float64

Parameters

x

- vector to be sorted

x sorted in ascending order

Function Overloads

T sort(T[[1]] x)

sort(direction)

Sort a public vector.

Detailed Description

Supported types - bool / uint8 / uint16 / uint32 / uint / int8 / int16 / int32 / int / float32 / float64

Parameters

x

- vector to be sorted

ascending

- boolean indicating if the input should be sorted in ascending or descending order

x sorted according to the ordering specified by ascending

Function Overloads

T sort(T[[1]] x, bool ascending)

sum

Function for finding the sum of all elements in the input vector.

Functions:

sum

D - all protection domains

Supported types - bool / uint8 / uint16 / uint32 / uint / int8 / int16 / int32 / int / float32 / float64

sum

Function for finding the sum of all elements in the input vector.

Detailed Description

D - all protection domains

Supported types - bool / uint8 / uint16 / uint32 / uint / int8 / int16 / int32 / int / float32 / float64

Uses accumulator to calculate sum. May be very inefficient for private domains.

Parameters

x

- input

returns the sum of all elements in input vector

None

Function Overloads

D T sum(D T x)

D uint sum(D bool[[1]] x)

D uint8 sum(D uint8[[1]] x)

D uint16 sum(D uint16[[1]] x)

D uint32 sum(D uint32[[1]] x)

D uint sum(D uint[[1]] x)

D int8 sum(D int8[[1]] x)

D int16 sum(D int16[[1]] x)

D int32 sum(D int32[[1]] x)

D int sum(D int[[1]] x)

D float32 sum(D float32[[1]] x)

D float64 sum(D float64[[1]] x)

sum(parts)

Function for finding the sum of all elements in the input vector in specified parts.

Detailed Description

D - all protection domains

Supported types - bool / uint8 / uint16 / uint32 / uint / int8 / int16 / int32 / int / float32 / float64

Uses accumulator to calculate sum. May be very inefficient for private domains.

Parameters

vec

- input

k

- an uint type scalar which specifies in how many parts the sum is found.

For example if k = 2 then the input vector is split into two parts and the sums of those parts are found seperately.

returns a vector with the sum of the specified number of parts in the input vector

None

Function Overloads

D uint sum(D bool[[1]] vec, uint k)

D uint8 sum(D uint8[[1]] vec, uint k)

D uint16 sum(D uint16[[1]] vec, uint k)

D uint32 sum(D uint32[[1]] vec, uint k)

D uint sum(D uint[[1]] vec, uint k)

D int8 sum(D int8[[1]] vec, uint k)

D int16 sum(D int16[[1]] vec, uint k)

D int32 sum(D int32[[1]] vec, uint k)

D int sum(D int[[1]] vec, uint k)

D float32 sum(D float32[[1]] vec, uint k)

D float64 sum(D float64[[1]] vec, uint k)