func NewMatrixFromFunction(rows, columns int, fn func(int, int) T) Matrix {
	checkRowColumnCount(rows, columns)
	elements := make([]T, rows*columns)
	for i := 0; i < rows; i++ {
		for j := 0; j < columns; j++ {
			elements[i*columns+j] = fn(i, j)
		}
	}
	return NewMatrixFromSlice(rows, columns, elements)
}
NewMatrixFromFunction returns a rows x columns matrix with elements
filled in from the given function, which is passed the row index
and the column index, and shouldn't rely on any particular call
ordering.
package gf2p16
import "errors"
type Matrix struct {
	rows, columns int
	elements []T
}
func checkRowColumnCount(rows, columns int) {
	if rows <= 0 {
		panic("invalid row count")
	}
	if columns <= 0 {
		panic("invalid column count")
	}
}
func NewZeroMatrix(rows, columns int) Matrix {
	checkRowColumnCount(rows, columns)
	return Matrix{rows, columns, make([]T, rows*columns)}
}
func NewMatrixFromSlice(rows, columns int, elements []T) Matrix {
	checkRowColumnCount(rows, columns)
	if len(elements) != rows*columns {
		panic("element count is not rows*columns")
	}
	elementsCopy := make([]T, len(elements))
	copy(elementsCopy, elements)
	return Matrix{rows, columns, elementsCopy}
}