Maintain code clarity by using appropriate type declarations and parameter passing conventions: 1. **Prefer explicit types over `auto` when the type is known and simple**:
Maintain code clarity by using appropriate type declarations and parameter passing conventions:
auto
when the type is known and simple:
```cpp
// Instead of:
auto device_ordinal = 0;// Prefer: int device_ordinal = 0;
2. **Use prefix form (`++i`) instead of postfix (`i++`) in loops** for better performance with non-primitive types:
```cpp
// Instead of:
for (int i = 0; i < perm.NumElements(); i++)
// Prefer:
for (int i = 0; i < perm.NumElements(); ++i)
const
when they’re not modified:
```cpp
// Instead of:
std::vector// Prefer:
const std::vector
4. **Pass parameters appropriately**:
- Pass lightweight objects like span by value: `void foo(absl::Span<int64_t> dims)`
- Pass `const&` for larger objects: `void foo(const std::vector<int>& vec)`
- Mark function parameters as `const` when they're not modified
5. **Use C++-style casts instead of C-style casts**:
```cpp
// Instead of:
*itr = bfloat16(data[i]);
rescaled_6 = (int64_t)std::round(6.0f / input_qtype.getScale()) + input_qtype.getZeroPoint();
// Prefer:
*itr = static_cast<bfloat16>(data[i]);
rescaled_6 = static_cast<int64_t>(std::round(6.0f / input_qtype.getScale())) + input_qtype.getZeroPoint();
// Prefer: if (crop_window_vec(2) < 0 || crop_window_vec(3) < 0) ```
Enter the URL of a public GitHub repository