mirror of
https://github.com/gonum/gonum.git
synced 2025-10-06 07:37:03 +08:00
mat: disallow New calls with zero length
This commit is contained in:

committed by
Dan Kortschak

parent
d41320af1e
commit
3b99883391
@@ -86,8 +86,12 @@ type VecDense struct {
|
||||
// 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 VecDense
|
||||
// will be reflected in data. If neither of these is true, NewVecDense will panic.
|
||||
// NewVecDense will panic if n is zero.
|
||||
func NewVecDense(n int, data []float64) *VecDense {
|
||||
if n < 0 {
|
||||
if n <= 0 {
|
||||
if n == 0 {
|
||||
panic(ErrZeroLength)
|
||||
}
|
||||
panic("mat: negative dimension")
|
||||
}
|
||||
if len(data) != n && data != nil {
|
||||
|
Reference in New Issue
Block a user