code: def kalman_forecast(n, Z, a, P, T, V, h):
      p = len(a)
  
      a = a.copy()
      anew = np.empty(p)
      Pnew = np.empty((p, p))
      mm = np.empty((p, p))
      forecasts = np.empty(n)
      se = np.empty(n)
      P = P.copy()
  
      for l in range(n):
          anew = T @ a
  
          a[:] = anew[:]
          forecasts[l] = anew @ Z
  
          for i in range(p):
              for j in range(p):
                  tmp = 0.0
                  for k in range(p):
                      tmp += T[i, k] * P[k, j]
                  mm[i, j] = tmp
  
          for i in range(p):
              for j in range(p):
                  tmp = V[i, j]
                  for k in range(p):
                      tmp += mm[i, k] * T[j, k]
                  Pnew[i, j] = tmp
  
          tmp = h
          for i in range(p):
              for j in range(p):
                  P[i, j] = Pnew[i, j]
                  tmp += Z[i] * Z[j] * P[i, j]
          se[l] = tmp
  
      return forecasts, se
  
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 19 for calling a global function with example usage: kalman_forecast(n, Z, a, P, T, V, h) and returns: forecasts,  se