Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reshape fails after a Mul of two views #144

Open
aglyzov opened this issue Dec 23, 2024 · 0 comments
Open

Reshape fails after a Mul of two views #144

aglyzov opened this issue Dec 23, 2024 · 0 comments

Comments

@aglyzov
Copy link

aglyzov commented Dec 23, 2024

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant