gorgonia / tensor

package tensor provides efficient and generic n-dimensional arrays in Go that are useful for machine learning and deep learning purposes
Apache License 2.0
359 stars 49 forks source link

fix: permute strides #84

Closed strigi-form closed 3 years ago

strigi-form commented 3 years ago

strides must be permuted for 2d tensors with any dimension == 1

chewxy commented 3 years ago

can you give an example?

strigi-form commented 3 years ago

Yes, it is in issue #83, here is a copy/paste This simple code panics 2020/10/15 13:11:28 (3, 1) C[-1 %!v(PANIC=Format method: runtime error: index out of range [3] with length 3)

package main

import (
"log"

"gorgonia.org/tensor"
)

func main() {
var T tensor.Tensor
T = tensor.New(
tensor.WithShape(1, 3),
tensor.WithBacking([]float64{-1, 0, 1}))
T, _ = tensor.T(T)
log.Printf("%v\n%v\n", T.Shape(), T)
}
strigi-form commented 3 years ago

The problem is you can't iterate on a transposed *tensor.Dense (tensor.AP in fact) when IsRowVec() is true:

it := tensor.IteratorFromDense(t.tens.(*tensor.Dense))
for i, ierr := it.Next(); ierr == nil; i, ierr = it.Next() {
 .....
}

First value for i is ok, but next is dimension (or stride which is 3 in my example), so panic out of range

chewxy commented 3 years ago

OK analysing

I edited your comment above to point to #83 which very clearly shows the problem

chewxy commented 3 years ago

This LGTM. It passes on my local machine. No idea why it fails in travis

coveralls commented 3 years ago

Coverage Status

Coverage increased (+0.06%) to 73.031% when pulling 300190ed6140b6d0204b846a00d7ef0211dacb07 on strigi-form:fix#83 into 0c8a1b67712c49909ea13fdd792649f92de5ba58 on gorgonia:master.