pyro-ppl / funsor

Functional tensors for probabilistic programming
https://funsor.pyro.ai
Apache License 2.0
236 stars 20 forks source link

Reshape using Variable in Named Tensor tutorial Part 1 #519

Closed ordabayevy closed 3 years ago

ordabayevy commented 3 years ago

I want to change reshaping in the tutorial to use Variable instead of Tensor. (Using Tensor feels more like indexing rather than reshaping.)

Use

layer = Variable("layer", Bint[9])

A_layer = A(height=layer // Number(3, 4), width=layer % Number(3, 4))

instead of

layer = Tensor(tensor([0, 1, 2, 3, 4, 5, 6, 7, 8]), dtype=9)["layer"]

A(height=layer // Number(3, 4), width=layer % Number(3, 4))

Also add reshaping back layer->(height,width) example:

height = Variable("height", Bint[3])
width = Variable("width", Bint[3])

A_layer(layer=height * Number(3, 4) + width % Number(3, 4))
ordabayevy commented 3 years ago

Thanks @eb8680 !