AryUtil

Usage

use AryUtil;

or

import AryUtil;
param bitsPerDigit = RSLSD_bitsPerDigit
const auLogger = new Logger(logLevel, logChannel)
var printThresh = 30

Threshold for the amount of data that will be printed. Arrays larger than printThresh will print less data.

proc formatAry(A: [?d]): string throws

Prints the passed array.

Arguments
  • name – name of the array

  • A – array to be printed

proc printAry(name: string, A)
proc printOwnership(x)

1.18 version print out localSubdomains

Arguments

x : [] – array

proc isSorted(A: [?D] ?t): bool

Determines if the passed array is sorted.

Arguments

A – array to check

proc isSortedOver(A: [?D] ?t, slice, axisIdx: int)

Determines if the passed array is sorted along a given axis, within a slice domain.

Arguments
  • A – array to check

  • slice – a slice domain (only the indices in this domain are checked)

  • axisIdx – the axis to check

proc validateNegativeAxes(axes: [?d] int, param nd: int): (bool, [d] int)

Modifies an array of (potentially negative) axis arguments to be positive and within the range of the number of dimensions, while confirming that the axes are valid.

A negative axis ‘a’ is converted to ‘nd + a’, where ‘nd’ is the number of dimensions in the array.

Arguments
  • axes – array of axis arguments

  • nd – number of dimensions in the array

Returns

a tuple of a boolean indicating whether the axes are valid, and the array of modified axes

proc reducedShape(shape: ?N*int, axes: [] int): N*int

Modify an array shape by making the specified axes degenerate.

Arguments
  • shape – array shape as a tuple of sizes

  • axes – array of axis arguments

Returns

a tuple of sizes where the specified axes have a size of 1

proc reducedShape(shape: ?N*int, axis: int): N*int
proc aStats(a: [?D] int): (int, int, real, real, real)

Returns stats on a given array in form (int,int,real,real,real).

Arguments

a : [] int – array to produce statistics on

Returns

a_min, a_max, a_mean, a_variation, a_stdDeviation

proc fillUniform(A: [?D] int, a_min: int, a_max: int, seed: int = 241)
proc concatArrays(a: [?aD] ?t, b: [?bD] t, ordered = true) throws

Concatenate 2 arrays and return the result.

iter offset(ind)  where isRange(ind) || isDomain(ind)

Iterate over indices (range/domain) ind but in an offset manner based on the locale id. Can be used to avoid doing communication in lockstep.

proc contiguousIndices(A: []) param

Determines if the passed array array maps contiguous indices to contiguous memory.

Arguments

A – array to check

proc validateArraysSameLength(n: int, names: [] string, types: [] string, st: borrowed SymTab) throws
  • Takes a variable number of array names from a command message and

  • validates them, checking that they all exist and are the same length

  • and returning metadata about them.

  • arg n

    number of arrays

  • arg fields

    the fields derived from the command message

  • arg st

    symbol table

  • returns

    (length, hasStr, names, objtypes)

proc getBitWidth(a: [?aD] int): (int, bool)
proc getBitWidth(a: [?aD] uint): (int, bool)
proc getBitWidth(a: [?aD] real): (int, bool)
proc getBitWidth(a: [?aD] bool): (int, bool)
proc getBitWidth(a: [?aD] (uint, uint)): (int, bool)
proc getBitWidth(a: [?aD] ?t): (int, bool)  where isHomogeneousTuple(t) && t == t.size * uint(bitsPerDigit)
proc getDigit(key: int, rshift: int, last: bool, negs: bool): int
proc getDigit(key: uint, rshift: int, last: bool, negs: bool): int
proc getDigit(in key: real, rshift: int, last: bool, negs: bool): int
proc getDigit(key: 2*(uint), rshift: int, last: bool, negs: bool): int
proc getDigit(key: _tuple, rshift: int, last: bool, negs: bool): int  where isHomogeneousTuple(key) && key.type == key.size * uint(bitsPerDigit)
proc getNumDigitsNumericArrays(names, st: borrowed SymTab) throws
proc mergeNumericArrays(param numDigits, size, totalDigits, bitWidths, negs, names, st) throws
record lowLevelLocalizingSlice

A localized “slice” of an array. This is meant to be a low-level alternative to array slice assignment with better performance (fewer allocations, especially when the region is local). When the region being sliced is local, a borrowed pointer is stored and isOwned is set to false. When the region is remote or non-contiguous, memory is copied to a local buffer and isOwned is true.

type t
var ptr: c_ptr(t) = nil

Pointer to localized memory

var isOwned: bool = false

Do we own the memory?

proc init(ref A: [] ?t, region: range())
proc deinit()
proc removeDegenRanks(A: [?D] ?t, param N: int) throws  where N <= D.rank

Create a rank ‘N’ array by removing the degenerate ranks from ‘A’ and copying it’s contents into the new array

‘N’ must be equal to ‘A’s rank minus the number of degenerate ranks; halts if this condition isn’t met.

See also: ‘ManipulationMsg.squeezeMsg’

proc broadcastShape(sa: ?Na*int, sb: ?Nb*int, param N: int): N*int throws

Algorithm to determine shape of broadcasted PD array given two array shapes

see: https://data-apis.org/array-api/latest/API_specification/broadcasting.html#algorithm

proc broadcastShape(sa: ?N1*int, sb: ?N2*int): N1*int throws  where N1 >= N2
proc broadcastShape(sa: ?N1*int, sb: ?N2*int): N2*int throws  where N1 < N2
proc removeAxis(shape: ?N*int, axis: int): (N-1)*int
proc appendAxis(shape: ?N*int, axis: int, param value: int): (N+1)*int throws
proc appendAxis(shape: int, axis: int, param value: int): 2*(int) throws
proc unflatten(const ref a: [?d] ?t, shape: ?N*int): [] t throws

unflatten a 1D array into a multi-dimensional array of the given shape

proc flatten(const ref a: [?d] ?t): [] t throws  where a.rank > 1

flatten a multi-dimensional array into a 1D array

record orderer
param rank: int
const accumRankSizes: [0..<rank] int
proc init(shape: ?N*int)
proc indexToOrder(idx: rank*int): int