tensor icon indicating copy to clipboard operation
tensor copied to clipboard

Reshape fails after a Mul of two views

Open aglyzov opened this issue 1 year ago • 0 comments

Here is a minimal failure demonstration:

package main

import (
    "fmt"
    "os"

    "gorgonia.org/tensor"
)

func main() {
    m := tensor.New(
        tensor.WithShape(2, 2),
        tensor.WithBacking([]float64{1, 2, 3, 4}),
    )
    x, err := m.Slice(nil, tensor.S(0))
    if err != nil {
        fmt.Println(err)
        os.Exit(1)
    }
    y, err := m.Slice(nil, tensor.S(1))
    if err != nil {
        fmt.Println(err)
        os.Exit(2)
    }

    c, err := tensor.Mul(x, y)
    if err != nil {
        fmt.Println(err)
        os.Exit(3)
    }

    err = c.Reshape(2, 1) // <-- this fails
    if err != nil {
        fmt.Println(err) // output: sanity check failed: Shape mismatch. Expected (2, 1). Got 3
        os.Exit(4)
    }

    fmt.Println(c)
}

And it fixes itself if I call Mul like this: c, err := tensor.Mul(x.Materialize(), y)

aglyzov avatar Dec 23 '24 09:12 aglyzov