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

A Strange Behavior of NewVector #249

Closed
zhenghaoz opened this issue Nov 8, 2018 · 2 comments
Closed

A Strange Behavior of NewVector #249

zhenghaoz opened this issue Nov 8, 2018 · 2 comments

Comments

@zhenghaoz
Copy link

Hi. I found something strange when using NewVector. When I create two vectors in a row:

g := gorgonia.NewGraph()
a := gorgonia.NewVector(g, gorgonia.Float64, gorgonia.WithShape(2))
b := gorgonia.NewVector(g, gorgonia.Float64, gorgonia.WithShape(2), 
    gorgonia.WithInit(gorgonia.Zeroes()))
fmt.Println(a.Value(), b.Value())
gorgonia.Let(a, tensor.New(tensor.WithShape(2), tensor.WithBacking([]float64{1,2})))
fmt.Println(a.Value(), b.Value())

The output indicates that the two vectors share the memory space.

<nil> <nil>
[1  2] [1  2]

However, if I give different names to two vectors:

g := gorgonia.NewGraph()
a := gorgonia.NewVector(g, gorgonia.Float64, gorgonia.WithName("a"), gorgonia.WithShape(2))
b := gorgonia.NewVector(g, gorgonia.Float64, gorgonia.WithName("b"), gorgonia.WithShape(2), 
    gorgonia.WithInit(gorgonia.Zeroes()))
fmt.Println(a.Value(), b.Value())
gorgonia.Let(a, tensor.New(tensor.WithShape(2), tensor.WithBacking([]float64{1,2})))
fmt.Println(a.Value(), b.Value())

They have individual memory spaces.

<nil> [0  0]
[1  2] [0  0]

It seems that:

  • They share the memory space if they have the same shape or name.
  • Otherwise, they have individual memory spaces.

Is it a bug or something wrong by myself? It's really strange.

The version is:

gorgonia.org/gorgonia v0.9.0-beta.0.20181027224840-11edd62a505a

Thanks a lot :D

@owulveryck
Copy link
Member

I will have a closer look, but it looks like that it is a duplicate of #87

@owulveryck
Copy link
Member

Closing as this issue is definitely related to issue 87.

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

2 participants