Repository navigation
Conversation
ValerianRey
left a comment
There was a problem hiding this comment.
Can we get rid of the Bar class and instead have just a function (e.g. multiset_lift) that will build a multiset-index multiset-valued tensor? I guess this requires either making tensors generic on their indexing too (be able to take multiset of indices instead of just normal indices), or making two kinds of tensors, those indexed by normal indices and those indexed by multisets of indices.
Can we get rid of BarComposition entirely, and instead just use LeftComposition of a reduction and a multiset-indexed multiset-valued tensor?
Can we get rid of ReductionTensor, that I think is now just a wrapper around a BarComposition?
I'm not sure about exactly what is possible among that, but the core idea is to avoid having too many classes.
|
In a sense the very concept of Not sure if these should be functions, classes or whatnot (not good enough at rust to know that), but that's the idea. So I guess this PR actually requires very deep changes to the whole library (almost an entire rewrite). But in the end it can be 5x simpler and more powerful. What do you think? |
|
Reworked it. Now there's one Function trait (input, output, apply) and everything implements it: tensors, index maps, index functions, reductions. compose(f, g) replaces RightComposition, LeftComposition and BarComposition, and multiset_lift replaces Bar. ReductionTensor isn't a class anymore, a sum tensor is just compose(Sum::new(), compose(multiset_lift(u), psi)) like in the paper. The 6 mapping traits became one too. I kept Tensor as a trait alias (any function from indices to values) so we can still write It's not 5x less code since most of it is the mappings themselves, but there are way fewer concepts now. What do you think? |
|
A few things I kept on purpose, and why:
About the 5x: most of the code is the mappings, the torch functions, printing and the lattice solver, and none of that changed, so the core is about the same size, just with fewer concepts. Two things we could do to go further:
Should I do one or both, and in this PR or a separate one? What do you think? |
Perfect.
I think the
What are functions on values? Why don't they have a domain? I don't understand. Also I'm not sure what you mean by "functions on multisets of indices report the set the indices come from".
|
Yeah Rust can do that. multiset_lift can return
Functions on values are things like square,
The domain of multiset_lift(u) is really the multisets of u's indices. In the code it just returns u's index set, because that's all the check needs: when composing with an index function, it compares that set with the indices the index function returns. 1 and 2 sound good, keeping the aliases and leaving the affine stuff for a future PR. |
Can't we just have also a
Seems like a core issue.
Seems very hacky too. Is there any way to fix those last two points? |
Not really in Rust. A type alias can only name a concrete type, or a
Yes, I tried it in a local copy and it works. The idea is that every domain and codomain becomes a real set:
So domain() and codomain() always return a set, no more None. square goes from Some side effects:
All tests pass (plus 2 new ones for the domains) and the demo output is the same. Is it okay if I go ahead with this? |
|
Sounds perfect, please go ahead! |
|
Done, pushed it. Every function has a real domain and codomain now, and MultisetLift is renamed to MultiFunction. |
ValerianRey
left a comment
There was a problem hiding this comment.
Very good, this is exactly what I had in mind. I think a few names can be a bit confusing though.
Could we maybe move Domain classes to sets.rs? IIUC Domains are a type of Sets, right?
Also, I think we should rename Domain to IndexSet.
Mapping (in mapping.rs) => IndexFunction.
IndexFunctionSignature => MultiIndexFunctionSignature
(and file rename, and other linked renames)
After that you can merge!
| } | ||
|
|
||
| /// `f ∘ g`: applies `g`, then `f` to the result. | ||
| pub struct Compose<F, G> { |
There was a problem hiding this comment.
rename to Composition? it would make sense that the function is called compose but the class is called Composition.
Closes #18
Multiset, stored as an array and printed as{{1, 3, 3}}.Functionwith a real domain and codomain (index sets,Values<A>orMultisets<S>), andcomposeandmultiset_liftreplace RightComposition, LeftComposition, BoxedTensor and the ReductionTensor struct.compose(Sum::new(), compose(multiset_lift(u), psi))and repeated indices count.