antirez / antirez/neural-redis

Maybe wrong matrix index calculation ?

Open
#19 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
2.2k
Forks
100
PR merge metrics
No merged PRs in 30d

Description

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](https://github.com/antirez/neural-redis/files/2129835/nn.zip)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.