code: def pack_elements_into_bits(
      elements: np.ndarray, nbits: int
  ) -> np.ndarray:
      """
      Pack elements into nbits representation, by starting with the least significant bit (LSB) and
      moving upward to the most significant bit (MSB).
  
      Returns packed elements as np.uint8.
      """
      if not np.issubdtype(elements.dtype, np.integer):
          raise ValueError(
              f"Only support packing integers elements, but got {elements.dtype}"
          )
  
      # Adjust allowed value range based on if the input is signed or unsigned.
      if np.issubdtype(elements.dtype, np.signedinteger):
          max_val = 2 ** (nbits - 1) - 1
          min_val = -max_val - 1
      else:
          max_val = 2**nbits - 1
          min_val = 0
      if np.max(elements) > max_val:
          raise ValueError(
              f"To pack elements into {nbits}-bit, the max value is {max_val}, but got {np.max(elements)}"
          )
      if np.min(elements) < min_val:
          raise ValueError(
              f"To pack elements into {nbits}-bit, the min value is {min_val}, but got {np.min(elements)}"
          )
  
      # As np.unpackbits only supports uint8, convert to uint8 first.
      # Notice that it will not lose information, because the bits are unchanged when converting int8
      # to uint8. For example, the signed int -6 has bit representation '11111010', and when we unpackbits
      # we get [0, 1, 0, 1, 1, 1, 1, 1], where only first 4 elements are needed for 4-bit representation.
      elements = elements.astype(np.uint8)
      bitarray = np.unpackbits(
          elements.reshape(-1, 1), bitorder="little", axis=-1
      )[:, :nbits]
      return np.packbits(bitarray.flatten(), bitorder="little")
  
imports: import math
  import numbers
  from typing import List, Tuple
  import numpy
  from coremltools.converters.mil.mil import Builder
  from coremltools.converters.mil.mil import Var, get_new_symbol, types
  from coremltools.converters.mil.mil.ops.defs.iOS15.elementwise_unary import cast
  from coremltools.converters.mil.mil.types import builtin_to_string, promote_dtypes
  from coremltools.converters.mil.mil.types.symbolic import is_symbolic
label_desc: Use image node_id 14 for calling a global function with example usage: pack_elements_into_bits(elements, nbits) and returns: np