-
Notifications
You must be signed in to change notification settings - Fork 5
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
fix: remove unnecessary casts of atom indices #9
Conversation
The idea here was that the use of u64 is an implementation detail (the
The last time I tried, rustfmt output was really bad, and not configurable on stable. Do you know if this changed? I'll try to give it a look too. |
Oh, I see. However there seems to be a general type mismatch then: a lot of other functions either return
Is making all index related data types
I haven't had any issues recently and I'm pretty sure that it works on stable now (except some minor features like formatting strings). But this is actually more a suggestion than a thought through plan. |
I would rather do this, yes 😃 |
Ok, then this won't be as quick and easy as I thought 😅 Will look into this...
Not sure if this is valid the other way around. Can't find any guarantee that |
return bonds | ||
.iter() | ||
.map(|tuple| [tuple[0] as usize, tuple[1] as usize]) | ||
.collect(); |
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.
Not sure how to handle this properly, this feels unidiomatic. Any suggestions?
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.
Yeah, I think this is why the API had mixed usize/u64 in the first place: we need to allocate new memory for bonds/angles/... to transform them from u64 to usize. This is a bit unfortunate, and I don't know how to improve it here.
But the way you are transforming from Vec<[u64; 2]> to Vec<[usize; 2]> looks good to me. It might be possible to optimize it by using Vec::reserve instead, but this iterator-based code should already be fast enough.
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 would avoid naming the variable in map tuple
, since it is not a tuple in Rust sense. How about bond
?
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.
Renaming makes sense, done.
I just learned, that collect
over iterators that are sized or owned tends to be quite performant. So I guess we wouldn't improve with Vec::reserve
.
There are a lot of clippy warnings because of |
c166573
to
d185594
Compare
What I mean by that is that all u64 values created by chemfiles will fit in an usize (even if usize is 32-bit), because they are all created from In the general case, u64 can overflow usize on platforms that use 32 or 16-bit indexing. |
d185594
to
6d308f9
Compare
I'm not worried about casting chemfiles |
6d308f9
to
1b38090
Compare
Some small changes:
u64
but some functions expectedusize
and then immediately cast the parameter tou64
.stutter
is deprecatedmodule_name_repetitions
globally, isn't it?BTW: Should we run
rustfmt
on all the files?