Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions NAM/convnet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<float>::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);
Expand All @@ -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);
Expand All @@ -145,9 +145,9 @@ void convnet::ConvNet::_verify_params(const int channels, const std::vector<int>
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);
}

Expand All @@ -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
Expand All @@ -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;
Expand All @@ -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;
}
24 changes: 12 additions & 12 deletions NAM/dsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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];
}

Expand Down Expand Up @@ -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)
Expand All @@ -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++)
Expand Down Expand Up @@ -179,7 +179,7 @@ Linear::Linear(const int receptive_field, const bool _bias, const std::vector<fl
Linear::Linear(const double loudness, const int receptive_field, const bool _bias, const std::vector<float>& 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");
Expand All @@ -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<const Eigen::VectorXf>(&this->_input_buffer[offset], this->_receptive_field);
this->_core_dsp_output[i] = this->_bias + this->_weight.dot(input);
}
Expand All @@ -215,18 +215,18 @@ void Conv1D::set_params_(std::vector<float>::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++);
}

void Conv1D::set_size_(const int in_channels, const int out_channels, const int kernel_size, const bool do_bias,
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)
Expand All @@ -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)
Expand All @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions NAM/get_dsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ std::unique_ptr<DSP> get_dsp(dspData& conf)
const int channels = config["channels"];
const bool batchnorm = config["batchnorm"];
std::vector<int> 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<convnet::ConvNet>(loudness, channels, dilations, batchnorm, activation, params);
Expand All @@ -173,11 +173,11 @@ std::unique_ptr<DSP> get_dsp(dspData& conf)
else if (architecture == "WaveNet" || architecture == "CatWaveNet")
{
std::vector<wavenet::LayerArrayParams> 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<int> 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"],
Expand Down
4 changes: 2 additions & 2 deletions NAM/lstm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}

Expand All @@ -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;
}
50 changes: 25 additions & 25 deletions NAM/wavenet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
}
Expand All @@ -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,
Expand All @@ -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<float>::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);
}
Expand All @@ -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;
}
Expand All @@ -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);
Expand All @@ -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;
Expand All @@ -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<float>::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);
}

Expand All @@ -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)
Expand All @@ -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);
}

Expand All @@ -237,7 +237,7 @@ wavenet::WaveNet::WaveNet(const double loudness, const std::vector<wavenet::Laye
if (with_head)
throw std::runtime_error("Head not implemented!");
this->_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,
Expand Down Expand Up @@ -270,14 +270,14 @@ void wavenet::WaveNet::finalize_(const int num_frames)
void wavenet::WaveNet::set_params_(std::vector<float>& params)
{
std::vector<float>::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.";
Expand All @@ -290,7 +290,7 @@ void wavenet::WaveNet::set_params_(std::vector<float>& 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);
}

Expand All @@ -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);
}

Expand All @@ -326,15 +326,15 @@ 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]];
}

// Main layer arrays:
// 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_(
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
}
Loading