code: def _asarray_validated(
      a,
      check_finite=True,
      sparse_ok=False,
      objects_ok=False,
      mask_ok=False,
      as_inexact=False,
  ):
      """
      Helper function for SciPy argument validation.
  
      Many SciPy linear algebra functions do support arbitrary array-like
      input arguments. Examples of commonly unsupported inputs include
      matrices containing inf/nan, sparse matrix representations, and
      matrices with complicated elements.
  
      Parameters
      ----------
      a : array_like
          The array-like input.
      check_finite : bool, optional
          Whether to check that the input matrices contain only finite numbers.
          Disabling may give a performance gain, but may result in problems
          (crashes, non-termination) if the inputs do contain infinities or NaNs.
          Default: True
      sparse_ok : bool, optional
          True if scipy sparse matrices are allowed.
      objects_ok : bool, optional
          True if arrays with dype('O') are allowed.
      mask_ok : bool, optional
          True if masked arrays are allowed.
      as_inexact : bool, optional
          True to convert the input array to a np.inexact dtype.
  
      Returns
      -------
      ret : ndarray
          The converted validated array.
  
      """
      if not sparse_ok:
          import scipy.sparse
  
          if scipy.sparse.issparse(a):
              msg = (
                  "Sparse matrices are not supported by this function. "
                  "Perhaps one of the scipy.sparse.linalg functions "
                  "would work instead."
              )
              raise ValueError(msg)
      if not mask_ok:
          if np.ma.isMaskedArray(a):
              raise ValueError("masked arrays are not supported")
      toarray = np.asarray_chkfinite if check_finite else np.asarray
      a = toarray(a)
      if not objects_ok:
          if a.dtype is np.dtype("O"):
              raise ValueError("object arrays are not supported")
      if as_inexact:
          if not np.issubdtype(a.dtype, np.inexact):
              a = toarray(a, dtype=np.float_)
      return a
  
imports: from contextlib import contextmanager
  import functools
  import operator
  import sys
  import warnings
  import numbers
  from collections import namedtuple
  import inspect
  import math
  from typing import Optional, Union, TYPE_CHECKING, TypeVar
  import numpy
label_desc: Use image node_id 8 for calling a global function with example usage: _asarray_validated(a, check_finite, sparse_ok, objects_ok, mask_ok, as_inexact) and returns: a