From 5cf6f991771d4260517d28812bfaef192c42ac97 Mon Sep 17 00:00:00 2001 From: Shawn Xu Date: Sun, 29 Dec 2024 09:32:29 -0800 Subject: [PATCH] Remove some incorrectly marked const qualifiers closes https://github.com/official-stockfish/Stockfish/pull/5744 No functional change --- src/nnue/network.cpp | 2 +- src/nnue/nnue_feature_transformer.h | 16 +++++++--------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/nnue/network.cpp b/src/nnue/network.cpp index 01cf2516..9191148b 100644 --- a/src/nnue/network.cpp +++ b/src/nnue/network.cpp @@ -101,7 +101,7 @@ bool read_parameters(std::istream& stream, T& reference) { // Write evaluation function parameters template -bool write_parameters(std::ostream& stream, const T& reference) { +bool write_parameters(std::ostream& stream, T& reference) { write_little_endian(stream, T::get_hash_value()); return reference.write_parameters(stream); diff --git a/src/nnue/nnue_feature_transformer.h b/src/nnue/nnue_feature_transformer.h index fa180678..556a114a 100644 --- a/src/nnue/nnue_feature_transformer.h +++ b/src/nnue/nnue_feature_transformer.h @@ -256,21 +256,20 @@ class FeatureTransformer { #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_AVX512) constexpr IndexType di = 16; #else constexpr IndexType di = 8; #endif - uint64_t* b = reinterpret_cast(const_cast(&biases[0])); + uint64_t* b = reinterpret_cast(&biases[0]); for (IndexType i = 0; i < HalfDimensions * sizeof(BiasType) / sizeof(uint64_t); i += di) order_fn(&b[i]); for (IndexType j = 0; j < InputDimensions; ++j) { - uint64_t* w = - reinterpret_cast(const_cast(&weights[j * HalfDimensions])); + uint64_t* w = reinterpret_cast(&weights[j * HalfDimensions]); for (IndexType i = 0; i < HalfDimensions * sizeof(WeightType) / sizeof(uint64_t); i += di) order_fn(&w[i]); @@ -278,17 +277,16 @@ class FeatureTransformer { #endif } - inline void scale_weights(bool read) const { + inline void scale_weights(bool read) { for (IndexType j = 0; j < InputDimensions; ++j) { - WeightType* w = const_cast(&weights[j * HalfDimensions]); + WeightType* w = &weights[j * HalfDimensions]; for (IndexType i = 0; i < HalfDimensions; ++i) w[i] = read ? w[i] * 2 : w[i] / 2; } - BiasType* b = const_cast(biases); 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 @@ -304,7 +302,7 @@ class FeatureTransformer { } // Write network parameters - bool write_parameters(std::ostream& stream) const { + bool write_parameters(std::ostream& stream) { permute_weights(order_packs); scale_weights(false);