Remove some incorrectly marked const qualifiers

closes https://github.com/official-stockfish/Stockfish/pull/5744

No functional change
This commit is contained in:
Shawn Xu
2024-12-29 09:32:29 -08:00
committed by Disservin
parent 78b5733939
commit 5cf6f99177
2 changed files with 8 additions and 10 deletions
+1 -1
View File
@@ -101,7 +101,7 @@ bool read_parameters(std::istream& stream, T& reference) {
// Write evaluation function parameters // Write evaluation function parameters
template<typename T> template<typename T>
bool write_parameters(std::ostream& stream, const T& reference) { bool write_parameters(std::ostream& stream, T& reference) {
write_little_endian<std::uint32_t>(stream, T::get_hash_value()); write_little_endian<std::uint32_t>(stream, T::get_hash_value());
return reference.write_parameters(stream); return reference.write_parameters(stream);
+7 -9
View File
@@ -256,21 +256,20 @@ class FeatureTransformer {
#endif #endif
} }
void permute_weights([[maybe_unused]] void (*order_fn)(uint64_t*)) const { void permute_weights([[maybe_unused]] void (*order_fn)(uint64_t*)) {
#if defined(USE_AVX2) #if defined(USE_AVX2)
#if defined(USE_AVX512) #if defined(USE_AVX512)
constexpr IndexType di = 16; constexpr IndexType di = 16;
#else #else
constexpr IndexType di = 8; constexpr IndexType di = 8;
#endif #endif
uint64_t* b = reinterpret_cast<uint64_t*>(const_cast<BiasType*>(&biases[0])); uint64_t* b = reinterpret_cast<uint64_t*>(&biases[0]);
for (IndexType i = 0; i < HalfDimensions * sizeof(BiasType) / sizeof(uint64_t); i += di) for (IndexType i = 0; i < HalfDimensions * sizeof(BiasType) / sizeof(uint64_t); i += di)
order_fn(&b[i]); order_fn(&b[i]);
for (IndexType j = 0; j < InputDimensions; ++j) for (IndexType j = 0; j < InputDimensions; ++j)
{ {
uint64_t* w = uint64_t* w = reinterpret_cast<uint64_t*>(&weights[j * HalfDimensions]);
reinterpret_cast<uint64_t*>(const_cast<WeightType*>(&weights[j * HalfDimensions]));
for (IndexType i = 0; i < HalfDimensions * sizeof(WeightType) / sizeof(uint64_t); for (IndexType i = 0; i < HalfDimensions * sizeof(WeightType) / sizeof(uint64_t);
i += di) i += di)
order_fn(&w[i]); order_fn(&w[i]);
@@ -278,17 +277,16 @@ class FeatureTransformer {
#endif #endif
} }
inline void scale_weights(bool read) const { inline void scale_weights(bool read) {
for (IndexType j = 0; j < InputDimensions; ++j) for (IndexType j = 0; j < InputDimensions; ++j)
{ {
WeightType* w = const_cast<WeightType*>(&weights[j * HalfDimensions]); WeightType* w = &weights[j * HalfDimensions];
for (IndexType i = 0; i < HalfDimensions; ++i) for (IndexType i = 0; i < HalfDimensions; ++i)
w[i] = read ? w[i] * 2 : w[i] / 2; w[i] = read ? w[i] * 2 : w[i] / 2;
} }
BiasType* b = const_cast<BiasType*>(biases);
for (IndexType i = 0; i < HalfDimensions; ++i) for (IndexType i = 0; i < HalfDimensions; ++i)
b[i] = read ? b[i] * 2 : b[i] / 2; biases[i] = read ? biases[i] * 2 : biases[i] / 2;
} }
// Read network parameters // Read network parameters
@@ -304,7 +302,7 @@ class FeatureTransformer {
} }
// Write network parameters // Write network parameters
bool write_parameters(std::ostream& stream) const { bool write_parameters(std::ostream& stream) {
permute_weights(order_packs); permute_weights(order_packs);
scale_weights(false); scale_weights(false);