code: def _posterior_samples_to_idata(samples, model):
      """Create InferenceData from samples.
  
      Parameters
      ----------
      samples: array
          Posterior samples
      model: PyMC model
  
      Returns
      -------
      An ArviZ's InferenceData object.
      """
      initial_point = model.initial_point()
      variables = model.value_vars
  
      var_info = {}
      for name, value in initial_point.items():
          var_info[name] = (value.shape, value.size)
  
      length_pos = len(samples)
      varnames = [v.name for v in variables]
  
      with model:
          strace = pm.backends.ndarray.NDArray(
              name=model.name
          )  # pylint:disable=no-member
          strace.setup(length_pos, 0)
      for i in range(length_pos):
          value = []
          size = 0
          for varname in varnames:
              shape, new_size = var_info[varname]
              var_samples = samples[i][size : size + new_size]
              value.append(var_samples.reshape(shape))
              size += new_size
          strace.record(point=dict(zip(varnames, value)))
  
      idata = pm.to_inference_data(
          pm.backends.base.MultiTrace([strace]), model=model
      )
      return idata
  
imports: import functools
  import logging
  import traceback
  from copy import deepcopy
  from importlib.metadata import version
  import numpy
  import pymc
  import pytensor.tensor
  from pytensor.tensor.special import softmax
  from bambi.backend.links import cloglog, identity, inverse_squared, logit, probit, arctan_2
  from bambi.backend.model_components import ConstantComponent, DistributionalComponent
  from bambi.utils import get_aliased_name
label_desc: Use image node_id 1 for calling a global function with example usage: _posterior_samples_to_idata(samples, model) and returns: idata