void realrft ( double *in, unsigned n, double *out ) { COMPLEX *c_in, *c_out; unsigned i; if (n == 0 || (c_in = (COMPLEX *) malloc (n * sizeof (COMPLEX))) == 0 || (c_out = (COMPLEX *) malloc (n * sizeof (COMPLEX))) == 0) return; c_re (c_in [0]) = in [0]; /* dc */ c_im (c_in [0]) = 0; for (i = 1; i < (n + 1) / 2; i++) { /* geconj. symm. harmonischen */ c_re (c_in [i]) = in [2 * i - 1] / 2; c_im (c_in [i]) = in [2 * i] / -2; c_re (c_in [n - i]) = in [2 * i - 1] / 2; c_im (c_in [n - i]) = in [2 * i] / 2; } if (n % 2 == 0) { /* Nyquist */ c_re (c_in [n / 2]) = in [n - 1]; c_im (c_in [n / 2]) = 0; } rft (c_in, n, c_out); for (i = 0; i < n; i++) out [i] = c_re (c_out [i]); free ((char *) c_in); free ((char *) c_out); }
Var* ff_fft(vfuncptr func, Var* arg) { Var *real = NULL, *img = NULL; double* data; int i, j, n, x, y, z; COMPLEX *in, *out; Alist alist[4]; alist[0] = make_alist("real", ID_VAL, NULL, &real); alist[1] = make_alist("img", ID_VAL, NULL, &img); alist[2].name = NULL; if (parse_args(func, arg, alist) == 0) return (NULL); if (real == NULL && img == NULL) { parse_error("%s: No real or imaginary objects specified\n", func->name); return (NULL); } x = GetSamples(V_SIZE(real), V_ORG(real)); y = GetLines(V_SIZE(real), V_ORG(real)); z = GetBands(V_SIZE(real), V_ORG(real)); if (img == NULL && x == 2) { n = y * z; in = (COMPLEX*)calloc(n, sizeof(COMPLEX)); out = (COMPLEX*)calloc(n, sizeof(COMPLEX)); for (i = 0; i < y; i++) { for (j = 0; j < z; j++) { in[i].re = extract_double(real, cpos(0, i, j, real)); in[i].im = extract_double(real, cpos(1, i, j, real)); } } } else { n = V_DSIZE(real); in = (COMPLEX*)calloc(n, sizeof(COMPLEX)); out = (COMPLEX*)calloc(n, sizeof(COMPLEX)); for (i = 0; i < n; i++) { in[i].re = extract_double(real, i); in[i].im = (img == NULL ? 0.0 : extract_double(img, i)); } } if (func->fdata == (void*)1) { fft(in, n, out); } else { rft(in, n, out); } data = (double*)calloc(n * 2, sizeof(double)); for (i = 0; i < n; i++) { data[i * 2] = out[i].re; data[i * 2 + 1] = out[i].im; } return (newVal(BSQ, 2, n, 1, DV_DOUBLE, data)); }
///Basic test for ReferenceFilterTask class. Tests the whole pipeline. TEST ( HifstReferenceFilter, basic_test ) { //Create test fst file expecto.fst. typedef fst::LexicographicArc< fst::StdArc::Weight, fst::StdArc::Weight> Arc; typedef fst::LexicographicWeight<fst::StdArc::Weight, fst::StdArc::Weight> Weight; fst::VectorFst<Arc> aux; fst::MakeWeight<Arc> mw; aux.AddState(); aux.AddState(); aux.AddState(); aux.SetStart ( 0 ); aux.SetFinal ( 2, Arc::Weight::One() ); aux.AddArc ( 0, Arc ( 10, 10, mw ( 0 ), 1 ) ); aux.AddArc ( 1, Arc ( 100, 100, mw ( 0 ), 2 ) ); fst::FstWrite ( aux, "expecto.fst" ); //Prepare RegistryPO object. unordered_map<std::string, boost::any> v; v[HifstConstants::kReferencefilterLoad] = std::string ( "expecto.fst" ); v[HifstConstants::kReferencefilterWrite] = std::string ( "" ); v[HifstConstants::kReferencefilterSubstring] = std::string ("yes"); v[HifstConstants::kReferencefilterPrunereferenceweight] = float ( std::numeric_limits<float>::max() ); v[HifstConstants::kReferencefilterPrunereferenceshortestpath] = unsigned ( std::numeric_limits<unsigned>::max() ); DataForReferenceFilter d; d.sidx = 0; const uu::RegistryPO rg ( v ); uh::ReferenceFilterTask<DataForReferenceFilter> rft ( rg ); EXPECT_EQ ( rft.getBuilt(), false ); EXPECT_EQ ( rft.getDisableSubString(), false ); EXPECT_EQ ( rft.getWeight(), std::numeric_limits<float>::max() ); EXPECT_EQ ( rft.getShortestPath(), std::numeric_limits<unsigned>::max() ); EXPECT_EQ ( rft.getVocabulary().size(), 0 ); EXPECT_EQ ( rft.getTranslationLatticeFile(), "expecto.fst" ); rft.run ( d ); EXPECT_EQ ( rft.getBuilt(), true ); ASSERT_EQ ( d.tvcb.size(), 2 ); EXPECT_TRUE ( d.tvcb.find ( "10" ) != d.tvcb.end() ); EXPECT_TRUE ( d.tvcb.find ( "100" ) != d.tvcb.end() ); ASSERT_EQ ( d.filters.size(), 1 ); EXPECT_EQ ( d.filters[0]->NumStates(), 3 ); std::stringstream ss; fst::PrintFst ( *d.filters[0], &ss ); EXPECT_EQ ( ss.str(), "0\t1\t10\t10\n0\t2\t100\t100\n0\n1\t2\t100\t100\n1\n2\n" ); bfs::remove ( bfs::path ( "expecto.fst" ) ); };
///Basic test for ReferenceFilterTask class. Tests the whole pipeline. TEST ( HifstReferenceFilter, empty ) { //Prepare RegistryPO object. unordered_map<std::string, boost::any> v; v[HifstConstants::kReferencefilterLoad] = std::string ( "" ); v[HifstConstants::kReferencefilterWrite] = std::string ( "" ); v[HifstConstants::kReferencefilterSubstring] = std::string ("yes"); v[HifstConstants::kReferencefilterPrunereferenceweight] = float ( std::numeric_limits<float>::max() ); v[HifstConstants::kReferencefilterPrunereferenceshortestpath] = unsigned ( std::numeric_limits<unsigned>::max() ); DataForReferenceFilter d; d.sidx = 0; const uu::RegistryPO rg ( v ); uh::ReferenceFilterTask<DataForReferenceFilter> rft ( rg ); rft.run ( d ); EXPECT_EQ ( rft.getBuilt(), false ); ASSERT_EQ ( d.filters.size(), 0 ); };
inline std::complex<T> GetRF (const double t) const { std::complex<T> rft (0.,0.); for (size_t i = 0; i < _rfs.size(); ++i) rft += (*_rfs[i])(t); return rft; }