|
NEML2 2.0.0
|
Linearly interpolate the parameter along a single axis. More...
Linearly interpolate the parameter along a single axis.
Currently, this object is hard-coded to always interpolate along the last batch dimension. A few examples of tensor shapes are listed below to demonstrate how broadcasting is handled:
Example 1: unbatched abscissa, unbatched ordinate (of type R2), unbatched input argument, interpolant size 100
Example 2: unbatched abscissa, unbatched ordinate (of type R2), batched input argument (with batch shape (2, 3)), interpolant size 100
Example 3: unbatched abscissa, batched ordinate (of type R2 and with batch shape (5, 1)), batched input argument (with batch shape (2, 5, 2)), interpolant size 100
Example 4: batched abscissa (with batch shape (7, 8, 1)), unbatched ordinate (of type R2), batched input argument (with batch shape (7, 8, 5)), interpolant size 100
#include <LinearInterpolation.h>

Public Member Functions | |
| LinearInterpolation (const OptionSet &options) | |
Public Member Functions inherited from Interpolation< T > | |
| Interpolation (const OptionSet &options) | |
Public Member Functions inherited from Model | |
| Model (const OptionSet &options) | |
| Construct a new Model object. | |
| void | setup () override |
| Setup this object. | |
| void | diagnose () const override |
| Check for common problems. | |
| virtual bool | defines_values () const |
| Whether this model defines output values. | |
| virtual bool | defines_derivatives () const |
| Whether this model defines first derivatives. | |
| virtual bool | defines_second_derivatives () const |
| Whether this model defines second derivatives. | |
| virtual bool | is_nonlinear_system () const |
| Whether this model defines one or more nonlinear equations to be solved. | |
| virtual bool | is_jit_enabled () const |
| Whether JIT is enabled. | |
| virtual void | to (const TensorOptions &options) |
| Send model to a different device or dtype. | |
| const std::vector< std::shared_ptr< Model > > & | registered_models () const |
| The models that may be used during the evaluation of this model. | |
| std::shared_ptr< Model > | registered_model (const std::string &name) const |
| Get a registered model by its name. | |
| void | register_nonlinear_parameter (const std::string &pname, const NonlinearParameter ¶m) |
| Register a nonlinear parameter. | |
| bool | has_nl_param (bool recursive=false) const |
| Whether this parameter store has any nonlinear parameter. | |
| const VariableBase * | nl_param (const std::string &) const |
| Query the existence of a nonlinear parameter. | |
| virtual std::map< std::string, NonlinearParameter > | named_nonlinear_parameters (bool recursive=false) const |
| Get all nonlinear parameters. | |
| std::set< VariableName > | consumed_items () const override |
| The variables that this model depends on. | |
| std::set< VariableName > | provided_items () const override |
| The variables that this model defines as part of its output. | |
| void | request_AD (VariableBase &y, const VariableBase &u) |
| Request to use AD to compute the first derivative of a variable. | |
| void | request_AD (VariableBase &y, const VariableBase &u1, const VariableBase &u2) |
| Request to use AD to compute the second derivative of a variable. | |
| void | forward (bool out, bool dout, bool d2out) |
| Forward operator without jit. | |
| void | forward_maybe_jit (bool out, bool dout, bool d2out) |
| Forward operator with jit. | |
| std::string | variable_name_lookup (const ATensor &var) |
| Look up the name of a variable in the traced graph. | |
| virtual ValueMap | value (const ValueMap &in) |
| Convenient shortcut to construct and return the model value. | |
| virtual ValueMap | value (ValueMap &&in) |
| virtual std::tuple< ValueMap, DerivMap > | value_and_dvalue (const ValueMap &in) |
| Convenient shortcut to construct and return the model value and its derivative. | |
| virtual std::tuple< ValueMap, DerivMap > | value_and_dvalue (ValueMap &&in) |
| virtual DerivMap | dvalue (const ValueMap &in) |
| Convenient shortcut to construct and return the derivative. | |
| virtual DerivMap | dvalue (ValueMap &&in) |
| virtual std::tuple< ValueMap, DerivMap, SecDerivMap > | value_and_dvalue_and_d2value (const ValueMap &in) |
| Convenient shortcut to construct and return the model's value, first and second derivative. | |
| virtual std::tuple< ValueMap, DerivMap, SecDerivMap > | value_and_dvalue_and_d2value (ValueMap &&in) |
| virtual SecDerivMap | d2value (const ValueMap &in) |
| Convenient shortcut to construct and return the model's second derivative. | |
| virtual SecDerivMap | d2value (ValueMap &&in) |
| virtual std::tuple< DerivMap, SecDerivMap > | dvalue_and_d2value (const ValueMap &in) |
| Convenient shortcut to construct and return the model's first and second derivative. | |
| virtual std::tuple< DerivMap, SecDerivMap > | dvalue_and_d2value (ValueMap &&in) |
Public Member Functions inherited from Data | |
| Data (const OptionSet &options) | |
| Construct a new Data object. | |
| const std::vector< std::shared_ptr< Data > > & | registered_data () const |
| All the registered data objects. | |
Public Member Functions inherited from NEML2Object | |
| NEML2Object ()=delete | |
| NEML2Object (NEML2Object &&)=delete | |
| NEML2Object (const NEML2Object &)=delete | |
| NEML2Object & | operator= (NEML2Object &&)=delete |
| NEML2Object & | operator= (const NEML2Object &)=delete |
| virtual | ~NEML2Object ()=default |
| NEML2Object (const OptionSet &options) | |
| Construct a new NEML2Object object. | |
| const OptionSet & | input_options () const |
| const std::string & | name () const |
| A readonly reference to the object's name. | |
| const std::string & | type () const |
| A readonly reference to the object's type. | |
| const std::string & | path () const |
| A readonly reference to the object's path. | |
| const std::string & | doc () const |
| A readonly reference to the object's docstring. | |
| Factory * | factory () const |
| Get the factory that created this object. | |
| const Settings & | settings () const |
| Settings. | |
| template<typename T = NEML2Object> | |
| const T * | host () const |
| Get a readonly pointer to the host. | |
| template<typename T = NEML2Object> | |
| T * | host () |
| Get a writable pointer to the host. | |
| template<typename T > | |
| const T & | resolve_tensor (const std::string &name) |
| Resolve a TensorName to a Tensor. | |
| template<class T > | |
| std::shared_ptr< T > | get_object (const std::string §ion, const std::string &name) |
| template<class T = Solver> | |
| std::shared_ptr< T > | get_solver (const std::string &name) |
| Get a solver from the factory. | |
| template<class T = Data> | |
| std::shared_ptr< T > | get_data (const std::string &name) |
| Get a data from the factory. | |
| template<class T = Model> | |
| std::shared_ptr< T > | get_model (const std::string &name) |
| Get a model from the factory. | |
| template<class T = Driver> | |
| std::shared_ptr< T > | get_driver (const std::string &name) |
| Get a driver from the factory. | |
| template<class T = WorkScheduler> | |
| std::shared_ptr< T > | get_scheduler (const std::string &name) |
| Get a scheduler from the factory. | |
Public Member Functions inherited from BufferStore | |
| BufferStore (NEML2Object *object) | |
| BufferStore (const BufferStore &)=delete | |
| BufferStore (BufferStore &&)=delete | |
| BufferStore & | operator= (const BufferStore &)=delete |
| BufferStore & | operator= (BufferStore &&)=delete |
| virtual | ~BufferStore ()=default |
| const std::map< std::string, std::unique_ptr< TensorValueBase > > & | named_buffers () const |
| std::map< std::string, std::unique_ptr< TensorValueBase > > & | named_buffers () |
| const TensorValueBase & | get_buffer (const std::string &name) const |
| }@ | |
| TensorValueBase & | get_buffer (const std::string &name) |
| Get a writable reference of a buffer. | |
Public Member Functions inherited from ParameterStore | |
| ParameterStore (Model *object) | |
| ParameterStore (const ParameterStore &)=delete | |
| ParameterStore (ParameterStore &&)=delete | |
| ParameterStore & | operator= (const ParameterStore &)=delete |
| ParameterStore & | operator= (ParameterStore &&)=delete |
| virtual | ~ParameterStore ()=default |
| const std::map< std::string, std::unique_ptr< TensorValueBase > > & | named_parameters () const |
| std::map< std::string, std::unique_ptr< TensorValueBase > > & | named_parameters () |
| const TensorValueBase & | get_parameter (const std::string &name) const |
| }@ | |
| TensorValueBase & | get_parameter (const std::string &name) |
| Get a writable reference of a parameter. | |
| void | set_parameter (const std::string &, const Tensor &) |
| Set the value for a parameter. | |
| void | set_parameters (const std::map< std::string, Tensor > &) |
| Set values for parameters. | |
Public Member Functions inherited from VariableStore | |
| VariableStore (Model *object) | |
| VariableStore (const VariableStore &)=delete | |
| VariableStore (VariableStore &&)=delete | |
| VariableStore & | operator= (const VariableStore &)=delete |
| VariableStore & | operator= (VariableStore &&)=delete |
| virtual | ~VariableStore ()=default |
| LabeledAxis & | declare_axis (const std::string &name) |
| virtual void | setup_layout () |
| Setup the layout of all the registered axes. | |
| const TensorOptions & | variable_options () const |
| Current tensor options for variables. | |
| LabeledAxis & | input_axis () |
| const LabeledAxis & | input_axis () const |
| LabeledAxis & | output_axis () |
| const LabeledAxis & | output_axis () const |
| VariableStorage & | input_variables () |
| const VariableStorage & | input_variables () const |
| VariableStorage & | output_variables () |
| const VariableStorage & | output_variables () const |
| VariableBase & | input_variable (const VariableName &) |
| const VariableBase & | input_variable (const VariableName &) const |
| VariableBase & | output_variable (const VariableName &) |
| const VariableBase & | output_variable (const VariableName &) const |
| virtual void | clear_derivatives () |
| void | assign_input (const ValueMap &vals) |
| void | assign_input (ValueMap &&vals) |
| Assign input variable values. | |
| void | assign_output (const ValueMap &vals) |
| Assign output variable values. | |
| void | assign_output_derivatives (const DerivMap &derivs) |
| Assign variable derivatives. | |
| ValueMap | collect_input () const |
| ValueMap | collect_output () const |
| DerivMap | collect_output_derivatives () const |
| Collect variable derivatives. | |
| SecDerivMap | collect_output_second_derivatives () const |
| Collect variable second derivatives. | |
Public Member Functions inherited from NonlinearSystem | |
| NonlinearSystem (const NonlinearSystem &)=default | |
| NonlinearSystem (NonlinearSystem &&) noexcept=default | |
| NonlinearSystem & | operator= (const NonlinearSystem &)=delete |
| NonlinearSystem & | operator= (NonlinearSystem &&)=delete |
| virtual | ~NonlinearSystem ()=default |
| NonlinearSystem (const OptionSet &options) | |
| virtual void | init_scaling (const Sol< false > &x, const bool verbose=false) |
| Compute algebraic Jacobian-based automatic scaling following https://cs.stanford.edu/people/paulliu/files/cs517-project.pdf. | |
| Res< true > | scale (const Res< false > &r) const |
| Apply scaling to the residual. | |
| Res< false > | unscale (const Res< true > &r) const |
| Remove scaling to the residual. | |
| Jac< true > | scale (const Jac< false > &J) const |
| Apply scaling to the Jacobian. | |
| Jac< false > | unscale (const Jac< true > &J) const |
| Remove scaling to the Jacobian. | |
| Sol< true > | scale (const Sol< false > &u) const |
| Apply scaling to the solution. | |
| Sol< false > | unscale (const Sol< true > &u) const |
| Remove scaling to the solution. | |
| void | set_guess (const Sol< true > &x) |
| Set the current guess. | |
| template<bool scaled> | |
| Res< scaled > | residual () |
| Assemble and return the residual. | |
| template<bool scaled> | |
| Res< scaled > | residual (const Sol< scaled > &x) |
| Convenient shortcut to set the current guess, assemble and return the residual. | |
| template<bool scaled> | |
| Jac< scaled > | Jacobian () |
| Assemble and return the Jacobian. | |
| template<bool scaled> | |
| Jac< scaled > | Jacobian (const Sol< scaled > &x) |
| Convenient shortcut to set the current guess, assemble and return the Jacobian. | |
| template<bool scaled> | |
| std::tuple< Res< scaled >, Jac< scaled > > | residual_and_Jacobian () |
| Assemble and return the residual and Jacobian. | |
| template<bool scaled> | |
| std::tuple< Res< scaled >, Jac< scaled > > | residual_and_Jacobian (const Sol< scaled > &x) |
| Convenient shortcut to set the current guess, assemble and return the residual and Jacobian. | |
Public Member Functions inherited from DependencyDefinition< VariableName > | |
| DependencyDefinition ()=default | |
| DependencyDefinition (DependencyDefinition &&)=delete | |
| DependencyDefinition (const DependencyDefinition &)=delete | |
| DependencyDefinition & | operator= (const DependencyDefinition &)=delete |
| DependencyDefinition & | operator= (DependencyDefinition &&)=delete |
| virtual | ~DependencyDefinition ()=default |
Public Member Functions inherited from DiagnosticsInterface | |
| DiagnosticsInterface ()=delete | |
| DiagnosticsInterface (NEML2Object *object) | |
| DiagnosticsInterface (DiagnosticsInterface &&)=delete | |
| DiagnosticsInterface (const DiagnosticsInterface &)=delete | |
| DiagnosticsInterface & | operator= (const DiagnosticsInterface &)=delete |
| DiagnosticsInterface & | operator= (DiagnosticsInterface &&)=delete |
| virtual | ~DiagnosticsInterface ()=default |
| const NEML2Object & | object () const |
| Get the object. | |
Static Public Member Functions | |
| static OptionSet | expected_options () |
| template<typename T2 > | |
| static T2 | mask (const T2 &in, const Scalar &m) |
Apply the mask tensor m on the input in. | |
Static Public Member Functions inherited from Interpolation< T > | |
| static OptionSet | expected_options () |
Static Public Member Functions inherited from Model | |
| static OptionSet | expected_options () |
Static Public Member Functions inherited from Data | |
| static OptionSet | expected_options () |
Static Public Member Functions inherited from NEML2Object | |
| static OptionSet | expected_options () |
Static Public Member Functions inherited from NonlinearSystem | |
| static OptionSet | expected_options () |
| static void | disable_automatic_scaling (OptionSet &options) |
| static void | enable_automatic_scaling (OptionSet &options) |
Protected Member Functions | |
| void | set_value (bool out, bool dout_din, bool d2out_din2) override |
| The map between input -> output, and optionally its derivatives. | |
Protected Member Functions inherited from Model | |
| void | diagnostic_assert_state (const VariableBase &v) const |
| void | diagnostic_assert_old_state (const VariableBase &v) const |
| void | diagnostic_assert_force (const VariableBase &v) const |
| void | diagnostic_assert_old_force (const VariableBase &v) const |
| void | diagnostic_assert_residual (const VariableBase &v) const |
| void | diagnostic_check_input_variable (const VariableBase &v) const |
| void | diagnostic_check_output_variable (const VariableBase &v) const |
| void | diagnose_nl_sys () const |
| Additional diagnostics for a nonlinear system. | |
| virtual void | link_input_variables () |
| virtual void | link_input_variables (Model *submodel) |
| virtual void | link_output_variables () |
| virtual void | link_output_variables (Model *submodel) |
| void | clear_input () override |
| void | clear_output () override |
| void | zero_input () override |
| void | zero_output () override |
| void | check_precision () const |
| Check the current default precision and warn if it's not double precision. | |
| virtual void | request_AD () |
| template<typename T = Model, typename = typename std::enable_if_t<std::is_base_of_v<Model, T>>> | |
| T & | register_model (const std::string &name, bool nonlinear=false, bool merge_input=true) |
| Register a model that the current model may use during its evaluation. | |
| void | assign_input_stack (jit::Stack &stack) |
| jit::Stack | collect_input_stack () const |
| void | set_guess (const Sol< false > &) override |
| Set the unscaled current guess. | |
| void | assemble (Res< false > *, Jac< false > *) override |
| Compute the unscaled residual and Jacobian. | |
Protected Member Functions inherited from Data | |
| template<typename T , typename = typename std::enable_if_t<std::is_base_of_v<Data, T>>> | |
| T & | register_data (const std::string &name) |
Protected Member Functions inherited from BufferStore | |
| virtual void | send_buffers_to (const TensorOptions &options) |
Send all buffers to options. | |
| template<typename T , typename = typename std::enable_if_t<std::is_base_of_v<TensorBase<T>, T>>> | |
| const T & | declare_buffer (const std::string &name, const T &rawval) |
| Declare a buffer. | |
| template<typename T , typename = typename std::enable_if_t<std::is_base_of_v<TensorBase<T>, T>>> | |
| const T & | declare_buffer (const std::string &name, const TensorName< T > &tensorname) |
| Declare a buffer. | |
| template<typename T , typename = typename std::enable_if_t<std::is_base_of_v<TensorBase<T>, T>>> | |
| const T & | declare_buffer (const std::string &name, const std::string &input_option_name) |
| Declare a buffer. | |
| void | assign_buffer_stack (jit::Stack &stack) |
| Assign stack to buffers. | |
| jit::Stack | collect_buffer_stack () const |
| Collect stack from buffers. | |
Protected Member Functions inherited from ParameterStore | |
| virtual void | send_parameters_to (const TensorOptions &options) |
| Send parameters to options. | |
| template<typename T , typename = typename std::enable_if_t<std::is_base_of_v<TensorBase<T>, T>>> | |
| const T & | declare_parameter (const std::string &name, const T &rawval) |
| Declare a parameter. | |
| template<typename T , typename = typename std::enable_if_t<std::is_base_of_v<TensorBase<T>, T>>> | |
| const T & | declare_parameter (const std::string &name, const TensorName< T > &tensorname, bool allow_nonlinear) |
| Declare a parameter. | |
| template<typename T , typename = typename std::enable_if_t<std::is_base_of_v<TensorBase<T>, T>>> | |
| const T & | declare_parameter (const std::string &name, const std::string &input_option_name, bool allow_nonlinear=false) |
| Declare a parameter. | |
| void | assign_parameter_stack (jit::Stack &stack) |
| Assign stack to parameters. | |
| jit::Stack | collect_parameter_stack () const |
| Collect stack from parameters. | |
Protected Member Functions inherited from VariableStore | |
| virtual void | send_variables_to (const TensorOptions &options) |
| Send padding variables to options. | |
| template<typename T > | |
| const Variable< T > & | declare_input_variable (const char *name, TensorShapeRef list_shape={}, bool allow_duplicate=false) |
| Declare an input variable. | |
| template<typename T > | |
| const Variable< T > & | declare_input_variable (const VariableName &name, TensorShapeRef list_shape={}, bool allow_duplicate=false) |
| Declare an input variable. | |
| template<typename T > | |
| Variable< T > & | declare_output_variable (const char *name, TensorShapeRef list_shape={}) |
| Declare an output variable. | |
| template<typename T > | |
| Variable< T > & | declare_output_variable (const VariableName &name, TensorShapeRef list_shape={}) |
| Declare an output variable. | |
| const VariableBase * | clone_input_variable (const VariableBase &var, const VariableName &new_name={}) |
| Clone a variable and put it on the input axis. | |
| VariableBase * | clone_output_variable (const VariableBase &var, const VariableName &new_name={}) |
| Clone a variable and put it on the output axis. | |
| void | assign_input_stack (jit::Stack &stack) |
| Assign stack to input variables. | |
| void | assign_output_stack (jit::Stack &stack, bool out, bool dout, bool d2out) |
| Assign stack to output variables and derivatives. | |
| jit::Stack | collect_input_stack () const |
| Collect stack from input variables. | |
| jit::Stack | collect_output_stack (bool out, bool dout, bool d2out) const |
| Collect stack from output variables and derivatives. | |
Protected Member Functions inherited from NonlinearSystem | |
Protected Attributes | |
| const Scalar & | _X |
| The abscissa values of the interpolant. | |
| const Variable< Scalar > & | _x |
| Argument of interpolation. | |
Protected Attributes inherited from Interpolation< T > | |
| const T & | _Y |
| The ordinate values of the interpolant. | |
| Variable< T > & | _p |
| The interpolated value. | |
Protected Attributes inherited from Model | |
| std::vector< std::shared_ptr< Model > > | _registered_models |
| Models this model may use during its evaluation. | |
Protected Attributes inherited from Data | |
| std::vector< std::shared_ptr< Data > > | _registered_data |
| Registered Data objects. | |
Protected Attributes inherited from NonlinearSystem | |
| const bool | _autoscale |
| If true, do automatic scaling. | |
| const double | _autoscale_tol |
| Tolerance for convergence check of the iterative automatic scaling algorithm. | |
| const unsigned int | _autoscale_miter |
| Maximum number of iterations allowed for the iterative automatic scaling algorithm. | |
| bool | _scaling_matrices_initialized = false |
| Flag to indicate whether scaling matrices have been computed. | |
| Tensor | _row_scaling |
| Row scaling "matrix" – since it's a batched diagonal matrix, we are only storing its diagonals. | |
| Tensor | _col_scaling |
| Column scaling "matrix" – since it's a batched diagonal matrix, we are only storing its diagonals. | |
Additional Inherited Members | |
Public Types inherited from VariableStore | |
| using | VariableStorage = std::map<VariableName, std::unique_ptr<VariableBase>> |
| LinearInterpolation | ( | const OptionSet & | options | ) |
|
static |
Apply the mask tensor m on the input in.
This method additionally handles the necessary expanding and reshaping based on two assumptions:
So if some day we relax the 2nd assumption, this method need to be adapted accordingly.
|
overrideprotectedvirtual |
The map between input -> output, and optionally its derivatives.
Implements Model.
|
protected |
The abscissa values of the interpolant.