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
362 stars 49 forks source link

Fixed a major bug when reusing an operand #126

Closed chewxy closed 2 years ago

chewxy commented 2 years ago

The bug is best exemplified by the following:

func main() {
    a := tensor.New(tensor.WithShape(2, 2), tensor.WithBacking([]float64{1, 2, 3, 4}))
    b := tensor.New(tensor.WithShape(2, 2), tensor.WithBacking([]float64{2, 2, 3, 3}))
    _, err := tensor.Div(a, b, tensor.WithReuse(b))
    if err != nil {
        log.Fatal(err)
    }
    log.Printf("a %v", a)
    log.Printf("b %v", b)
}

When an operand is reused, weird things happen, and the results are incorrect. This has now been fixed

coveralls commented 2 years ago

Coverage Status

Coverage decreased (-0.4%) to 21.541% when pulling 3fd5e14728ef8eced2f5fab9c4ded6146ca65bd7 on fixNonCommutative into 763642a4ad6214b09cf3e9b341fe46b272f42fe2 on master.

coveralls commented 2 years ago

Coverage Status

Coverage decreased (-0.4%) to 21.512% when pulling f808797aa4e9718d9b5fa95e608dd407e4714702 on fixNonCommutative into 763642a4ad6214b09cf3e9b341fe46b272f42fe2 on master.