insertleftunit, insertrightunit and removeunit#187
Conversation
fbddfd6 to
b4919f8
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #187 +/- ##
==========================================
- Coverage 83.16% 82.92% -0.24%
==========================================
Files 42 42
Lines 5257 5312 +55
==========================================
+ Hits 4372 4405 +33
- Misses 885 907 +22 ☔ View full report in Codecov by Sentry. |
|
Thanks for this; looks great. Regarding names, sounds good to me. The only other thing I can come up with is "apply_unitor" 😺 . |
|
It does seem like the Also, if you want, could you add the doc references in the |
|
You mean that the constant propagation is not working on 1.10 right? I could be convinced to ignore that, but this ties in with the following comment: The main problem (and what I like the least about the interface right now) is that if you want to insert a unit between the codomain and domain, it's unclear whether that should end up in the domain or codomain. This is also what's bothering the constant propagation I think, since that involves an additional flag to control that... It's just very unfortunate that I can't come up with a good way to disambiguate between these with just an integer. |
|
Well, if you want to stick to the category language, there is a left and right unitor. So you could say, Also, I haven't checked in detail whether the constant propagation failing is only for the case where |
b4919f8 to
cb84560
Compare
insertunit and removeunitinsertleftunit, insertrightunit and removeunit
|
So, I actually prefer the |
|
So it does seem there is still an issue with constant propagation on julia-latest. I am not entirely sure but I think a construct like |
9707392 to
2e4a8ce
Compare
|
So I played around with this on Julia master to test what is going on. The reason that function removeunit(P::ProductSpace, i::Int)
1 ≤ i ≤ length(P) || _boundserror(P, i)
isisomorphic(P[i], oneunit(P[i])) || _nontrivialspaceerror(P, i)
return ProductSpace{spacetype(P)}(TupleTools.deleteat(P.spaces, i))
end
@noinline function _boundserror(P, i)
throw(BoundsError(P, i))
end
@noinline function _nontrivialspaceerror(P, i)
throw(ArgumentError(lazy"Attempting to remove a non-trivial space $(P[i])"))
endOn a different note, as I then tried to insert the same bounds check for |
|
I agree that it's a bit counterintuitive, but it's actually required (but could maybe do with some better explanation): |
|
Ok I hadn't thought about that. But then what if you want to turn a N,0 into an N,1 tensor? is that possible even? |
|
It should be: insertleftunit N+1 would do that |
|
I tried making the changes and still ran into some type-instabilities, so I just caved and added the |
Here I extend the
insertunitfunction, which previously only worked forProductSpace, to also includeHomSpaceandTensorMapinstances. As this is an operation which is quite common in MPSKit, it would be nice to have a centralized implementation for it, which is also more efficient than the current approach which contracts with a trivial vector.Additionally, I add the
removeunitfunction to undo that operation.I'm not entirely sold on the names and interface I currently have for the function, but I'm struggling to come up with anything better. If you would have more inspiration, I'm all ears.