Documentation
¶
Index ¶
- func Compare(x float32, y float32) (max float32, min float32)
- func Contains(slice []float32, s float32) bool
- func Cumsum(slice []float32) []float32
- func Delta(slice []float32) []float32
- func DropNan(slice []float32) []float32
- func DropNanInplace(slice *[]float32)
- func FillNan(slice []float32, method string, prefill bool, validTime int) []float32
- func FillNanInplace(slice *[]float32, method string, prefill bool, validTime int)
- func FindIndex(slice []float32, val float32) (int, bool)
- func GetIndex(slice []float32, val float32) int
- func Insert(slice []float32, idx int, val float32) []float32
- func IsEqualSlice(s1, s2 []float32) bool
- func IsSameSign(x float32, y float32) bool
- func IsValid(value float32) bool
- func Max(a, b float32) float32
- func MaxFrom(s []float32) (max float32)
- func Median(data []float32) float32
- func MedianFromSorted(data []float32) float32
- func Min(a, b float32) float32
- func MinFrom(s []float32) (min float32)
- func MulSlices(s1, s2 []float32) []float32
- func NanSlice(size int) (nanslice []float32)
- func NumRange(start int, end int, step int) (numberrange []float32)
- func PrettyPerc(v1, v2 float32, decimals int) float32
- func QuickSelect(data []float32, k int) float32
- func QuickSelects(data []float32, k int) (float32, float32)
- func Quicksort(data []float32)
- func RemoveFrom(slice []float32, s int) []float32
- func ReplaceNan(value float32, replacewith float32) float32
- func ReplaceNans(values []float32, replacewith float32) []float32
- func ReplaceNansInplace(values *[]float32, replacewith float32)
- func RoundTo(val float32, digits int) float32
- func RoundToNearest(value float32, nearest float32) float32
- func Select(condition bool, i1, i2 float32) float32
- func SetDefault(defaultval float32, confval float32) float32
- func SliceOf(value float32, size int) []float32
- func Sum(s []float32) (sum float32)
- func SwitchIf(condition bool, i1, i2 float32) (float32, float32)
- type Rounded
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Delta ¶
Returns the delta between all consecutive floats. Returned slice length is one item shorter.
func FillNan ¶
Fills NaN values with a value based on given method:
"previous" // fills the NaNs with previous value "linear" // fills the NaNs with linear interpolation
Filling starts from first valid value, thus leaving any preceding NaNs untouched. By setting prefill = true, first valid value is used to replace also the preceding NaNs.
One sample's lifetime can be set by setting validTime value to > 0. Filling is then performed for validTime samples. Using validTime overrides prefill = true -setting
func FillNanInplace ¶
Fills NaN values inplace with a value based on given method:
"previous" // fills the NaNs with previous value "linear" // fills the NaNs with linear interpolation
Filling starts from first valid value, thus leaving any preceding NaNs untouched. By setting prefill = true, first valid value is used to replace also the preceding NaNs.
One sample's lifetime can be set by setting validTime value to > 0. Filling is then performed for validTime samples. Using validTime overrides prefill = true -setting
func GetIndex ¶
Finds the index of first occurrence of the given value and returns the index. If not found index = -1.
func IsEqualSlice ¶
Checks if two slices are equal, element-wise. NaN and Inf are also handled.
func IsSameSign ¶
Checks if two values have same sign. Zero sign is ambiguous and is considered to be both positive and negative.
func Median ¶
Finds the middle value or mean of middle values from dataset using Quickselect Note: Contents of data is altered
func NumRange ¶
Returns an evenly spaced slice of floats, between <start> and <end> with spacing <step>.
func PrettyPerc ¶
Calculate ratio v1/v2 as percentage value with defined amount of decimals
func QuickSelect ¶
Finds kth largest value from data. NOTE: Will crash if len(data)=0
func QuickSelects ¶
Finds kth and (k+1) th largest value from data. NOTE: Will crash if len(data)=0
func Quicksort ¶
func Quicksort(data []float32)
Sorts data into ascending order using Quicksort. Note: Not safe to use with NaNs. If data is already sorted, the algorithm will be very slow compared to regular sort.
func RemoveFrom ¶
Removes an integer from given index
func ReplaceNan ¶
Replaces given value with a new one, if given value is NaN or Inf.
func ReplaceNans ¶
Replaces all NaNs in a slice with given value and returns a new slice.
func ReplaceNansInplace ¶
Replaces all NaNs in a slice in place with given value.
func RoundToNearest ¶
Rounds <value> to <nearest> value
func SetDefault ¶
Replaces default value for a parameter, if the configuration value is zero (ie. initialized empty variable). Note that the function does not make any difference, if the configuration is set to zero on purpose.
Types ¶
type Rounded ¶
type Rounded struct { Rawvalue float32 // raw value with given digits but no prefix Prefix string // prefix string Value float32 // rounded value with given digits and prefix Response string // response string as <Value> <Prefix><unit> Prettyvalue float32 // rounded value with one decimal Prettyresponse string // response string as <Value> <Prefix><unit> ; if value is <0.1 , shows "less than 0.1" }
func RoundWithPrefix ¶
Returns the rounded value to given digits and correct prefix (M for Megas, k for Kilos etc.) Special case is abs(value) between 1000....10000, which is not converted to kilos (because it looks nicer) set prefix to force certain prefix, otherwise the function figures it out on its' own. These units are excluded from having a prefix
noprefixUnits := []string{"%", "cycles", "years", "°c", "°lon", "°lat", "events", "", " "}