Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Reshape fails after a Mul of two views #144

@aglyzov

Description

@aglyzov

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions