Skip to content

Conversation

@ChrisRackauckas-Claude
Copy link

Summary

This PR adds a Number dispatch to StatelessApplyWrapper that allows using scalar variables directly without wrapping them in arrays, as suggested by @ChrisRackauckas in #83.

Previously, users had to write:

sym_nn([X], θ)[1]

Now they can write:

sym_nn(X, θ)[1]

The array syntax still works for backward compatibility.

Implementation

Added a new method to StatelessApplyWrapper at src/ModelingToolkitNeuralNets.jl:124-126:

function (wrapper::StatelessApplyWrapper)(input::Number, nn_p::AbstractVector)
    wrapper([input], nn_p)
end

This method wraps scalar inputs in an array and delegates to the existing AbstractArray dispatch.

Test plan

  • Added comprehensive test in test/scalar_dispatch.jl demonstrating scalar dispatch usage
  • Verified backward compatibility with existing array syntax
  • Ran full test suite with Pkg.test() - all tests pass (27/27)
  • Formatted code with JuliaFormatter using SciMLStyle

Fixes #83

🤖 Generated with Claude Code

ChrisRackauckas and others added 2 commits October 25, 2025 19:34
This commit adds a Number dispatch to StatelessApplyWrapper that allows
using scalar variables directly without wrapping them in arrays.

Previously, users had to write:
  sym_nn([X], θ)[1]

Now they can write:
  sym_nn(X, θ)[1]

The array syntax still works for backward compatibility.

Fixes SciML#83

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@ChrisRackauckas ChrisRackauckas merged commit 6bdf82a into SciML:main Oct 26, 2025
11 of 13 checks passed
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.

Is there any actual need for array input in SymbolicNeuralNetwork-created neural networks?

2 participants