HexOrderParameter take k=float, should be int and cast later

Issue #100 resolved
Eric Harper created an issue

Even if k needs to be used as an int later, it should be cast at c++ or cython from int

Comments (10)

  1. Eric Harper reporter
    1. 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?

  2. Bradley Dice

    @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!

  3. Chengyu Dai

    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 class HexOrderParameter:

    .. 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

  4. Bradley Dice

    @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 of getK() should be an integer as well. I don't think there are any sensible reasons why non-integer k would be useful. Internally, we would convert its type back to float before doing computations.

  5. Vyas Ramasubramani

    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.

  6. Log in to comment