code: def ordinary_quantile_regression(
      x: np.array,
      y: np.array,
      q: float,
      sample_weight: Optional[np.array] = None,
      max_iter: int = 200,
      tol: float = 1e-2,
  ) -> np.array:
      """Implements the quantile regression without penalty terms.
      Supports sample weight.
  
      Applies the iterative re-weighted least square (IRLS) algorithm
      to solve the quantile regression without regularization. Minimizes
  
          beta = argmin 1/n * sum {w_i * [(1 - q) * (y_i - x_i^T beta)_- + q * (y_i - x_i^T beta)_+]}
  
      This works for singular matrix and supports sample weights, while statsmodels does not.
      Please make sure the design matrix has an intercept as intercept is very important to quantile regression.
  
      Parameters
      ----------
      x : `numpy.array`
          The design matrix.
      y : `numpy.array`
          The response vector.
      q : `float` between 0.0 and 1.0
          The quantile of the response to model.
      sample_weight : `numpy.array` or None, default None
          The sample weight in the loss function.
      max_iter : int, default 200
          The maximum number of iterations.
      tol : float, default 1e-2
          The tolerance to stop the algorithm.
  
      Returns
      -------
      beta : numpy.array
          The estimated coefficients.
      """
      # Uses IRLS to solve the problem.
      n, p = x.shape
      if sample_weight is None:
          sample_weight = np.ones(n)
      # Minimum constant for denominator to prevent from dividing by zero.
      delta = 1e-6
      beta = np.zeros(p)
      for i in range(max_iter):
          eta = x @ beta
          eps = np.abs(y - eta)
          # Re-weights.
          left = np.where(y < eta, q, 1 - q) / sample_weight
          right = np.where(eps > delta, eps, delta)
          s = (left * right).reshape(-1, 1)
          # Solves with formula.
          # Multiplies weights to x first to speed up.
          x_l = x / s
          # Tries to solve with `scipy.linalg.solve`, which gives a more stable solution.
          # In cases it fails, uses `numpy.linalg.pinv`.
          try:
              beta_new = scipy.linalg.solve(
                  x_l.T @ x, x_l.T @ y, assume_a="pos"
              )
          except np.linalg.LinAlgError:
              beta_new = np.linalg.pinv(x_l.T @ x) @ (x_l.T @ y)
          err = (np.abs(beta_new - beta) / np.abs(beta)).max()
          beta = beta_new
          if err < tol:
              break
          if i == max_iter - 1:
              log_message(
                  message=f"Max number of iterations reached. "
                  f"Deviation is {err}. "
                  f"Consider increasing max_iter.",
                  level=LoggingLevelEnum.WARNING,
              )
  
      return beta
  
imports: from __future__ import annotations
  from typing import Dict
  from typing import Optional
  import cvxpy
  import numpy
  import pandas
  import scipy
  from sklearn.base import BaseEstimator
  from sklearn.base import RegressorMixin
  from greykite.algo.common.partial_regularize_regression import constant_col_finder
  from greykite.common.logging import LoggingLevelEnum
  from greykite.common.logging import log_message
label_desc: Use image node_id 1 for calling a global function with example usage: ordinary_quantile_regression(x, y, q, sample_weight, max_iter, tol) and returns: beta