Version: v0.0.0-...-040724e Latest Latest

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

Go to latest
Published: Jun 6, 2019 License: BSD-3-Clause, GPL-2.0, BSD-3-Clause, GPL-2.0 Imports: 6 Imported by: 0



Package num provides tools for floats arithmetic.


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).


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.



View Source
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).
	// Valid - returns the output of length max(M, N) - min(M, N) + 1.


This section is empty.


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:

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.

Jump to

Keyboard shortcuts

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