It seems that if the expression is a bit long then @.
allocates memory whereas manually using .
does not. Why?
Here is an expression. No memory allocation if NOT including the last term within the brackets, but allocates if it is included.
@. f_Fe = 1.0/(1.0 + KFeCl*ClBW + KFeSO4*THSO4*f_SO4 + KFeCO3*TCO2*f_CO3 + KFeCO3OH*TCO2*f_CO3*KW/H + KFeHS*TH2S*f_HS + KFeS*TH2S*f_HS/H)
This does not allocate
f_Fe .= 1.0./(1.0 .+ KFeCl.*ClBW .+ KFeSO4.*THSO4.*f_SO4 .+ KFeCO3.*TCO2.*f_CO3 .+ KFeCO3OH.*TCO2.*f_CO3.*KW./H + KFeHS.*TH2S.*f_HS .+ KFeS.*TH2S.*f_HS./H)
Aren’t they supposed to be identical?
So is there a limit of the length of the expression?
The problem you’re running into is that Julia currently treats + as an n-ary operation, but gets mad when it is called with too many arguments. The short term fix is to add parentheses to break things up slightly.
1 Like
That works but it’s tricky to figure out where to put the brackets!
You can do
const ⊕ = +
and just use that instead of +
…
1 Like
what’s the theory behind that?
Then it no longer parses a n-ary.
1 Like
Cool. Thanks!