code: def _max_helper_double_log_recursive(enc_tensor, dim):
      """Recursive subroutine for computing max via double log reduction algorithm"""
      n = enc_tensor.size(dim)
      # compute integral sqrt(n) and the integer number of sqrt(n) size
      # vectors that can be extracted from n
      sqrt_n = int(math.sqrt(n))
      count_sqrt_n = n // sqrt_n
      # base case for recursion: no further splits along dimension dim
      if n == 1:
          return enc_tensor
      else:
          # split into tensors that can be broken into vectors of size sqrt(n)
          # and the remainder of the tensor
          size_arr = [sqrt_n * count_sqrt_n, n % sqrt_n]
          split_enc_tensor, remainder = enc_tensor.split(
              size_arr, dim=dim
          )
  
          # reshape such that dim holds sqrt_n and dim+1 holds count_sqrt_n
          updated_enc_tensor_size = [
              sqrt_n,
              enc_tensor.size(dim + 1) * count_sqrt_n,
          ]
          size_arr = [
              enc_tensor.size(i) for i in range(enc_tensor.dim())
          ]
          size_arr[dim], size_arr[dim + 1] = updated_enc_tensor_size
          split_enc_tensor = split_enc_tensor.reshape(size_arr)
  
          # recursive call on reshaped tensor
          split_enc_max = _max_helper_double_log_recursive(
              split_enc_tensor, dim
          )
  
          # reshape the result to have the (dim+1)th dimension as before
          # and concatenate the previously computed remainder
          size_arr[dim], size_arr[dim + 1] = [
              count_sqrt_n,
              enc_tensor.size(dim + 1),
          ]
          enc_max_tensor = split_enc_max.reshape(size_arr)
          full_max_tensor = mpc.cat(
              [enc_max_tensor, remainder], dim=dim
          )
  
          # call the max function on dimension dim
          with cfg.temp_override({"functions.max_method": "pairwise"}):
              enc_max, enc_arg_max = full_max_tensor.max(
                  dim=dim, keepdim=True
              )
          # compute max over the resulting reduced tensor with n^2 algorithm
          # note that the resulting one-hot vector we get here finds maxes only
          # over the reduced vector in enc_tensor_reduced, so we won't use it
          return enc_max
  
file_path: FATE/python/fate/arch/protocol/mpc/functions/maximum.py
imports: import math
  import torch
  from fate.arch.protocol import mpc
  from fate.arch.protocol.mpc.config import cfg
label_desc: Use image node_id 8 for calling a global function with example usage: _max_helper_double_log_recursive(enc_tensor, dim) and returns: enc_tensor, enc_max