{"record":{"id":"d12b7ef1b8bca31e","repo":"keras-team/keras","slug":"invalid-ord-argument-expected-one-of-fro-n","errorCode":null,"errorMessage":"Invalid `ord` argument. Expected one of {'fro', 'nuc'} when using string. Received: ord={ord}","messagePattern":"Invalid `ord` argument\\. Expected one of (.+?) when using string\\. Received: ord=(.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/ops/linalg.py","lineNumber":288,"sourceCode":"    x = backend.convert_to_tensor(x)\n    _assert_2d(x)\n    if backend.backend() == \"tensorflow\":\n        try:\n            _assert_square(x)\n        except ValueError as e:\n            raise ValueError(\n                f\"LU decomposition failed: {e}. LU decomposition is only \"\n                \"supported for square matrices in Tensorflow.\"\n            )\n    return backend.linalg.lu_factor(x)\n\n\nclass Norm(Operation):\n    def __init__(self, ord=None, axis=None, keepdims=False, *, name=None):\n        super().__init__(name=name)\n        if isinstance(ord, str):\n            if ord not in (\"fro\", \"nuc\"):\n                raise ValueError(\n                    \"Invalid `ord` argument. \"\n                    \"Expected one of {'fro', 'nuc'} when using string. \"\n                    f\"Received: ord={ord}\"\n                )\n        if isinstance(axis, int):\n            axis = [axis]\n        self.ord = ord\n        self.axis = axis\n        self.keepdims = keepdims\n\n    def compute_output_spec(self, x):\n        output_dtype = backend.standardize_dtype(x.dtype)\n        if \"int\" in output_dtype or output_dtype == \"bool\":\n            output_dtype = backend.floatx()\n        if self.axis is None:\n            axis = tuple(range(len(x.shape)))\n        else:\n            axis = self.axis","sourceCodeStart":270,"sourceCodeEnd":306,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/ops/linalg.py#L270-L306","documentation":"Norm.__init__ validates the ord argument: when a string is supplied it must be exactly 'fro' (Frobenius) or 'nuc' (nuclear). These string norms are only defined for matrices, so anything else — 'l2', 'inf', 'L2' — is rejected at construction time.","triggerScenarios":"keras.ops.linalg.Norm(ord='l2'); keras.ops.linalg.norm(x, ord='inf'); passing a NumPy-style string not in the allowed set.","commonSituations":"Porting code from numpy.linalg.norm and assuming string ords exist; typos or casing issues like 'Fro' or 'frobenius'.","solutions":["Use numeric ords for vectors/matrices: 1, 2, np.inf, -np.inf.","Use 'fro' or 'nuc' strings only, and only with 2 axes.","Fix casing/typos: it is 'fro', not 'Fro' or 'frobenius'."],"exampleFix":"# before\nn = keras.ops.linalg.norm(x, ord='l2')\n\n# after\nn = keras.ops.linalg.norm(x, ord=2)","handlingStrategy":"validation","validationCode":"assert not isinstance(ord, str) or ord in ('fro', 'nuc'), ord","typeGuard":"def valid_ord(o):\n    return o is None or (isinstance(o, (int, float)) and not isinstance(o, bool)) or (isinstance(o, str) and o in ('fro', 'nuc'))","tryCatchPattern":null,"preventionTips":["Use numeric ords (1, 2, np.inf) for everything except matrix fro/nuc.","Centralize norm construction behind a small wrapper that validates ord."],"tags":["keras","linalg","norm","argument-validation"],"backgroundTag":"argument-validation-failed","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}