Skip to content
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

Additional functionality for offsets in index expressions #6 #12

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

ntezak
Copy link
Contributor

@ntezak ntezak commented Sep 6, 2016

This introduces additional capabilities for handling multiple different offsets for RHS index expressions as well as a modified convention for un-allocated negative indices.

@ntezak
Copy link
Contributor Author

ntezak commented Sep 6, 2016

I would be happy to add documentation and tests.

@ntezak
Copy link
Contributor Author

ntezak commented Sep 6, 2016

Actually, I think this convention for determining the allocation size is still not quite clean, let me think about it a little more.

@ahwillia
Copy link
Owner

ahwillia commented Sep 6, 2016

Documentation for the offsets would be greatly appreciated!

@ahwillia
Copy link
Owner

ahwillia commented Sep 6, 2016

Actually, I think this convention for determining the allocation size is still not quite clean

Yes, I agree. Cross-referencing from your examples in #6 (comment)

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!

@ntezak
Copy link
Contributor Author

ntezak commented Sep 15, 2016

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?

@ahwillia
Copy link
Owner

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]

@mcabbott
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants