Skip to content

Commit 0546aa4

Browse files
futz12github-actions[bot]
authored andcommitted
apply code-format changes
1 parent 18bac4c commit 0546aa4

File tree

2 files changed

+36
-35
lines changed

2 files changed

+36
-35
lines changed

src/layer/x86/spectrogram_x86.cpp

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -99,37 +99,38 @@ int Spectrogram_x86::load_param(const ParamDict& pd)
9999
if (onesided)
100100
{
101101
n_freq = n_fft / 2 + 1;
102-
} else
102+
}
103+
else
103104
{
104105
n_freq = n_fft;
105106
}
106-
theta.create(n_fft,n_freq,size_t(8));
107+
theta.create(n_fft, n_freq, size_t(8));
107108

108-
for (int i = 0; i<n_freq; i++)
109+
for (int i = 0; i < n_freq; i++)
109110
{
110-
for (int j = 0; j<n_fft; j++)
111+
for (int j = 0; j < n_fft; j++)
111112
{
112113
theta.row<double>(i)[j] = 2 * 3.14159265358979323846 * i * j / n_fft;
113114
}
114115
}
115116

116117
Mat real_basis, imag_basis;
117-
real_basis.create(n_fft,n_freq,size_t(8));
118-
imag_basis.create(n_fft,n_freq,size_t(8));
118+
real_basis.create(n_fft, n_freq, size_t(8));
119+
imag_basis.create(n_fft, n_freq, size_t(8));
119120

120-
for (int i = 0; i<n_freq; i++)
121+
for (int i = 0; i < n_freq; i++)
121122
{
122-
for (int j = 0; j<n_fft; j++)
123+
for (int j = 0; j < n_fft; j++)
123124
{
124125
real_basis.row<double>(i)[j] = cos(theta.row<double>(i)[j]);
125126
imag_basis.row<double>(i)[j] = -sin(theta.row<double>(i)[j]);
126127
}
127128
}
128129

