HexOrderParameter take k=float, should be int and cast later
Even if k needs to be used as an int later, it should be cast at c++ or cython from int
Comments (10)
-
-
reporter - This is not minimum reproduction code. Something like
from freud.order import HexOrderParameter diam_cut=3.0 test = HexOrderParameter(diam_cut,k=4.)
For what it's worth, this code does not cause an error for my install of freud. What version of freud is this failing for, and can you post the traceback?
-
reporter @daich is this still happening?
-
@daich Can you please follow up with me about this issue? The code sample above does not produce an error for me. Can you help me understand the expected behavior if it differs from what you're seeing? Thanks!
-
-
assigned issue to
-
assigned issue to
-
Hi I was unable to produce an error either. I think my point at that time was simply saying that we should throw an error when a float is provided for k, as the code says in
freud / freud / order.pxi
classHexOrderParameter
:.. note:: While :math:
k
is a float, this is due to its use in calculations requiring floats. Passing in non-integer values will result in undefined behavior -
@vramasub What do you think about this? It seems to me like we should cast the argument
k
to an integer, and the return type ofgetK()
should be an integer as well. I don't think there are any sensible reasons why non-integerk
would be useful. Internally, we would convert its type back tofloat
before doing computations. -
I agree, we should just be typecasting where floats are needed but the type of
k
stored internally should be an integer. We can specify that the argument should be an integer and throw an error if it isn't. If the internal type is an integer then getK will automatically return an integer, so that should be fine. People using python2 should be importing division from future anyway so the division should work out fine. -
- changed status to open
PR submitted.
-
- changed status to resolved
Fixed in Pull Request #131
- Log in to comment
test = HexOrderParameter(diam_cut,k=4.)
minimum reproduction code