Documentation
¶
Overview ¶
package utl implements functions for simplifying calculations and allocation of structures such as slices and slices of slices. It also contains functions for sorting quantities.
Index ¶
- Constants
- func BestSquare(size int) (nrow, ncol int)
- func Dbl2Str(v []float64, format string) (s []string)
- func DblArrayToMat(v []float64, m, n int) (a [][]float64)
- func DblCopy(in []float64) (out []float64)
- func DblDsort3(a, b, c *float64)
- func DblGetSorted(A []float64) (Asorted []float64)
- func DblMatToArray(a [][]float64) (v []float64)
- func DblMinMax(v []float64) (mi, ma float64)
- func DblOnes(n int) (res []float64)
- func DblSort3(a, b, c *float64)
- func DblSplit(s string) (r []float64)
- func DblSum(v []float64) (sum float64)
- func DblVals(n int, v float64) (res []float64)
- func DblsAlloc(m, n int) (mat [][]float64)
- func Deep3Deserialize(I, P []int, S []float64, debug bool) (A [][][]float64)
- func Deep3GetInfo(I, P []int, S []float64, verbose bool) (nitems, nrows, ncols_tot int, ncols []int)
- func Deep3Serialize(A [][][]float64) (I, P []int, S []float64)
- func Deep3alloc(n1, n2, n3 int) (a [][][]float64)
- func Deep3set(a [][][]float64, v float64)
- func Deep4alloc(n1, n2, n3, n4 int) (a [][][][]float64)
- func Deep4set(a [][][][]float64, v float64)
- func Digits(maxint int) (ndigits int, format string)
- func DoProf(silent bool) func()
- func DurSum(v []time.Duration) (seconds float64)
- func Expon(val float64) (ndigits int)
- func GetITout(all_output_times, time_stations_out []float64, tol float64) (I []int, T []float64)
- func IntAddScalar(a []int, s int) (res []int)
- func IntBoolMapSort(m map[int]bool) (sorted_keys []int)
- func IntFill(s []int, val int)
- func IntFilter(a []int, out func(idx int) bool) (res []int)
- func IntIndexSmall(a []int, val int) int
- func IntIntsMapAppend(m *map[int][]int, key int, item int)
- func IntMinMax(v []int) (mi, ma int)
- func IntNegOut(a []int) (res []int)
- func IntPy(a []int) (res string)
- func IntRange(n int) (res []int)
- func IntRange2(start, stop int) []int
- func IntRange3(start, stop, step int) (res []int)
- func IntUnique(slices ...[]int) (res []int)
- func IntVals(n int, val int) (s []int)
- func IntsAlloc(m, n int) (mat [][]int)
- func LinSpace(start, stop float64, num int) (res []float64)
- func LinSpaceOpen(start, stop float64, num int) (res []float64)
- func MeshGrid2D(xmin, xmax, ymin, ymax float64, nx, ny int) (x, y [][]float64)
- func PrintDeep3(name string, A [][][]float64)
- func PrintDeep4(name string, A [][][][]float64, format string)
- func ProfCPU(dirout, filename string, silent bool) func()
- func ProfMEM(dirout, filename string, silent bool) func()
- func SortQuadruples(i []int, x, y, z []float64, by string) (I []int, X, Y, Z []float64, err error)
- func Str2Dbl(s []string) (v []float64)
- func StrBoolMapSort(m map[string]bool) (sorted_keys []string)
- func StrBoolMapSortSplit(m map[string]bool) (sorted_keys []string, sorted_vals []bool)
- func StrDblMapSort(m map[string]float64) (sorted_keys []string)
- func StrDblMapSortSplit(m map[string]float64) (sorted_keys []string, sorted_vals []float64)
- func StrDblsMapAppend(m *map[string][]float64, key string, item float64)
- func StrIndexSmall(a []string, val string) int
- func StrIntMapSort(m map[string]int) (sorted_keys []string)
- func StrIntMapSortSplit(m map[string]int) (sorted_keys []string, sorted_vals []int)
- func StrIntsMapAppend(m *map[string][]int, key string, item int)
- func StrVals(n int, val string) (s []string)
- type DblList
- type DblSlist
- type Quadruple
- type Quadruples
- type QuadruplesByI
- type QuadruplesByX
- type QuadruplesByY
- type QuadruplesByZ
Constants ¶
const PRINTDEEPZERO = 1e-3
Variables ¶
This section is empty.
Functions ¶
func BestSquare ¶
BestSquare finds the best square for given size=Nrows * Ncolumns
func DblArrayToMat ¶
DblArrayToMat converts a column-major array to a matrix
func DblGetSorted ¶
DblGetSorted returns a sorted (increasing) copy of 'A'
func DblMatToArray ¶
DblMatToArray converts a matrix into a column-major array
func DblMinMax ¶
DblMinMax returns the maximum and minimum elements in v
NOTE: this is not efficient and should be used for small slices only
func DblSum ¶
DblSum sums all items in v
NOTE: this is not efficient and should be used for small slices only
func Deep3Deserialize ¶
Deep3Deserialize deserializes an array of array of array in column-compressed format
Example:
func Deep3GetInfo ¶
func Deep3GetInfo(I, P []int, S []float64, verbose bool) (nitems, nrows, ncols_tot int, ncols []int)
Deep3GetInfo returns information of serialized array of array of array
Example:
func Deep3Serialize ¶
Deep3Serialize serializes an array of array of array in column-compressed format
Example:
func Deep3alloc ¶
Deep3alloc allocates a slice of slice of slice
func Deep4alloc ¶
Deep4alloc allocates a slice of slice of slice of slice
func DoProf ¶
func DoProf(silent bool) func()
DoProf runs either CPU profiling or MEM profiling
Notes:
1) based on input flags: -cpuprof (preferred); or
-memprof
2) returns a "stop()" function to be called before shutting down
3) output files are saved to "/tmp/gosl/cpu.pprof"; or
"/tmp/gosl/mem.pprof"
func DurSum ¶
DurSum sums all seconds in v
NOTE: this is not efficient and should be used for small slices only
func GetITout ¶
GetITout returns indices and output times
Input: all_output_times -- array with all output times. ex: [0,0.1,0.2,0.22,0.3,0.4] time_stations_out -- time stations for output: ex: [0,0.2,0.4] tol -- tolerance to compare times Output: iout -- indices of times in all_output_times tout -- times corresponding to iout Notes: use -1 in all_output_times to enforce output of last timestep
func IntAddScalar ¶
IntAddScalar adds a scalar to all values in a slice of integers
func IntBoolMapSort ¶
func IntFilter ¶
IntFilter filters out components in slice
NOTE: this function is not efficient and should be used with small slices only
func IntIndexSmall ¶
IntIndexSmall finds the index of an item in a slice of ints
NOTE: this function is not efficient and should be used with small slices only; say smaller than 20
func IntIntsMapAppend ¶
IntIntsMapAppend appends a new item to a map of slice.
Note: this function creates a new slice in the map if key is not found.
func IntMinMax ¶
IntMinMax returns the maximum and minimum elements in v
NOTE: this is not efficient and should be used for small slices only
func IntNegOut ¶
IntNegOut filters out negative components in slice
NOTE: this function is not efficient and should be used with small slices only
func IntRange3 ¶
IntRange3 generates a slice of integers from start to stop (but not stop), afer each 'step'
func LinSpaceOpen ¶
LinSpaceOpen returns evenly spaced numbers over a specified open interval.
func PrintDeep3 ¶
PrintDeep3 prints an array of array of array
func PrintDeep4 ¶
PrintDeep4 prints an array of array of array
func ProfCPU ¶
ProfCPU activates CPU profiling
Note: returns a "stop()" function to be called before shutting down
func ProfMEM ¶
ProfMEM activates memory profiling
Note: returns a "stop()" function to be called before shutting down
func SortQuadruples ¶
SortQuadruples sorts i, x, y, and z by "i", "x", "y", or "z"
Note: either i, x, y, or z can be nil; i.e. at least one of them must be non nil
func StrBoolMapSort ¶
func StrBoolMapSortSplit ¶
func StrDblMapSort ¶
func StrDblMapSortSplit ¶
func StrDblsMapAppend ¶
StrDblsMapAppend appends a new item to a map of slice.
Note: this function creates a new slice in the map if key is not found.
func StrIndexSmall ¶
StrIndexSmall finds the index of an item in a slice of strings
NOTE: this function is not efficient and should be used with small slices only; say smaller than 20
func StrIntMapSort ¶
func StrIntMapSortSplit ¶
func StrIntsMapAppend ¶
StrIntsMapAppend appends a new item to a map of slice.
Note: this function creates a new slice in the map if key is not found.
Types ¶
type DblList ¶
type DblList struct {
Vals [][]float64 // values
}
DblList implements a tabular list with variable number of columns
Example:
Vals = [][]float64{
{0.0},
{1.0, 1.1, 1.2, 1.3},
{2.0, 2.1},
{3.0, 3.1, 3.2},
}
type DblSlist ¶
DblSlist implements a tabular list with variable number of columns using a serial representation
Example:
0.0
1.0 1.1 1.2 1.3
2.0 2.1
3.0 3.1 3.2
becomes:
(0) (1) 2 3 4 (5) 6 (7) 8 9 (10)
Vals = 0.0 | 1.0 1.1 1.2 1.3 | 2.0 2.1 | 3.0 3.1 3.2 |
Ptrs = 0 1 5 7 10
Notes:
len(Ptrs) = nrows + 1
Ptrs[len(Ptrs)-1] = len(Vals)
type Quadruples ¶
type Quadruples []*Quadruple
Quadruples helps to sort quadruples
func BuildQuadruples ¶
func BuildQuadruples(i []int, x, y, z []float64) (q Quadruples)
Init initialise Quadruples with i, x, y, and z
Note: i, x, y, or z can be nil; but at least one of them must be non nil
func (Quadruples) String ¶
func (o Quadruples) String() string
String returns the string representation of Quadruples
type QuadruplesByI ¶
type QuadruplesByI struct{ Quadruples }
Sort Quadruples by I
func (QuadruplesByI) Less ¶
func (o QuadruplesByI) Less(i, j int) bool
type QuadruplesByX ¶
type QuadruplesByX struct{ Quadruples }
Sort Quadruples by X
func (QuadruplesByX) Less ¶
func (o QuadruplesByX) Less(i, j int) bool
type QuadruplesByY ¶
type QuadruplesByY struct{ Quadruples }
Sort Quadruples by Y
func (QuadruplesByY) Less ¶
func (o QuadruplesByY) Less(i, j int) bool
type QuadruplesByZ ¶
type QuadruplesByZ struct{ Quadruples }
Sort Quadruples by Z
func (QuadruplesByZ) Less ¶
func (o QuadruplesByZ) Less(i, j int) bool