diff --git a/NAM/convnet.cpp b/NAM/convnet.cpp index 3018473..7e2a68a 100644 --- a/NAM/convnet.cpp +++ b/NAM/convnet.cpp @@ -106,7 +106,7 @@ convnet::ConvNet::ConvNet(const double loudness, const int channels, const std:: this->_verify_params(channels, dilations, batchnorm, params.size()); this->_blocks.resize(dilations.size()); std::vector::iterator it = params.begin(); - for (int i = 0; i < dilations.size(); i++) + for (size_t i = 0; i < dilations.size(); i++) this->_blocks[i].set_params_(i == 0 ? 1 : channels, channels, dilations[i], batchnorm, activation, it); this->_block_vals.resize(this->_blocks.size() + 1); this->_head = _Head(channels, it); @@ -125,7 +125,7 @@ void convnet::ConvNet::_process_core_() // TODO one unnecessary copy :/ #speed for (auto i = i_start; i < i_end; i++) this->_block_vals[0](0, i) = this->_input_buffer[i]; - for (auto i = 0; i < this->_blocks.size(); i++) + for (size_t i = 0; i < this->_blocks.size(); i++) this->_blocks[i].process_(this->_block_vals[i], this->_block_vals[i + 1], i_start, i_end); // TODO clean up this allocation this->_head.process_(this->_block_vals[this->_blocks.size()], this->_head_output, i_start, i_end); @@ -145,9 +145,9 @@ void convnet::ConvNet::_verify_params(const int channels, const std::vector void convnet::ConvNet::_update_buffers_() { this->Buffer::_update_buffers_(); - const long buffer_size = this->_input_buffer.size(); + const size_t buffer_size = this->_input_buffer.size(); this->_block_vals[0].resize(1, buffer_size); - for (long i = 1; i < this->_block_vals.size(); i++) + for (size_t i = 1; i < this->_block_vals.size(); i++) this->_block_vals[i].resize(this->_blocks[i - 1].get_out_channels(), buffer_size); } @@ -157,7 +157,7 @@ void convnet::ConvNet::_rewind_buffers_() // resets the offset index // The last _block_vals is the output of the last block and doesn't need to be // rewound. - for (long k = 0; k < this->_block_vals.size() - 1; k++) + for (size_t k = 0; k < this->_block_vals.size() - 1; k++) { // We actually don't need to pull back a lot...just as far as the first // input sample would grab from dilation @@ -176,7 +176,7 @@ void convnet::ConvNet::_anti_pop_() if (this->_anti_pop_countdown >= this->_anti_pop_ramp) return; const float slope = 1.0f / float(this->_anti_pop_ramp); - for (int i = 0; i < this->_core_dsp_output.size(); i++) + for (size_t i = 0; i < this->_core_dsp_output.size(); i++) { if (this->_anti_pop_countdown >= this->_anti_pop_ramp) break; @@ -190,7 +190,7 @@ void convnet::ConvNet::_reset_anti_pop_() { // You need the "real" receptive field, not the buffers. long receptive_field = 1; - for (int i = 0; i < this->_blocks.size(); i++) + for (size_t i = 0; i < this->_blocks.size(); i++) receptive_field += this->_blocks[i].conv.get_dilation(); this->_anti_pop_countdown = -receptive_field; } diff --git a/NAM/dsp.cpp b/NAM/dsp.cpp index 6d10231..ebed1a1 100644 --- a/NAM/dsp.cpp +++ b/NAM/dsp.cpp @@ -62,7 +62,7 @@ void DSP::_apply_input_level_(double** inputs, const int num_channels, const int { // Must match exactly; we're going to use the size of _input_post_gain later // for num_frames. - if (this->_input_post_gain.size() != num_frames) + if ((int)this->_input_post_gain.size() != num_frames) this->_input_post_gain.resize(num_frames); // MONO ONLY const int channel = 0; @@ -79,7 +79,7 @@ void DSP::_ensure_core_dsp_output_ready_() void DSP::_process_core_() { // Default implementation is the null operation - for (int i = 0; i < this->_input_post_gain.size(); i++) + for (size_t i = 0; i < this->_input_post_gain.size(); i++) this->_core_dsp_output[i] = this->_input_post_gain[i]; } @@ -124,7 +124,7 @@ void Buffer::_update_buffers_() // frames needed! { const long minimum_input_buffer_size = (long)this->_receptive_field + _INPUT_BUFFER_SAFETY_FACTOR * num_frames; - if (this->_input_buffer.size() < minimum_input_buffer_size) + if ((long)this->_input_buffer.size() < minimum_input_buffer_size) { long new_buffer_size = 2; while (new_buffer_size < minimum_input_buffer_size) @@ -135,7 +135,7 @@ void Buffer::_update_buffers_() // If we'd run off the end of the input buffer, then we need to move the data // back to the start of the buffer and start again. - if (this->_input_buffer_offset + num_frames > this->_input_buffer.size()) + if (this->_input_buffer_offset + num_frames > (long)this->_input_buffer.size()) this->_rewind_buffers_(); // Put the new samples into the input buffer for (long i = this->_input_buffer_offset, j = 0; j < num_frames; i++, j++) @@ -179,7 +179,7 @@ Linear::Linear(const int receptive_field, const bool _bias, const std::vector& params) : Buffer(loudness, receptive_field) { - if (params.size() != (receptive_field + (_bias ? 1 : 0))) + if ((int)params.size() != (receptive_field + (_bias ? 1 : 0))) throw std::runtime_error( "Params vector does not match expected size based " "on architecture parameters"); @@ -196,9 +196,9 @@ void Linear::_process_core_() this->Buffer::_update_buffers_(); // Main computation! - for (long i = 0; i < this->_input_post_gain.size(); i++) + for (size_t i = 0; i < this->_input_post_gain.size(); i++) { - const long offset = this->_input_buffer_offset - this->_weight.size() + i + 1; + const size_t offset = this->_input_buffer_offset - this->_weight.size() + i + 1; auto input = Eigen::Map(&this->_input_buffer[offset], this->_receptive_field); this->_core_dsp_output[i] = this->_bias + this->_weight.dot(input); } @@ -215,10 +215,10 @@ void Conv1D::set_params_(std::vector::iterator& params) // Crazy ordering because that's how it gets flattened. for (auto i = 0; i < out_channels; i++) for (auto j = 0; j < in_channels; j++) - for (auto k = 0; k < this->_weight.size(); k++) + for (size_t k = 0; k < this->_weight.size(); k++) this->_weight[k](i, j) = *(params++); } - for (int i = 0; i < this->_bias.size(); i++) + for (long i = 0; i < this->_bias.size(); i++) this->_bias(i) = *(params++); } @@ -226,7 +226,7 @@ void Conv1D::set_size_(const int in_channels, const int out_channels, const int const int _dilation) { this->_weight.resize(kernel_size); - for (int i = 0; i < this->_weight.size(); i++) + for (size_t i = 0; i < this->_weight.size(); i++) this->_weight[i].resize(out_channels, in_channels); // y = Ax, input array (C,L) if (do_bias) @@ -247,7 +247,7 @@ void Conv1D::process_(const Eigen::MatrixXf& input, Eigen::MatrixXf& output, con const long j_start) const { // This is the clever part ;) - for (long k = 0; k < this->_weight.size(); k++) + for (size_t k = 0; k < this->_weight.size(); k++) { const long offset = this->_dilation * (k + 1 - this->_weight.size()); if (k == 0) @@ -262,7 +262,7 @@ void Conv1D::process_(const Eigen::MatrixXf& input, Eigen::MatrixXf& output, con long Conv1D::get_num_params() const { long num_params = this->_bias.size(); - for (long i = 0; i < this->_weight.size(); i++) + for (size_t i = 0; i < this->_weight.size(); i++) num_params += this->_weight[i].size(); return num_params; } diff --git a/NAM/get_dsp.cpp b/NAM/get_dsp.cpp index f2791cc..db4977f 100644 --- a/NAM/get_dsp.cpp +++ b/NAM/get_dsp.cpp @@ -150,7 +150,7 @@ std::unique_ptr get_dsp(dspData& conf) const int channels = config["channels"]; const bool batchnorm = config["batchnorm"]; std::vector dilations; - for (int i = 0; i < config["dilations"].size(); i++) + for (size_t i = 0; i < config["dilations"].size(); i++) dilations.push_back(config["dilations"][i]); const std::string activation = config["activation"]; return std::make_unique(loudness, channels, dilations, batchnorm, activation, params); @@ -173,11 +173,11 @@ std::unique_ptr get_dsp(dspData& conf) else if (architecture == "WaveNet" || architecture == "CatWaveNet") { std::vector layer_array_params; - for (int i = 0; i < config["layers"].size(); i++) + for (size_t i = 0; i < config["layers"].size(); i++) { nlohmann::json layer_config = config["layers"][i]; std::vector dilations; - for (int j = 0; j < layer_config["dilations"].size(); j++) + for (size_t j = 0; j < layer_config["dilations"].size(); j++) dilations.push_back(layer_config["dilations"][j]); layer_array_params.push_back( wavenet::LayerArrayParams(layer_config["input_size"], layer_config["condition_size"], layer_config["head_size"], diff --git a/NAM/lstm.cpp b/NAM/lstm.cpp index a08e30d..5287d6e 100644 --- a/NAM/lstm.cpp +++ b/NAM/lstm.cpp @@ -111,7 +111,7 @@ void lstm::LSTM::_process_core_() this->_stale_params = false; } // Process samples, placing results in the required output location - for (int i = 0; i < this->_input_post_gain.size(); i++) + for (size_t i = 0; i < this->_input_post_gain.size(); i++) this->_core_dsp_output[i] = this->_process_sample(this->_input_post_gain[i]); } @@ -121,7 +121,7 @@ float lstm::LSTM::_process_sample(const float x) return x; this->_input_and_params(0) = x; this->_layers[0].process_(this->_input_and_params); - for (int i = 1; i < this->_layers.size(); i++) + for (size_t i = 1; i < this->_layers.size(); i++) this->_layers[i].process_(this->_layers[i - 1].get_hidden_state()); return this->_head_weight.dot(this->_layers[this->_layers.size() - 1].get_hidden_state()) + this->_head_bias; } diff --git a/NAM/wavenet.cpp b/NAM/wavenet.cpp index cfeff30..034fb14 100644 --- a/NAM/wavenet.cpp +++ b/NAM/wavenet.cpp @@ -61,10 +61,10 @@ wavenet::_LayerArray::_LayerArray(const int input_size, const int condition_size : _rechannel(input_size, channels, false) , _head_rechannel(channels, head_size, head_bias) { - for (int i = 0; i < dilations.size(); i++) + for (size_t i = 0; i < dilations.size(); i++) this->_layers.push_back(_Layer(condition_size, channels, kernel_size, dilations[i], activation, gated)); const long receptive_field = this->_get_receptive_field(); - for (int i = 0; i < dilations.size(); i++) + for (size_t i = 0; i < dilations.size(); i++) { this->_layer_buffers.push_back(Eigen::MatrixXf(channels, LAYER_ARRAY_BUFFER_SIZE + receptive_field - 1)); this->_layer_buffers[i].setZero(); @@ -80,7 +80,7 @@ void wavenet::_LayerArray::advance_buffers_(const int num_frames) long wavenet::_LayerArray::get_receptive_field() const { long result = 0; - for (int i = 0; i < this->_layers.size(); i++) + for (size_t i = 0; i < this->_layers.size(); i++) result += this->_layers[i].get_dilation() * (this->_layers[i].get_kernel_size() - 1); return result; } @@ -103,8 +103,8 @@ void wavenet::_LayerArray::process_(const Eigen::MatrixXf& layer_inputs, const E Eigen::MatrixXf& head_outputs) { this->_layer_buffers[0].middleCols(this->_buffer_start, layer_inputs.cols()) = this->_rechannel.process(layer_inputs); - const long last_layer = this->_layers.size() - 1; - for (auto i = 0; i < this->_layers.size(); i++) + const size_t last_layer = this->_layers.size() - 1; + for (size_t i = 0; i < this->_layers.size(); i++) { this->_layers[i].process_(this->_layer_buffers[i], condition, head_inputs, i == last_layer ? layer_outputs : this->_layer_buffers[i + 1], this->_buffer_start, @@ -125,14 +125,14 @@ void wavenet::_LayerArray::set_num_frames_(const long num_frames) << "); copy errors could occur!\n"; throw std::runtime_error(ss.str().c_str()); } - for (int i = 0; i < this->_layers.size(); i++) + for (size_t i = 0; i < this->_layers.size(); i++) this->_layers[i].set_num_frames_(num_frames); } void wavenet::_LayerArray::set_params_(std::vector::iterator& params) { this->_rechannel.set_params_(params); - for (int i = 0; i < this->_layers.size(); i++) + for (size_t i = 0; i < this->_layers.size(); i++) this->_layers[i].set_params_(params); this->_head_rechannel.set_params_(params); } @@ -146,7 +146,7 @@ long wavenet::_LayerArray::_get_receptive_field() const { // TODO remove this and use get_receptive_field() instead! long res = 1; - for (int i = 0; i < this->_layers.size(); i++) + for (size_t i = 0; i < this->_layers.size(); i++) res += (this->_layers[i].get_kernel_size() - 1) * this->_layers[i].get_dilation(); return res; } @@ -156,7 +156,7 @@ void wavenet::_LayerArray::_rewind_buffers_() // Can make this smaller--largest dilation, not receptive field! { const long start = this->_get_receptive_field() - 1; - for (int i = 0; i < this->_layer_buffers.size(); i++) + for (size_t i = 0; i < this->_layer_buffers.size(); i++) { const long d = (this->_layers[i].get_kernel_size() - 1) * this->_layers[i].get_dilation(); this->_layer_buffers[i].middleCols(start - d, d) = this->_layer_buffers[i].middleCols(this->_buffer_start - d, d); @@ -168,8 +168,8 @@ void wavenet::_LayerArray::_rewind_buffers_() wavenet::_Head::_Head(const int input_size, const int num_layers, const int channels, const std::string activation) : _channels(channels) -, _activation(activations::Activation::get_activation(activation)) , _head(num_layers > 0 ? channels : input_size, 1, true) +, _activation(activations::Activation::get_activation(activation)) { assert(num_layers > 0); int dx = input_size; @@ -184,7 +184,7 @@ wavenet::_Head::_Head(const int input_size, const int num_layers, const int chan void wavenet::_Head::set_params_(std::vector::iterator& params) { - for (int i = 0; i < this->_layers.size(); i++) + for (size_t i = 0; i < this->_layers.size(); i++) this->_layers[i].set_params_(params); } @@ -197,7 +197,7 @@ void wavenet::_Head::process_(Eigen::MatrixXf& inputs, Eigen::MatrixXf& outputs) else { this->_buffers[0] = this->_layers[0].process(inputs); - for (int i = 1; i < num_layers; i++) + for (size_t i = 1; i < num_layers; i++) { // Asserted > 0 layers this->_apply_activation_(this->_buffers[i - 1]); if (i < num_layers - 1) @@ -210,7 +210,7 @@ void wavenet::_Head::process_(Eigen::MatrixXf& inputs, Eigen::MatrixXf& outputs) void wavenet::_Head::set_num_frames_(const long num_frames) { - for (int i = 0; i < this->_buffers.size(); i++) + for (size_t i = 0; i < this->_buffers.size(); i++) this->_buffers[i].resize(this->_channels, num_frames); } @@ -237,7 +237,7 @@ wavenet::WaveNet::WaveNet(const double loudness, const std::vector_init_parametric_(parametric); - for (int i = 0; i < layer_array_params.size(); i++) + for (size_t i = 0; i < layer_array_params.size(); i++) { this->_layer_arrays.push_back(wavenet::_LayerArray( layer_array_params[i].input_size, layer_array_params[i].condition_size, layer_array_params[i].head_size, @@ -270,14 +270,14 @@ void wavenet::WaveNet::finalize_(const int num_frames) void wavenet::WaveNet::set_params_(std::vector& params) { std::vector::iterator it = params.begin(); - for (int i = 0; i < this->_layer_arrays.size(); i++) + for (size_t i = 0; i < this->_layer_arrays.size(); i++) this->_layer_arrays[i].set_params_(it); // this->_head.set_params_(it); this->_head_scale = *(it++); if (it != params.end()) { std::stringstream ss; - for (int i = 0; i < params.size(); i++) + for (size_t i = 0; i < params.size(); i++) if (params[i] == *it) { ss << "Parameter mismatch: assigned " << i + 1 << " parameters, but " << params.size() << " were provided."; @@ -290,7 +290,7 @@ void wavenet::WaveNet::set_params_(std::vector& params) void wavenet::WaveNet::_advance_buffers_(const int num_frames) { - for (int i = 0; i < this->_layer_arrays.size(); i++) + for (size_t i = 0; i < this->_layer_arrays.size(); i++) this->_layer_arrays[i].advance_buffers_(num_frames); } @@ -304,7 +304,7 @@ void wavenet::WaveNet::_init_parametric_(nlohmann::json& parametric) void wavenet::WaveNet::_prepare_for_frames_(const long num_frames) { - for (auto i = 0; i < this->_layer_arrays.size(); i++) + for (size_t i = 0; i < this->_layer_arrays.size(); i++) this->_layer_arrays[i].prepare_for_frames_(num_frames); } @@ -326,7 +326,7 @@ void wavenet::WaveNet::_process_core_() this->_condition(0, j) = this->_input_post_gain[j]; if (this->_stale_params) // Column-major assignment; good for Eigen. Let the // compiler optimize this. - for (int i = 0; i < this->_param_names.size(); i++) + for (size_t i = 0; i < this->_param_names.size(); i++) this->_condition(i + 1, j) = (float)this->_params[this->_param_names[i]]; } @@ -334,7 +334,7 @@ void wavenet::WaveNet::_process_core_() // Layer-to-layer // Sum on head output this->_head_arrays[0].setZero(); - for (int i = 0; i < this->_layer_arrays.size(); i++) + for (size_t i = 0; i < this->_layer_arrays.size(); i++) this->_layer_arrays[i].process_(i == 0 ? this->_condition : this->_layer_array_outputs[i - 1], this->_condition, this->_head_arrays[i], this->_layer_array_outputs[i], this->_head_arrays[i + 1]); // this->_head.process_( @@ -365,13 +365,13 @@ void wavenet::WaveNet::_set_num_frames_(const long num_frames) return; this->_condition.resize(1 + this->_param_names.size(), num_frames); - for (int i = 0; i < this->_head_arrays.size(); i++) + for (size_t i = 0; i < this->_head_arrays.size(); i++) this->_head_arrays[i].resize(this->_head_arrays[i].rows(), num_frames); - for (int i = 0; i < this->_layer_array_outputs.size(); i++) + for (size_t i = 0; i < this->_layer_array_outputs.size(); i++) this->_layer_array_outputs[i].resize(this->_layer_array_outputs[i].rows(), num_frames); this->_head_output.resize(this->_head_output.rows(), num_frames); - for (int i = 0; i < this->_layer_arrays.size(); i++) + for (size_t i = 0; i < this->_layer_arrays.size(); i++) this->_layer_arrays[i].set_num_frames_(num_frames); // this->_head.set_num_frames_(num_frames); this->_num_frames = num_frames; @@ -382,7 +382,7 @@ void wavenet::WaveNet::_anti_pop_() if (this->_anti_pop_countdown >= this->_anti_pop_ramp) return; const float slope = 1.0f / float(this->_anti_pop_ramp); - for (int i = 0; i < this->_core_dsp_output.size(); i++) + for (size_t i = 0; i < this->_core_dsp_output.size(); i++) { if (this->_anti_pop_countdown >= this->_anti_pop_ramp) break; @@ -396,7 +396,7 @@ void wavenet::WaveNet::_reset_anti_pop_() { // You need the "real" receptive field, not the buffers. long receptive_field = 1; - for (int i = 0; i < this->_layer_arrays.size(); i++) + for (size_t i = 0; i < this->_layer_arrays.size(); i++) receptive_field += this->_layer_arrays[i].get_receptive_field(); this->_anti_pop_countdown = -receptive_field; } diff --git a/NAM/wavenet.h b/NAM/wavenet.h index 71ea572..12ae29a 100644 --- a/NAM/wavenet.h +++ b/NAM/wavenet.h @@ -23,11 +23,11 @@ class _Layer public: _Layer(const int condition_size, const int channels, const int kernel_size, const int dilation, const std::string activation, const bool gated) - : _activation(activations::Activation::get_activation(activation)) - , _gated(gated) - , _conv(channels, gated ? 2 * channels : channels, kernel_size, true, dilation) + : _conv(channels, gated ? 2 * channels : channels, kernel_size, true, dilation) , _input_mixin(condition_size, gated ? 2 * channels : channels, false) - , _1x1(channels, channels, true){}; + , _1x1(channels, channels, true) + , _activation(activations::Activation::get_activation(activation)) + , _gated(gated){}; void set_params_(std::vector::iterator& params); // :param `input`: from previous layer // :param `output`: to next layer @@ -67,7 +67,7 @@ class LayerArrayParams , gated(gated_) , head_bias(head_bias_) { - for (int i = 0; i < dilations_.size(); i++) + for (size_t i = 0; i < dilations_.size(); i++) this->dilations.push_back(dilations_[i]); };