code: def create_sum_stat_op_from_fn(fn):
      vectorX = (
          pt.dvector
          if pytensor.config.floatX == "float64"
          else pt.fvector
      )
  
      # Check if callable returns TensorVariable with dummy inputs
      try:
          res = fn(vectorX())
          if isinstance(res, TensorVariable):
              return fn
      except Exception:
          pass
  
      # Otherwise, automatically wrap in PyTensor Op
      class SumStat(Op):
          def make_node(self, x):
              x = pt.as_tensor_variable(x)
              return Apply(self, [x], [vectorX()])
  
          def perform(self, node, inputs, outputs):
              (x,) = inputs
              outputs[0][0] = np.atleast_1d(fn(x)).astype(
                  pytensor.config.floatX
              )
  
      return SumStat()
  
imports: import logging
  import numpy
  import pytensor
  import pytensor.tensor
  from pytensor.graph.op import Apply, Op
  from pytensor.tensor.random.op import RandomVariable
  from pytensor.tensor.variable import TensorVariable
  from scipy.spatial import cKDTree
  from pymc.distributions.distribution import Distribution, _moment
  from pymc.logprob.abstract import _logprob
  from pymc.pytensorf import floatX
label_desc: Use image node_id 6 for calling a global function with example usage: create_sum_stat_op_from_fn(fn) and returns: SumStat, fn, Apply