# tfg.math.interpolation.bspline.knot_weights

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/graphics/blob/master/tensorflow_graphics/math/interpolation/bspline.py#L101-L213) |

Function that converts cardinal B-spline positions to knot weights.

    tfg.math.interpolation.bspline.knot_weights(
        positions: type_alias.TensorLike,
        num_knots: type_alias.TensorLike,
        degree: int,
        cyclical: bool,
        sparse_mode: bool = False,
        name: str = 'bspline_knot_weights'
    ) -> Union[tf.Tensor, Tuple[tf.Tensor, tf.Tensor]]

<br />

<br />

<br />

| ## Note ||
|---|---|
| In the following, A1 to An are optional batch dimensions. ||

<br />

<br />

<br />

<br />

| ## Args ||
|---|---|
| `positions` | A tensor with shape `[A1, .. An]`. Positions must be between `[0, C - D)` for non-cyclical and `[0, C)` for cyclical splines, where `C` is the number of knots and `D` is the spline degree. |
| `num_knots` | A strictly positive `int` describing the number of knots in the spline. |
| `degree` | An `int` describing the degree of the spline, which must be smaller than `num_knots`. |
| `cyclical` | A `bool` describing whether the spline is cyclical. |
| `sparse_mode` | A `bool` describing whether to return a result only for the knots with nonzero weights. If set to True, the function returns the weights of only the `degree` + 1 knots that are non-zero, as well as the indices of the knots. |
| `name` | A name for this op. Defaults to "bspline_knot_weights". |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A tensor with dense weights for each control point, with the shape `[A1, ... An, C]` if `sparse_mode` is False. Otherwise, returns a tensor of shape `[A1, ... An, D + 1]` that contains the non-zero weights, and a tensor with the indices of the knots, with the type tf.int32. ||

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `ValueError` | If degree is greater than 4 or num_knots - 1, or less than 0. |
| `InvalidArgumentError` | If positions are not in the right range. |

<br />