set_order#

rateslib.dual.set_order(val, order)#

Changes the order of a Dual or Dual2 and a sets a Variable.

Parameters:
  • val (float, Dual, Dual2, Variable) – The value to convert the order of.

  • order (int in [0, 1, 2]) – The AD order to convert to. If val is float or int 0 will be used.

Return type:

float, Dual or Dual2

Notes

floats are not affected by this function. There is no benefit to converting one of these types to a dual number type with no tagged variable sensitivity.

If order is zero, all objects are converted to float.

If order is one, Dual2 are converted to Dual by dropping second order gradients.

If order is two, Dual are converted to DUal2 by setting second order gradients to default zero values.