Here I attempt to create a matrix, by assigning arrays to a pointer reference:
bb_ANN(int num_Weights, int num_Layers, int num_Nodes, double * inputs){
//create an array that will hold pointers
struct ANN_Node *layer[num_Layers];
//create an array of nodes
struct ANN_Node **arr = malloc(sizeof(struct ANN_Node **) *num_Layers);
//initialize Nodes
for(int i=0;i<num_Layers;i++)
{
// layer heads
layer[i] = ANN_Init_Node(num_Weights);
for(int j=0; j<num_Nodes;j++)
//push nodes into each layer head
{ push_ANN_Node(&layer[i],num_Weights); }
// converting each list into an array, then each embedding into arr[]
arr[i] = arrayOfList(layer[i]);
}
printf("f(x):%f ", arr[0][1].weights[0]);
////////////
This is the arrayOfList definition :
struct ANN_Node *arrayOfList(struct ANN_Node *listP){
int i = lengthOfList(listP) ; //make i the length of the list
struct ANN_Node **ptr= malloc(sizeof(struct ANN_Node **) *i);
for(i=0;listP != NULL;listP=listP->next,i++)
{ ptr[i] = listP; }
return ptr;
}
Now what I am attempting to do, is to make a sort of matrix of 'ANN_Nodes' :
-->[ 0 0 0 ]
-->[ 0 0 0 ]
-->[ 0 0 0 ]
whereby, I create a loop which goes through each layer and inserts an array that my arrayOfList function would return.
Now there's this resulting thing:
arr[0][0].weights[0]
and this is fine.
So is this arr[1][0].weights[0]
and this arr[2][0].weights[0]
etcetera.
But I have failed to actually create something two dimensional : arr[0][1].weights[0]
this is a failure and a segfault.
Does what I am attempting to do make sense, is it feasible, and how might I actually achieve a two dimensional array structure so that I can carry on with my purposes ?
PS. I have checked out multidimensional arrays already but I think my case is a bit different from the majority of examples and tutorials I find on the internet, I am trying to sort of inject a returned array into and array of arrays if that makes sense...