{"record":{"id":"4f4355e762662446","repo":"TheAlgorithms/Python","slug":"tableau-must-have-type-float64","errorCode":null,"errorMessage":"Tableau must have type float64","messagePattern":"Tableau must have type float64","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"linear_programming/simplex.py","lineNumber":47,"sourceCode":"    >>> Tableau(np.array([[-1,-1,0,0,-1],[1,3,1,0,4],[3,1,0,1,4.]]), 2, 2)\n    Traceback (most recent call last):\n    ...\n    ValueError: RHS must be > 0\n\n    >>> Tableau(np.array([[-1,-1,0,0,1],[1,3,1,0,4],[3,1,0,1,4.]]), -2, 2)\n    Traceback (most recent call last):\n    ...\n    ValueError: number of (artificial) variables must be a natural number\n    \"\"\"\n\n    # Max iteration number to prevent cycling\n    maxiter = 100\n\n    def __init__(\n        self, tableau: np.ndarray, n_vars: int, n_artificial_vars: int\n    ) -> None:\n        if tableau.dtype != \"float64\":\n            raise TypeError(\"Tableau must have type float64\")\n\n        # Check if RHS is negative\n        if not (tableau[:, -1] >= 0).all():\n            raise ValueError(\"RHS must be > 0\")\n\n        if n_vars < 2 or n_artificial_vars < 0:\n            raise ValueError(\n                \"number of (artificial) variables must be a natural number\"\n            )\n\n        self.tableau = tableau\n        self.n_rows, n_cols = tableau.shape\n\n        # Number of decision variables x1, x2, x3...\n        self.n_vars, self.n_artificial_vars = n_vars, n_artificial_vars\n\n        # 2 if there are >= or == constraints (nonstandard), 1 otherwise (std)\n        self.n_stages = (self.n_artificial_vars > 0) + 1","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/linear_programming/simplex.py#L29-L65","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Convert explicitly at construction: tableau.astype(np.float64).","Create the tableau with float64 from the start: np.zeros((m, n), dtype=np.float64).","If loading from CSV/pandas, ensure values are parsed as float (e.g. df.values.astype(np.float64))."],"exampleFix":"# before\ntableau = np.array([[1, 2, 1, 10], [1, 1, 1, 8]])\nsolver = Simplex(tableau, 2, 0)\n\n# after\ntableau = np.array([[1, 2, 1, 10], [1, 1, 1, 8]], dtype=np.float64)\nsolver = Simplex(tableau, 2, 0)","handlingStrategy":"type-guard","validationCode":"tableau = np.asarray(tableau, dtype=np.float64)\nassert tableau.dtype == np.float64\nsolver = Simplex(tableau, n_vars, n_artificial_vars)","typeGuard":"def is_float64_tableau(t: np.ndarray) -> bool:\n    return isinstance(t, np.ndarray) and t.dtype == np.float64","tryCatchPattern":"try:\n    Simplex(tableau, n_vars, n_artificial_vars)\nexcept TypeError as e:\n    if \"float64\" in str(e):\n        Simplex(tableau.astype(np.float64), n_vars, n_artificial_vars)\n    else:\n        raise","preventionTips":["Always construct the tableau with dtype=np.float64.","Coerce at the boundary: np.asarray(rows, dtype=np.float64).","Watch for int dtypes when constraints have only integer coefficients."],"tags":["linear-programming","simplex","numpy","dtype","typeerror"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}