matrix

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Matrix

type Matrix[T any] struct {
	// contains filtered or unexported fields
}

Matrix is a two-dimensional array of values. The zero value is ready to use. Do not copy a non-zero Matrix.

func Add added in v1.3.0

func Add[T math.Real](matrices ...*Matrix[T]) *Matrix[T]

Add adds multiple matrices together and returns the result. If the matrices are not of the same size, it panics. If no matrices are provided, it returns nil.

func DotMultiply added in v1.3.0

func DotMultiply[T math.Real](matrices ...*Matrix[T]) *Matrix[T]

DotMultiply multiplies multiple matrices together and returns the result. This function is equivalent to multiplying the matrices element by element. If the matrices are not of the same size, it panics. If no matrices are provided, it returns nil.

func Identity added in v1.3.0

func Identity[T math.Number](size Size) *Matrix[T]

Identity returns an identity matrix of the given size. Identity matrix is a square matrix with ones on the main diagonal and zeros elsewhere.

func Multiply added in v1.3.0

func Multiply[T math.Real](first, second *Matrix[T]) *Matrix[T]

Multiply multiplies two matrices together and returns the result.

func Negate added in v1.3.2

func Negate[T math.Real](matrix *Matrix[T]) *Matrix[T]

Negate negates the matrix and returns the result.

func New

func New[T any](size Size) *Matrix[T]

New creates a new matrix with the given size.

func NewFromSlices added in v1.6.0

func NewFromSlices[T any](values [][]T) *Matrix[T]

NewFromSlices creates a new matrix from the given slices.

func Ones added in v1.3.0

func Ones[T math.Number](size Size) *Matrix[T]

Ones returns a matrix of the given size filled with ones.

func ScalarMultiply added in v1.3.0

func ScalarMultiply[T math.Real](matrix *Matrix[T], scalar T) *Matrix[T]

ScalarMultiply multiplies the matrix with a scalar and returns the result.

func Subtract added in v1.3.0

func Subtract[T math.Real](first, second *Matrix[T]) *Matrix[T]

Subtract subtracts the second matrix from the first and returns the result. If the matrices are not of the same size, it panics.

func Zeros added in v1.3.0

func Zeros[T math.Number](size Size) *Matrix[T]

Zeros returns a matrix of the given size filled with zeros.

func (*Matrix[T]) AppendColumn added in v0.8.0

func (matrix *Matrix[T]) AppendColumn(column []T)

AppendColumn appends a column to the matrix.

func (*Matrix[T]) AppendRow added in v0.8.0

func (matrix *Matrix[T]) AppendRow(row []T)

AppendRow appends a row to the matrix.

func (*Matrix[T]) Clone

func (matrix *Matrix[T]) Clone() *Matrix[T]

Clone returns a copy of the matrix.

func (*Matrix[T]) Get

func (matrix *Matrix[T]) Get(row, column int) T

Get returns the value at the given position.

func (*Matrix[T]) GetRef added in v1.0.0

func (matrix *Matrix[T]) GetRef(row, column int) *T

GetRef returns a reference to the value at the given position.

func (*Matrix[T]) InsertColumn added in v1.3.0

func (matrix *Matrix[T]) InsertColumn(index int, column []T)

InsertColumn inserts a column at the given index.

func (*Matrix[T]) InsertRow added in v1.3.0

func (matrix *Matrix[T]) InsertRow(index int, row []T)

InsertRow inserts a row at the given index.

func (*Matrix[T]) RemoveColumn added in v1.3.0

func (matrix *Matrix[T]) RemoveColumn(index int)

RemoveColumn removes the column at the given index.

func (*Matrix[T]) RemoveRow added in v1.3.0

func (matrix *Matrix[T]) RemoveRow(index int)

RemoveRow removes the row at the given index.

func (*Matrix[T]) Reshape added in v1.3.0

func (matrix *Matrix[T]) Reshape(newSize Size)

Reshape reshapes the matrix into the given size. The number of elements must be the same. The matrix is reshaped in row-major order.

func (*Matrix[T]) Set

func (matrix *Matrix[T]) Set(row, column int, value T)

Set sets the value at the given position.

func (*Matrix[T]) Size

func (matrix *Matrix[T]) Size() Size

Size returns the size of the matrix.

func (*Matrix[T]) Transpose added in v1.3.0

func (matrix *Matrix[T]) Transpose()

Transpose transposes the matrix.

type Size added in v1.3.0

type Size struct {
	Height, Width int // Height is the number of rows, Width is the number of columns.
}

Size represents the size of a matrix.

func (Size) Elements added in v1.3.0

func (size Size) Elements() int

Elements returns the number of elements in the matrix of the given size.

func (Size) Index added in v1.3.0

func (size Size) Index(row, column int) int

Index returns the index of the element at the given row and column.

func (Size) String added in v1.3.0

func (size Size) String() string

String returns a string representation of the size.

func (Size) Transposed added in v1.3.0

func (size Size) Transposed() Size

Transposed returns the size of a transposed matrix.

Jump to

Keyboard shortcuts

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