code: def _ndcg_at_k(
      target: np.ndarray, preds: np.ndarray, top_k: Optional[int] = None
  ):
      """Adapting `from sklearn.metrics.ndcg_score`."""
      assert target.shape == preds.shape
      assert (
          len(target.shape) == 1
      )  # works only with single dimension inputs
  
      if (
          target.shape[0] < 2
      ):  # ranking is equal to ideal ranking with a single document
          return np.array(1.0)
  
      preds = np.expand_dims(preds, axis=0)
      target = np.expand_dims(target, axis=0)
  
      return ndcg_score(target, preds, k=top_k)
  
imports: from typing import Callable, Optional, Union
  import numpy
  import pytest
  import torch
  from sklearn.metrics import ndcg_score
  from torch import Tensor
  from torchmetrics.functional.retrieval.ndcg import retrieval_normalized_dcg
  from torchmetrics.retrieval.ndcg import RetrievalNormalizedDCG
  from typing_extensions import Literal
  from unittests.helpers import seed_all
  from unittests.retrieval.helpers import RetrievalMetricTester, _concat_tests, _custom_aggregate_fn, _default_metric_class_input_arguments_ignore_index, _default_metric_class_input_arguments_with_non_binary_target, _default_metric_functional_input_arguments_with_non_binary_target, _errors_test_class_metric_parameters_k, _errors_test_class_metric_parameters_with_nonbinary, _errors_test_functional_metric_parameters_k, _errors_test_functional_metric_parameters_with_nonbinary
label_desc: Use image node_id 1 for calling a global function with example usage: _ndcg_at_k(target, preds, top_k) and returns: ndcg_score, np