{"record":{"id":"11ae949cee06242a","repo":"jax-ml/jax","slug":"ormqr-with-left-false-expects-c-to-have-the-same-n","errorCode":null,"errorMessage":"ormqr with left=False expects c to have the same number of columns as the Householder matrix a has rows. Got a shape {a_shape} and c shape {c_shape}.","messagePattern":"ormqr with left=False expects c to have the same number of columns as the Householder matrix a has rows\\. Got a shape (.+?) and c shape (.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/lax/linalg.py","lineNumber":1531,"sourceCode":"    >>> 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\n  # Householder vectors: lower triangle of a with unit diagonal.\n  eye = lax._eye(a.dtype, (m, k))\n  if batch_dims:\n    eye = lax.broadcast(eye, tuple(batch_dims))","sourceCodeStart":1513,"sourceCodeEnd":1549,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/lax/linalg.py#L1513-L1549","documentation":"jax/_src/lax/linalg.py:1531 in _ormqr_shape_rule. With left=False, ormqr applies Q from the right (c @ Q), so c's column count (c.shape[1]) must equal the row count of the reflector matrix a (a.shape[0]). A mismatch raises this ValueError.","triggerScenarios":"Calling jax.lax.linalg.ormqr(a, taus, c, left=False) with c.shape[1] != a.shape[0]; e.g. applying the transpose-Q to a wide RHS whose width does not match the QR'd matrix's rows.","commonSituations":"Solving least-squares normal equations manually; using Q^T on both sides of a rectangular problem with inconsistent shapes; ported LAPACK code where 'left'/'trans' flags were flipped.","solutions":["Adjust c so c.shape[1] == a.shape[0] (transpose, pad, or slice appropriately)","Consider left=True with c.T then transpose the result if that matches your math","Validate shapes with an assert before the call during development"],"exampleFix":"// before\ny = jax.lax.linalg.ormqr(a, taus, c, left=False)  # c.shape[1] != a.shape[0]\n// after\nassert c.shape[1] == a.shape[0], (c.shape, a.shape)\ny = jax.lax.linalg.ormqr(a, taus, c, left=False)","handlingStrategy":"validation","validationCode":"assert c.shape[1] == a.shape[0], (a.shape, c.shape)","typeGuard":"def ormqr_right_ok(a, c) -> bool:\n    return c.shape[1] == a.shape[0]","tryCatchPattern":null,"preventionTips":["Right application means c's columns match a's rows"],"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"}