vec

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2022 License: MIT Imports: 2 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func VectorContainsData

func VectorContainsData(vector ReadOnlyVector, data []float64) bool

VectorContainsData tests whether a given vector contains exactly the same data as the slice of float64 numbers.

Both need to be of the same size in order for this test to be true.

Types

type MutableVector added in v0.2.0

type MutableVector interface {
	ReadOnlyVector

	/* Methods */
	SetValue(i int, value float64)
	SetZero(i int)
}

func Make

func Make(size int) MutableVector

Make returns a vector with the given size all filled with zeroes.

func MakeWithValues

func MakeWithValues(vals []float64) MutableVector

MakeWithValues returns a vector with the given values.

type ReadOnlyVector added in v0.2.0

type ReadOnlyVector interface {
	/* Properties */
	Length() int
	Norm() float64

	/* Methods */
	Value(i int) float64
	Opposite() ReadOnlyVector
	Scaled(factor float64) ReadOnlyVector
	Plus(other ReadOnlyVector) ReadOnlyVector
	Minus(other ReadOnlyVector) ReadOnlyVector
	Times(other ReadOnlyVector) float64

	Clone() ReadOnlyVector
	Equals(other ReadOnlyVector) bool
	AsMutable() MutableVector
}

A ReadOnlyVector is a Vector whose operations never mutate the internal state.

func MakeReadOnly added in v0.2.0

func MakeReadOnly(size int) ReadOnlyVector

MakeReadOnly returns a read-only vector with the given size all filled with zeroes.

type Vector

type Vector struct {
	// contains filtered or unexported fields
}

Vector is a one-dimension array of float64 values.

func (Vector) AsMutable added in v0.2.0

func (v Vector) AsMutable() MutableVector

As Mutable returns this vector typed as a mutable one.

func (Vector) Clone

func (v Vector) Clone() ReadOnlyVector

Clone creates an exact copy of the vector.

func (Vector) Equals

func (v Vector) Equals(other ReadOnlyVector) bool

Equals compares two vectors and returns true if they contain the same elements.

func (Vector) Length

func (v Vector) Length() int

Length is the size of the vector.

func (Vector) Minus

func (v Vector) Minus(other ReadOnlyVector) ReadOnlyVector

Minus subtracts two vectors.

func (Vector) Norm

func (v Vector) Norm() float64

Norm returns the L2-norm of the vector.

func (Vector) Opposite

func (v Vector) Opposite() ReadOnlyVector

Opposite creates a new vector which is the opposite of this one, that is, points in the opposite direction.

func (Vector) Plus

func (v Vector) Plus(other ReadOnlyVector) ReadOnlyVector

Plus adds two vectors.

func (Vector) Scaled

func (v Vector) Scaled(factor float64) ReadOnlyVector

Scaled creates a new vector consisting on the scaled projections of this vector.

func (*Vector) SetValue

func (v *Vector) SetValue(i int, value float64)

SetValue sets the given value at the given index.

func (*Vector) SetZero

func (v *Vector) SetZero(i int)

SetZero sets a zero value in the given index.

func (Vector) Times

func (v Vector) Times(other ReadOnlyVector) float64

Times multiplies two vectors as v' · other.

func (Vector) Value

func (v Vector) Value(i int) float64

Value returns the value at the given index.

Jump to

Keyboard shortcuts

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