Git Product home page Git Product logo

Comments (2)

TallJimbo avatar TallJimbo commented on May 26, 2024

I tend to avoid using bp::optional<> (and the BOOST_PYTHON_FUNCTION_OVERLOADS macros) for exactly this reason, even though it's what you'll find in the Boost.Python tutorial.

Instead you can duplicate the default values when telling Boost.Python about the keyword arguments; in this case, that's
(bp::arg("u_"), bp::arg("mean")=0., bp::arg("sigma")=1.)

The downside is that you have to put the defaults in two places and keep them in sync. The upside is that keyword arguments now work just like they do in Python.

By the way, I tend to also rename C++ arguments sometimes when specifying the Python keyword arguments. In C++, the argument names aren't used by the caller, and they can have funny names for technical reasons (like u_ instead of u). We don't have to make them the same in both places, and I'd recommend changing the Python keyword argument in this case to something more descriptive (e.g. "uniform"), or at least dropping the _.

from galsim.

barnabytprowe avatar barnabytprowe commented on May 26, 2024

Hi Jim,

Great, thanks!

On 28 Mar 2012, at 09:30, Jim Bosch wrote:

I tend to avoid using bp::optional<> (and the BOOST_PYTHON_FUNCTION_OVERLOADS macros) for exactly this reason, even though it's what you'll find in the Boost.Python tutorial.

Instead you can duplicate the default values when telling Boost.Python about the keyword arguments; in this case, that's
(bp::arg("u_"), bp::arg("mean")=0., bp::arg("sigma")=1.)

The downside is that you have to put the defaults in two places and keep them in sync. The upside is that keyword arguments now work just like they do in Python.

By the way, I tend to also rename C++ arguments sometimes when specifying the Python keyword arguments. In C++, the argument names aren't used by the caller, and they can have funny names for technical reasons (like "u_" instead of "u"). We don't have to make them the same in both places, and I'd recommend changing the Python keyword argument in this case to something more descriptive (e.g. "uniform"), or at least dropping the "_".


Reply to this email directly or view it on GitHub:
#58 (comment)

Barnaby Rowe

Jet Propulsion Laboratory
California Institute of Technology
MS 169-237
4800 Oak Grove Drive
Pasadena CA 91109
United States of America

Department of Physics & Astronomy
University College London
Gower Street
London WC1E 6BT
United Kingdom

from galsim.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.