Skip to content

Commit dd9be5e

Browse files
BatchNorm1d and custom TanhGate activation function for the dscnn
1 parent fdb7496 commit dd9be5e

File tree

4 files changed

+33
-3
lines changed

4 files changed

+33
-3
lines changed

c_reference/include/conv1d.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,10 @@ int Conv1D_Depth_LR(float *output_signal, unsigned out_T, const float *input_sig
5353
unsigned in_T, unsigned in_channels, int padding, unsigned kernel_size,
5454
const void* params, int activations);
5555

56-
//Pool
56+
// Auxillary Layers
5757
int AvgPool1D(float *output_signal, unsigned out_T, const float *input_signal, unsigned in_T, unsigned in_channels,
5858
int padding, unsigned kernel_size, int activations);
5959

60+
int BatchNorm1d(float* output_signal, float* input_signal, unsigned in_T, unsigned in_channels,
61+
float* mean, float* stddev, unsigned in_place);
6062
#endif

c_reference/include/conv_utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
#define __CONVLAYER_UTILS__
33

44
#include <math.h>
5-
#include <float.h>
65

76
int prepareLowRankConvMat(float* out, float* W1, float* W2, unsigned rank, unsigned I, unsigned J);
7+
int TanhGate(float* output_signal, float* input_signal, unsigned in_T, unsigned in_channels);
88
float sigmoid(float x);
99
float relu(float x);
1010

c_reference/src/conv1d.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,4 +208,23 @@ int AvgPool1D(float *output_signal, unsigned out_T, const float *input_signal, u
208208
}
209209
}
210210
return 0;
211+
}
212+
213+
int BatchNorm1d(float* output_signal, float* input_signal, unsigned in_T, unsigned in_channels,
214+
float* mean, float* stddev, unsigned in_place){
215+
if(in_place){
216+
for(int t = 0; t < in_T ; t++){
217+
for(int d = 0 ; d < in_channels ; d++){
218+
input_signal[t * in_channels + d] = (input_signal[t * in_channels + d] - mean[d])/stddev[d];
219+
}
220+
}
221+
}
222+
else{
223+
for(int t = 0; t < in_T ; t++){
224+
for(int d = 0 ; d < in_channels ; d++){
225+
output_signal[t * in_channels + d] = (input_signal[t * in_channels + d] - mean[d])/stddev[d];
226+
}
227+
}
228+
}
229+
return 0;
211230
}

c_reference/src/conv_utils.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include"conv_utils.h"
22
#include <math.h>
3-
#include <float.h>
43

54
int prepareLowRankConvMat(float* out, float* W1, float* W2, unsigned rank, unsigned I, unsigned J){
65
for(int i = 0 ; i < I; i++){
@@ -15,6 +14,16 @@ int prepareLowRankConvMat(float* out, float* W1, float* W2, unsigned rank, unsig
1514
return 0;
1615
}
1716

17+
int TanhGate(float* output_signal, float* input_signal, unsigned in_T, unsigned in_channels){
18+
unsigned int piv = in_channels>>2;
19+
for(int t = 0 ; t < in_T ; t++){
20+
for(int d = 0 ; d < piv ; d++){
21+
output_signal[t * piv + d] = input_signal[t * in_channels + d] * input_signal[t * in_channels + (d + piv)];
22+
}
23+
}
24+
return 0;
25+
}
26+
1827
float relu(float x) {
1928
if (x < 0.0) return 0.0;
2029
else return x;

0 commit comments

Comments
 (0)