code: def _get_encode3d_kernel(size_max, marker=-2147483648):
      """Pack array coordinates into a single integer."""
      if size_max > 1024:
          int_type = "ptrdiff_t"  # int64_t
      else:
          int_type = "int"  # int32_t
  
      # value must match TOID macro in the C++ code!
      if size_max > 1024:
          value = """(((x) << 40) | ((y) << 20) | (z))"""
      else:
          value = """(((x) << 20) | ((y) << 10) | (z))"""
  
      code = f"""
      if (arr[i]) {{
          out[i] = {marker};
      }} else {{
          {int_type} shape_2 = arr.shape()[2];
          {int_type} shape_1 = arr.shape()[1];
          {int_type} _i = i;
          {int_type} x = _i % shape_2;
          _i /= shape_2;
          {int_type} y = _i % shape_1;
          _i /= shape_1;
          {int_type} z = _i;
          out[i] = {value};
      }}
      """
      return cupy.ElementwiseKernel(
          in_params="raw B arr",
          out_params="raw I out",
          operation=code,
          options=("--std=c++11",),
      )
  
imports: import math
  import os
  import cupy
  import numpy
  from ._util import _get_inttype
  from ._pba_2d import _check_distances, _check_indices, _distance_tranform_arg_check, _generate_indices_ops, _generate_shape, _get_block_size, lcm
label_desc: Use image node_id 2 for calling a global function with example usage: _get_encode3d_kernel(size_max, marker) and returns: cupy