-
-
Notifications
You must be signed in to change notification settings - Fork 359
Fixing Julia for Thomas algorithm #495
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
Fixing Julia for Thomas algorithm #495
Conversation
… clearly didn't know what they were doing...
This new implementation that returns the solution vector still modifies the |
to be fair, this implementation seems to modify both This is a bit of a mess all around |
+1 on not modifying any input. Functional programming FTW :) |
It's not that difficult to change the algorithm to not modify |
To be fair, we are heavily using the mathematical notation of the chapter. While we are revising the implementation, maybe we should also change the variable names to Then the modified temp variable can be |
We are not questioning the notations |
I was bringing up the topic because |
I like |
|
d[i] = (d[i] - a[i] * d[i-1]) * scale | ||
end | ||
c_prime[1] = c_prime[1] / b[1] | ||
x[1] = x[1] / b[1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I usually suggest things like a = a / b
get converted to a /= b
, but what do you think? No opinion here.
d::Vector{Float64}, n::Int64) | ||
|
||
x = d | ||
c_prime = c |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These need to be
x = copy(d)
c_prime = copy(d)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(otherwise you're still overwriting the input.)
I was not here for the modifying input vs. returning conversation, but my 2 cents: I don't think the average numerical algorithm is more understandable by being made pure, and most people who want to understand the algorithm so they can implement it should rather implement the version that mutates a preallocated input argument. Maybe it should go as far as using other input arguments as scratch, as this and other implementations used to. This is how many calls to BLAS and LAPACK work. Passing matrices around with copy-by-value semantics is a death sentence for performance. Perhaps the solution is to say "there should be no surprises". This is well-documented behavior in real code, but not in the AAA, so being pure is good. Sorry for the inconclusive language, but I never read this rebuttal against "make everything more functional" even though writing pure code prevents necessary memory optimizations in numerical code. /rant over TL;DR looks good. |
I agree with @berquist , though. I am not sure what is the best way to do this. I know we are returning values for readability, but in some languages, this does kill performance and code shouldn't be written in general like that. |
We were never concerned with performance though, so I'm not worried about that. |
That is possible, yes. It is also possible that the people who would be affected already know about this sort of thing. I am fine with making everything pure, but only pointing out something I have never seen written down that I think should be revisited in some form later (chapter?). |
Yeah. That last version of Julia was complete and utter garbage. This fixes that and is modelled after the C code.