feat(example/tensor): a working example of wraping Ctype tensor (torch.Tensor()) to Go C_tensor type
This commit is contained in:
parent
b1c70b1dde
commit
313590d87b
|
@ -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))
|
||||
}
|
||||
|
|
|
@ -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))}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user