def _compare_moments(model, inputs, expected, use_cpu_only=True, num_moments=10):
        """
        This utility function is used for validate random distributions layers.
        It validates the first 10 moments of prediction and expected values.
        """

        def get_moment(data, k):
            return np.mean(np.power(data - np.mean(data), k))

        if isinstance(model, str):
            model = coremltools.models.MLModel(model)

        if use_cpu_only:
            compute_unit=ComputeUnit.CPU_ONLY
        else:
            compute_unit=ComputeUnit.ALL

        model = coremltools.models.MLModel(model, compute_units=compute_unit)
        prediction = model.predict(inputs)

        for output_name in expected:
            np_preds = expected[output_name]
            coreml_preds = prediction[output_name]

            np_moments = [get_moment(np_preds.flatten(), k) for k in range(num_moments)]
            coreml_moments = [
                get_moment(coreml_preds.flatten(), k) for k in range(num_moments)
            ]

            np.testing.assert_almost_equal(np_moments, coreml_moments, decimal=2)

        # override expected values to allow element-wise compares
        for output_name in expected:
            expected[output_name] = prediction[output_name]

        This utility function is used for validate random distributions layers.
        It validates the first 10 moments of prediction and expected values.
        
coremltools/test/neural_network/test_numpy_nn_layers.py