-
Notifications
You must be signed in to change notification settings - Fork 259
Make API more idiomatic, simplify code, improve style #612
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
Conversation
… size check and slice indexing with `.get()`; refactor hard-coded header size into common constant; remove unconditional cloning of metadata in deserialization; remove double negation in `if-else`; etc.
…ary allocation; improve benchmark code
@Narsil I believe this PR is now complete. |
@Narsil Hey, can I possibly get some feedback on this? Thanks! |
This clearly isn't going anywhere; closing. |
Hey, First of all, sorry to not have seen that PR before. I just don't read PRs on every repo every day. Now, thanks a lot for the propositions. I'll break down my comments here:
In order to merge PRs, I think having very small ones would be an easier start. This crate and python package is relied upon by many, so I try to make changes as few as possible (so breaking is much less likely). |
Hi there!
Most of the improvements in this PR are not, in fact, purely stylistic, perhaps except for some newlines that make trait impls with many consecutive
Again, please see the thread starter comment. It's mostly the forcing of There's also this unnecessary
The error messages (and in some cases,
I don't think the API of the Python package is affected in any way. Please see the individual commits for different aspects of the changes. I'm sorry but you also have to understand that it would be really hard for me to basically un-do everything but some very specific changes. The changes in this PR are coherent, and you don't have to take them at face value – feel free to ask any other experienced Rust programmer and they'll confirm that they improve the code. |
Do you mind opening small PRs instead of this giant one. I see a few things slip which are not exactly obvious and making sure none slips review is hard. Keep write!(f, "{}...") everywhere. It's just easier to read when code is uniform. Anything that touches comments is very easy to review since it doesn't touch any logic.
Definitely a leftover, thanks for flagging. Ah and another one, remove the The commented out code for the TensorIndexer should be left alone (yes it is in version control), but it's also purposefully not enabled since most tensors never exceed certain dimensions, however, it should be trivial to add for users that want to play around. There is no downside to it. |
Oh, that's definitely intentional, because the formatting mechanism is slow, so it's unnecessarily wasteful to
Okay, I can do that. |
@Narsil I have split this into 4 separate PRs, split by the "theme" of the PR:
I hope this is now acceptable, and you can review and hopefully merge them. |
What does this PR do?
There are a number of issues with the current code style, for example:
&Option<T>
forces the caller to have an ownedT
, whereasOption<&T>
doesn't, and can be obtained from anOption<T>
viaOption::<T>::as_ref()
)if let
"triangles of hell", which can be replaced bylet … else
and early returns)source()
method onimpl Error for SafeTensorsError
)String
s in value formatting, extensively commented-out code (that could just be deleted since it's already in version control history), or manual, verbose, inline impls ofOption
combinators such asmap_or
.This PR fixes the aforementioned stylistic and API issues. Note that some of these are technically breaking change, but since the library is still relatively young, and hasn't reached 1.0 yet, this should not be a problem.