TheAlgorithms/Python · error · TypeError

Tableau must have type float64

Error message

Tableau must have type float64

What it means

Raised as TypeError by the simplex solver's __init__ when the tableau ndarray's dtype is anything other than float64. The pivoting arithmetic (row operations, ratios) assumes float64 semantics, so integer or float32 tableaus are rejected before the algorithm starts.

Source

Thrown at linear_programming/simplex.py:47

    >>> Tableau(np.array([[-1,-1,0,0,-1],[1,3,1,0,4],[3,1,0,1,4.]]), 2, 2)
    Traceback (most recent call last):
    ...
    ValueError: RHS must be > 0

    >>> Tableau(np.array([[-1,-1,0,0,1],[1,3,1,0,4],[3,1,0,1,4.]]), -2, 2)
    Traceback (most recent call last):
    ...
    ValueError: number of (artificial) variables must be a natural number
    """

    # Max iteration number to prevent cycling
    maxiter = 100

    def __init__(
        self, tableau: np.ndarray, n_vars: int, n_artificial_vars: int
    ) -> None:
        if tableau.dtype != "float64":
            raise TypeError("Tableau must have type float64")

        # Check if RHS is negative
        if not (tableau[:, -1] >= 0).all():
            raise ValueError("RHS must be > 0")

        if n_vars < 2 or n_artificial_vars < 0:
            raise ValueError(
                "number of (artificial) variables must be a natural number"
            )

        self.tableau = tableau
        self.n_rows, n_cols = tableau.shape

        # Number of decision variables x1, x2, x3...
        self.n_vars, self.n_artificial_vars = n_vars, n_artificial_vars

        # 2 if there are >= or == constraints (nonstandard), 1 otherwise (std)
        self.n_stages = (self.n_artificial_vars > 0) + 1

View on GitHub (pinned to f5988cc097)

Solutions

  1. Convert explicitly at construction: tableau.astype(np.float64).
  2. Create the tableau with float64 from the start: np.zeros((m, n), dtype=np.float64).
  3. If loading from CSV/pandas, ensure values are parsed as float (e.g. df.values.astype(np.float64)).

Example fix

# before
tableau = np.array([[1, 2, 1, 10], [1, 1, 1, 8]])
solver = Simplex(tableau, 2, 0)

# after
tableau = np.array([[1, 2, 1, 10], [1, 1, 1, 8]], dtype=np.float64)
solver = Simplex(tableau, 2, 0)
Defensive patterns

Strategy: type-guard

Validate before calling

tableau = np.asarray(tableau, dtype=np.float64)
assert tableau.dtype == np.float64
solver = Simplex(tableau, n_vars, n_artificial_vars)

Type guard

def is_float64_tableau(t: np.ndarray) -> bool:
    return isinstance(t, np.ndarray) and t.dtype == np.float64

Try / catch

try:
    Simplex(tableau, n_vars, n_artificial_vars)
except TypeError as e:
    if "float64" in str(e):
        Simplex(tableau.astype(np.float64), n_vars, n_artificial_vars)
    else:
        raise

Prevention

When it happens

Trigger: Constructing the solver class with a tableau built via np.array of Python ints (dtype int64), np.zeros(..., dtype=int), or an array read with float32/float16 dtype.

Common situations: Hand-assembling the tableau from integer constraint coefficients, loading data from int-typed CSV columns, or a pipeline that standardizes dtypes to float32 for memory savings.

Related errors


AI-assisted analysis of TheAlgorithms/Python@f5988cc097 (2026-08-14). Data as JSON: /api/errors/4f4355e762662446. Report an issue: GitHub.