class_docstr: Base class for NMF and MiniBatchNMF.
class_docstr_tok: ["Base","class","for","NMF","and","MiniBatchNMF","."]
docstr: Check W and H, or initialize them.
code: def _check_w_h(self, X, W, H, update_H):
      """Check W and H, or initialize them."""
      n_samples, n_features = X.shape
      if self.init == "custom" and update_H:
          _check_init(
              H, (self._n_components, n_features), "NMF (input H)"
          )
          _check_init(
              W, (n_samples, self._n_components), "NMF (input W)"
          )
          if H.dtype != X.dtype or W.dtype != X.dtype:
              raise TypeError(
                  "H and W should have the same dtype as X. Got "
                  "H.dtype = {} and W.dtype = {}.".format(
                      H.dtype, W.dtype
                  )
              )
      elif not update_H:
          _check_init(
              H, (self._n_components, n_features), "NMF (input H)"
          )
          if H.dtype != X.dtype:
              raise TypeError(
                  "H should have the same dtype as X. Got H.dtype = {}.".format(
                      H.dtype
                  )
              )
          # 'mu' solver should not be initialized by zeros
          if self.solver == "mu":
              avg = np.sqrt(X.mean() / self._n_components)
              W = np.full(
                  (n_samples, self._n_components), avg, dtype=X.dtype
              )
          else:
              W = np.zeros(
                  (n_samples, self._n_components), dtype=X.dtype
              )
      else:
          W, H = _initialize_nmf(
              X,
              self._n_components,
              init=self.init,
              random_state=self.random_state,
          )
      return W, H
  
imports: import itertools
  import time
  import warnings
  from abc import ABC
  from math import sqrt
  from numbers import Integral, Real
  import numpy
  import scipy.sparse
  from scipy import linalg
  from .._config import config_context
  from ..base import BaseEstimator, ClassNamePrefixFeaturesOutMixin, TransformerMixin, _fit_context
  from ..exceptions import ConvergenceWarning
  from ..utils import check_array, check_random_state, gen_batches, metadata_routing
  from ..utils._param_validation import Interval, StrOptions, validate_params
  from ..utils.extmath import randomized_svd, safe_sparse_dot, squared_norm
  from ..utils.validation import check_is_fitted, check_non_negative
  from ._cdnmf_fast import _update_cdnmf_fast
label_desc: Use image node_id 3 for calling the _BaseNMF obj's underlying member method code with example usage: obj._check_w_h(X, W, H, update_H) and returns: W,  H