-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for offsets in indices #6
Comments
There has been a bit of discussion about this in the past, see #2 I'm not opposed to this at all and think it could be quite nice. I think we need to think carefully about conventions. How would we handle the following: @einsum A[j] := X[j+3] Note that Do we also want to support this? offset = 3
@einsum A[j] := X[j+$offset] |
Those are good questions!
|
👍 to this. I think this is a good place to start.
Perhaps my use of @einsum A[j] := X[j+$offset] Would expand to: for j = 1:(length(X)-offset)
A[j] = X[j+offset]
end I.e. it would not expand to So I think this would be totally feasible and not hurt performance. |
Oh ok, gotcha, yeah, I think that should definitely be supported! |
We should use |
I'm somewhat close to having this work. I still need to figure out conventions though. @einsum A[j] := X[j + :offset] What is the appropriate dimension check for this? @assert size(A,1) == size(X,1) - offset
@assert size(A,1) >= size(X,1) - offset Or we could opt for: i_max = min(size(A,1), size(X,1) - offset)
for i = 1:i_max
A[i] = X[i+offset]
end I kind of like this last convention the best. |
Closed by #9 |
Hi, sorry for being out of touch! I think there are some issues with this current implementation:
X = randn(10)
@einsum A[i] := X[i-5]
@test size(A) == (10,)
@test all(A[6:end] .== X[1:5]) => currently fails X = randn(10)
@einsum A[i] := X[i+3]*X[i-3]
@test size(A) == (7,)
@test isapprox(A[4:7], X[7:end].*X[1:4]) => currently fails I have a working branch here that addresses both of these. I can make a pull request anytime! |
Hi, for my use-cases (quantum dynamics solvers) it would be super useful to be able to specify integer offsets in the indices. As an example
Here the macro ought to infer that effectively
A[1:7] = X[1:7] .* Y[4:10]
andA[8:10] = 0
.Taken just by itself it may not be obvious why this is more useful than just using subarrays but especially in combination with in-place operations (see issue #5) this could be quite powerful.
If this seems of general use, I would be happy to take care of the implementation.
The text was updated successfully, but these errors were encountered: