github.com/wzzhu/tensor@v0.9.24/errors.go (about) 1 package tensor 2 3 import "fmt" 4 5 // NoOpError is a useful for operations that have no op. 6 type NoOpError interface { 7 NoOp() bool 8 } 9 10 // MathError is an error that occurs in an Array. It lists the indices for which an error has happened 11 type MathError interface { 12 Indices() []int 13 } 14 15 type noopError struct{} 16 17 func (e noopError) NoOp() bool { return true } 18 func (e noopError) Error() string { return "NoOp" } 19 20 func handleNoOp(err error) error { 21 if err == nil { 22 return nil 23 } 24 if _, ok := err.(NoOpError); ok { 25 return nil 26 } 27 return err 28 } 29 30 type errorIndices []int 31 32 func (e errorIndices) Indices() []int { return []int(e) } 33 func (e errorIndices) Error() string { return fmt.Sprintf("Error in indices %v", []int(e)) } 34 35 const ( 36 emptyTensor = "Tensor is uninitialized (no shape, no data)" 37 dimMismatch = "Dimension mismatch. Expected %d, got %d" 38 atleastDims = "Tensor has to be at least %d dimensions" 39 dtypeMismatch = "Dtype mismatch. Expected %v. Got %v" 40 indexOOBAxis = "Index %d is out of bounds for axis %d which has size %d" 41 invalidAxis = "Invalid axis %d for ndarray with %d dimensions" 42 repeatedAxis = "repeated axis %d in permutation pattern" 43 invalidSliceIndex = "Invalid slice index. Start: %d, End: %d" 44 sliceIndexOOB = "Slice index out of bounds: Start: %d, End: %d. Length: %d" 45 broadcastError = "Cannot broadcast together. Resulting shape will be at least (%d, 1). Repeats is (%d, 1)" 46 lenMismatch = "Cannot compare with differing lengths: %d and %d" 47 typeMismatch = "TypeMismatch: a %v and b %v" 48 typeclassMismatch = "Typeclass mismatch on %v" 49 shapeMismatch = "Shape mismatch. Expected %v. Got %v" 50 sizeMismatch = "Size Mismatch. %d and %d" 51 reuseReshapeErr = "Failed to reshape the reuse *Dense from into %v. Size was: %d" 52 incrReshapeErr = "Failed to reshape the incr *Dense into %v. Size was: %d" 53 retValReshapeErr = "Failed to reshape the retVal *Dense into %v. Size was: %d" 54 div0 = "Division by 0. Index was %v" 55 div0General = "Division by 0" 56 opFail = "Failed to perform %v" 57 extractionFail = "Failed to extract %v from %T" 58 unknownState = "Unknown state reached: Safe %t, Incr %t, Reuse %t" 59 unsupportedDtype = "Array of %v is unsupported for %v" 60 maskRequired = "Masked array type required for %v" 61 inaccessibleData = "Data in %p inaccessible" 62 63 methodNYI = "%q not yet implemented for %v" 64 typeNYI = "%q not yet implemented for interactions with %T" 65 )