AlabamaASRL / asset_asrl

https://alabamaasrl.github.io/asset_asrl/
Apache License 2.0
29 stars 6 forks source link

Decouple C++ Implementations from Python Bindings #47

Open wgledbe opened 3 months ago

wgledbe commented 3 months ago

It would be unbelievably nice to use the core objects in other projects without being married to the Python bindings.

A potential refactor could look something like:

// Current
template<class Stuff>
struct Thing {
  // Blah...

  static void Build(py::module& m, const char* name) {
    auto obj = py::class_<Thing<Stuff>>(m, name);

    // more stuff

    Base::DenseBaseBuild(obj);
};

static void BuildThings(py::module& m) {
  Thing<Wow>::Build(m, "ThingWow");
  Thing<Fake>::Build(m, "ThingFake");
}

becomes

// Proposed
#include "Thing.h"
#include "BuildDenseBase.h"

template<class Stuff>
static void BuildThing(py::module& m, const char* name) {
  auto obj = py::class_<Thing<Stuff>>(m, name);

  // You already know

  BuildDenseBase<Thing<Stuff>>(obj);
}

static void BuildThings(py::module& m) {
  BuildThing<Wow>(m, "ThingWow");
  BuildThing<Fake>(m, "ThingFake");
}

This way, you'd have a totally separate folder (I like calling it bind) that only contains a bunch of these BuildWhatever functions. The core implementations wouldn't know about the bindings at all. Really just flipping it all inside-out.

wgledbe commented 3 months ago

Proposed directory structure:

|-- repo root
    `-- asset
        |-- bind
        |-- include
        |   `-- ASSET
        |-- examples
        `-- src
wgledbe commented 3 months ago

Completed refactor of Solvers, Utils, and VectorFunctions. Did not touch OptimalControl or anything that depends on it.