def add_rank_preserving_reshape(self, name, input_name, output_name, output_shape):
        """
        Add a rank_preserving_reshape layer to the model that reshapes the input
        tensor without altering the rank of the tensor.
        Refer to the ``RankPreservingReshapeLayerParams`` message in the specification
        (NeuralNetwork.proto) for more details.

        Parameters
        ----------
        name: str
            The name of this layer.
        input_name: str
            The input blob name of this layer.
        output_name: str
            The output blob name of this layer.
        output_shape: list of int or tuple of int
            Determines the shape of the output blob.
            0: copy the dimension of the input to output
            -1: calculate dimensions from the rest of the shape

        See Also
        --------
        add_reshape, add_reshape_like, add_reshape_static, add_reshape_dynamic
        """

        spec_layer = self._add_generic_layer(
            name,
            [input_name],
            [output_name],
            input_ranks=[len(output_shape)],
            input_shapes=[[int(x) for x in output_shape]],
            output_ranks=[len(output_shape)],
            output_shapes=[[int(x) for x in output_shape]],
        )

        spec_layer_params = spec_layer.rankPreservingReshape
        spec_layer_params.targetShape.extend(map(int, output_shape))
        return spec_layer

        Add a rank_preserving_reshape layer to the model that reshapes the input
        tensor without altering the rank of the tensor.
        Refer to the ``RankPreservingReshapeLayerParams`` message in the specification
        (NeuralNetwork.proto) for more details.

        Parameters
        ----------
        name: str
            The name of this layer.
        input_name: str
            The input blob name of this layer.
        output_name: str
            The output blob name of this layer.
        output_shape: list of int or tuple of int
            Determines the shape of the output blob.
            0: copy the dimension of the input to output
            -1: calculate dimensions from the rest of the shape

        See Also
        --------
        add_reshape, add_reshape_like, add_reshape_static, add_reshape_dynamic
        
coremltools/models/neural_network/builder.py