gitee.com/zhongguo168a/gocodes@v0.0.0-20230609140523-e1828349603f/thirdpart/vector/errors.go (about) 1 // Author: slowpoke <proxypoke at lavabit dot com> 2 // Repository: https://gist.github.com/proxypoke/vector 3 // 4 // This program is free software under the non-terms 5 // of the Anti-License. Do whatever the fuck you want. 6 7 package vector 8 9 import ( 10 "strconv" 11 ) 12 13 // For missmatched dimensions. 14 type DimError struct { 15 Dim_a, Dim_b uint 16 } 17 18 type ( 19 // For out-of-range indexes. 20 IndexError uint 21 // For cross products where either ndim != 3. 22 CrossError DimError 23 ) 24 25 func (e DimError) Error() string { 26 return "Missmatched dimensions: " + 27 strconv.Itoa(int(e.Dim_b)) + 28 " != " + 29 strconv.Itoa(int(e.Dim_b)) 30 } 31 32 func (e IndexError) Error() string { 33 return "Index out of range: " + strconv.Itoa(int(e)) 34 } 35 36 func (e CrossError) Error() string { 37 return "Invalid dimensions: " + 38 strconv.Itoa(int(e.Dim_a)) + 39 ", " + 40 strconv.Itoa(int(e.Dim_b)) + 41 " (must be 3)" 42 }