Opened 3 years ago

Closed 4 weeks ago

Last modified 4 weeks ago

#569 closed defect (fixed)

revise embedded C handling in sasmodels

Reported by: pkienzle Owned by:
Priority: minor Milestone: SasView 4.2.0
Component: SasView Keywords:
Cc: Work Package: SasView Bug Fixing

Description

Remove the Iq="""… function body …""" option from sasmodels.

This makes for cleaner code since we don't have to test whether Iq exists, and if so, whether it is a string or a callable.

Those who can program in C are surprised by the missing function declaration. Those who don't know C are going to be surprised that the tutorials for writing C functions include the function definition, but they don't have to.

Instead use c_include=["list", "of", "sources"] and optional c_source="""extra source after the included sources""".

Because c_source contains top-level C code rather than just the function body, this means we can define helper functions in single file model files, which we otherwise cannot do in the current system.

A custom model

    def form_volume(...): ...
    def Iq(q, ...): ...
    def Iqxy(qx, qy, ...): ...

becomes

    c_source = """
    static double form_volume(...) { ...; }
    static double Iq(double q, ...) { ...; }
    static double Iqxy(double qx, double qy, ...) { ...; }
    """

This is a reasonably natural transformation for someone who knows both C and python.

If the C source is later moved into model.c (so that you can edit it with C syntax highlighting), this becomes

c_include=["model.c"]

The main advantage of the existing scheme, which is that the parameters in the function definition are automatically generated for the C code in the correct order from the parameter table, is not a big advantage in sasview since the New Model dialog creates the python definitions with the correct parameters already, and that can be easily edited.

Change History (3)

comment:1 Changed 2 years ago by butler

  • Milestone changed from SasView 4.0.0 to SasView Next Release +1

As agreed on fortnightly call of June 21, am moving all minor priority tickets to next release (+1) given the resources and time available to get this release out.

comment:2 Changed 4 weeks ago by pkienzle

  • Resolution set to fixed
  • Status changed from new to closed

Added as c_code=... on 2017-12-14.

comment:3 Changed 4 weeks ago by butler

  • Milestone changed from SasView Next Release +1 to SasView 4.2.0
Note: See TracTickets for help on using tickets.