vector

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2020 License: MIT Imports: 1 Imported by: 0

README

Vector

test Go Report Card codecov

This library provides basic implementation of linear algebra "vector" data structure with basic operations. It was made as small test assignment. So only basic things has been implemented.

Supported operations:

  • Length
  • Add
  • Subtract
  • ScalarMultiply
  • DotProduct
  • CrossProduct

Almost all functions within this package panics when vectors used in a wrong way. For example: It panics if 2 vectors has different dimensions. For more information see package documentation.

Test

Just run go test -v -race -cover ./...

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Vector

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

Vector described mathematical Vector. It stores []float64 array under the hood.

func NewVector

func NewVector(data ...float64) Vector

NewVector creates new vector. It panics when there is less than 2 arguments provided.

func NewVectorFromFloat64Array

func NewVectorFromFloat64Array(data []float64) Vector

NewVectorFromFloat64Array creates new vector from float64 slice. It panics when array length is less than 2.

func (Vector) Add

func (v Vector) Add(v1 Vector) Vector

Add adds v1 to current vector. It don't mutate current vector but return a new one. Also this function panics when vector dimensions are not the same.

func (Vector) CrossProduct

func (v Vector) CrossProduct(v1 Vector) Vector

CrossProduct do cross product of current vector with v1. It don't mutate current vector but return a new one. Also this function panics when vector dimension are not equal to 3.

func (Vector) Dimension

func (v Vector) Dimension() int

Dimension returns length of underlying array.

func (Vector) DotProduct

func (v Vector) DotProduct(v1 Vector) float64

DotProduct do dot product of current vector with v1. It don't mutate current vector but return a new one. Also this function panics when vector dimensions are not the same.

func (Vector) Length

func (v Vector) Length() float64

Length returns vector length.

func (Vector) ScalarMultiply

func (v Vector) ScalarMultiply(scalar float64) Vector

ScalarMultiply multiply current vector with scalar. It don't mutate current vector but return a new one.

func (Vector) Subtract

func (v Vector) Subtract(v1 Vector) Vector

Subtract subtracts v1 from current vector. It don't mutate current vector but return a new one. Also this function panics when vector dimensions are not the same.

func (Vector) ToFloat64Array

func (v Vector) ToFloat64Array() []float64

ToFloat64Array Convert vector to []float64 array.

Jump to

Keyboard shortcuts

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