code: def _rolling_lstsq(x, y):
      
      if x.ndim == 2:
          # Treat everything as 3d and avoid AxisError on .swapaxes(1, 2) below
          # This means an original input of:
          #     array([0., 1., 2., 3., 4., 5., 6.])
          # becomes:
          # array([[[0.],
          #         [1.],
          #         [2.],
          #         [3.]],
          #
          #        [[1.],
          #         [2.],
          #         ...
          x = x[:, :, None]
      elif x.ndim <= 1:
          raise np.AxisError("x should have ndmi >= 2")
      return np.squeeze(
          np.matmul(
              np.linalg.inv(np.matmul(x.swapaxes(1, 2), x)),
              np.matmul(x.swapaxes(1, 2), np.atleast_3d(y)),
          )
      )
docs: Finds solution for the rolling case.  Matrix formulation.