Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Holger Nahrstaedt 2016-03-09 15:47:21 +01:00
commit aad90aebfc
4 changed files with 53 additions and 28 deletions

View File

@ -204,5 +204,7 @@ void conv_fft(const conv_object obj,fft_type *inp1,fft_type *inp2,fft_type *oup)
void free_conv(conv_object object) { void free_conv(conv_object object) {
free_real_fft(object->fobj);
free_real_fft(object->iobj);
free(object); free(object);
} }

View File

@ -106,6 +106,7 @@ void fft_c2r_exec(fft_real_object obj,fft_data *inp,fft_type *oup) {
} }
void free_real_fft(fft_real_object object) { void free_real_fft(fft_real_object object) {
free_fft(object->cobj);
free(object); free(object);
} }

View File

@ -3038,7 +3038,7 @@ int filtlength(const char* name) {
} }
else if (len > 2 && strstr(name, "db") != NULL) else if (len > 2 && strstr(name, "db") != NULL)
{ {
new_str = malloc(sizeof(char)*(len-2 + 1)); new_str = (char*)malloc(sizeof(char)*(len-2 + 1));
for (i = 2; i < len + 1; i++) for (i = 2; i < len + 1; i++)
new_str[i - 2] = name[i]; new_str[i - 2] = name[i];
@ -3158,7 +3158,7 @@ int filtlength(const char* name) {
} }
else if (len > 4 && strstr(name, "coif") != NULL) else if (len > 4 && strstr(name, "coif") != NULL)
{ {
new_str = malloc(sizeof(char)*(len - 4 + 1)); new_str = (char*)malloc(sizeof(char)*(len - 4 + 1));
for (i = 4; i < len + 1; i++) for (i = 4; i < len + 1; i++)
new_str[i - 4] = name[i]; new_str[i - 4] = name[i];
@ -3174,7 +3174,7 @@ int filtlength(const char* name) {
} }
else if (len > 3 && strstr(name, "sym") != NULL) else if (len > 3 && strstr(name, "sym") != NULL)
{ {
new_str = malloc(sizeof(char)*(len - 3 + 1)); new_str = (char*)malloc(sizeof(char)*(len - 3 + 1));
for (i = 3; i < len + 1; i++) for (i = 3; i < len + 1; i++)
new_str[i - 3] = name[i]; new_str[i - 3] = name[i];
@ -3206,7 +3206,7 @@ void qmf_wrev(const double *in, int N, double *out)
{ {
int count = 0; int count = 0;
double *sigOutTemp; double *sigOutTemp;
sigOutTemp = malloc(N*sizeof(double)); sigOutTemp = (double*)malloc(N*sizeof(double));
qmf_even(in, N, sigOutTemp); qmf_even(in, N, sigOutTemp);
copy_reverse(sigOutTemp, N, out); copy_reverse(sigOutTemp, N, out);
@ -3764,7 +3764,7 @@ int filtcoef(const char* name, double *lp1, double *hp1, double *lp2, double *hp
} }
else if (!strcmp(name,"coif1")){ else if (!strcmp(name,"coif1")){
double *coeffTemp; double *coeffTemp;
coeffTemp = malloc(N*sizeof(double)); coeffTemp = (double*)malloc(N*sizeof(double));
copy(coif1, N, coeffTemp); copy(coif1, N, coeffTemp);
for (i = 0; i < N; ++i) { for (i = 0; i < N; ++i) {
@ -3781,7 +3781,7 @@ int filtcoef(const char* name, double *lp1, double *hp1, double *lp2, double *hp
} }
else if (!strcmp(name,"coif2")){ else if (!strcmp(name,"coif2")){
double *coeffTemp; double *coeffTemp;
coeffTemp = malloc(N*sizeof(double)); coeffTemp = (double*)malloc(N*sizeof(double));
copy(coif2, N, coeffTemp); copy(coif2, N, coeffTemp);
for (i = 0; i < N; ++i) { for (i = 0; i < N; ++i) {
@ -3798,7 +3798,7 @@ int filtcoef(const char* name, double *lp1, double *hp1, double *lp2, double *hp
} }
else if (!strcmp(name,"coif3")){ else if (!strcmp(name,"coif3")){
double *coeffTemp; double *coeffTemp;
coeffTemp = malloc(N*sizeof(double)); coeffTemp = (double*)malloc(N*sizeof(double));
copy(coif3, N, coeffTemp); copy(coif3, N, coeffTemp);
for (i = 0; i < N; ++i) { for (i = 0; i < N; ++i) {
@ -3815,7 +3815,7 @@ int filtcoef(const char* name, double *lp1, double *hp1, double *lp2, double *hp
} }
else if (!strcmp(name,"coif4")){ else if (!strcmp(name,"coif4")){
double *coeffTemp; double *coeffTemp;
coeffTemp = malloc(N*sizeof(double)); coeffTemp = (double*)malloc(N*sizeof(double));
copy(coif4, N, coeffTemp); copy(coif4, N, coeffTemp);
for (i = 0; i < N; ++i) { for (i = 0; i < N; ++i) {
@ -3832,7 +3832,7 @@ int filtcoef(const char* name, double *lp1, double *hp1, double *lp2, double *hp
} }
else if (!strcmp(name,"coif5")){ else if (!strcmp(name,"coif5")){
double *coeffTemp; double *coeffTemp;
coeffTemp = malloc(N*sizeof(double)); coeffTemp = (double*)malloc(N*sizeof(double));
copy(coif5, N, coeffTemp); copy(coif5, N, coeffTemp);
for (i = 0; i < N; ++i) { for (i = 0; i < N; ++i) {
@ -3849,7 +3849,7 @@ int filtcoef(const char* name, double *lp1, double *hp1, double *lp2, double *hp
} }
else if (!strcmp(name, "coif6")){ else if (!strcmp(name, "coif6")){
double *coeffTemp; double *coeffTemp;
coeffTemp = malloc(N*sizeof(double)); coeffTemp = (double*)malloc(N*sizeof(double));
copy(coif6, N, coeffTemp); copy(coif6, N, coeffTemp);
for (i = 0; i < N; ++i) { for (i = 0; i < N; ++i) {
@ -3866,7 +3866,7 @@ int filtcoef(const char* name, double *lp1, double *hp1, double *lp2, double *hp
} }
else if (!strcmp(name, "coif7")){ else if (!strcmp(name, "coif7")){
double *coeffTemp; double *coeffTemp;
coeffTemp = malloc(N*sizeof(double)); coeffTemp = (double*)malloc(N*sizeof(double));
copy(coif7, N, coeffTemp); copy(coif7, N, coeffTemp);
for (i = 0; i < N; ++i) { for (i = 0; i < N; ++i) {
@ -3883,7 +3883,7 @@ int filtcoef(const char* name, double *lp1, double *hp1, double *lp2, double *hp
} }
else if (!strcmp(name, "coif8")){ else if (!strcmp(name, "coif8")){
double *coeffTemp; double *coeffTemp;
coeffTemp = malloc(N*sizeof(double)); coeffTemp = (double*)malloc(N*sizeof(double));
copy(coif8, N, coeffTemp); copy(coif8, N, coeffTemp);
for (i = 0; i < N; ++i) { for (i = 0; i < N; ++i) {
@ -3900,7 +3900,7 @@ int filtcoef(const char* name, double *lp1, double *hp1, double *lp2, double *hp
} }
else if (!strcmp(name, "coif9")){ else if (!strcmp(name, "coif9")){
double *coeffTemp; double *coeffTemp;
coeffTemp = malloc(N*sizeof(double)); coeffTemp = (double*)malloc(N*sizeof(double));
copy(coif9, N, coeffTemp); copy(coif9, N, coeffTemp);
for (i = 0; i < N; ++i) { for (i = 0; i < N; ++i) {
@ -3917,7 +3917,7 @@ int filtcoef(const char* name, double *lp1, double *hp1, double *lp2, double *hp
} }
else if (!strcmp(name, "coif10")){ else if (!strcmp(name, "coif10")){
double *coeffTemp; double *coeffTemp;
coeffTemp = malloc(N*sizeof(double)); coeffTemp = (double*)malloc(N*sizeof(double));
copy(coif10, N, coeffTemp); copy(coif10, N, coeffTemp);
for (i = 0; i < N; ++i) { for (i = 0; i < N; ++i) {
@ -3934,7 +3934,7 @@ int filtcoef(const char* name, double *lp1, double *hp1, double *lp2, double *hp
} }
else if (!strcmp(name, "coif11")){ else if (!strcmp(name, "coif11")){
double *coeffTemp; double *coeffTemp;
coeffTemp = malloc(N*sizeof(double)); coeffTemp = (double*)malloc(N*sizeof(double));
copy(coif11, N, coeffTemp); copy(coif11, N, coeffTemp);
for (i = 0; i < N; ++i) { for (i = 0; i < N; ++i) {
@ -3951,7 +3951,7 @@ int filtcoef(const char* name, double *lp1, double *hp1, double *lp2, double *hp
} }
else if (!strcmp(name, "coif12")){ else if (!strcmp(name, "coif12")){
double *coeffTemp; double *coeffTemp;
coeffTemp = malloc(N*sizeof(double)); coeffTemp = (double*)malloc(N*sizeof(double));
copy(coif12, N, coeffTemp); copy(coif12, N, coeffTemp);
for (i = 0; i < N; ++i) { for (i = 0; i < N; ++i) {
@ -3968,7 +3968,7 @@ int filtcoef(const char* name, double *lp1, double *hp1, double *lp2, double *hp
} }
else if (!strcmp(name, "coif13")){ else if (!strcmp(name, "coif13")){
double *coeffTemp; double *coeffTemp;
coeffTemp = malloc(N*sizeof(double)); coeffTemp = (double*)malloc(N*sizeof(double));
copy(coif13, N, coeffTemp); copy(coif13, N, coeffTemp);
for (i = 0; i < N; ++i) { for (i = 0; i < N; ++i) {
@ -3985,7 +3985,7 @@ int filtcoef(const char* name, double *lp1, double *hp1, double *lp2, double *hp
} }
else if (!strcmp(name, "coif14")){ else if (!strcmp(name, "coif14")){
double *coeffTemp; double *coeffTemp;
coeffTemp = malloc(N*sizeof(double)); coeffTemp = (double*)malloc(N*sizeof(double));
copy(coif14, N, coeffTemp); copy(coif14, N, coeffTemp);
for (i = 0; i < N; ++i) { for (i = 0; i < N; ++i) {
@ -4002,7 +4002,7 @@ int filtcoef(const char* name, double *lp1, double *hp1, double *lp2, double *hp
} }
else if (!strcmp(name, "coif15")){ else if (!strcmp(name, "coif15")){
double *coeffTemp; double *coeffTemp;
coeffTemp = malloc(N*sizeof(double)); coeffTemp = (double*)malloc(N*sizeof(double));
copy(coif15, N, coeffTemp); copy(coif15, N, coeffTemp);
for (i = 0; i < N; ++i) { for (i = 0; i < N; ++i) {
@ -4019,7 +4019,7 @@ int filtcoef(const char* name, double *lp1, double *hp1, double *lp2, double *hp
} }
else if (!strcmp(name, "coif16")){ else if (!strcmp(name, "coif16")){
double *coeffTemp; double *coeffTemp;
coeffTemp = malloc(N*sizeof(double)); coeffTemp = (double*)malloc(N*sizeof(double));
copy(coif16, N, coeffTemp); copy(coif16, N, coeffTemp);
for (i = 0; i < N; ++i) { for (i = 0; i < N; ++i) {
@ -4036,7 +4036,7 @@ int filtcoef(const char* name, double *lp1, double *hp1, double *lp2, double *hp
} }
else if (!strcmp(name, "coif17")){ else if (!strcmp(name, "coif17")){
double *coeffTemp; double *coeffTemp;
coeffTemp = malloc(N*sizeof(double)); coeffTemp = (double*)malloc(N*sizeof(double));
copy(coif17, N, coeffTemp); copy(coif17, N, coeffTemp);
for (i = 0; i < N; ++i) { for (i = 0; i < N; ++i) {

View File

@ -5,12 +5,26 @@
#include "BoostTest.h" #include "BoostTest.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <math.h> #include <math.h>
#include <cmath>
#include <iostream>
#include "wavelib.h" #include "wavelib.h"
#include<vector> #include<vector>
#include <random> #include <random>
namespace patch
{
template < typename T > std::string to_string( const T& n )
{
std::ostringstream stm ;
stm << n ;
return stm.str() ;
}
}
double absmax(double *array, int N) { double absmax(double *array, int N) {
double max; double max;
int i; int i;
@ -117,15 +131,15 @@ BOOST_AUTO_TEST_CASE(ReconstructionTest)
for (unsigned int j = 0; j < 36; j++) for (unsigned int j = 0; j < 36; j++)
{ {
waveletNames.push_back(std::string("db") + std::to_string(j + 1)); waveletNames.push_back(std::string("db") + patch::to_string(j + 1));
} }
for (unsigned int j = 0; j < 17; j++) for (unsigned int j = 0; j < 17; j++)
{ {
waveletNames.push_back(std::string("coif") + std::to_string(j + 1)); waveletNames.push_back(std::string("coif") + patch::to_string(j + 1));
} }
for (unsigned int j = 1; j < 20; j++) for (unsigned int j = 1; j < 20; j++)
{ {
waveletNames.push_back(std::string("sym") + std::to_string(j + 1)); waveletNames.push_back(std::string("sym") + patch::to_string(j + 1));
} }
waveletNames.push_back("bior1.1"); waveletNames.push_back("bior1.1");
@ -198,14 +212,17 @@ BOOST_AUTO_TEST_CASE(ReconstructionTest)
wt_free(wt); wt_free(wt);
} }
wave_free(obj); wave_free(obj);
delete[] name;
} }
} }
} }
free(out); free(out);
free(inp); free(inp);
} }
BOOST_AUTO_TEST_CASE(DBCoefTests) BOOST_AUTO_TEST_CASE(DBCoefTests)
{ {
wave_object obj; wave_object obj;
@ -214,7 +231,7 @@ BOOST_AUTO_TEST_CASE(DBCoefTests)
waveletNames.resize(38); waveletNames.resize(38);
for (unsigned int i = 0; i < waveletNames.size();i++) for (unsigned int i = 0; i < waveletNames.size();i++)
{ {
waveletNames[i] = std::string("db") + std::to_string(i+1); waveletNames[i] = std::string("db") + patch::to_string(i+1);
} }
for (unsigned int j = 0; j < waveletNames.size(); j++) for (unsigned int j = 0; j < waveletNames.size(); j++)
@ -229,6 +246,7 @@ BOOST_AUTO_TEST_CASE(DBCoefTests)
for (int m = 1; m < (obj->lpr_len / 2) - 1;m++) for (int m = 1; m < (obj->lpr_len / 2) - 1;m++)
BOOST_CHECK_SMALL(sum5(obj->lpr, obj->lpr_len, m), epsilon); BOOST_CHECK_SMALL(sum5(obj->lpr, obj->lpr_len, m), epsilon);
wave_free(obj); wave_free(obj);
delete[] name;
} }
} }
@ -241,7 +259,7 @@ BOOST_AUTO_TEST_CASE(CoifCoefTests)
waveletNames.resize(17); waveletNames.resize(17);
for (unsigned int i = 0; i < waveletNames.size(); i++) for (unsigned int i = 0; i < waveletNames.size(); i++)
{ {
waveletNames[i] = std::string("coif") + std::to_string(i + 1); waveletNames[i] = std::string("coif") + patch::to_string(i + 1);
} }
for (unsigned int j = 0; j < waveletNames.size(); j++) for (unsigned int j = 0; j < waveletNames.size(); j++)
@ -256,6 +274,7 @@ BOOST_AUTO_TEST_CASE(CoifCoefTests)
for (int m = 1; m < (obj->lpr_len / 2) - 1; m++) for (int m = 1; m < (obj->lpr_len / 2) - 1; m++)
BOOST_CHECK_SMALL(sum5(obj->lpr, obj->lpr_len, m), epsilon); BOOST_CHECK_SMALL(sum5(obj->lpr, obj->lpr_len, m), epsilon);
wave_free(obj); wave_free(obj);
delete[] name;
} }
} }
@ -266,7 +285,7 @@ BOOST_AUTO_TEST_CASE(SymCoefTests)
std::vector<std::string > waveletNames; std::vector<std::string > waveletNames;
for (unsigned int i = 1; i < 20; i++) for (unsigned int i = 1; i < 20; i++)
{ {
waveletNames.push_back(std::string("sym") + std::to_string(i + 1)); waveletNames.push_back(std::string("sym") + patch::to_string(i + 1));
} }
for (unsigned int j = 0; j < waveletNames.size(); j++) for (unsigned int j = 0; j < waveletNames.size(); j++)
@ -281,6 +300,7 @@ BOOST_AUTO_TEST_CASE(SymCoefTests)
for (int m = 1; m < (obj->lpr_len / 2) - 1; m++) for (int m = 1; m < (obj->lpr_len / 2) - 1; m++)
BOOST_CHECK_SMALL(sum5(obj->lpr, obj->lpr_len, m), epsilon); BOOST_CHECK_SMALL(sum5(obj->lpr, obj->lpr_len, m), epsilon);
wave_free(obj); wave_free(obj);
delete[] name;
} }
} }
@ -318,6 +338,7 @@ BOOST_AUTO_TEST_CASE(BiorCoefTests)
BOOST_CHECK_SMALL(sum3(obj->lpr, obj->lpr_len) - 1. / sqrt(2.0), epsilon); BOOST_CHECK_SMALL(sum3(obj->lpr, obj->lpr_len) - 1. / sqrt(2.0), epsilon);
BOOST_CHECK_SMALL(sum3(obj->lpd, obj->lpd_len) - 1. / sqrt(2.0), epsilon); BOOST_CHECK_SMALL(sum3(obj->lpd, obj->lpd_len) - 1. / sqrt(2.0), epsilon);
wave_free(obj); wave_free(obj);
delete[] name;
} }
} }
@ -355,6 +376,7 @@ BOOST_AUTO_TEST_CASE(RBiorCoefTests)
BOOST_CHECK_SMALL(sum3(obj->lpr, obj->lpr_len) - 1. / sqrt(2.0), epsilon); BOOST_CHECK_SMALL(sum3(obj->lpr, obj->lpr_len) - 1. / sqrt(2.0), epsilon);
BOOST_CHECK_SMALL(sum3(obj->lpd, obj->lpd_len) - 1. / sqrt(2.0), epsilon); BOOST_CHECK_SMALL(sum3(obj->lpd, obj->lpd_len) - 1. / sqrt(2.0), epsilon);
wave_free(obj); wave_free(obj);
delete[] name;
} }
} }