def check_kernel_gradient_functions(kern, X=None, X2=None, output_ind=None, verbose=False, fixed_X_dims=None):
pass_checks = True<EOL>if X is None:<EOL><INDENT>X = np.random.randn(<NUM_LIT:10>, kern.input_dim)<EOL>if output_ind is not None:<EOL><INDENT>X[:, output_ind] = np.random.randint(kern.output_dim, X.shape[<NUM_LIT:0>])<EOL><DEDENT><DEDENT>if X2 is None:<EOL><INDENT>X2 = np.random.randn(<NUM_LIT:20>, kern.input_dim)<EOL>if output_ind is not None:<EOL><INDENT>X2[:, output_ind] = np.random.randint(kern.output_dim, X2.shape[<NUM_LIT:0>])<EOL><DEDENT><DEDENT>if verbose:<EOL><INDENT>print("<STR_LIT>")<EOL><DEDENT>result = Kern_check_model(kern, X=X).is_positive_semi_definite()<EOL>if result and verbose:<EOL><INDENT>print("<STR_LIT>")<EOL><DEDENT>if not result:<EOL><INDENT>print(("<STR_LIT>" + kern.name + "<STR_LIT>"))<EOL>pass_checks = False<EOL>assert(result)<EOL>return False<EOL><DEDENT>if verbose:<EOL><INDENT>print("<STR_LIT>")<EOL><DEDENT>result = Kern_check_dK_dtheta(kern, X=X, X2=None).checkgrad(verbose=verbose)<EOL>if result and verbose:<EOL><INDENT>print("<STR_LIT>")<EOL><DEDENT>if not result:<EOL><INDENT>print(("<STR_LIT>" + kern.name + "<STR_LIT>"))<EOL>Kern_check_dK_dtheta(kern, X=X, X2=None).checkgrad(verbose=True)<EOL>pass_checks = False<EOL>assert(result)<EOL>return False<EOL><DEDENT>if verbose:<EOL><INDENT>print("<STR_LIT>")<EOL><DEDENT>try:<EOL><INDENT>result = Kern_check_dK_dtheta(kern, X=X, X2=X2).checkgrad(verbose=verbose)<EOL><DEDENT>except NotImplementedError:<EOL><INDENT>result=True<EOL>if verbose:<EOL><INDENT>print(("<STR_LIT>" + kern.name))<EOL><DEDENT><DEDENT>if result and verbose:<EOL><INDENT>print("<STR_LIT>")<EOL><DEDENT>if not result:<EOL><INDENT>print(("<STR_LIT>" + kern.name + "<STR_LIT>"))<EOL>Kern_check_dK_dtheta(kern, X=X, X2=X2).checkgrad(verbose=True)<EOL>pass_checks = False<EOL>assert(result)<EOL>return False<EOL><DEDENT>if verbose:<EOL><INDENT>print("<STR_LIT>")<EOL><DEDENT>try:<EOL><INDENT>result = Kern_check_dKdiag_dtheta(kern, X=X).checkgrad(verbose=verbose)<EOL><DEDENT>except NotImplementedError:<EOL><INDENT>result=True<EOL>if verbose:<EOL><INDENT>print(("<STR_LIT>" + kern.name))<EOL><DEDENT><DEDENT>if result and verbose:<EOL><INDENT>print("<STR_LIT>")<EOL><DEDENT>if not result:<EOL><INDENT>print(("<STR_LIT>" + kern.name + "<STR_LIT>"))<EOL>Kern_check_dKdiag_dtheta(kern, X=X).checkgrad(verbose=True)<EOL>pass_checks = False<EOL>assert(result)<EOL>return False<EOL><DEDENT>if verbose:<EOL><INDENT>print("<STR_LIT>")<EOL><DEDENT>try:<EOL><INDENT>testmodel = Kern_check_dK_dX(kern, X=X, X2=None)<EOL>if fixed_X_dims is not None:<EOL><INDENT>testmodel.X[:,fixed_X_dims].fix()<EOL><DEDENT>result = testmodel.checkgrad(verbose=verbose)<EOL><DEDENT>except NotImplementedError:<EOL><INDENT>result=True<EOL>if verbose:<EOL><INDENT>print(("<STR_LIT>" + kern.name))<EOL><DEDENT><DEDENT>if result and verbose:<EOL><INDENT>print("<STR_LIT>")<EOL><DEDENT>if not result:<EOL><INDENT>print(("<STR_LIT>" + kern.name + "<STR_LIT>"))<EOL>testmodel.checkgrad(verbose=True)<EOL>assert(result)<EOL>pass_checks = False<EOL>return False<EOL><DEDENT>if verbose:<EOL><INDENT>print("<STR_LIT>")<EOL><DEDENT>try:<EOL><INDENT>testmodel = Kern_check_dK_dX(kern, X=X, X2=X2)<EOL>if fixed_X_dims is not None:<EOL><INDENT>testmodel.X[:,fixed_X_dims].fix()<EOL><DEDENT>result = testmodel.checkgrad(verbose=verbose)<EOL><DEDENT>except NotImplementedError:<EOL><INDENT>result=True<EOL>if verbose:<EOL><INDENT>print(("<STR_LIT>" + kern.name))<EOL><DEDENT><DEDENT>if result and verbose:<EOL><INDENT>print("<STR_LIT>")<EOL><DEDENT>if not result:<EOL><INDENT>print(("<STR_LIT>" + kern.name + "<STR_LIT>"))<EOL>testmodel.checkgrad(verbose=True)<EOL>assert(result)<EOL>pass_checks = False<EOL>return False<EOL><DEDENT>if verbose:<EOL><INDENT>print("<STR_LIT>")<EOL><DEDENT>try:<EOL><INDENT>testmodel = Kern_check_dKdiag_dX(kern, X=X)<EOL>if fixed_X_dims is not None:<EOL><INDENT>testmodel.X[:,fixed_X_dims].fix()<EOL><DEDENT>result = testmodel.checkgrad(verbose=verbose)<EOL><DEDENT>except NotImplementedError:<EOL><INDENT>result=True<EOL>if verbose:<EOL><INDENT>print(("<STR_LIT>" + kern.name))<EOL><DEDENT><DEDENT>if result and verbose:<EOL><INDENT>print("<STR_LIT>")<EOL><DEDENT>if not result:<EOL><INDENT>print(("<STR_LIT>" + kern.name + "<STR_LIT>"))<EOL>Kern_check_dKdiag_dX(kern, X=X).checkgrad(verbose=True)<EOL>pass_checks = False<EOL>assert(result)<EOL>return False<EOL><DEDENT>if verbose:<EOL><INDENT>print("<STR_LIT>")<EOL><DEDENT>try:<EOL><INDENT>testmodel = Kern_check_d2K_dXdX(kern, X=X, X2=X2)<EOL>if fixed_X_dims is not None:<EOL><INDENT>testmodel.X[:,fixed_X_dims].fix()<EOL><DEDENT>result = testmodel.checkgrad(verbose=verbose)<EOL><DEDENT>except NotImplementedError:<EOL><INDENT>result=True<EOL>if verbose:<EOL><INDENT>print(("<STR_LIT>" + kern.name))<EOL><DEDENT><DEDENT>if result and verbose:<EOL><INDENT>print("<STR_LIT>")<EOL><DEDENT>if not result:<EOL><INDENT>print(("<STR_LIT>" + kern.name + "<STR_LIT>"))<EOL>testmodel.checkgrad(verbose=True)<EOL>assert(result)<EOL>pass_checks = False<EOL>return False<EOL><DEDENT>if verbose:<EOL><INDENT>print("<STR_LIT>")<EOL><DEDENT>try:<EOL><INDENT>testmodel = Kern_check_d2K_dXdX(kern, X=X, X2=None)<EOL>if fixed_X_dims is not None:<EOL><INDENT>testmodel.X[:,fixed_X_dims].fix()<EOL><DEDENT>result = testmodel.checkgrad(verbose=verbose)<EOL><DEDENT>except NotImplementedError:<EOL><INDENT>result=True<EOL>if verbose:<EOL><INDENT>print(("<STR_LIT>" + kern.name))<EOL><DEDENT><DEDENT>if result and verbose:<EOL><INDENT>print("<STR_LIT>")<EOL><DEDENT>if not result:<EOL><INDENT>print(("<STR_LIT>" + kern.name + "<STR_LIT>"))<EOL>testmodel.checkgrad(verbose=True)<EOL>assert(result)<EOL>pass_checks = False<EOL>return False<EOL><DEDENT>if verbose:<EOL><INDENT>print("<STR_LIT>")<EOL><DEDENT>try:<EOL><INDENT>testmodel = Kern_check_d2Kdiag_dXdX(kern, X=X)<EOL>if fixed_X_dims is not None:<EOL><INDENT>testmodel.X[:,fixed_X_dims].fix()<EOL><DEDENT>result = testmodel.checkgrad(verbose=verbose)<EOL><DEDENT>except NotImplementedError:<EOL><INDENT>result=True<EOL>if verbose:<EOL><INDENT>print(("<STR_LIT>" + kern.name))<EOL><DEDENT><DEDENT>if result and verbose:<EOL><INDENT>print("<STR_LIT>")<EOL><DEDENT>if not result:<EOL><INDENT>print(("<STR_LIT>" + kern.name + "<STR_LIT>"))<EOL>testmodel.checkgrad(verbose=True)<EOL>assert(result)<EOL>pass_checks = False<EOL>return False<EOL><DEDENT>return pass_checks<EOL>
This function runs on kernels to check the correctness of their
implementation. It checks that the covariance function is positive definite
for a randomly generated data set.

:param kern: the kernel to be tested.
:type kern: GPy.kern.Kernpart
:param X: X input values to test the covariance function.
:type X: ndarray
:param X2: X2 input values to test the covariance function.
:type X2: ndarray