Utilities

OMFrontend.ListUtil and OMFrontend.ArrayUtil hold the list and array functions the frontend is written with. They were the packages ListUtil.jl and ArrayUtil.jl until OMFrontend 2.1.0 and keep their names and functions.

ListUtil

OMFrontend.ListUtil — Module

The list functions of OMFrontend (OpenModelica's List package, the part the frontend uses).

Every function that builds a list takes the element type TO of the result as its last argument and builds Cons{TO} cells; the result is a TypedList{TO} (nil or a Cons{TO}). A fold takes the type of its accumulator (TO for fold, TA for the argument of mapFold). The caller passes the element type it declares (List{Subscript} → Subscript), so the result is stored without a conversion (convert copies a list of another element type cell by cell) and every local in the loops has a concrete or small union type.

A list argument may have cells of any element type: it is read, and copied only where a result needs Cons{TO} cells and the input has others.

Small functions that take an element as an argument (isMemberOnTrue, consOnTrue, ...) are @inline: a call with an argument of abstract type (Expression, Subscript) is a run-time dispatch unless it is inlined.

Failures (fail()) are kept where OpenModelica's functions fail: callers inside @matchcontinue rely on them.

source
OMFrontend.ListUtil._copyOnto — Method
_copyOnto(::Type{TO}, lst, acc) -> TypedList{TO}

The elements of lst, in order, in front of acc; lst itself is shared when acc is empty.

source
OMFrontend.ListUtil._norm — Method
_norm(lst) -> Union{Nil{Any}, Cons{T}}

A rest of a list (a tail field, of type Union{Nil, Cons{T}}) with its empty list as nil.

source
OMFrontend.ListUtil._reverseTyped — Method
_reverseTyped(::Type{TO}, acc) -> TypedList{TO}

The accumulator acc, built reversed, in order. An accumulator of zero or one element is returned as it is.

source
OMFrontend.ListUtil._typed — Method
_typed(::Type{TO}, lst) -> TypedList{TO}

lst as a TypedList{TO}: itself when it is empty or has Cons{TO} cells, else a copy.

source
OMFrontend.ListUtil._unionAdd — Method
_unionAdd(acc, inList, inCompFunc, TO) -> TypedList{TO}

The elements of inList not yet in acc (inCompFunc) pushed onto acc. The membership loop is written out: a call with an element of abstract type and a union argument is a run-time dispatch.

source
OMFrontend.ListUtil.deleteMemberOnTrue — Method
deleteMemberOnTrue(inValue, inList, inCompareFunc, TO) -> (TypedList{TO}, Option{TO})

inList without the first element for which inCompareFunc(inValue, e) holds, and SOME of that element; (inList, NONE()) if there is none. Example: deleteMemberOnTrue(2, {1, 2, 3, 2}, intEq, Int) => ({1, 3, 2}, SOME(2)).

source
OMFrontend.ListUtil.fill — Method
fill(inElement, inCount, TO) -> TypedList{TO}

A list of inCount copies of inElement. Example: fill(2, 3, Int) => {2, 2, 2}.

source
OMFrontend.ListUtil.filterOnTrue — Method
filterOnTrue(inList, inFilterFunc, TO) -> TypedList{TO}

The elements for which inFilterFunc holds, in order. Example: filterOnTrue({1, 2, 3, 4}, iseven, Int) => {2, 4}.

source
OMFrontend.ListUtil.flatten — Method
flatten(inList, TO) -> TypedList{TO}

The lists of inList joined. Example: flatten({{1, 2}, {3, 4, 5}, {6}, {}}, Int) => {1, 2, 3, 4, 5, 6}.

source
OMFrontend.ListUtil.flattenReverse — Method
flattenReverse(inList, TO) -> TypedList{TO}

The lists of inList joined, the last first, each one in its own order (OpenModelica's List.flattenReverse).

source
OMFrontend.ListUtil.fold — Method
fold(inList, inFoldFunc, inStartValue, TO) -> TO

inFoldFunc(e, acc) over the elements, from inStartValue. Example: fold({1, 2, 3}, intAdd, 2, Int) => 8.

source
OMFrontend.ListUtil.fold1 — Method
fold1(inList, inFoldFunc, inExtraArg, inStartValue, TO) -> TO

inFoldFunc(e, inExtraArg, acc) over the elements, from inStartValue.

source
OMFrontend.ListUtil.foldr — Method
foldr(inList, inFoldFunc, inStartValue, TO) -> TO

As fold, with the arguments of inFoldFunc swapped: inFoldFunc(acc, e).

source
OMFrontend.ListUtil.map1Fold — Method
map1Fold(inList, inFunc, inConstArg, inArg, TO, TA) -> (TypedList{TO}, TA)

(e1, arg) = inFunc(e, inConstArg, arg) for each element; the list of the e1 and the last arg.

source
OMFrontend.ListUtil.map1_2 — Method
map1_2(inList, inFunc, inArg1, TO1, TO2) -> (TypedList{TO1}, TypedList{TO2})

The two results of inFunc(e, inArg1) for each element, as two lists.

source
OMFrontend.ListUtil.map2FoldCheckReferenceEq — Method
map2FoldCheckReferenceEq(inList, inFunc, inConstArg, inConstArg2, inArg, TO, TA) -> (TypedList{TO}, TA)

(e1, arg) = inFunc(e, inConstArg, inConstArg2, arg) for each element. The list is inList itself, without allocating, when every e1 is the element it came from (referenceEq) and inList has Cons{TO} cells; otherwise a new list.

source
OMFrontend.ListUtil.map2List — Method
map2List(inListList, inFunc, inArg1, inArg2, TO) -> TypedList{List{TO}}

inFunc(e, inArg1, inArg2) for each element of each list.

source
OMFrontend.ListUtil.map2Option — Method
map2Option(inList, inFunc, inArg1, inArg2, TO) -> TypedList{TO}

inFunc(e, inArg1, inArg2) for each SOME(e); NONE() elements are left out.

source
OMFrontend.ListUtil.map3 — Method
map3(inList, inFunc, inArg1, inArg2, inArg3, TO) -> TypedList{TO}

inFunc(e, inArg1, inArg2, inArg3) for each element.

source
OMFrontend.ListUtil.mapFlat — Method
mapFlat(inList, inMapFunc, TO) -> TypedList{TO}

The lists inMapFunc(e) joined, the last first (OpenModelica's List.mapFlat: the reverse of listAppend(inMapFunc(e_n), ... listAppend(inMapFunc(e_1), {}))).

source
OMFrontend.ListUtil.mapFold — Method
mapFold(inList, inFunc, inArg, TO, TA) -> (TypedList{TO}, TA)

(e1, arg) = inFunc(e, arg) for each element; the list of the e1 and the last arg.

source
OMFrontend.ListUtil.mapFoldSO — Method
mapFoldSO(inList, inFunc, inArg, TO) -> TypedList{TO}

inFunc(e, inArg) for each element (mapFold where the argument is not updated).

source
OMFrontend.ListUtil.mapList — Method
mapList(inListList, inFunc, TO) -> TypedList{List{TO}}

inFunc applied to each element of each list. Example: mapList({{1, 2}, {3}}, intString, String) => {{"1", "2"}, {"3"}}.

source
OMFrontend.ListUtil.partition — Method
partition(inList, inPartitionLength, TO) -> TypedList{List{TO}}

inList in parts of inPartitionLength elements, the last one shorter if needed. Example: partition({1, 2, 3, 4, 5}, 2, Int) => {{1, 2}, {3, 4}, {5}}.

source
OMFrontend.ListUtil.reduce — Method
reduce(inList, inReduceFunc, TO) -> TO

inReduceFunc over the elements, left to right; fails for the empty list. Example: reduce({1, 2, 3}, intAdd, Int) => 6.

source
OMFrontend.ListUtil.replaceOnTrue — Method
replaceOnTrue(inReplacement, inList, inFunc, TO) -> (TypedList{TO}, Bool)

inList with the first element for which inFunc holds replaced by inReplacement, and whether one was. Example: replaceOnTrue(4, {1, 2, 3}, isTwo, Int) => ({1, 4, 3}, true).

source
OMFrontend.ListUtil.set — Method
set(inList, inN, inElement, TO) -> TypedList{TO}

inList with the element at the one-based position inN replaced. Example: set({2,1,4,2}, 2, 3, Int) => {2,3,4,2}.

source
OMFrontend.ListUtil.sort — Method
sort(inList, inCompFunc, TO) -> TypedList{TO}

inList sorted (stable); inCompFunc(a, b) is true when a comes after b. Example: sort({2, 1, 3}, intGt, Int) => {1, 2, 3}.

source
OMFrontend.ListUtil.sortedUnique — Method
sortedUnique(inList, inCompFunc, TO) -> TypedList{TO}

The elements of a sorted list without repeats; inCompFunc tells whether two neighbors are equal.

source
OMFrontend.ListUtil.split — Method
split(inList, inPosition, TO) -> (TypedList{TO}, List)

The first inPosition elements and the rest (shared). Example: split({1, 2, 5, 7}, 2, Int) => ({1, 2}, {5, 7}).

source
OMFrontend.ListUtil.splitLast — Method
splitLast(inList, TO) -> (TO, TypedList{TO})

The last element and the elements before it; fails if the list is empty. Example: splitLast({3, 5, 7}, Int) => (7, {3, 5}).

source
OMFrontend.ListUtil.splitOnTrue — Method
splitOnTrue(inList, inFunc, TO) -> (TypedList{TO}, TypedList{TO})

The elements for which inFunc holds and the others, each in the order of inList.

source
OMFrontend.ListUtil.splitr — Method
splitr(inList, inPosition, TO) -> (TypedList{TO}, List)

As split, the first list reversed. Example: splitr({1, 2, 5, 7}, 2, Int) => ({2, 1}, {5, 7}).

source
OMFrontend.ListUtil.stripN — Method
stripN(inList, inN) -> List

inList without its first inN elements (shared); fails if there are fewer or inN is negative.

source
OMFrontend.ListUtil.threadMapAllValue — Method
threadMapAllValue(inList1, inList2, inMapFunc, inValue)

Fails unless the lists have the same length and inMapFunc(e1, e2) equals inValue (valueEq) for every pair.

source
OMFrontend.ListUtil.threadTuple — Method
threadTuple(inList1, inList2, TO) -> TypedList{TO}

The pairs of elements at the same position, up to the end of the shorter list; TO is the pair type. Example: threadTuple({1, 2}, {true, false}, Tuple{Int, Bool}) => {(1, true), (2, false)}.

source
OMFrontend.ListUtil.toString — Method
toString(inList, inPrintFunc, inListNameStr, inBeginStr, inDelimitStr, inEndStr, inPrintEmpty) -> String

inListNameStr, inBeginStr, the elements printed with inPrintFunc separated by inDelimitStr, and inEndStr. An empty list gives inListNameStr * inBeginStr * inEndStr, or only inListNameStr if inPrintEmpty is false. Example: toString({1, 2, 3}, intString, "nums", "{", ";", "}", true) => "nums{1;2;3}".

source
OMFrontend.ListUtil.trim — Method
trim(lst, pred_func) -> List

lst without the elements at its head for which pred_func holds (shared). Example: trim({2, 4, 3, 6}, iseven) => {3, 6}.

source
OMFrontend.ListUtil.union — Method
union(inList1, inList2, TO) -> TypedList{TO}

The elements of both lists without duplicates (isequal). Example: union({0, 1}, {2, 1}, Int) => {0, 1, 2}. An empty list and a list give that list as it is.

source
OMFrontend.ListUtil.unionOnTrue — Method
unionOnTrue(inList1, inList2, inCompFunc, TO) -> TypedList{TO}

The elements of both lists without duplicates (inCompFunc), in order of first occurrence. Example: unionOnTrue({1, 2}, {2, 3}, intEq, Int) => {1, 2, 3}.

source

ArrayUtil

OMFrontend.ArrayUtil.compare — Method
compare(arr1, arr2, comp_func) -> Int

Compare two arrays element-wise using comp_func(e1, e2) which must return an integer (-1, 0, or 1). Returns the result of the first non-zero comparison, or compares array lengths if all corresponding elements are equal.

source
OMFrontend.ArrayUtil.consToElement — Method

Concatenates an element to a list element of an array. The array may be typed Vector{List} (untyped element lists); do not constrain the element to the list type.

source
OMFrontend.ArrayUtil.copy — Method

Copies all values from inArraySrc to inArrayDest. Fails if inArraySrc is larger than inArrayDest.

NOTE: There's also a builtin arrayCopy operator that should be used if the purpose is only to duplicate an array.

source
OMFrontend.ArrayUtil.copyN — Method

Copies the first inN values from inArraySrc to inArrayDest. Fails if inN is larger than either inArraySrc or inArrayDest.

source
OMFrontend.ArrayUtil.fold — Method

Takes an array, a function, and a start value of type TO. The function is applied to each array element, and the start value is passed to the function and updated: inFunction(e, acc)::TO.

source
OMFrontend.ArrayUtil.fold1 — Method

Takes an array, a function, and a start value. The function is applied to each array element, and the start value is passed to the function and updated.

source
OMFrontend.ArrayUtil.fold2 — Method

Takes an array, a function, a constant parameter, and a start value. The function is applied to each array element, and the start value is passed to the function and updated.

source
OMFrontend.ArrayUtil.fold3 — Method

Takes an array, a function, a constant parameter, and a start value. The function is applied to each array element, and the start value is passed to the function and updated.

source
OMFrontend.ArrayUtil.fold4 — Method

Takes an array, a function, four constant parameters, and a start value. The function is applied to each array element, and the start value is passed to the function and updated.

source
OMFrontend.ArrayUtil.fold5 — Method

Takes an array, a function, four constant parameters, and a start value. The function is applied to each array element, and the start value is passed to the function and updated.

source
OMFrontend.ArrayUtil.fold6 — Method

Takes an array, a function, four constant parameters, and a start value. The function is applied to each array element, and the start value is passed to the function and updated.

source
OMFrontend.ArrayUtil.foldIndex — Method

Takes an array, a function, and a start value. The function is applied to each array element, and the start value is passed to the function and updated, additional the index of the passed element is also passed to the function.

source
OMFrontend.ArrayUtil.isEqualOnTrue — Method
isEqualOnTrue(arr1, arr2, eq_func) -> Bool

Return true if arr1 and arr2 have the same length and eq_func(arr1[i], arr2[i]) returns true for all corresponding pairs.

source
OMFrontend.ArrayUtil.map — Method

Takes an array and a function over the elements of the array, which is applied to each element. The updated elements will form a new array, leaving the original array unchanged.

source
OMFrontend.ArrayUtil.map1 — Method

Takes an array, an extra arguments, and a function over the elements of the array, which is applied to each element. The updated elements will form a new array, leaving the original array unchanged.

source
OMFrontend.ArrayUtil.map1Fold — Method
map1Fold

Takes a Vector, an extra argument, an extra constant argument, and a function. The function will be applied to each element in the list, and the extra argument will be passed to the function and updated.

source
OMFrontend.ArrayUtil.mapBoolAnd — Method
mapBoolAnd(arr, pred_func) -> Bool

Apply pred_func to each element of arr; return true only if all applications return true (logical AND over mapped results).

source
OMFrontend.ArrayUtil.mapFold — Method

Takes a vector, an extra argument and a function. The function will be applied to each element in the list, and the extra argument will be passed to the function and updated.

source
OMFrontend.ArrayUtil.mapNoCopy — Method

Takes an array and a function over the elements of the array, which is applied for each element. Since it will update the array values the returned array must have the same type, and thus the applied function must also return the same type.

source
OMFrontend.ArrayUtil.partition — Method

function partition(inList::Vector{T}, inPartitionLength::Int) where {T} Partitions a vector of elements into sublists of length n. Example:

julia> partition([1, 2, 3, 4, 5], 2) => [[1, 2], [3, 4], [5]]
source
OMFrontend.ArrayUtil.reduce — Method

Takes a list and a function operating on two elements of the array. The function performs a reduction of the array to a single value using the function. Example: reduce([1, 2, 3], intAdd) => 6

source
OMFrontend.ArrayUtil.replaceAtWithFill — Method

Takes

  • an element,
  • a position (1..n)
  • an array and
  • a fill value

The function replaces the value at the given position in the array, if the given position is out of range, the fill value is used to padd the array up to that element position and then insert the value at the position.

Example: replaceAtWithFill('A', 5, {'a', 'b', 'c'}, 'dummy') => {'a', 'b', 'c', 'dummy', 'A'}

source
OMFrontend.ArrayUtil.select — Method

Takes an array and a list of indices, and returns a new array with the indexed elements. Will fail if any index is out of bounds.

source
OMFrontend.ArrayUtil.split — Method

Takes a list and a position, and splits the list at the position given. Example:

julia> split([1, 2, 5, 7], 2) => ([1, 2], [5, 7])
source
OMFrontend.ArrayUtil.threadMap — Method
threadMap(arr1, arr2, map_func) -> Vector

Apply map_func(arr1[i], arr2[i]) for each index, returning a new vector of the results. Both input arrays must have the same length.

source
OMFrontend.ArrayUtil.transpose — Method
transpose(arr::Vector{Vector{T}}) -> Vector{Vector{T}}

Transpose a vector of vectors (matrix in row-major form). Returns a new vector of vectors where rows become columns and vice versa.

Example: transpose([[1,2,3], [4,5,6]]) returns [[1,4], [2,5], [3,6]].

source