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

Thomas algorithm implementation in Common Lisp #604

Merged
merged 8 commits into from
Jul 7, 2020

Conversation

Trashtalk217
Copy link
Contributor

While I probably could've done some funky recursion with this. I'm keeping it simple for this first submission. The svref and the setf syntax is wordy and annoying so I might make a specific function or even a macro for that. The function is destructive so I either have to find a copy command for a vector or re-write the entire function.

It'd be great to first have a review though.

@june128 june128 added the Implementation This provides an implementation for an algorithm. (Code and maybe md files are edited.) label Jun 5, 2019
@berquist berquist self-assigned this Oct 6, 2019
contents/thomas_algorithm/code/clisp/thomas.lisp Outdated Show resolved Hide resolved
contents/thomas_algorithm/code/clisp/thomas.lisp Outdated Show resolved Hide resolved
contents/thomas_algorithm/code/clisp/thomas.lisp Outdated Show resolved Hide resolved
(setf
(svref d i)
(/
(- (svref d i) (* (svref a i) (svref d (1- i))))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to write a macro, (- (svref d i) (* (svref a i) (svref d (1- i)))) is probably the level of granularity that you want, with a separate macro for the 1+ version. Since you aren't shortening the code by using macros, make sure you use a descriptive macro name.

(defun thomas (a b c d)
"Returns the solutions to a tri-diagonal matrix destructively"
(setf (svref c 0) (/ (svref c 0) (svref b 0)))
(setf (svref d 0) (/ (svref d 0) (svref b 0)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment about the macro here. Give them good docstrings.

@berquist
Copy link
Member

berquist commented Jul 5, 2020

Poke for rebase. I think the only thing I care about from the review is printing in floating point.

@Trashtalk217
Copy link
Contributor Author

I'm almost done, I found that (helper b a c i) is used twice so I might make that a separate variable in the loop. I also need an explanation for what the helper function actually does. I discovered that I didn't need macros and that functions could do the job.

Copy link
Member

@berquist berquist left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, this one is over a year old...and done.

@berquist berquist merged commit 532f7cf into algorithm-archivists:master Jul 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Implementation This provides an implementation for an algorithm. (Code and maybe md files are edited.)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants