{"record":{"id":"3f38f057054d861e","repo":"rohitg00/ai-engineering-from-scratch","slug":"only-one-dimension-can-be-1","errorCode":null,"errorMessage":"Only one dimension can be -1","messagePattern":"Only one dimension can be -1","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"phases/01-math-foundations/12-tensor-operations/code/tensors.py","lineNumber":105,"sourceCode":"        if not isinstance(indices, tuple):\n            indices = (indices,)\n        if len(indices) == len(self._shape):\n            return self._data[self._flat_index(indices)]\n        raise IndexError(\"Partial indexing not supported in this basic implementation\")\n\n    def __setitem__(self, indices, value):\n        if not isinstance(indices, tuple):\n            indices = (indices,)\n        self._data[self._flat_index(indices)] = value\n\n    def reshape(self, new_shape):\n        new_shape = list(new_shape)\n        neg_idx = -1\n        known_product = 1\n        for i, s in enumerate(new_shape):\n            if s == -1:\n                if neg_idx != -1:\n                    raise ValueError(\"Only one dimension can be -1\")\n                neg_idx = i\n            else:\n                known_product *= s\n\n        if neg_idx != -1:\n            new_shape[neg_idx] = self.size // known_product\n\n        total = reduce(lambda a, b: a * b, new_shape, 1)\n        if total != self.size:\n            raise ValueError(\n                f\"Cannot reshape {self.size} elements into shape {tuple(new_shape)}\"\n            )\n\n        result = Tensor.__new__(Tensor)\n        result._data = self._data[:]\n        result._shape = tuple(new_shape)\n        result._strides = self._compute_strides(result._shape)\n        return result","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/rohitg00/ai-engineering-from-scratch/blob/39ea8a1c6d0b61f071226eff7ede4d4105fed820/phases/01-math-foundations/12-tensor-operations/code/tensors.py#L87-L123","documentation":"Error \"Only one dimension can be -1\" thrown in rohitg00/ai-engineering-from-scratch.","triggerScenarios":"Thrown at phases/01-math-foundations/12-tensor-operations/code/tensors.py:105 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"39ea8a1c6d0b61f071226eff7ede4d4105fed820","analyzedAt":"2026-08-26T03:13:46.626Z","schemaVersion":2},"datasetVersion":"2026-08-26T07:17:17.940Z"}