def compress(val, mode, nbits=None, lut_function=None) -> "optimize_utils.LutParamsIos16":
        """
        [Legacy] Per-tensor palletization.

        This API is for backward compatibility only. It's no longer used inside the coremltools.
        It's recommended to use `blockwise_compress` instead, which is more general.
        """
        def check_lut_parameters_are_valid(val, lut, indices):
            if not isinstance(lut, np.ndarray) or not isinstance(indices, np.ndarray):
                raise ValueError("LUT and indices must be type of numpy array.")

            if indices.size != val.size:
                msg = "Indices size ({}) mismatched with the original weight({}).".format(
                    indices.size, val.size
                )
                raise ValueError(msg)

            if len(indices.shape) != 1 or indices.dtype != np.uint8:
                msg = "Indices must be a numpy vector of type uint8. Found shape {} with type {}".format(
                    indices.shape, indices.dtype
                )
                raise ValueError(msg)

            if lut.dtype != val.dtype:
                msg = "Dtype mismatched between LUT ({}) and weight ({})".format(
                    lut.dtype, val.dtype
                )
                raise ValueError(msg)

        if not isinstance(val, (np.ndarray, np.generic)):
            raise ValueError(f"Only numpy arrays are supported. Got {type(val)}")

        lut, indices = palettize_weights._get_lut_and_indices(val, mode, nbits, lut_function)

        check_lut_parameters_are_valid(val, lut, indices)

        params = optimize_utils.LutParamsIos16(
            lut=lut,
            indices=optimize_utils.pack_elements_into_bits(indices, int(np.log2(lut.shape[0]))),
            shape=val.shape,
        )
        return params

        [Legacy] Per-tensor palletization.

        This API is for backward compatibility only. It's no longer used inside the coremltools.
        It's recommended to use `blockwise_compress` instead, which is more general.
        
coremltools/optimize/coreml/_quantization_passes.py