Back to godoc.org

Package num

v0.0.0-...-040724e
Latest Go to latest

The latest major version is .

Published: Jun 6, 2019 | Licenses: BSD-3-Clause , GPL2 , BSD-3-Clause , GPL2 | Module: github.com/antha-lang/antha

Overview

Package num provides tools for floats arithmetic.

Overview

The aim of this package is to provide Antha users with a library containing basic float vectors operations.

The package supplements the gonum package and provides a simpler interface for some of its parts. While gonum focuses on efficiency and tends to avoid allocations inside its functions, the num package allows to do multiple element-wise operations more concisely (though at the cost of some additional allocations).

Example:

x := []float64{1, 2, 3}
linear_transformed_x := num.Add(num.Mul(a, x), b)

Also num is aimed at implementing at least some basic numpy functionality currently missing in gonum.

Index

Constants

const (
	// Full - returns the convolution at each point of overlap, i.e. of length N+M-1.
	Full = iota
	// Same - returns the output of length max(M, N).
	Same
	// Valid - returns the output of length max(M, N) - min(M, N) + 1.
	Valid
)

func Add

func Add(a, b []float64) []float64

Add adds two vectors.

func AddConst

func AddConst(a []float64, b float64) []float64

AddConst adds a scalar to a vector.

func Arange

func Arange(start int, stop int) []float64

Arange implements `np.arange` - i.e. returns a list of integers (start, ..., stop - 1) in the form of []float64

func Convolve

func Convolve(a, v []float64, mode ConvolutionMode) []float64

Convolve is a (very naive) implementation of precise discrete convolution. The results are numerically equivalent to `np.convolve(a, v, mode)` - it looks like that `np.convolve` uses precise convolution as well (but not an FFT approximation). TODO: optimize the implementation - the current one has O((M+N)^2) time complexity. Looks like it's possible to achieve at least O(MN).

func Div

func Div(a, b []float64) []float64

Div divides one vector by another.

func DivByConst

func DivByConst(a []float64, b float64) []float64

DivByConst divides a vector by a scalar.

func DivConst

func DivConst(a float64, b []float64) []float64

DivConst divides a scalar by a vector.

func Linspace

func Linspace(start, end float64, num int) []float64

Linspace implements `np.linspace` - i.e. splits the interval [start, end] into `num - 1` equal intervals and returns `num` split points.

func LstSq

func LstSq(a, b *mat.Dense) *mat.Dense

LstSq computes least-squares solution to equation A*x = b, i.e. computes a vector x such that the 2-norm ``|b - A x|`` is minimized. Based on: https://github.com/scipy/scipy/blob/v1.3.0rc1/scipy/linalg/basic.py#L1042

func Mul

func Mul(a, b []float64) []float64

Mul multiplies two vectors.

func MulByConst

func MulByConst(a []float64, b float64) []float64

MulByConst multiplies a vector by a scalar.

func Ones

func Ones(size int) []float64

Ones return an array of ones of specified size.

func Sub

func Sub(a, b []float64) []float64

Sub subtracts one vector from another.

func SubConst

func SubConst(a []float64, b float64) []float64

SubConst subtracts a scalar from a vector.

func SubFromConst

func SubFromConst(a float64, b []float64) []float64

SubFromConst subtracts a vector from a scalar.

func Zeroes

func Zeroes(size int) []float64

Zeroes returns an array of zeroes of specified size. It's encouraged to use it instead of just make() in case the further code relies on the fact that the array contains zeroes.

type ConvolutionMode

type ConvolutionMode int

ConvolutionMode defines convolution output array length.

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier