Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Renamed source template files to match resulting file extensions.

Expanding files in binary mode.
Removed unnecessary trailing whitespaces.

--HG--
rename : src/c_wt.pxd.template => src/c_wt.template.pxd
rename : src/convolution.c.template => src/convolution.template.c
rename : src/convolution.h.template => src/convolution.template.h
rename : src/wavelets.c.template => src/wavelets.template.c
rename : src/wavelets.h.template => src/wavelets.template.h
rename : src/wavelets_coeffs.h.template => src/wavelets_coeffs.template.h
rename : src/wt.c.template => src/wt.c.template.c
rename : src/wt.h.template => src/wt.template.h
  • Loading branch information...
commit b22fb83805a9fbb7f1edf3952ade830adbbd3847 1 parent 3739d0a
@nigma authored
View
0  src/c_wt.pxd.template → src/c_wt.template.pxd
File renamed without changes
View
138 src/convolution.c.template → src/convolution.template.c
@@ -17,7 +17,7 @@ int $DTYPE$_downsampling_convolution_periodization(const $DTYPE$* input, const_i
index_t start;
$DTYPE$ sum;
$DTYPE$* ptr_w = output;
-
+
i = step-1; // first element taken from input is input[step-1]
//extending by (F-2)/2 elements
start = F_2 = F/2;
@@ -45,19 +45,19 @@ int $DTYPE$_downsampling_convolution_periodization(const $DTYPE$* input, const_i
// F - N-1 - filter in input range
// most time is spent in this loop
- for(; i < N; i+=step){ // input elements,
+ for(; i < N; i+=step){ // input elements,
sum = 0;
- for(j = 0; j < F; ++j)
+ for(j = 0; j < F; ++j)
sum += input[i-j]*filter[j];
*(ptr_w++) = sum;
- }
-
+ }
+
for(; i < N-step + (F/2)+1 + N%2; i += step){ // input elements
sum = 0;
k = i-N+1;
for(j = k; j < F; ++j) // overlapped elements
sum += filter[j]*input[i-j];
-
+
if(N%2 == 0){
for(j = 0; j < k; ++j){ // out of boundary (filter elements [0, k-1])
sum += filter[j]*input[k-1-j];
@@ -107,7 +107,7 @@ int $DTYPE$_downsampling_convolution(const $DTYPE$* input, const_index_t N,
#endif
$DTYPE$* ptr_w = output;
-
+
i = start = step-1; // first element taken from input is input[step-1]
if(F <= N){
@@ -131,7 +131,7 @@ int $DTYPE$_downsampling_convolution(const $DTYPE$* input, const_index_t N,
for(j = i+1; j < F; ++j)
sum += filter[j] * input[j-k];
*(ptr_w++) = sum;
- }
+ }
break;
case MODE_ASYMMETRIC:
@@ -143,7 +143,7 @@ int $DTYPE$_downsampling_convolution(const $DTYPE$* input, const_index_t N,
for(j = i+1; j < F; ++j)
sum += filter[j] * (input[0] - input[j-k]); // -=
*(ptr_w++) = sum;
- }
+ }
break;
case MODE_CONSTANT_EDGE:
@@ -151,13 +151,13 @@ int $DTYPE$_downsampling_convolution(const $DTYPE$* input, const_index_t N,
sum = 0;
for(j = 0; j <= i; ++j)
sum += filter[j]*input[i-j];
-
+
k = i+1;
for(j = i+1; j < F; ++j)
sum += filter[j] * input[0];
*(ptr_w++) = sum;
- }
+ }
break;
case MODE_SMOOTH:
@@ -167,10 +167,10 @@ int $DTYPE$_downsampling_convolution(const $DTYPE$* input, const_index_t N,
sum += filter[j]*input[i-j];
tmp = input[0]-input[1];
for(j = i+1; j < F; ++j){
- sum += filter[j] * (input[0] + tmp * (j-i));
+ sum += filter[j] * (input[0] + tmp * (j-i));
}
*(ptr_w++) = sum;
- }
+ }
break;
case MODE_PERIODIC:
@@ -178,13 +178,13 @@ int $DTYPE$_downsampling_convolution(const $DTYPE$* input, const_index_t N,
sum = 0;
for(j = 0; j <= i; ++j)
sum += filter[j]*input[i-j];
-
+
k = N+i;
for(j = i+1; j < F; ++j)
sum += filter[j] * input[k-j];
*(ptr_w++) = sum;
- }
+ }
break;
case MODE_ZEROPAD:
@@ -194,7 +194,7 @@ int $DTYPE$_downsampling_convolution(const $DTYPE$* input, const_index_t N,
for(j = 0; j <= i; ++j)
sum += filter[j]*input[i-j];
*(ptr_w++) = sum;
- }
+ }
break;
}
@@ -206,13 +206,13 @@ int $DTYPE$_downsampling_convolution(const $DTYPE$* input, const_index_t N,
// manually unroll the loop a bit
//printf("F: %d, N: %d, i: %d\n", F, N, i);
if((N - F)/step > 4) {
- for(; i < (N - (3*step)); i += 4*step){ // input elements,
+ for(; i < (N - (3*step)); i += 4*step){ // input elements,
//printf("EO4 iter: %d\n", i);
sum = input[i] * filter[0];
sum2 = input[i+step] * filter[0];
sum3 = input[i+(2*step)] * filter[0];
sum4 = input[i+(3*step)] * filter[0];
- for(j = 1; j < F; ++j){
+ for(j = 1; j < F; ++j){
sum += input[i-j] * filter[j];
sum2 += input[(step+i)-j] * filter[j];
sum3 += input[(2*step+i)-j] * filter[j];
@@ -225,14 +225,14 @@ int $DTYPE$_downsampling_convolution(const $DTYPE$* input, const_index_t N,
}
}
#endif
-
+
#ifdef OPT_UNROLL2
if((N - F)/step > 2) {
- for(; i < (N - step); i += 2*step){ // input elements,
+ for(; i < (N - step); i += 2*step){ // input elements,
//printf("EO2 iter: %d\n", i);
sum = input[i] * filter[0];
sum2 = input[i+step] * filter[0];
- for(j = 1; j < F; ++j){
+ for(j = 1; j < F; ++j){
sum += input[i-j] * filter[j];
sum2 += input[(step+i)-j] * filter[j];
}
@@ -241,8 +241,8 @@ int $DTYPE$_downsampling_convolution(const $DTYPE$* input, const_index_t N,
}
}
#endif
-
- for(; i < N; i+=step){ // input elements,
+
+ for(; i < N; i+=step){ // input elements,
sum = input[i] * filter[0];
for(j = 1; j < F; ++j){
//printf("EO1 iter: %d\n", i);
@@ -265,7 +265,7 @@ int $DTYPE$_downsampling_convolution(const $DTYPE$* input, const_index_t N,
sum += filter[j]*input[N-k+j]; // j-i-1 0*(N-1), 0*(N-2) 1*(N-1)
*(ptr_w++) = sum;
- }
+ }
break;
case MODE_ASYMMETRIC:
@@ -276,9 +276,9 @@ int $DTYPE$_downsampling_convolution(const $DTYPE$* input, const_index_t N,
sum += filter[j]*input[i-j];
for(j = 0; j < k; ++j) // out of boundary
- sum += filter[j]*(input[N-1]-input[N-k-1+j]); // -= j-i-1
+ sum += filter[j]*(input[N-1]-input[N-k-1+j]); // -= j-i-1
*(ptr_w++) = sum;
- }
+ }
break;
case MODE_CONSTANT_EDGE:
@@ -292,7 +292,7 @@ int $DTYPE$_downsampling_convolution(const $DTYPE$* input, const_index_t N,
sum += filter[j]*input[N-1]; // input[N-1] = const
*(ptr_w++) = sum;
- }
+ }
break;
case MODE_SMOOTH:
@@ -318,7 +318,7 @@ int $DTYPE$_downsampling_convolution(const $DTYPE$* input, const_index_t N,
for(j = 0; j < k; ++j) // out of boundary (filter elements [0, k-1])
sum += filter[j]*input[k-1-j];
*(ptr_w++) = sum;
- }
+ }
break;
case MODE_ZEROPAD:
@@ -328,9 +328,9 @@ int $DTYPE$_downsampling_convolution(const $DTYPE$* input, const_index_t N,
for(j = i-(N-1); j < F; ++j)
sum += input[i-j]*filter[j];
*(ptr_w++) = sum;
- }
+ }
break;
- }
+ }
}
return 0;
@@ -355,7 +355,7 @@ int $DTYPE$_allocating_downsampling_convolution(const $DTYPE$* input, const_inde
$DTYPE$ sum, tmp;
$DTYPE$ *buffer;
$DTYPE$* ptr_w = output;
-
+
F_minus_1 = F - 1;
start = F_minus_1+step-1;
@@ -402,7 +402,7 @@ int $DTYPE$_allocating_downsampling_convolution(const $DTYPE$* input, const_inde
for(j = 0; j < F/2-1; ++j) // copy from 'buffer' to left
buffer[F/2-2-j] = buffer[N_extended_right_start-j];
} else {
- for(j = 0; j < F/2; ++j)
+ for(j = 0; j < F/2; ++j)
buffer[N_extended_right_start+j] = input[j%N]; // copy from begining of `input` to right
for(j = 0; j < F/2-1; ++j) // copy from 'buffer' to left
buffer[F/2-2-j] = buffer[N_extended_right_start-1-j];
@@ -448,17 +448,17 @@ int $DTYPE$_allocating_downsampling_convolution(const $DTYPE$* input, const_inde
case MODE_CONSTANT_EDGE:
for(j = 0; j < F_minus_1; ++j){
- buffer[j] = input[0];
+ buffer[j] = input[0];
buffer[N_extended_right_start+j] = input[N-1];
}
break;
case MODE_PERIODIC:
- for(j = 0; j < F_minus_1; ++j)
+ for(j = 0; j < F_minus_1; ++j)
buffer[N_extended_right_start+j] = input[j%N]; // copy from beggining of `input` to right
-
+
for(j = 0; j < F_minus_1; ++j) // copy from 'buffer' to left
- buffer[F_minus_1-1-j] = buffer[N_extended_right_start-1-j];
+ buffer[F_minus_1-1-j] = buffer[N_extended_right_start-1-j];
break;
case MODE_ZEROPAD:
@@ -479,7 +479,7 @@ int $DTYPE$_allocating_downsampling_convolution(const $DTYPE$* input, const_inde
sum += buffer[i-j]*filter[j];
}
*(ptr_w++) = sum;
- }
+ }
// free memory
wtfree(buffer);
@@ -510,7 +510,7 @@ int $DTYPE$_upsampling_convolution_full(const $DTYPE$* input, const_index_t N,
// f1 f2 -> o2
// f1 f2 f3 -> o3
- for(j = 0; j < F; ++j)
+ for(j = 0; j < F; ++j)
ptr_out[j] += input[i] * filter[j]; // input[i] - const in loop
ptr_out -= 2;
}
@@ -520,7 +520,7 @@ int $DTYPE$_upsampling_convolution_full(const $DTYPE$* input, const_index_t N,
///////////////////////////////////////////////////////////////////////////////
// performs IDWT for PERIODIZATION mode only
// (refactored from the upsamplind_convolution_valid_sf function)
-//
+//
// The upsampling is performed by splitting filters to even and odd elements
// and performing 2 convolutions
//
@@ -530,7 +530,7 @@ int $DTYPE$_upsampling_convolution_valid_sf_periodization(const $DTYPE$* input,
const $DTYPE$* filter, const_index_t F,
$DTYPE$* output, const_index_t O)
{
-
+
$DTYPE$ *ptr_out = output;
$DTYPE$ *filter_even, *filter_odd;
$DTYPE$ *periodization_buf = NULL;
@@ -553,17 +553,17 @@ int $DTYPE$_upsampling_convolution_valid_sf_periodization(const $DTYPE$* input,
// Input data for periodization mode has to be periodically extended
// New length for temporary input
- N_p = F_2-1 +N;
+ N_p = F_2-1 +N;
// periodization_buf will hold periodically copied input coeffs values
periodization_buf = wtcalloc(N_p, sizeof($DTYPE$));
-
+
if(periodization_buf == NULL)
return -1;
// Copy input data to it's place in the periodization_buf
// -> [0 0 0 i1 i2 i3 0 0 0]
- k = (F_2-1)/2;
+ k = (F_2-1)/2;
for(i=k; i < k+N; ++i)
periodization_buf[i] = input[(i-k)%N];
@@ -587,11 +587,11 @@ int $DTYPE$_upsampling_convolution_valid_sf_periodization(const $DTYPE$* input,
periodization_buf[i] = periodization_buf_rear[j];
--j;
}
-
+
// Now perform the valid convolution
if(F_2%2){
$DTYPE$_upsampling_convolution_valid_sf(periodization_buf, N_p, filter, F, output, O, MODE_ZEROPAD);
-
+
// The F_2%2==0 case needs special result fix (oh my, another one..)
} else {
@@ -645,7 +645,7 @@ int $DTYPE$_upsampling_convolution_valid_sf_periodization(const $DTYPE$* input,
// Check if extending is really needed
N_p = F_2-1 + (index_t) ceil(k/2.); /*split filter len correct. + extra samples*/
-
+
// ok, if is then do:
// 1. Allocate buffers for front and rear parts of extended input
// 2. Copy periodically appriopriate elements from input to the buffers
@@ -669,22 +669,22 @@ int $DTYPE$_upsampling_convolution_valid_sf_periodization(const $DTYPE$* input,
wtfree(filter_even);
return -1;
}
-
+
// Fill buffers with appriopriate elements
memcpy(periodization_buf + N_p - k, input, k * sizeof($DTYPE$)); // copy from beginning of input to end of buffer
- for(i = 1; i <= (N_p - k); ++i) // kopiowanie 'cykliczne' od ko�ca input
+ for(i = 1; i <= (N_p - k); ++i) // kopiowanie 'cykliczne' od końca input
periodization_buf[(N_p - k) - i] = input[N - (i%N)];
memcpy(periodization_buf_rear, input + N - k, k * sizeof($DTYPE$)); // copy from end of input to begginning of buffer
- for(i = 0; i < (N_p - k); ++i) // kopiowanie 'cykliczne' od pocz�tku input
+ for(i = 0; i < (N_p - k); ++i) // kopiowanie 'cykliczne' od początku input
periodization_buf_rear[k + i] = input[i%N];
-
+
///////////////////////////////////////////////////////////////////
// Convolve filters with the (front) periodization_buf and compute
// the first part of output
ptr_base = periodization_buf + F_2 - 1;
-
+
if(k%2 == 1){
sum_odd = 0;
@@ -695,9 +695,9 @@ int $DTYPE$_upsampling_convolution_valid_sf_periodization(const $DTYPE$* input,
--k;
if(k)
$DTYPE$_upsampling_convolution_valid_sf(periodization_buf + 1, N_p-1, filter, F, ptr_out, O-1, MODE_ZEROPAD);
-
+
ptr_out += k; // k0 - 1 // really move backward by 1
-
+
} else if(k){
$DTYPE$_upsampling_convolution_valid_sf(periodization_buf, N_p, filter, F, ptr_out, O, MODE_ZEROPAD);
ptr_out += k;
@@ -712,16 +712,16 @@ int $DTYPE$_upsampling_convolution_valid_sf_periodization(const $DTYPE$* input,
ptr_base = ($DTYPE$*)input + F_2 - 1;
for(i = 0; i < N-(F_2-1); ++i){ // sliding over signal from left to right
-
+
sum_even = 0;
sum_odd = 0;
-
+
for(j = 0; j < F_2; ++j){
sum_even += filter_even[j] * ptr_base[i-j];
sum_odd += filter_odd[j] * ptr_base[i-j];
}
- *(ptr_out++) += sum_even;
+ *(ptr_out++) += sum_even;
*(ptr_out++) += sum_odd;
}
//
@@ -740,7 +740,7 @@ int $DTYPE$_upsampling_convolution_valid_sf_periodization(const $DTYPE$* input,
if(F_2%2 == 0){ // remaining one element
ptr_base = periodization_buf_rear + N_p - 1;
-
+
sum_even = 0;
for(j = 0; j < F_2; ++j){
sum_even += filter_even[j] * ptr_base[-j];
@@ -755,7 +755,7 @@ int $DTYPE$_upsampling_convolution_valid_sf_periodization(const $DTYPE$* input,
}
if(periodization_buf != NULL) wtfree(periodization_buf);
if(periodization_buf_rear != NULL) wtfree(periodization_buf_rear);
-
+
wtfree(filter_even);
wtfree(filter_odd);
@@ -766,7 +766,7 @@ int $DTYPE$_upsampling_convolution_valid_sf_periodization(const $DTYPE$* input,
///////////////////////////////////////////////////////////////////////////////
// performs IDWT for all modes
-//
+//
// The upsampling is performed by splitting filters to even and odd elements
// and performing 2 convolutions.
// After refactoring the PERIODIZATION mode case to separate function this
@@ -776,7 +776,7 @@ int $DTYPE$_upsampling_convolution_valid_sf(const $DTYPE$* input, const_index_t
const $DTYPE$* filter, const_index_t F,
$DTYPE$* output, const_index_t O,
MODE mode){
-
+
$DTYPE$ *ptr_out = output;
$DTYPE$ *filter_even, *filter_odd;
$DTYPE$ *ptr_base;
@@ -797,9 +797,9 @@ int $DTYPE$_upsampling_convolution_valid_sf(const $DTYPE$* input, const_index_t
if(mode == MODE_PERIODIZATION) // Special case
return $DTYPE$_upsampling_convolution_valid_sf_periodization(input, N, filter, F, output, O);
-
+
if((F%2) || (N < F_2)) // Filter must have even length.
- return -1;
+ return -1;
// Allocate memory for even and odd elements of the filter
filter_even = wtmalloc(F_2 * sizeof($DTYPE$));
@@ -833,12 +833,12 @@ int $DTYPE$_upsampling_convolution_valid_sf(const $DTYPE$* input, const_index_t
sum_even2 = filter_even[0] * ptr_base[i+1];
sum_even3 = filter_even[0] * ptr_base[i+2];
sum_even4 = filter_even[0] * ptr_base[i+3];
-
+
sum_odd = filter_odd[0] * ptr_base[i];
sum_odd2 = filter_odd[0] * ptr_base[i+1];
sum_odd3 = filter_odd[0] * ptr_base[i+2];
sum_odd4 = filter_odd[0] * ptr_base[i+3];
-
+
for(j = 1; j < F_2; ++j){
sum_even += filter_even[j] * ptr_base[i-j];
sum_even2 += filter_even[j] * ptr_base[(i+1)-j];
@@ -867,10 +867,10 @@ int $DTYPE$_upsampling_convolution_valid_sf(const $DTYPE$* input, const_index_t
for(; i < N-(F_2+1); i+=2){ // sliding over signal from left to right
sum_even = filter_even[0] * ptr_base[i];
sum_even2 = filter_even[0] * ptr_base[i+1];
-
+
sum_odd = filter_odd[0] * ptr_base[i];
sum_odd2 = filter_odd[0] * ptr_base[i+1];
-
+
for(j = 1; j < F_2; ++j){
sum_even += filter_even[j] * ptr_base[i-j];
sum_even2 += filter_even[j] * ptr_base[(i+1)-j];
@@ -885,17 +885,17 @@ int $DTYPE$_upsampling_convolution_valid_sf(const $DTYPE$* input, const_index_t
*(ptr_out++) += sum_odd2;
}
#endif
-
+
for(; i < N-(F_2-1); ++i){ // sliding over signal from left to right
sum_even = filter_even[0] * ptr_base[i];
sum_odd = filter_odd[0] * ptr_base[i];
-
+
for(j = 1; j < F_2; ++j){
sum_even += filter_even[j] * ptr_base[i-j];
sum_odd += filter_odd[j] * ptr_base[i-j];
}
- *(ptr_out++) += sum_even;
+ *(ptr_out++) += sum_even;
*(ptr_out++) += sum_odd;
}
View
0  src/convolution.h.template → src/convolution.template.h
File renamed without changes
View
0  src/wavelets.c.template → src/wavelets.template.c
File renamed without changes
View
0  src/wavelets.h.template → src/wavelets.template.h
File renamed without changes
View
0  src/wavelets_coeffs.h.template → src/wavelets_coeffs.template.h
File renamed without changes
View
0  src/wt.c.template → src/wt.c.template.c
File renamed without changes
View
0  src/wt.h.template → src/wt.template.h
File renamed without changes
View
11 util/templating.py
@@ -94,9 +94,14 @@ def expand_files(glob_pattern, force_update=False):
files = glob.glob(glob_pattern)
for name in files:
- new_name = splitext(name)[0]
+ new_name, ext = splitext(name) # main extension
+ while "." in new_name:
+ # remove .template extension for files like file.template.c
+ new_name = splitext(new_name)[0]
+ new_name = new_name + ext
if not exists(new_name) or force_update or getmtime(new_name) < getmtime(name):
print "expanding template: %s -> %s" % (name, new_name)
- new_file = open(new_name, 'w')
- new_file.write(expand_template(open(name).read()))
+ content = expand_template(open(name, "rb").read())
+ new_file = open(new_name, "wb")
+ new_file.write(content)
new_file.close()
Please sign in to comment.
Something went wrong with that request. Please try again.