def validate_graph(csgraph, directed, dtype=DTYPE,<EOL>csr_output=True, dense_output=True,<EOL>copy_if_dense=False, copy_if_sparse=False,<EOL>null_value_in=<NUM_LIT:0>, null_value_out=np.inf,<EOL>infinity_null=True, nan_null=True):
if not (csr_output or dense_output):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if (not directed) and isspmatrix_csc(csgraph):<EOL><INDENT>csgraph = csgraph.T<EOL><DEDENT>if isspmatrix(csgraph):<EOL><INDENT>if csr_output:<EOL><INDENT>csgraph = csr_matrix(csgraph, dtype=DTYPE, copy=copy_if_sparse)<EOL><DEDENT>else:<EOL><INDENT>csgraph = csgraph_to_dense(csgraph, null_value=null_value_out)<EOL><DEDENT><DEDENT>elif np.ma.isMaskedArray(csgraph):<EOL><INDENT>if dense_output:<EOL><INDENT>mask = csgraph.mask<EOL>csgraph = np.array(csgraph.data, dtype=DTYPE, copy=copy_if_dense)<EOL>csgraph[mask] = null_value_out<EOL><DEDENT>else:<EOL><INDENT>csgraph = csgraph_from_masked(csgraph)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if dense_output:<EOL><INDENT>csgraph = csgraph_masked_from_dense(csgraph,<EOL>copy=copy_if_dense,<EOL>null_value=null_value_in,<EOL>nan_null=nan_null,<EOL>infinity_null=infinity_null)<EOL>mask = csgraph.mask<EOL>csgraph = np.asarray(csgraph.data, dtype=DTYPE)<EOL>csgraph[mask] = null_value_out<EOL><DEDENT>else:<EOL><INDENT>csgraph = csgraph_from_dense(csgraph, null_value=null_value_in,<EOL>infinity_null=infinity_null,<EOL>nan_null=nan_null)<EOL><DEDENT><DEDENT>if csgraph.ndim != <NUM_LIT:2>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if csgraph.shape[<NUM_LIT:0>] != csgraph.shape[<NUM_LIT:1>]:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>return csgraph<EOL>
Routine for validation and conversion of csgraph inputs