You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix d_out check bug and add descriptive error messages to VectorTransform assertions (#5047)
Summary:
Pull Request resolved: #5047
## Summary
This diff fixes a bug and improves error message quality in `VectorTransform.cpp`.
### Bug Fix (line 153)
`VectorTransform::check_identical()` had a copy-paste bug where `d_in` was checked twice and `d_out` was never checked:
```cpp
// Before (buggy):
FAISS_THROW_IF_NOT(other.d_in == d_in && other.d_in == d_in);
// After (fixed):
FAISS_THROW_IF_NOT_MSG(
other.d_in == d_in && other.d_out == d_out,
"input and output dimensions must match");
```
This meant two VectorTransforms with matching `d_in` but different `d_out` would incorrectly pass the identity check. This could lead to subtle bugs when comparing or serializing transform chains (e.g., in `IndexPreTransform`).
### Error Message Improvements
All 28 bare `FAISS_THROW_IF_NOT()` calls in `VectorTransform.cpp` have been converted to `FAISS_THROW_IF_NOT_MSG()` with clear, actionable error messages. Previously, assertion failures would only show the raw C++ condition (e.g., `"Error: 'p > 0' failed"`), which is unhelpful for users. Now each assertion provides semantic context:
- **Dynamic cast failures**: `"failed to cast to HadamardRotation"` instead of `"hr"`
- **Dimension mismatches**: `"input and output dimensions must match when PCA is disabled"` instead of `"din == dout"`
- **Training state errors**: `"CenteringTransform has not been trained"` instead of `"is_trained"`
- **LAPACK errors**: `"LAPACK dgesvd workspace query failed"` instead of `"info == 0"`
- **Parameter validation**: `"map entries must be -1 (unused) or valid input dimension indices"` instead of raw condition
### Affected classes
- `VectorTransform` (base class)
- `LinearTransform`
- `HadamardRotation`
- `PCAMatrix`
- `ITQMatrix`
- `ITQTransform`
- `OPQMatrix`
- `NormalizationTransform`
- `CenteringTransform`
- `RemapDimensionsTransform`
### Design decisions
- Used `FAISS_THROW_IF_NOT_MSG` (not `FAISS_THROW_IF_NOT_FMT`) since all messages are static strings — no runtime formatting needed, keeping zero overhead.
- Error messages follow existing Faiss patterns seen in `index_read.cpp` and other files.
- Each message describes the semantic meaning of the condition, not just the code.
Reviewed By: mnorris11
Differential Revision: D99674067
fbshipit-source-id: cf0fe9a8a7f047013011683d76221682d97beb6c
0 commit comments