{"record":{"id":"c8888a05ecb94d02","repo":"jax-ml/jax","slug":"dot-general-requires-lhs-contracting-dimensions-to","errorCode":null,"errorMessage":"dot_general requires lhs contracting dimensions to be distinct, got lhs_contracting {lhs_contracting}.","messagePattern":"dot_general requires lhs contracting dimensions to be distinct, got lhs_contracting (.+?)\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"jax/_src/lax/lax.py","lineNumber":5720,"sourceCode":"    raise TypeError(msg)\n  if len(lhs_batch) != len(rhs_batch):\n    msg = (\"dot_general requires equal numbers of lhs_batch and rhs_batch \"\n           \"dimensions, got lhs_batch {} and rhs_batch {}.\")\n    raise TypeError(msg.format(lhs_batch, rhs_batch))\n  lhs_contracting_set, lhs_batch_set = set(lhs_contracting), set(lhs_batch)\n  rhs_contracting_set, rhs_batch_set = set(rhs_contracting), set(rhs_batch)\n  if len(lhs_batch_set) != len(lhs_batch):\n    msg = (\"dot_general requires lhs batch dimensions to be distinct, got \"\n           f\"lhs_batch {lhs_batch}.\")\n    raise TypeError(msg)\n  if len(rhs_batch_set) != len(rhs_batch):\n    msg = (\"dot_general requires rhs batch dimensions to be distinct, got \"\n           f\"rhs_batch {rhs_batch}.\")\n    raise TypeError(msg)\n  if len(lhs_contracting_set) != len(lhs_contracting):\n    msg = (\"dot_general requires lhs contracting dimensions to be distinct, \"\n           f\"got lhs_contracting {lhs_contracting}.\")\n    raise TypeError(msg)\n  if len(rhs_contracting_set) != len(rhs_contracting):\n    msg = (\"dot_general requires rhs contracting dimensions to be distinct, \"\n           f\"got rhs_contracting {rhs_contracting}.\")\n    raise TypeError(msg)\n  if lhs_contracting_set & lhs_batch_set:\n    msg = (\"dot_general requires lhs batch dimensions to be disjoint from \"\n           \"contracting dimensions, got lhs_batch {} and lhs_contracting {}.\")\n    raise TypeError(msg.format(lhs_batch, lhs_contracting))\n  if rhs_contracting_set & rhs_batch_set:\n    msg = (\"dot_general requires rhs batch dimensions to be disjoint from \"\n           \"contracting dimensions, got rhs_batch {} and rhs_contracting {}.\")\n    raise TypeError(msg.format(rhs_batch, rhs_contracting))\n  lhs_batch_shape = tuple(lhs.shape[i] for i in lhs_batch)\n  rhs_batch_shape = tuple(rhs.shape[i] for i in rhs_batch)\n  if not core.definitely_equal_shape(lhs_batch_shape, rhs_batch_shape):\n    msg = (\"dot_general requires lhs batch dimensions and rhs batch dimensions \"\n           \"to have the same shape, got {} and {}.\")\n    raise TypeError(msg.format(lhs_batch_shape, rhs_batch_shape))","sourceCodeStart":5702,"sourceCodeEnd":5738,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/lax/lax.py#L5702-L5738","documentation":"Raised by lax.dot_general validation when lhs_contracting contains duplicate indices. Contracting dims are summed over; listing one twice is ambiguous and illegal.","triggerScenarios":"jax.lax.dot_general with dimension_numbers[0][0] repeating an index, e.g. (((1, 1), (0, 0)), ((), ())) intending a double contraction.","commonSituations":"Trying to contract two axes of the same operand against one axis of the other; porting einsum specs like 'iji,j->' naively into dimension numbers.","solutions":["Remove duplicates from lhs_contracting; to contract two lhs axes you need two distinct rhs axes","Verify len(lhs_contracting) == len(rhs_contracting)","Let jnp.einsum lower to dot_general automatically for multi-axis contractions"],"exampleFix":"// before\nres = lax.dot_general(x, y, (((1, 1), (0, 0)), ((), ())))\n// after: contract distinct axes\nres = lax.dot_general(x, y, (((1, 2), (0, 0)), ((), ())))","handlingStrategy":"validation","validationCode":"lhs_c = dimension_numbers[0][0]\nassert len(set(lhs_c)) == len(lhs_c), 'duplicate lhs contracting dims'","typeGuard":"def valid_contracting(dn):\n    (lc, rc), _ = dn\n    return len(set(lc)) == len(lc) and len(set(rc)) == len(rc) and len(lc) == len(rc)","tryCatchPattern":null,"preventionTips":["Derive contracting dims from an einsum spec rather than by hand"],"tags":["jax","dot-general","dimension-numbers","contraction"],"backgroundTag":"invalid-dimension-numbers","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}