mat: allow slice to increase matrix size to caps
MODIFY
mat/dense.go
mat/dense.go
@@ -275,13 +275,13 @@ func (m *Dense) rawRowView(i int) []float64 {
}
// Slice returns a new Matrix that shares backing data with the receiver.
-// The returned matrix starts at {i,j} of the recevier and extends k-i rows
+// The returned matrix starts at {i,j} of the receiver and extends k-i rows
// and l-j columns. The final row in the resulting matrix is k-1 and the
// final column is l-1.
-// Slice panics with ErrIndexOutOfRange if the slice is outside the bounds
+// Slice panics with ErrIndexOutOfRange if the slice is outside the capacity
// of the receiver.
func (m *Dense) Slice(i, k, j, l int) Matrix {
- mr, mc := m.Dims()
+ mr, mc := m.Caps()
if i < 0 || mr <= i || j < 0 || mc <= j || k <= i || mr < k || l <= j || mc < l {
panic(ErrIndexOutOfRange)
}

MODIFY
mat/symmetric.go
mat/symmetric.go
@@ -79,10 +79,16 @@ func NewSymDense(n int, data []float64) *SymDense {
}
}
+// Dims returns the number of rows and columns in the matrix.
func (s *SymDense) Dims() (r, c int) {
return s.mat.N, s.mat.N
}
+// Caps returns the number of rows and columns in the backing matrix.
+func (s *SymDense) Caps() (r, c int) {
+ return s.cap, s.cap
+}
+
// T implements the Matrix interface. Symmetric matrices, by definition, are
// equal to their transpose, and this is a no-op.
func (s *SymDense) T() Matrix {
@@ -402,12 +408,12 @@ func (s *SymDense) SubsetSym(a Symmetric, set []int) {
}
// SliceSquare returns a new Matrix that shares backing data with the receiver.
-// The returned matrix starts at {i,i} of the recevier and extends k-i rows
+// The returned matrix starts at {i,i} of the receiver and extends k-i rows
// and columns. The final row and column in the resulting matrix is k-1.
-// SliceSquare panics with ErrIndexOutOfRange if the slice is outside the bounds
+// SliceSquare panics with ErrIndexOutOfRange if the slice is outside the capacity
// of the receiver.
func (s *SymDense) SliceSquare(i, k int) Matrix {
- sz := s.Symmetric()
+ sz := s.cap
if i < 0 || sz < i || k < i || sz < k {
panic(ErrIndexOutOfRange)
}

MODIFY
mat/vector.go
mat/vector.go
@@ -64,6 +64,7 @@ func (v *Vector) SliceVec(i, k int) *Vector {
}
}
+// Dims returns the number of rows and columns in the matrix. Columns is always 1.
func (v *Vector) Dims() (r, c int) {
if v.isZero() {
return 0, 0

mat: allow slice to increase matrix size to caps