Open ntezak opened 8 years ago
I would be happy to add documentation and tests.
Actually, I think this convention for determining the allocation size is still not quite clean, let me think about it a little more.
Documentation for the offsets would be greatly appreciated!
Actually, I think this convention for determining the allocation size is still not quite clean
Yes, I agree. Cross-referencing from your examples in https://github.com/ahwillia/Einsum.jl/issues/6#issuecomment-245061487
I think I would prefer:
X = randn(10)
@einsum A[i] := X[i-5]
@test size(A) == (5,)
@test all(A .== X[6:end])
Does that make sense? Thanks so much for catching my oversights!
Hey Alex, that would be an option but then there would be a marked difference between the behavior of a pre-allocated array (in which case I don't think we should shift the LHS indices) and a non-pre-allocated array.
I think the simplest thing may just be to not allow any offset indices in combination with :=
, i.e., non-pre-allocated expressions. What do you think?
What are the desired rules for pre-allocated arrays?
B = collect(1:10)
# produce errors?
A = zeros(5)
@einsum A[i] = B[i+5]
@einsum A[i] = B[i-5]
# legal?
A = zeros(10)
@einsum A[i] = B[i+5]
A == [6, 7, 8, 9, 10, 0, 0, 0, 0, 0]
A = zeros(10)
@einsum A[i] = B[i-5]
A == [0, 0, 0, 0, 0, 1, 2, 3, 4, 5]
If this is the case, then I guess it would make sense to allocate A
to be the size of B
in all these cases and the behavior would be consistent.
Side note. This is silly, but would be kind of cool to support this:
B = collect(1:10)
A = zeros(10)
@einsum A[i] = B[i>>5]
A == [6, 7, 8, 9, 10, 1, 2, 3, 4, 5]
@einsum A[i] = B[i<<2]
A == [3, 4, 5, 6, 7, 8, 9, 10, 1, 2]
In case someone is watching this: index shifts of the form @einsum A[i] := X[i+:offset]
seem to be broken on Julia 1.0. This feature never made it into the readme but was in the tests... and in #29 I commented these out. It should still work as before on 0.6, but someone who needs this would have to fix it on 1.0.
This introduces additional capabilities for handling multiple different offsets for RHS index expressions as well as a modified convention for un-allocated negative indices.