129130
// multiply window
130-
for (int i = 0; i<n_freq; i++)
131+
for (int i = 0; i < n_freq; i++)
131132
{
132-
for (int j = 0; j<n_fft; j++)
133+
for (int j = 0; j < n_fft; j++)
133134
{
134135
real_basis.row<double>(i)[j] *= window_data[j];
135136
imag_basis.row<double>(i)[j] *= window_data[j];
@@ -139,34 +140,34 @@ int Spectrogram_x86::load_param(const ParamDict& pd)
139140
if (normalized == 1)
140141
{
141142
double scale = 1.f / sqrt(n_fft);
142-
for (int i = 0; i<n_freq; i++)
143+
for (int i = 0; i < n_freq; i++)
143144
{
144-
for (int j = 0; j<n_fft; j++)
145+
for (int j = 0; j < n_fft; j++)
145146
{
146147
real_basis.row<double>(i)[j] *= scale;
147148
imag_basis.row<double>(i)[j] *= scale;
148149
}
149150
}
150151
}
151152

152-
conv_data.create(n_fft,1,n_freq * 2);
153+
conv_data.create(n_fft, 1, n_freq * 2);
153154

154-
for (int i = 0; i<n_freq; i++)
155+
for (int i = 0; i < n_freq; i++)
155156
{
156-
for (int j = 0; j<n_fft; j++)
157+
for (int j = 0; j < n_fft; j++)
157158
{
158-
conv_data.channel(i).row<float>(0)[j]= (float)real_basis.row<double>(i)[j];
159-
conv_data.channel(i+n_freq).row<float>(0)[j] = (float)imag_basis.row<double>(i)[j];
159+
conv_data.channel(i).row<float>(0)[j] = (float)real_basis.row<double>(i)[j];
160+
conv_data.channel(i + n_freq).row<float>(0)[j] = (float)imag_basis.row<double>(i)[j];
160161
}
161162
}
162163

163164
conv_transpose = ncnn::create_layer("Convolution1D");
164165
ncnn::ParamDict conv_transpose_pd;
165166

166-
conv_transpose_pd.set(0,2 * n_freq); // num_output
167-
conv_transpose_pd.set(1,n_fft); // kernel_w
168-
conv_transpose_pd.set(3,hoplen); // stride_w
169-
conv_transpose_pd.set(19,1); // dynamic_weight
167+
conv_transpose_pd.set(0, 2 * n_freq); // num_output
168+
conv_transpose_pd.set(1, n_fft); // kernel_w
169+
conv_transpose_pd.set(3, hoplen); // stride_w
170+
conv_transpose_pd.set(19, 1); // dynamic_weight
170171

171172
conv_transpose->load_param(conv_transpose_pd);
172173

@@ -226,7 +227,7 @@ int Spectrogram_x86::forward(const Mat& bottom_blob, Mat& top_blob, const Option
226227
opt_conv.use_packing_layout = false;
227228

228229
conv_transpose->create_pipeline(opt_conv);
229-
conv_transpose->forward(inputs,outputs,opt_conv);
230+
conv_transpose->forward(inputs, outputs, opt_conv);
230231
conv_transpose->destroy_pipeline(opt_conv);
231232

232233
Mat conv_top_blob = outputs[0]; // (2 * n_freq, frames)
@@ -235,15 +236,16 @@ int Spectrogram_x86::forward(const Mat& bottom_blob, Mat& top_blob, const Option
235236
if (power == 0) // as complex
236237
{
237238
// copy
238-
for (int i = 0; i<frames; i++)
239+
for (int i = 0; i < frames; i++)
239240
{
240-
for (int j = 0; j<n_freq; j++)
241+
for (int j = 0; j < n_freq; j++)
241242
{
242243
top_blob.channel(j).row<float>(i)[0] = conv_top_data[j * frames + i];
243244
top_blob.channel(j).row<float>(i)[1] = conv_top_data[(j + n_freq) * frames + i];
244245
}
245246
}
246-
} else
247+
}
248+
else
247249
{
248250
if (power == 1) // magnitude sqrt(re * re + im * im);
249251
{
@@ -255,12 +257,13 @@ int Spectrogram_x86::forward(const Mat& bottom_blob, Mat& top_blob, const Option
255257
top_blob.row<float>(j)[i] = sqrtf(conv_top_data[j * frames + i] * conv_top_data[j * frames + i] + conv_top_data[(j + n_freq) * frames + i] * conv_top_data[(j + n_freq) * frames + i]);
256258
}
257259
}
258-
} else if (power == 2) // power re * re + im * im;
260+
}
261+
else if (power == 2) // power re * re + im * im;
259262
{
260263
// copy
261264
for (int i = 0; i < frames; i++)
262265
{
263-
for (int j = 0; j< n_freq; j++)
266+
for (int j = 0; j < n_freq; j++)
264267
{
265268
top_blob.row<float>(j)[i] = conv_top_data[j * frames + i] * conv_top_data[j * frames + i] + conv_top_data[(j + n_freq) * frames + i] * conv_top_data[(j + n_freq) * frames + i];
266269
}

tests/test_spectrogram.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ static int test_spectrogram_0()
5050
|| test_spectrogram(124, 55, 2, 12, 55, 1, 1, 2, 2, 0);
5151
}
5252

53-
static int test_spectrogram_eval(int size, int n_fft, int power, int hoplen, int winlen, int window_type, int center, int pad_type, int normalized, int onesided,float * in,float * std)
53+
static int test_spectrogram_eval(int size, int n_fft, int power, int hoplen, int winlen, int window_type, int center, int pad_type, int normalized, int onesided, float* in, float* std)
5454
{
55-
ncnn::Layer * layer = ncnn::create_layer("Spectrogram");
55+
ncnn::Layer* layer = ncnn::create_layer("Spectrogram");
5656

5757
ncnn::ParamDict pd;
5858
pd.set(0, n_fft);
@@ -82,7 +82,7 @@ static int test_spectrogram_eval(int size, int n_fft, int power, int hoplen, int
8282

8383
for (int i = 0; i < output.c; i++)
8484
{
85-
float * output_data = output.channel(i);
85+
float* output_data = output.channel(i);
8686
for (int j = 0; j < output.h; j++)
8787
{
8888
for (int k = 0; k < output.w; k++)
@@ -113,11 +113,9 @@ static int test_spectrogram_1()
113113
0.28284273f, 0.49497476f, 0.70710677f, 0.24271232f, 0.42322639f, 0.60407096f, 0.14577380f, 0.25000000f, 0.35531676f, 0.04838108f, 0.07667736f, 0.10652842f, 0.00000000f, 0.00000002f, 0.00000000f, 0.04838108f, 0.07667736f, 0.10652842f, 0.14577380f, 0.25000000f, 0.35531676f, 0.24271232f, 0.42322639f, 0.60407096f
114114
};
115115

116-
return
117-
test_spectrogram_eval(16, 4, 1, 2, 4, 1, 1, 0, 0, 1, input_0, std_0)
118-
|| test_spectrogram_eval(16, 8, 1, 2, 4, 1, 0, 0, 0, 1, input_0, std_1)
119-
|| test_spectrogram_eval(16, 8, 1, 3, 4, 1, 0, 0, 1, 0, input_0, std_2);
120-
116+
return test_spectrogram_eval(16, 4, 1, 2, 4, 1, 1, 0, 0, 1, input_0, std_0)
117+
|| test_spectrogram_eval(16, 8, 1, 2, 4, 1, 0, 0, 0, 1, input_0, std_1)
118+
|| test_spectrogram_eval(16, 8, 1, 3, 4, 1, 0, 0, 1, 0, input_0, std_2);
121119
}
122120

123121
int main()

0 commit comments

Comments
 (0)