Comments (2)
Hello Tobyn. Glad to see you back !
First one word about your 2nd issue: docstrings. You are right to ask for a single message in all functions. For me, the best one (the most recently written !) is the one in linopt
and ohmi_envelope
. It can be improved as:
refpts elements at which data is returned. It can be
1) an integer in the range [-len(ring), len(ring)-1] selecting the
element according to python indexing rules. As a special case,
len(ring) is allowed and refers to the end of the last element,
2) an ordered list of such integers,
3) a numpy array of booleans of maximum length len(ring)+1, where
selected elements are true.
Defaults to None
...
All values are given at the entrance of each element specified in refpts
and copied (or referenced to) everywhere. The additional note in lattice_pass
only points out evidences, it can be removed though I do not see how it contradicts with the other descriptions.
About your table of tests: only the 1st line shows an error. In all other cases; the behaviour is correct and the error message could be improved (something like 'unordered list or element out of range'
)
Conclusion 2: the maximum length of refpts
is indeed n_elements+1
for both integer and boolean inputs. It can be shorter in both cases, even empty, and missing booleans are considered False
. A longer array implies there is a duplicate, and such an error is already correctly reported, so there is no need for an additional check (assuming the message is improved). Except in the case of the 1st line of your table: you are right, the check is skipped. Beware: contrary to what you wrote, refpts=n_elements
(not n_elements+1
) refers to the same as refpts=0
.
Conclusion 3: strictly speaking, the useful range is [-n_elems
, n_elems
]. However , values outside that range are properly handled assuming a closed ring: k*n_elems
always refers to the 1st element for any k
, and so on. Any additional test must be almost transparent since uint32_refpts can be called repeatedly many times in functions calling another one. That's probably why I assumed (wrongly) that if the type was already uint32
, the check had already been done previously…
Conclusion 4: you are welcome of course to factorise any piece of code commonly used ! In this particular case, I suggest that the name uint32_refpts
still groups both parsing and conversion: it is used for argument checking at the beginning of almost any AT function where both are needed. And a pure validity check is not useful in bool_refpts
since the boolean mask already ensures range, ordering and unicity of references.
from at.
@lfarv Thank you. My apologies, my confusion about what was equivalent to refpts=0
led me to believe this was a larger issue.
On the topic of docstrings, I think your new proposed explanation is much more understandable; the only thing I would ask is that we specifically mention that duplicates are not allowed, perhaps: 2) an ordered list of such integers without duplicates,
Though it is unusual I do not have any problem with allowing indexes outside the specified range to be used in a wrap-around style, if it is intended behaviour. That said considering we now clearly state the range of valid values for refpts
in the new docstring, it would be expected behaviour as far as the user is concerned for any value outside that range to raise an error. So if we are to keep allowing this, I would recommend either raising a warning or having a specific note about this use case in the docstring.
As for the error message, I am happy so long as it specifically mentions all three "throw" cases:
- unordered list,
- duplicates in list,
- value outside of range resulting in duplicate upon conversion to valid refpoint
If refpts
of data type uint32
are checked properly too, then fully considering the above I do not think uint32_refpts
needs rewriting.
from at.
Related Issues (20)
- pyat shift_elem ignores R1,R2 and the effect of bending angles HOT 5
- pyAT Distinguish between a sector bending magnet and a rectangular bending magnet HOT 2
- Reduce behaves differently in Matlab and python
- B0 added twice in exactkickrad HOT 2
- python: ringparam not well identified by lattice_load HOT 6
- bug is saving lattice HOT 4
- Bug: atwiggler HOT 13
- problem with display of correctly initialised VariableMultipole element HOT 1
- Change Legend Labels for plot_trajectory() function HOT 12
- fast_ring when having harmonic cavities in the lattice HOT 4
- AT_2_Elegant uses deprecated N_KICKS
- Factor 4 missing in Touschek scattering B2 expression HOT 5
- pyAT Error when calculating damping ring HOT 3
- Rotation of dipoles HOT 18
- matlab atlinopt4 check on 6d is disabled
- Severe bug introduced by #766 HOT 2
- Bug in Lattice.avlinopt HOT 7
- ring.get_lifetime fails if list of reference indexes has only one valid element HOT 1
- Compilation error when building from repository HOT 27
- VariableMultipole Usage HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from at.