code: def arima_like(y, phi, theta, delta, a, P, Pn, up, use_resid):
      n = len(y)
      rd = len(a)
      p = len(phi)
      q = len(theta)
      d = len(delta)
      r = rd - d
  
      sumlog = 0.0
      ssq = 0.0
      nu = 0
  
      P = P.ravel()
      Pnew = Pn.ravel()
      anew = np.empty(rd)
      M = np.empty(rd)
      if d > 0:
          mm = np.empty(rd * rd)
  
      if use_resid:
          rsResid = np.empty(n)
  
      for l in range(n):
          for i in range(r):
              tmp = a[i + 1] if i < r - 1 else 0.0
              if i < p:
                  tmp += phi[i] * a[0]
              anew[i] = tmp
          if d > 0:
              for i in range(r + 1, rd):
                  anew[i] = a[i - 1]
              tmp = a[0]
              for i in range(d):
                  tmp += delta[i] * a[r + i]
              anew[r] = tmp
          if l > up:
              if d == 0:
                  for i in range(r):
                      vi = 0.0
                      if i == 0:
                          vi = 1.0
                      elif i - 1 < q:
                          vi = theta[i - 1]
                      for j in range(r):
                          tmp = 0.0
                          if j == 0:
                              tmp = vi
                          elif j - 1 < q:
                              tmp = vi * theta[j - 1]
                          if i < p and j < p:
                              tmp += phi[i] * phi[j] * P[0]
                          if i < r - 1 and j < r - 1:
                              tmp += P[i + 1 + r * (j + 1)]
                          if i < p and j < r - 1:
                              tmp += phi[i] * P[j + 1]
                          if j < p and i < r - 1:
                              tmp += phi[j] * P[i + 1]
                          Pnew[i + r * j] = tmp
              else:
                  # mm = TP
                  for i in range(r):
                      for j in range(rd):
                          tmp = 0.0
                          if i < p:
                              tmp += phi[i] * P[rd * j]
                          if i < r - 1:
                              tmp += P[i + 1 + rd * j]
                          mm[i + rd * j] = tmp
                  for j in range(rd):
                      tmp = P[rd * j]
                      for k in range(d):
                          tmp += delta[k] * P[r + k + rd * j]
                      mm[r + rd * j] = tmp
                  for i in range(1, d):
                      for j in range(rd):
                          mm[r + i + rd * j] = P[r + i - 1 + rd * j]
  
                  # Pnew = mmT'
                  for i in range(r):
                      for j in range(rd):
                          tmp = 0.0
                          if i < p:
                              tmp += phi[i] * mm[j]
                          if i < r - 1:
                              tmp += mm[rd * (i + 1) + j]
                          Pnew[j + rd * i] = tmp
                  for j in range(rd):
                      tmp = mm[j]
                      for k in range(d):
                          tmp += delta[k] * mm[rd * (r + k) + j]
                      Pnew[rd * r + j] = tmp
                  for i in range(1, d):
                      for j in range(rd):
                          Pnew[rd * (r + i) + j] = mm[
                              rd * (r + i - 1) + j
                          ]
                  for i in range(q + 1):
                      vi = 1.0 if i == 0 else theta[i - 1]
                      for j in range(q + 1):
                          Pnew[i + rd * j] += vi * (
                              1.0 if j == 0 else theta[j - 1]
                          )
  
          if not math.isnan(y[l]):
              resid = y[l] - anew[0]
              for i in range(d):
                  resid -= delta[i] * anew[r + i]
              for i in range(rd):
                  tmp = Pnew[i]
                  for j in range(d):
                      tmp += Pnew[i + (r + j) * rd] * delta[j]
                  M[i] = tmp
              gain = M[0]
              for j in range(d):
                  gain += delta[j] * M[r + j]
              if gain < 1e4:
                  nu += 1
                  ssq += (
                      resid * resid / gain if gain != 0.0 else math.inf
                  )
                  sumlog += math.log(gain)
              if use_resid:
                  rsResid[l] = (
                      resid / math.sqrt(gain)
                      if gain != 0.0
                      else math.inf
                  )
              for i in range(rd):
                  a[i] = (
                      anew[i] + M[i] * resid / gain
                      if gain != 0.0
                      else math.inf
                  )
              for i in range(rd):
                  for j in range(rd):
                      P[i + j * rd] = (
                          Pnew[i + j * rd] - M[i] * M[j] / gain
                          if gain != 0.0
                          else math.inf
                      )
          else:
              a[:] = anew[:]
              P[:] = Pnew[:]
              if use_resid:
                  rsResid[l] = np.nan
      if not use_resid:
          rsResid = None
      return ssq, sumlog, nu, rsResid
  
imports: import math
  import warnings
  from collections import namedtuple
  from functools import partial
  from typing import Optional, Dict, Union, Tuple
  import numpy
  import pandas
  import statsmodels.api
  from numba import njit
  from scipy.optimize import minimize
  from scipy.stats import norm
  from .mstl import mstl
  from .utils import CACHE, NOGIL
label_desc: Use image node_id 13 for calling a global function with example usage: arima_like(y, phi, theta, delta, a, P, Pn, up, use_resid) and returns: ssq,  sumlog,  nu,  rsResid