opeltre / topos

Statistics and Topology
MIT License
8 stars 0 forks source link

Field access: local getters and setters #36

Open opeltre opened 1 year ago

opeltre commented 1 year ago

Implement local getters and setters so that Field instances really behave like dictionnaries.

G = Graph([[0,1,2], [[0, 1], [1, 2]]], FreeFunctor(2))
x = G.zeros(1)
# setter
x.set([0, 1], torch.ones([2, 2]))
# getter
x.get([1, 2]) == torch.zeros([2, 2])

N.B. Probably best to avoid __getitem__ and __setitem__ and not override fp.Tensor behaviour: x remains a 1D-vector internally.

opeltre commented 1 year ago

N.B. Right now G.index behaves just like G.scalars().index. The functorial start index should be recovered as:

#--- given coord of degree d
idx1 = G.index(coord)
idx0 = idx1 - G.begin[d]
idx = G[d].begin[idx0]