Skip to content

Maybe wrong matrix index calculation ? #19

@mingodad

Description

@mingodad

Hello !
I'm refactoring a bit nn.c/h and I think I found a mistake in the calculation of the matrix index for weight, gradient, sgradient, pgradient and delta:

#define WEIGHT(net,l,i,j) (net)->layer[l].weight[((j)*(net)->layer[l].units)+(i)]
#define GRADIENT(net,l,i,j) (net)->layer[l].gradient[((j)*(net)->layer[l].units)+(i)]
#define SGRADIENT(net,l,i,j) (net)->layer[l].sgradient[((j)*(net)->layer[l].units)+(i)]
#define PGRADIENT(net,l,i,j) (net)->layer[l].pgradient[((j)*(net)->layer[l].units)+(i)]
#define DELTA(net,l,i,j) (net)->layer[l].delta[((j)*(net)->layer[l].units)+(i)]

Looking at the allocation code for them it seems that the correct way to index is to multiply "units" by "i" and then add "j":

#define WEIGHT(net,l,i,j) (net)->layer[l].weight[((i)*(net)->layer[l].units)+(j)]
...

Attached are the refactored nn.c/h so far (compiles but doesn't seem to work properly).
The idea is to allocate units rounded up by SIMDF for alignment and be able to do full calculations directly using simd without left overs.

nn.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions