class_docstr: Reshapes input Tensor, preserving the batch dimension.
  
  For example, given an input tensor with shape ``[B, H, W, C, D]``::
  
      >>> B, H, W, C, D = range(1, 6)
      >>> x = tf.ones([B, H, W, C, D])
  
  The default behavior when ``output_shape`` is ``(-1, D)`` is to flatten
  all dimensions between ``B`` and ``D``::
  
      >>> mod = snt.Reshape(output_shape=(-1, D))
      >>> assert mod(x).shape == [B, H*W*C, D]
  
  You can change the number of preserved leading dimensions via
  ``preserve_dims``::
  
      >>> mod = snt.Reshape(output_shape=(-1, D), preserve_dims=2)
      >>> assert mod(x).shape == [B, H, W*C, D]
  
      >>> mod = snt.Reshape(output_shape=(-1, D), preserve_dims=3)
      >>> assert mod(x).shape == [B, H, W, C, D]
  
      >>> mod = snt.Reshape(output_shape=(-1, D), preserve_dims=4)
      >>> assert mod(x).shape == [B, H, W, C, 1, D]
class_docstr_tok: ["Reshapes","input","Tensor",",","preserving","the","batch","dimension",".","For","example",",","given","an","input","tensor","with","shape","``","[","B",",","H",",","W",",","C",",","D","]","``",":",":",">",">",">","B",",","H",",","W",",","C",",","D","=","range","(","1",",","6",")",">",">",">","x","=","tf.ones","(","[","B",",","H",",","W",",","C",",","D","]",")","The","default","behavior","when","``","output_shape","``","is","``","(","-1",",","D",")","``","is","to","flatten","all","dimensions","between","``","B","``","and","``","D","``",":",":",">",">",">","mod","=","snt.Reshape","(","output_shape=","(","-1",",","D",")",")",">",">",">","assert","mod","(","x",")",".shape","==","[","B",",","H","*","W","*","C",",","D","]","You","can","change","the","number","of","preserved","leading","dimensions","via","``","preserve_dims","``",":",":",">",">",">","mod","=","snt.Reshape","(","output_shape=","(","-1",",","D",")",",","preserve_dims=2",")",">",">",">","assert","mod","(","x",")",".shape","==","[","B",",","H",",","W","*","C",",","D","]",">",">",">","mod","=","snt.Reshape","(","output_shape=","(","-1",",","D",")",",","preserve_dims=3",")",">",">",">","assert","mod","(","x",")",".shape","==","[","B",",","H",",","W",",","C",",","D","]",">",">",">","mod","=","snt.Reshape","(","output_shape=","(","-1",",","D",")",",","preserve_dims=4",")",">",">",">","assert","mod","(","x",")",".shape","==","[","B",",","H",",","W",",","C",",","1",",","D","]"]
docstr: Reshapes ``inputs``.
  
  Args:
    inputs: A tensor of shape ``[b_1, b_2, ..., b_preserve_dims,
      b_preserve_dims + 1, ...]``.
  
  Returns:
    A tensor of shape
      ``[b_1, b_2, ..., b_preserve_dims, b_reshape_1, b_reshape_2, ...]``,
      with reshaping defined by the constructor ``output_shape`` parameter.
  
  Raises:
    ValueError: If ``output_shape`` is incompatible with shape of the
      ``inputs``; or if ``output_shape`` contains more than one wildcard -1;
      or if the ``inputs`` rank is less than ``preserved_dims``; or if
      the ``inputs`` shape contains unknown, non-preserved dimensions
      (except when the unknown dimension is the only non-preserved
      dimension and doesn't actually need reshaping).
docstr_tok: ["Reshapes","``","inputs","``",".","Args",":","inputs",":","A","tensor","of","shape","``","[","b_1",",","b_2",",","...",",","b_preserve_dims",",","b_preserve_dims","+","1",",","...","]","``",".","Returns",":","A","tensor","of","shape","``","[","b_1",",","b_2",",","...",",","b_preserve_dims",",","b_reshape_1",",","b_reshape_2",",","...","]","``",",","with","reshaping","defined","by","the","constructor","``","output_shape","``","parameter",".","Raises",":","ValueError",":","If","``","output_shape","``","is","incompatible","with","shape","of","the","``","inputs","``",";","or","if","``","output_shape","``","contains","more","than","one","wildcard","-1",";","or","if","the","``","inputs","``","rank","is","less","than","``","preserved_dims","``",";","or","if","the","``","inputs","``","shape","contains","unknown",",","non-preserved","dimensions","(","except","when","the","unknown","dimension","is","the","only","non-preserved","dimension","and","does","n't","actually","need","reshaping",")","."]
code: def __call__(self, inputs: tf.Tensor) -> tf.Tensor:
      """Reshapes ``inputs``.
  
      Args:
        inputs: A tensor of shape ``[b_1, b_2, ..., b_preserve_dims,
          b_preserve_dims + 1, ...]``.
  
      Returns:
        A tensor of shape
          ``[b_1, b_2, ..., b_preserve_dims, b_reshape_1, b_reshape_2, ...]``,
          with reshaping defined by the constructor ``output_shape`` parameter.
  
      Raises:
        ValueError: If ``output_shape`` is incompatible with shape of the
          ``inputs``; or if ``output_shape`` contains more than one wildcard -1;
          or if the ``inputs`` rank is less than ``preserved_dims``; or if
          the ``inputs`` shape contains unknown, non-preserved dimensions
          (except when the unknown dimension is the only non-preserved
          dimension and doesn't actually need reshaping).
      """
      self._initialize(inputs)
  
      # Resolve the wildcard if any.
      output_shape = tuple(self._output_shape)
      if -1 in output_shape:
          reshaped_shape = inputs.shape[self._preserve_dims :]
          if reshaped_shape.is_fully_defined():
              output_shape = _infer_shape(output_shape, reshaped_shape)
  
      preserved_shape = inputs.shape[: self._preserve_dims]
      if preserved_shape.is_fully_defined():
          output = tf.reshape(
              inputs, tuple(preserved_shape) + output_shape
          )
      else:
          dynamic_preserved_shape = tf.shape(inputs)[
              : self._preserve_dims
          ]
          output = tf.reshape(
              inputs,
              tf.concat(
                  [dynamic_preserved_shape, output_shape], axis=0
              ),
          )
      return output
  
file_path: sonnet/sonnet/src/reshape.py
imports: from typing import Optional, Sequence
  import numpy
  from sonnet.src import base
  from sonnet.src import once
  from sonnet.src import types
  import tensorflow
label_desc: Use image node_id 3 for calling the Reshape obj's underlying member method code with example usage: obj.__call__(inputs) and returns: output