Documentation ¶
Index ¶
- type Matrix
- func Add[T math.Real](matrices ...*Matrix[T]) *Matrix[T]
- func DotMultiply[T math.Real](matrices ...*Matrix[T]) *Matrix[T]
- func Identity[T math.Number](size Size) *Matrix[T]
- func Multiply[T math.Real](first, second *Matrix[T]) *Matrix[T]
- func Negate[T math.Real](matrix *Matrix[T]) *Matrix[T]
- func New[T any](size Size) *Matrix[T]
- func NewFromSlices[T any](values [][]T) *Matrix[T]
- func Ones[T math.Number](size Size) *Matrix[T]
- func ScalarMultiply[T math.Real](matrix *Matrix[T], scalar T) *Matrix[T]
- func Subtract[T math.Real](first, second *Matrix[T]) *Matrix[T]
- func Zeros[T math.Number](size Size) *Matrix[T]
- func (matrix *Matrix[T]) AppendColumn(column []T)
- func (matrix *Matrix[T]) AppendRow(row []T)
- func (matrix *Matrix[T]) Clone() *Matrix[T]
- func (matrix *Matrix[T]) Get(row, column int) T
- func (matrix *Matrix[T]) GetRef(row, column int) *T
- func (matrix *Matrix[T]) InsertColumn(index int, column []T)
- func (matrix *Matrix[T]) InsertRow(index int, row []T)
- func (matrix *Matrix[T]) RemoveColumn(index int)
- func (matrix *Matrix[T]) RemoveRow(index int)
- func (matrix *Matrix[T]) Reshape(newSize Size)
- func (matrix *Matrix[T]) Set(row, column int, value T)
- func (matrix *Matrix[T]) Size() Size
- func (matrix *Matrix[T]) Transpose()
- type Size
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
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
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
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 NewFromSlices ¶ added in v1.6.0
NewFromSlices creates a new matrix from the given slices.
func ScalarMultiply ¶ added in v1.3.0
ScalarMultiply multiplies the matrix with a scalar and returns the result.
func Subtract ¶ added in v1.3.0
Subtract subtracts the second matrix from the first and returns the result. If the matrices are not of the same size, it panics.
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]) GetRef ¶ added in v1.0.0
GetRef returns a reference to the value at the given position.
func (*Matrix[T]) InsertColumn ¶ added in v1.3.0
InsertColumn inserts a column at the given index.
func (*Matrix[T]) RemoveColumn ¶ added in v1.3.0
RemoveColumn removes the column at the given index.
func (*Matrix[T]) Reshape ¶ added in v1.3.0
Reshape reshapes the matrix into the given size. The number of elements must be the same. The matrix is reshaped in row-major order.
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
Elements returns the number of elements in the matrix of the given size.
func (Size) Index ¶ added in v1.3.0
Index returns the index of the element at the given row and column.
func (Size) Transposed ¶ added in v1.3.0
Transposed returns the size of a transposed matrix.