Skip to content

Conversation

@jrmaddison
Copy link
Contributor

@jrmaddison jrmaddison commented Oct 22, 2025

Use SymPy for autodiff and code generation. Not intended to be efficient -- the only nod to efficiency is the use of an LRU cache, arbitrarily set to size 256.

np.sin(AdjFloat) etc are annotated.

@jrmaddison jrmaddison marked this pull request as ready for review October 22, 2025 15:23
@jrmaddison jrmaddison force-pushed the jrmaddison/float_codegen branch 2 times, most recently from dd36bfe to 5c9a778 Compare October 22, 2025 16:12
@jrmaddison jrmaddison force-pushed the jrmaddison/float_codegen branch from 5c9a778 to d4cd44b Compare October 22, 2025 16:16
@jrmaddison jrmaddison force-pushed the jrmaddison/float_codegen branch from 63f1a3a to 8b96da6 Compare October 22, 2025 19:09
@jrmaddison jrmaddison force-pushed the jrmaddison/float_codegen branch from 51636fe to 4ed0833 Compare October 23, 2025 07:41
@jrmaddison jrmaddison force-pushed the jrmaddison/float_codegen branch from 24df5ab to d854085 Compare October 23, 2025 08:17
@jrmaddison jrmaddison linked an issue Oct 23, 2025 that may be closed by this pull request
Copy link
Member

@dham dham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks nice but is the test coverage adequate for the huge list of operations that seem to be added above?

@jrmaddison jrmaddison force-pushed the jrmaddison/float_codegen branch from 1f590b9 to f1e51a9 Compare October 30, 2025 08:46
@jrmaddison jrmaddison force-pushed the jrmaddison/float_codegen branch from f1e51a9 to 5afd925 Compare October 30, 2025 08:53
@jrmaddison
Copy link
Contributor Author

This looks nice but is the test coverage adequate for the huge list of operations that seem to be added above?

Tests added.

The new tests hit a divide-by-zero corner case in the power operator. There might be better workarounds than the one I've added (which essentially codes in SymPy), but that would probably be over-complicating things.

@jrmaddison
Copy link
Contributor Author

jrmaddison commented Oct 30, 2025

A couple of points:

  • Code generation uses exec via sp.lambdify.
  • The implementation still silently drops annotation of operators which are not handled.
  • In principle AdjFloatExprBlock might be used directly for more complicated expressions -- but at that point it would probably be better to switch to a less basic system (e.g. JAX etc).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Terms missing in ExpBlock and LogBlock Hessian evaluation

2 participants