Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
Here's what happened
void neural_network_lib::Weight::fSetMemWeights() //+
{
this->d->pppdWeights = new double**[this->d->iQuantLayer];
for (int i = 0; i < this->d->iQuantLayer; i++)
this->d->pppdWeights[i] = new double*[this->d->piQuantNInLayer[i]];
for (int i = 0; i < this->d->iQuantLayer; i++)
for (int j = 0; j < this->d->piQuantNInLayer[i + 1]; j++)
this->d->pppdWeights[i][j] = new double[this->d->piQuantNInLayer[i + 1]];
}
Let's start with the fact that double ***array
-- is not an array of arrays of arrays, but a pointer to a pointer to a pointer to double. An array of arrays of arrays is a double array[A][B][C]. It is initialized as usual:
double array [A][B][C] = {
{
{
1., 2., 3., ...
}, {
...
}
}, {
...
}
};
If the overhead is not critical - a nested vector.
If you want optimally - a class with two set / get functions and a constructor to which the dimensions are passed. Inside, the dimensions and a flat dynamic array are stored, the cell number in which is elementarily calculated at each call.
Hipster variant
#include <iostream>
#include <array>
#include <vector>
template <typename V, typename... T>
constexpr auto make_array(V &&v, T&&... t) -> std::array < V , sizeof...(T) + 1 >
{
return {{v, std::forward<T>(t)... }};
}
int main()
{
auto array = make_array(
make_array(make_array(1.,2.,3.,4.),make_array(5.,6.,7.,8.),make_array(9.,10.,11.,12.)),
make_array(make_array(14.,15.,16.,17.),make_array(18.,19.,20.,21.),make_array(22.,23.,24.,25.))
);
for(auto && v: array[0][2]){
std::cout << v << ',';
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question