diff --git a/CHANGELOG.md b/CHANGELOG.md index 98860f3..8b2ae46 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - reworked `ts.Format()` - Added conv2d benchmark - Fixed #88 memory leak at `example/char-rnn` +- Added missing tensor `Stride()` ## [Nofix] - ctype `long` caused compiling error in MacOS as noted on [#44]. Not working on linux box. diff --git a/libtch/tensor.go b/libtch/tensor.go index 6143a0b..8233533 100644 --- a/libtch/tensor.go +++ b/libtch/tensor.go @@ -100,6 +100,12 @@ func AtShape(t Ctensor, ptr unsafe.Pointer) { C.at_shape(t, c_ptr) } +// void at_stride(tensor, int64_t *); +func AtStride(t Ctensor, ptr unsafe.Pointer) { + c_ptr := (*C.int64_t)(ptr) + C.at_stride(t, c_ptr) +} + // int at_scalar_type(tensor); func AtScalarType(t Ctensor) int32 { result := C.at_scalar_type(t) diff --git a/ts/tensor.go b/ts/tensor.go index 2c49c9e..7aadd7a 100644 --- a/ts/tensor.go +++ b/ts/tensor.go @@ -40,11 +40,15 @@ type bigStruct struct { lots [1e5]byte // 100k - always on host memory. } -// Tensor is a Go wrapper to a C tensor pointer - 8 Bytes (64-bits OS) or 4 Bytes (32-bits OS) -// ctensor is just a C pointer to `torch::Tensor` +// Tensor is a Go wrapper of a "C tensor pointer" - 8 Bytes (64-bits OS) +// or 4 Bytes (32-bits OS). +// `ctensor` is just a "C pointer" to `torch::Tensor` (torch::Tensor *lib.Ctensor) // -// NOTE.Tensor should be big enough to be in a heap. -// See. https://stackoverflow.com/questions/10866195 +// NOTE.Tensor should be big enough to be in heap memory. +// (yes, we choose to place tensor consistently in heap memory so that +// it can be targeted by Go garbage collector). +// +// For heap allocation see. https://stackoverflow.com/questions/10866195 type Tensor struct { d *bigStruct name string