{"record":{"id":"5928ed36b6b408ea","repo":"numpy/numpy","slug":"valueerror-order-must-be-one-of-c-f-a-or","errorCode":null,"errorMessage":"ValueError: order must be one of 'C', 'F', 'A', or 'K' (got '{order}')","messagePattern":"ValueError: order must be one of 'C', 'F', 'A', or 'K' \\(got '(.+?)'\\)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"numpy/_core/einsumfunc.py","lineNumber":1138,"sourceCode":"        perm_ab,\n        False,  # pure_multiplication=False\n    )\n\n\n@functools.lru_cache(maxsize=64)\ndef _parse_output_order(order, a_is_fcontig, b_is_fcontig):\n    order = order.upper()\n    if order == \"K\":\n        return None\n    elif order in \"CF\":\n        return order\n    elif order == \"A\":\n        if a_is_fcontig and b_is_fcontig:\n            return \"F\"\n        else:\n            return \"C\"\n    else:\n        raise ValueError(\n            \"ValueError: order must be one of \"\n            f\"'C', 'F', 'A', or 'K' (got '{order}')\"\n        )\n\n\ndef bmm_einsum(eq, a, b, out=None, **kwargs):\n    \"\"\"Perform arbitrary pairwise einsums using only ``matmul``, or\n    ``multiply`` if no contracted indices are involved (plus maybe single term\n    ``einsum`` to prepare the terms individually). The logic for each is cached\n    based on the equation and array shape, and each step is only performed if\n    necessary.\n\n    Parameters\n    ----------\n    eq : str\n        The einsum equation.\n    a : array_like\n        The first array to contract.","sourceCodeStart":1120,"sourceCodeEnd":1156,"githubUrl":"https://github.com/numpy/numpy/blob/e117b3ca4edacf581f440dccfd7f3242f0312afa/numpy/_core/einsumfunc.py#L1120-L1156","documentation":"Raised by _parse_output_order when the order keyword passed to an optimized einsum contraction is not one of 'C', 'F', 'A', 'K' (compared case-insensitively after .upper()). Note the message redundantly prefixes itself with 'ValueError:'; the value of order is echoed. This parser decides the memory layout of the matmul result.","triggerScenarios":"np.einsum('ij,jk->ik', a, b, optimize=True, order='Z') or order='Row-major' or any string other than C/F/A/K (case-insensitive). Also triggered by a non-string order that has no matching upper().","commonSituations":"Passing a layout constant from another library; typo like 'c ' with trailing space (actually fine after upper/strip? no—no strip, so ' c' fails); confusing with numpy's set_printoptions or ndarray order semantics.","solutions":["Use one of 'C', 'F', 'A', 'K' (any case).","Use 'K' (default) to keep input memory order, or 'C'/'F' to force a layout.","Avoid trailing spaces; the value is uppercased but not stripped."],"exampleFix":"// before\nnp.einsum('ij,jk->ik', a, b, optimize=True, order='Z')\n// after\nnp.einsum('ij,jk->ik', a, b, optimize=True, order='K')  # C, F, A, or K","handlingStrategy":"validation","validationCode":"VALID_ORDER = {'C', 'F', 'A', 'K'}\ndef safe_order(order):\n    if order is None:\n        return 'K'\n    o = str(order).upper()\n    if o not in VALID_ORDER:\n        raise ValueError(f\"order must be one of C/F/A/K, got {order!r}\")\n    return o","typeGuard":"null","tryCatchPattern":"null","preventionTips":["Default to 'K' to preserve memory layout.","Avoid trailing whitespace in order strings (not stripped).","Centralize layout constants."],"tags":["numpy","einsum","memory-layout","argument-validation"],"analyzedSha":"e117b3ca4edacf581f440dccfd7f3242f0312afa","analyzedAt":"2026-08-07T01:25:31.049Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}