-
Notifications
You must be signed in to change notification settings - Fork 29
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
More multi line confusion. Inconsistent local scoping: soft or hard?? #143
Comments
I strongly urge you not to write into an array within the block, like The basic use is that the right hand side should be a pure function of some arrays of numbers, which is evaluated at every value of every visible index. It won't really handle arrays of arrays, except maybe arrays of StaticArrays. That's what the Macros don't have to define a scope, but for Tullio, everything is evaluated within a function, which does. So soft scope weirdness shouldn't apply. I'm not sure what most of these examples are hoping to achieve. If there are particular formulae you want to encode, then perhaps that's easier than explaining why these don't work? Or if you want to explore what it does, the "Internals" section writes out an example. Which I hope should make the output of |
Thanks. Looking only at the C examples. The first version is easy and works:
After that I explored different versions that seem plausible alternatives, and when it doesn't work understand why and improve the docs. The code I have in a project is about 10 lines of Tullio that I would like to have in a single block to minimise allocations and hopefully better optimisation. I renumbered the examples. Having read your post on Discourse, the following is clear, although I wasn't certain that indexes that are not repeated should be summed over. But at long as this is the consistent behaviour, all good. Those examples all work and return a scalar.
But then this should not work, but C6 is instead a 2x2 matrix!
The allocation to TMP should be a scalar, and should throw an error give C2 is an array. This seems reasonable. First line creates the proper 2x2 matrix, the second returns TMP as an object to be assigned to C9, the same way this is valid.
However, if TMP7 is not already allocated, the error is
If the problem is that Tullio doesn't guess the dimensions of TMP7, the following does not help. TMP8 is not defined.
If the code inside the block is pure Julia, I would have expected this to work:
Why? Because in Julia an allocation statement returns the allocated value.
Since the errors sometimes refer to temporary matrices not being allocated. For example, this breaks with
Let's have a look when defining.
This breaks. Error is This one is what I mean about soft vs hard scope. Same as C10, but adding indexes to TMP.
It works giving the same result as the one-liner. BUT:
|
This is perhaps weird if you expect more Einstein-ish behaviour. It just sums the entire RHS over all free indices. See also #133
This is just like the difference between writing
This writes into TMP7 at every iteration. If it decides to multi-thread, it will write different values simultaneously. But then it returns the whole array TMP7, at every
No, it's not. You can always mutate the contents of a global variable,
There are 4 loops over |
I have read carefully your answers and come up with a list of principles to keep in mind. Please have look to see where I am off. I must be off somewhere since in the examples below, I still don't understand the errors. Note, I have the impression that the errors have little to do with the mistakes in the code. That's macros... STATEMENT 0: STATEMENT 1:
The value return by the block is line 3. STATEMENT 2: STATEMENT 3: STATEMENT 4: STATEMENT 4 bis: STATEMENT 5: Here is the list of tests. I understand more than before, but I still don't understand 6, 6_2, 7, 9, 10. I know you explained 7, but I still don't get it.
|
A lot of examples with inconsistent results. But bottom line, the behaviour breaks my assumption that macros define a hard local scope (they are hygienic).
What is even weirder is that the macro behaves a mix of soft and hard scope. I am utterly confused.
(Note: I posted the same on Discourse: https://discourse.julialang.org/t/tullio-multiline-syntax-unknown-symbols/77616/5 )
The text was updated successfully, but these errors were encountered: