I want to get into neural networks and that's why I want to write my own C++ matrix class. The problem is that I'm also pretty new to C++ and to keep things simple, I want to use a std::vector instead of an 2D-Array. At the moment my class looks something like
class Matrix {
private:
std::vector<std::vector<float>> data_;
public:
Matrix(const int& rows, const int& columns);
};
I know that a std::vector is a bit of overhead but I want to keep that overhead as small as possible with shrinking the vector only to the exact size needed:
Matrix::Matrix(const int &rows, const int &columns) {
this->data_ = std::vector<std::vector<float>>{};
this->data_.resize(rows);
for (auto col : this->data_) {
col.resize(columns);
}
}
My question is: Does this shrinking work the way I intended or is there a better way to do it?
Thanks alot!