Improve documentation about underlying types
MODIFY
mat64/dense.go
mat64/dense.go
@@ -36,24 +36,26 @@ type Dense struct {
capRows, capCols int
}
-// NewDense creates a new matrix of type Dense with dimensions r and c.
-// If the mat argument is nil, a new data slice is allocated.
+// NewDense creates a new Dense matrix with r rows and c columns. If data == nil,
+// a new slice is allocated for the backing slice. If len(data) == r*c, data is
+// used as the backing slice, and changes to the elements of the returned Dense
+// will be reflected in data. If neither of these is true, NewDense will panic.
//
// The data must be arranged in row-major order, i.e. the (i*c + j)-th
-// element in mat is the {i, j}-th element in the matrix.
-func NewDense(r, c int, mat []float64) *Dense {
- if mat != nil && r*c != len(mat) {
+// element in the data slice is the {i, j}-th element in the matrix.
+func NewDense(r, c int, data []float64) *Dense {
+ if data != nil && r*c != len(data) {
panic(matrix.ErrShape)
}
- if mat == nil {
- mat = make([]float64, r*c)
+ if data == nil {
+ data = make([]float64, r*c)
}
return &Dense{
mat: blas64.General{
Rows: r,
Cols: c,
Stride: c,
- Data: mat,
+ Data: data,
},
capRows: r,
capCols: c,

MODIFY
mat64/symmetric.go
mat64/symmetric.go
@@ -51,25 +51,29 @@ type MutableSymmetric interface {
SetSym(i, j int, v float64)
}
-// NewSymDense constructs an n x n symmetric matrix. If len(mat) == n * n,
-// mat will be used to hold the underlying data, or if mat == nil, new data will be allocated.
-// The underlying data representation is the same as a Dense matrix, except
-// the values of the entries in the lower triangular portion are completely ignored.
-func NewSymDense(n int, mat []float64) *SymDense {
+// NewSymDense creates a new Symmetric matrix with n rows and columns. If data == nil,
+// a new slice is allocated for the backing slice. If len(data) == n*n, data is
+// used as the backing slice, and changes to the elements of the returned SymDense
+// will be reflected in data. If neither of these is true, NewSymDense will panic.
+//
+// The data must be arranged in row-major order, i.e. the (i*c + j)-th
+// element in the data slice is the {i, j}-th element in the matrix.
+// Only the values in the upper triangular portion of the matrix are used.
+func NewSymDense(n int, data []float64) *SymDense {
if n < 0 {
panic("mat64: negative dimension")
}
- if mat != nil && n*n != len(mat) {
+ if data != nil && n*n != len(data) {
panic(matrix.ErrShape)
}
- if mat == nil {
- mat = make([]float64, n*n)
+ if data == nil {
+ data = make([]float64, n*n)
}
return &SymDense{
mat: blas64.Symmetric{
N: n,
Stride: n,
- Data: mat,
+ Data: data,
Uplo: blas.Upper,
},
cap: n,

MODIFY
mat64/triangular.go
mat64/triangular.go
@@ -91,22 +91,23 @@ func (t TransposeTri) UntransposeTri() Triangular {
return t.Triangular
}
-// NewTriDense constructs an n x n triangular matrix with the orientation
-// specified by kind.
-// If len(mat) == n * n, mat will be used to hold the underlying data, if
-// mat == nil, new data will be allocated, and will panic if neither of these
-// cases is true.
-// The underlying data representation is the same as that of a Dense matrix,
-// except the values of the entries in the opposite half are completely ignored.
-func NewTriDense(n int, kind matrix.TriKind, mat []float64) *TriDense {
+// NewTriDense creates a new Triangular matrix with n rows and columns. If data == nil,
+// a new slice is allocated for the backing slice. If len(data) == n*n, data is
+// used as the backing slice, and changes to the elements of the returned TriDense
+// will be reflected in data. If neither of these is true, NewTriDense will panic.
+//
+// The data must be arranged in row-major order, i.e. the (i*c + j)-th
+// element in the data slice is the {i, j}-th element in the matrix.
+// Only the values in the triangular portion corresponding to kind are used.
+func NewTriDense(n int, kind matrix.TriKind, data []float64) *TriDense {
if n < 0 {
panic("mat64: negative dimension")
}
- if mat != nil && len(mat) != n*n {
+ if data != nil && len(data) != n*n {
panic(matrix.ErrShape)
}
- if mat == nil {
- mat = make([]float64, n*n)
+ if data == nil {
+ data = make([]float64, n*n)
}
uplo := blas.Lower
if kind == matrix.Upper {
@@ -116,7 +117,7 @@ func NewTriDense(n int, kind matrix.TriKind, mat []float64) *TriDense {
mat: blas64.Triangular{
N: n,
Stride: n,
- Data: mat,
+ Data: data,
Uplo: uplo,
Diag: blas.NonUnit,
},

MODIFY
mat64/vector.go
mat64/vector.go
@@ -28,9 +28,10 @@ type Vector struct {
// Vector must have positive increment in this package.
}
-// NewVector creates a new Vector of length n. If len(data) == n, data is used
-// as the backing data slice. If data == nil, a new slice is allocated. If
-// neither of these is true, NewVector will panic.
+// NewVector creates a new Vector of length n. If data == nil,
+// a new slice is allocated for the backing slice. If len(data) == n, data is
+// used as the backing slice, and changes to the elements of the returned Vector
+// will be reflected in data. If neither of these is true, NewVector will panic.
func NewVector(n int, data []float64) *Vector {
if len(data) != n && data != nil {
panic(matrix.ErrShape)

Improve documentation about underlying types