feat(example/tensor): a working example of wraping Ctype tensor (torch.Tensor()) to Go C_tensor type

This commit is contained in:
sugarme 2020-05-26 16:28:09 +10:00
parent b1c70b1dde
commit 313590d87b
2 changed files with 13 additions and 8 deletions

View File

@ -1,10 +1,15 @@
package main
import (
"fmt"
"reflect"
t "github.com/sugarme/gotch/torch"
)
func main() {
t.NewTensor()
t := t.NewTensor()
fmt.Printf("Type of t: %v\n", reflect.TypeOf(t))
}

View File

@ -5,16 +5,16 @@ package torch
import "C"
import (
"fmt"
"reflect"
// "fmt"
// "reflect"
"unsafe"
)
type C_tensor struct {
_private []uint8
_private uint8
}
func NewTensor() {
t := C.at_new_tensor()
fmt.Printf("Tensor Type: %v\n", reflect.TypeOf(t).Kind())
fmt.Printf("Tensor Value: %v\n", t)
func NewTensor() *C_tensor {
ct := C.at_new_tensor()
return &C_tensor{_private: *(*uint8)(unsafe.Pointer(&ct))}
}