ints

package module
v0.0.0-...-e7b9a0e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 25, 2014 License: MIT Imports: 2 Imported by: 10

README

ints

Golang lib for working with slices of ints

Ported from: https://github.com/gonum/floats

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add

func Add(dst []int, slices ...[]int) []int

Add returns the element-wise sum of all the slices with the results stored in the first slice. For computational efficiency, it is assumed that all of the variadic arguments have the same length. If this is in doubt, EqLen can be used.

func AddConst

func AddConst(c int, s []int)

AddConst adds the value c to all of the values in s.

func AddScaled

func AddScaled(dst []int, alpha int, s []int)

AddScaled performs dst = dst + alpha * s. It panics if the lengths of dst and s are not equal.

func AddScaledTo

func AddScaledTo(dst []int, y []int, alpha int, s []int) []int

AddScaledTo performs dst = y + alpha * s. It panics if the lengths of dst, y, and s are not equal.

func Apply

func Apply(f func(int) int, s []int)

ApplyFunc applies a function f (math.Exp, math.Sin, etc.) to every element of the slice s.

func Argsort

func Argsort(s []int, inds []int)

Argsort sorts the elements of s while tracking their original order. At the conclusion of Argsort, s will contain the original elements of s but sorted in increasing order, and inds will contain the original position of the elements in the slice such that s[i] = sOrig[inds[i]].

func Count

func Count(f func(int) bool, s []int) int

Count applies the function f to every element of s and returns the number of times the function returned true.

func CumProd

func CumProd(dst, s []int) []int

Cumprod finds the cumulative product of the first i elements in s and puts them in place into the ith element of the destination. A panic will occur if lengths of do not match.

func CumSum

func CumSum(dst, s []int) []int

Cumsum finds the cumulative sum of the first i elements in s and puts them in place into the ith element of the destination. A panic will occur if lengths of arguments do not match.

func Div

func Div(s []int, t []int)

Div performs element-wise division between s and t and stores the value in s. It panics if the lengths of s and t are not equal.

func DivTo

func DivTo(dst []int, s []int, t []int) []int

DivTo performs element-wise division between s and t and stores the value in dst. It panics if the lengths of s, t, and dst are not equal.

func Dot

func Dot(s1, s2 []int) int

Dot computes the dot product of s1 and s2, i.e. sum_{i = 1}^N s1[i]*s2[i]. A panic will occur if lengths of arguments do not match.

func Equal

func Equal(s1, s2 []int) bool

Equal returns true if the slices have equal lengths and all elements are numerically identical.

func EqualFunc

func EqualFunc(s1, s2 []int, f func(int, int) bool) bool

EqualsFunc returns true if the slices have the same lengths and the function returns true for all element pairs.

func EqualLengths

func EqualLengths(slices ...[]int) bool

Eqlen returns true if all of the slices have equal length, and false otherwise. Returns true if there are no input slices.

func Fill

func Fill(f func() int, s []int)

Fill loops over the elements of s and stores a value generated from f. f is called n times, where n = len(s)

func Find

func Find(inds []int, f func(int) bool, s []int, k int) ([]int, error)

Find applies f to every element of s and returns the indices of the first k elements for which the f returns true, or all such elements if k < 0. Find will reslice inds to have 0 length, and will append found indices to inds. If k > 0 and there are fewer than k elements in s satisfying f, all of the found elements will be returned along with an error.

func Max

func Max(s []int) (max int, ind int)

Max returns the maximum value in the slice and the location of the maximum value. If the input slice is empty, Max will panic.

func Min

func Min(s []int) (min int, ind int)

Min returns the minimum value in the slice and the index of the minimum value. If the input slice is empty, Min will panic.

func Mul

func Mul(s []int, t []int)

Mul performs element-wise multiplication between s and t and stores the value in s. Panics if the lengths of s and t are not equal.

func MulTo

func MulTo(dst []int, s []int, t []int) []int

MulTo performs element-wise multiplication between s and t and stores the value in dst. Panics if the lengths of s, t, and dst are not equal.

func Prod

func Prod(s []int) (prod int)

Prod returns the product of the elements of the slice Returns 1 if len(s) = 0.

func Scale

func Scale(c int, s []int)

Scale multiplies every element in s by c.

func Span

func Span(dst []int, l, u int) []int

Span returns a set of N equally spaced points between l and u, where N is equal to the length of the destination. The first element of the destination is l, the final element of the destination is u. Panics if len(dst) < 2.

func Sub

func Sub(s, t []int)

Sub subtracts, element-wise, the first argument from the second. Assumes the lengths of s and t match (can be tested with EqLen).

func SubTo

func SubTo(dst, s, t []int) []int

SubTo subtracts, element-wise, the first argument from the second and stores the result in dest. Panics if the lengths of s and t do not match.

func Sum

func Sum(s []int) (sum int)

Sum returns the sum of the elements of the slice.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL