<!--
This file is generated by a tool. Do not edit directly.
For open-source contributions the docs will be updated automatically.
-->

*Last updated: 2023-03-16.*

<div itemscope itemtype="http://developers.google.com/ReferenceObject">
<meta itemprop="name" content="tf_quant_finance.math.piecewise.convert_to_tensor_or_func" />
<meta itemprop="path" content="Stable" />
</div>

# tf_quant_finance.math.piecewise.convert_to_tensor_or_func

<!-- Insert buttons and diff -->

<table class="tfo-notebook-buttons tfo-api" align="left">
</table>

<a target="_blank" href="https://github.com/paolodelia99/tf-quant-finance/blob/main/tf_quant_finance/math/piecewise.py">View source</a>



Returns either a `PiecewiseConstantFunc` or x converted to a `Tensor`.

```python
tf_quant_finance.math.piecewise.convert_to_tensor_or_func(
    x, dtype=None, name=None
)
```



<!-- Placeholder for "Used in" -->

Converts the input argument into a `Tensor` unless the input is of type
`PiecewiseConstantFunc` when the input is returned unchanged.  This function
helps pricing models to preprocess inputs that can be either constant or time
dependent as represented by a PiecewiseConstantFunc.

#### Example:

class GeometricBrownianMotion(object)
  def __init__(self, mu, sigma):
    self._mu, self._mu_is_constant = piecewise.convert_to_tensor_or_func(
      mu)
    self._sigma, self._sigma_is_constant =
      piecewise.convert_to_tensor_or_func(sigma)



#### Args:


* <b>`x`</b>: Either a 'Tensor' or 'PiecewiseConstantFunc'.
* <b>`dtype`</b>: The default dtype to use when converting values to `Tensor`s.
  Default value: `None` which means that default dtypes inferred by
    TensorFlow are used.
* <b>`name`</b>: Python string. The name to give to the ops created by this class.
  Default value: `None` which maps to the default name
  'PiecewiseConstantFunc_tensor_or_func'.

#### Returns:

A tuple (y, flag) where y is either a Tensor or PiecewiseConstantFunc
and flag which is False if x is of type PiecewiseConstantFunc and True
otherwise.
