'Finds and replaces a missing dimension in an output shape.
This is a near direct port of the internal Numpy function
`_fix_unknown_dimension` in `numpy/core/src/multiarray/shape.c`
# Arguments
input_shape: original shape of array being reshaped
output_shape: target shape of the array, with at most
a single -1 which indicates a dimension that should be
derived from the input shape.
# Returns
The new output shape with a `-1` replaced with its computed value.
# Raises
ValueError: if `input_shape` and `output_shape` do not match.'

def _fix_unknown_dimension(self, input_shape, output_shape):

    output_shape = list(output_shape)
    msg = 'total    size    of    new    array    must    be    unchanged'
    (known, unknown) = (1, None)
    for (index, dim) in enumerate(output_shape):
        if (dim < 0):
            if (unknown is None):
                unknown = index
            else:
                raise ValueError('Can    only    specify    one    unknown    dimension.')
        else:
            known *= dim
    original = np.prod(input_shape, dtype=int)
    if (unknown is not None):
        if ((known == 0) or ((original % known) != 0)):
            raise ValueError(msg)
        output_shape[unknown] = (original // known)
    elif (original != known):
        raise ValueError(msg)
    return tuple(output_shape)
