{"record":{"id":"125bc6261596b1b7","repo":"jax-ml/jax","slug":"ormqr-with-left-true-expects-c-to-have-the-same-nu","errorCode":null,"errorMessage":"ormqr with left=True expects c to have the same number of rows as the Householder matrix a. Got a shape {a_shape} and c shape {c_shape}.","messagePattern":"ormqr with left=True expects c to have the same number of rows as the Householder matrix a\\. Got a shape (.+?) and c shape (.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/lax/linalg.py","lineNumber":1527,"sourceCode":"    >>> h, taus = jnp.linalg.qr(a, mode=\"raw\")\n    >>> c = jnp.eye(3)\n    >>> Q_times_c = ormqr(h.mT, taus, c)\n    >>> Q_direct, _ = jnp.linalg.qr(a, mode=\"complete\")\n    >>> jnp.allclose(Q_times_c, Q_direct, atol=1e-5)\n    Array(True, dtype=bool)\n\n  See also:\n    - :func:`jax.scipy.linalg.qr_multiply`: Higher-level API for computing\n      Q @ C or C @ Q from a matrix ``a`` directly.\n  \"\"\"\n  a, taus, c = core.auto_insert_reshard(a, taus, c)\n  return ormqr_p.bind(a, taus, c, left=left, transpose=transpose)\n\n\ndef _ormqr_shape_rule(a_shape, taus_shape, c_shape, *, left, transpose):\n  m = a_shape[0]\n  if left and c_shape[0] != m:\n    raise ValueError(\n      \"ormqr with left=True expects c to have the same number of rows as \"\n      f\"the Householder matrix a. Got a shape {a_shape} and c shape {c_shape}.\")\n  if not left and c_shape[1] != m:\n    raise ValueError(\n      \"ormqr with left=False expects c to have the same number of columns as \"\n      f\"the Householder matrix a has rows. Got a shape {a_shape} and c shape {c_shape}.\")\n  return c_shape\n\n\n@config.default_matmul_precision(\"highest\")\ndef _ormqr_lowering(a, taus, c, *, left, transpose):\n  # Apply Householder reflectors H_i = I - tau_i * v_i * v_i^H directly to c\n  # without materializing Q. Cost: O(k * m * c_cols) if left,\n  # O(k * c_rows * m) otherwise, where c has shape (..., c_rows, c_cols).\n  *batch_dims, m, n = a.shape\n  k = taus.shape[-1]\n  is_complex = dtypes.issubdtype(a.dtype, np.complexfloating)\n","sourceCodeStart":1509,"sourceCodeEnd":1545,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/lax/linalg.py#L1509-L1545","documentation":"jax/_src/lax/linalg.py:1527 in _ormqr_shape_rule. ormqr(a, taus, c, left=True) applies the Householder product Q (encoded in a, shape (m, n)) from the left, so c must have exactly m rows. A mismatch between c.shape[0] and a.shape[0] raises this ValueError.","triggerScenarios":"Calling jax.lax.linalg.ormqr with left=True where the operand c has a different row count than the reflector matrix a — e.g. applying Q to a matrix of incompatible batch or row shape, or forgetting to broadcast c correctly after qr of a transposed matrix.","commonSituations":"Applying Q from a QR of A to the right-hand side of a different size in custom solvers; applying Q to multiple blocks with inconsistent shapes; porting LAPACK ormqr calls with m/n arguments mixed up.","solutions":["Reshape or pad/slice c so c.shape[0] == a.shape[0] before calling","If you only need Q, use jnp.linalg.qr(a) directly which returns it","Double-check which axis left=True multiplies: Q @ c requires row match"],"exampleFix":"// before\ny = jax.lax.linalg.ormqr(a, taus, c, left=True)  # c.shape[0] != a.shape[0]\n// after\nc = jnp.pad(c, ((0, a.shape[0] - c.shape[0]),) + ((0, 0),) * (c.ndim - 1))\ny = jax.lax.linalg.ormqr(a, taus, c, left=True)","handlingStrategy":"validation","validationCode":"assert c.shape[0] == a.shape[0], (a.shape, c.shape)","typeGuard":"def ormqr_left_ok(a, c) -> bool:\n    return c.shape[0] == a.shape[0]","tryCatchPattern":null,"preventionTips":["Left application means row counts must match"],"tags":["jax","linalg","ormqr","shape-validation","qr"],"backgroundTag":"invalid-matrix-dimensions","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}