added debug stack trace to tensor error

This commit is contained in:
sugarme 2023-07-28 18:06:53 +10:00
parent 3cd8d8560f
commit bdf252d831

View File

@ -5,6 +5,7 @@ import "C"
import ( import (
"fmt" "fmt"
"runtime/debug"
"unsafe" "unsafe"
lib "github.com/sugarme/gotch/libtch" lib "github.com/sugarme/gotch/libtch"
@ -41,7 +42,8 @@ func TorchErr() error {
cptr := (*C.char)(lib.GetAndResetLastErr()) cptr := (*C.char)(lib.GetAndResetLastErr())
errStr := ptrToString(cptr) errStr := ptrToString(cptr)
if errStr != "" { if errStr != "" {
return fmt.Errorf("Libtorch API Error: %v\n", errStr) trace := string(debug.Stack())
return fmt.Errorf("Libtorch API Error: %v\n%v\n", errStr, trace)
} }
return nil return nil