code: def image_from_array(
      ctx, ary, num_channels=None, mode="r", norm_int=False
  ):
      if not ary.flags.c_contiguous:
          raise ValueError("array must be C-contiguous")
  
      dtype = ary.dtype
      if num_channels is None:
          try:
              (
                  dtype,
                  num_channels,
              ) = pyopencl.cltypes.vec_type_to_scalar_and_count[dtype]
          except KeyError:
              # It must be a scalar type then.
              num_channels = 1
  
          shape = ary.shape
          strides = ary.strides
  
      elif num_channels == 1:
          shape = ary.shape
          strides = ary.strides
      else:
          if ary.shape[-1] != num_channels:
              raise RuntimeError(
                  "last dimension must be equal to number of channels"
              )
  
          shape = ary.shape[:-1]
          strides = ary.strides[:-1]
  
      if mode == "r":
          mode_flags = mem_flags.READ_ONLY
      elif mode == "w":
          mode_flags = mem_flags.WRITE_ONLY
      else:
          raise ValueError("invalid value '%s' for 'mode'" % mode)
  
      img_format = {
          1: channel_order.R,
          2: channel_order.RG,
          3: channel_order.RGB,
          4: channel_order.RGBA,
      }[num_channels]
  
      assert ary.strides[-1] == ary.dtype.itemsize
  
      if norm_int:
          channel_type = DTYPE_TO_CHANNEL_TYPE_NORM[dtype]
      else:
          channel_type = DTYPE_TO_CHANNEL_TYPE[dtype]
  
      return Image(
          ctx,
          mode_flags | mem_flags.COPY_HOST_PTR,
          ImageFormat(img_format, channel_type),
          shape=shape[::-1],
          pitches=strides[::-1][1:],
          hostbuf=ary,
      )
  
imports: from sys import intern
  from warnings import warn
  from typing import Any, Dict, List, Optional, Sequence, Tuple, Union
  from pyopencl.version import VERSION, VERSION_STATUS, VERSION_TEXT
  import pyopencl.cltypes
  import logging
  import os
  import numpy
  import sys
  from pyopencl._cl import get_cl_header_version, program_kind, status_code, platform_info, device_type, device_info, device_topology_type_amd, device_fp_config, device_mem_cache_type, device_local_mem_type, device_exec_capabilities, device_svm_capabilities, command_queue_properties, context_info, gl_context_info, context_properties, command_queue_info, queue_properties, mem_flags, svm_mem_flags, channel_order, channel_type, mem_object_type, mem_info, image_info, pipe_info, pipe_properties, addressing_mode, filter_mode, sampler_info, sampler_properties, map_flags, program_info, program_build_info, program_binary_type, kernel_info, kernel_arg_info, kernel_arg_address_qualifier, kernel_arg_access_qualifier, kernel_arg_type_qualifier, kernel_work_group_info, kernel_sub_group_info, event_info, command_type, command_execution_status, profiling_info, mem_migration_flags, device_partition_property, device_affinity_domain, device_atomic_capabilities, device_device_enqueue_capabilities, version_bits, khronos_vendor_id, Error, MemoryError, LogicError, RuntimeError, Platform, get_platforms, Device, Context, CommandQueue, LocalMemory, MemoryObjectHolder, MemoryObject, MemoryMap, Buffer, _Program, Kernel, Event, wait_for_events, NannyEvent, enqueue_nd_range_kernel, _enqueue_marker, _enqueue_read_buffer, _enqueue_write_buffer, _enqueue_copy_buffer, _enqueue_read_buffer_rect, _enqueue_write_buffer_rect, _enqueue_copy_buffer_rect, _enqueue_read_image, _enqueue_copy_image, _enqueue_write_image, _enqueue_copy_image_to_buffer, _enqueue_copy_buffer_to_image, have_gl, ImageFormat, get_supported_image_formats, Image, Sampler, Pipe
  import inspect
label_desc: Use image node_id 13 for calling a global function with example usage: image_from_array(ctx, ary, num_channels, mode, norm_int) and returns: Image