66 for (
size_t i = 0; i < n; ++i)
67 a.
append(
static_cast<double>(1 + i % 17) / 17.0);
72 std::string text(
const size_t n)
75 for (
size_t i = 0; i < n; ++i)
76 s +=
static_cast<char>(
'a' + (i * 7) % 5);
83 for (
const T & item : items)
91 for (
size_t i = 0; i < signal.
size(); ++i)
92 for (
size_t j = 0; j < kernel.
size(); ++j)
93 out(i + j) += signal[i] * kernel[j];
102 for (
size_t n = 0; n < x.
size(); ++n)
106 acc += b[
k] * x[n -
k];
108 acc -= a[
k] *
y[n -
k];
117 for (
size_t i = 0; i < got.
size(); ++i)
118 EXPECT_NEAR(got[i],
expected[i], 1e-9);
126 static F::Plan
make(
const size_t n) {
return F::Plan(n | 1); }
127 static bool is_empty(
const F::Plan & p) {
return p.size() == 0; }
128 static void use(F::Plan & p)
131 for (
size_t i = 0; i < a.
size(); ++i)
132 a(i) =
Complex(
static_cast<double>(i % 7), 1.0);
133 const Array<Complex> back = p.inverse_transform(p.transformed(a));
135 for (
size_t i = 0; i < a.
size(); ++i)
136 EXPECT_LT(std::abs(back[i] - a[i]), 1e-9);
144 static F::OverlapAdd
make(
const size_t n)
146 F::OverlapAdd c(ramp(n / 10 + 1), n);
147 (void) c.process_block(ramp(n));
152 return c.kernel().is_empty()
and c.block_size() == 0
and c.fft_size() == 0
153 and c.overlap_size() == 0;
155 static void use(F::OverlapAdd & c)
157 if (c.kernel().is_empty())
160 EXPECT_THROW((
void) c.process_block(ramp(8)), std::runtime_error);
161 EXPECT_THROW((
void) c.pprocess_block(pool, ramp(8)), std::runtime_error);
162 EXPECT_THROW((
void) c.convolve(ramp(8)), std::runtime_error);
163 EXPECT_THROW((
void) c.pconvolve(pool, ramp(8)), std::runtime_error);
165 EXPECT_TRUE(c.flush().is_empty());
171 expect_near(c.convolve(signal),
expected);
174 append_all(streamed, c.flush());
184 for (
size_t c = 0; c < channels; ++c)
188 static F::OverlapAddBank
make(
const size_t n)
190 F::OverlapAddBank b(n < 10 ? 1 : 3, ramp(n / 10 + 1), n);
191 (void) b.process_block(signals(b.num_channels(), n));
196 return b.num_channels() == 0
and b.kernel().is_empty()
and b.block_size() == 0
197 and b.overlap_size() == 0;
199 static void use(F::OverlapAddBank & b)
201 if (b.kernel().is_empty())
205 EXPECT_THROW((
void) b.process_block(
none), std::runtime_error);
206 EXPECT_THROW((
void) b.pprocess_block(pool,
none), std::runtime_error);
207 EXPECT_THROW((
void) b.convolve(
none), std::runtime_error);
208 EXPECT_THROW((
void) b.pconvolve(pool,
none), std::runtime_error);
210 EXPECT_TRUE(b.flush().is_empty());
216 ASSERT_EQ(
out.size(), in.
size());
220 ASSERT_EQ(streamed.
size(), in.
size());
222 for (
size_t c = 0; c < in.
size(); ++c)
226 append_all(streamed(c), tails[c]);
234 static F::OverlapSave
make(
const size_t n)
236 F::OverlapSave c(ramp(n / 10 + 1), n);
237 (void) c.process_block(ramp(n + n / 2));
242 return c.kernel().is_empty()
and c.block_size() == 0
and c.fft_size() == 0
243 and c.overlap_size() == 0;
245 static void use(F::OverlapSave & c)
247 if (c.kernel().is_empty())
249 EXPECT_THROW((
void) c.process_block(ramp(8)), std::runtime_error);
250 EXPECT_THROW((
void) c.convolve(ramp(8)), std::runtime_error);
252 EXPECT_TRUE(c.flush().is_empty());
258 expect_near(c.convolve(signal),
expected);
260 append_all(streamed, c.flush());
267 static F::PartitionedConvolver
make(
const size_t n)
269 F::PartitionedConvolver c(ramp(n + 1), n < 10 ? 2 : 32);
270 (void) c.process_block(ramp(n / 2 + 1));
273 static bool is_empty(
const F::PartitionedConvolver & c)
275 return c.kernel().is_empty()
and c.partition_size() == 0
and c.fft_size() == 0;
277 static void use(F::PartitionedConvolver & c)
279 if (c.kernel().is_empty())
281 EXPECT_THROW((
void) c.process_block(ramp(8)), std::runtime_error);
282 EXPECT_THROW((
void) c.convolve(ramp(8)), std::runtime_error);
284 EXPECT_TRUE(c.flush().is_empty());
288 const Array<double> signal = ramp(3 * c.partition_size() + 1);
290 expect_near(c.convolve(signal),
expected);
292 append_all(streamed, c.flush());
304 static F::STFTProcessor
make(
const size_t n)
306 const size_t frame = n < 10 ? 2 : n / 4;
308 o.hop_size = frame / 2;
309 F::STFTProcessor s(ramp(frame), o);
310 (void) s.process_block(ramp(n));
315 return not s.configured()
and s.frame_size() == 0
and s.fft_size() == 0;
319 if (not s.configured())
321 F::STFTProcessor
copy(s);
322 return copy.process_block(ramp(3 * s.frame_size()));
324 static void use(F::STFTProcessor & s)
326 if (not s.configured())
328 EXPECT_THROW((
void) s.process_block(ramp(8)), std::runtime_error);
329 EXPECT_THROW(s.reset(), std::runtime_error);
334 o.hop_size = s.hop_size();
335 o.fft_size = s.fft_size();
336 o.centered = s.centered();
337 o.pad_end = s.pad_end();
342 append_all(frames, s.flush());
344 for (
size_t f = 0; f < frames.
size(); ++f)
347 for (
size_t k = 0;
k < frames[f].
size(); ++
k)
348 EXPECT_LT(std::abs(frames[f][
k] -
expected[f][
k]), 1e-9);
355 static F::ISTFTOptions
options(
const size_t hop)
363 const size_t fft,
const size_t n)
368 return F::stft(ramp(n), ramp(frame), o);
370 static F::ISTFTProcessor
make(
const size_t n)
372 const size_t frame = n < 10 ? 2 : n / 4;
373 const size_t fft = std::bit_ceil(frame);
374 F::ISTFTProcessor p(fft, ramp(frame),
options(frame / 2));
375 (void) p.process_block(spectrogram(frame, frame / 2, fft, n));
380 return not p.configured()
and p.frame_size() == 0
and p.fft_size() == 0;
384 if (not p.configured())
386 F::ISTFTProcessor
copy(p);
387 return copy.process_block(
388 spectrogram(p.frame_size(), p.hop_size(), p.fft_size(), 3 * p.frame_size()));
390 static void use(F::ISTFTProcessor & p)
392 if (not p.configured())
394 EXPECT_THROW((
void) p.process_frame(
Array<Complex>({Complex(1.0, 0.0)})),
396 EXPECT_THROW((
void) p.flush(), std::runtime_error);
401 spectrogram(p.frame_size(), p.hop_size(), p.fft_size(), 5 * p.frame_size());
405 append_all(streamed, p.flush());
412 static F::LFilter
make(
const size_t n)
414 const bool small = n < 10;
417 (void) f.filter(ramp(n));
422 return not f.configured()
and f.order() == 0
and f.state().is_empty();
426 if (not f.configured())
429 return copy.filter(ramp(20));
431 static void use(F::LFilter & f)
433 if (not f.configured())
435 EXPECT_THROW((
void) f.filter(ramp(8)), std::runtime_error);
436 EXPECT_THROW(f.reset(), std::runtime_error);
442 expect_near(f.filter(signal),
443 direct_iir(signal, f.coefficients().numerator, f.coefficients().denominator));
444 EXPECT_EQ(f.state().size(), f.order());
452 static F::BiquadSection
section() {
return {0.2, 0.3, 0.1, 1.0, -0.4, 0.1}; }
453 static F::SOSFilter
make(
const size_t n)
456 (void) f.filter(ramp(n));
461 return not f.configured()
and f.num_sections() == 0;
465 if (not f.configured())
467 F::SOSFilter
copy(f);
468 return copy.filter(ramp(20));
470 static void use(F::SOSFilter & f)
472 if (not f.configured())
474 EXPECT_THROW((
void) f.filter(ramp(8)), std::runtime_error);
475 EXPECT_THROW(f.reset(), std::runtime_error);
482 for (
size_t i = 0; i < f.num_sections(); ++i)
484 expect_near(f.filter(signal),
expected);
485 for (
size_t i = 0; i < f.num_sections(); ++i)
486 EXPECT_EQ(f.state(i).size(), 2u);
499 for (
size_t i = 0; i < a.
size(); ++i)
503 for (
size_t i = 0; i < a.
size(); ++i)
504 EXPECT_EQ(back[i], a[i]);
522 for (
size_t i = 0; i < n; ++i)
534 EXPECT_FALSE(ac.
pattern(i).empty());
540 found = found or (
m.pattern_id ==
id and m.position == 2);
562 EXPECT_GT(sam.
states()[i].len, 0u);
585 for (
const size_t child : node.children)
590 ASSERT_EQ(positions.
size(), 2u);
591 EXPECT_EQ(positions[0], 1u);
592 EXPECT_EQ(positions[1], 3u);
601 for (
size_t i = 0; i < n; ++i)
610 EXPECT_EQ(t.
query(-1, 1 << 20, -1, 1 << 20).size(), t.
size());
616 EXPECT_EQ(t.
size(), 2u);
617 EXPECT_EQ(t.
query(0, 2, 0, 3).size(), 1u);
626 for (
size_t i = 0; i < n; ++i)
627 entries.
append({Rectangle(i, i, i + 2, i + 2), i});
642 EXPECT_THROW((
void) t.
root_bbox(), std::domain_error);
652 ASSERT_EQ(hits.
size(), 1u);
653 EXPECT_EQ(hits[0], 7u);
662 for (
size_t i = 0; i < n; ++i)
663 (
void) c(
static_cast<int>(i));
673 const size_t before = c.
size();
675 EXPECT_EQ(c.
size(), before + 1);
684using Numeric = ::testing::Types<F::Plan, F::OverlapAdd, F::OverlapAddBank, F::OverlapSave,
685 F::PartitionedConvolver, F::STFTProcessor, F::ISTFTProcessor,
Multi-pattern string matching with the Aho-Corasick automaton.
Suffix structures: suffix array/LCP, suffix tree, suffix automaton.
size_t size_t int32_t * out
Axis-aligned bounding box tree for spatial queries.
Rectangle root_bbox() const
Return the root bounding box (union of all entries).
size_t build(Array< size_t > &idx, const size_t lo, const size_t hi)
bool is_empty() const
Whether the tree is empty.
size_t size() const
Number of entries.
DebugSnapshot debug_snapshot() const
Return the full tree structure for visualization/debug.
Array< size_t > query(const Rectangle &query) const
Find all entries whose bounding box overlaps the query rectangle.
Array< size_t > query_point(const Point &p) const
Find all entries whose bounding box contains the query point.
Aho-Corasick multi-pattern automaton.
const std::string & pattern(const size_t id) const
Return the pattern text by id.
bool contains_any(const std::string_view text) const
Return true if at least one pattern appears in the text.
void clear()
Clear all patterns and reset to an empty automaton.
size_t pattern_count() const noexcept
Return the number of inserted patterns.
bool is_built() const noexcept
Return whether build() has been executed since last insertion.
void build()
Build failure links and transition completion.
size_t add_pattern(std::string pattern)
Add one pattern to the automaton.
Array< Match > search(const std::string_view text) const
Search all patterns in a text.
Simple dynamic array with automatic resizing and functional operations.
constexpr size_t size() const noexcept
Return the number of elements stored in the stack.
static Array create(const size_t n)
Create an array with n logical elements.
T & append(const T &data)
Append a copy of data
Doubly-linked list (defined in tpl_dynList.H).
T & append(const T &item)
T & get_last()
Return the last item of the list.
size_t size() const noexcept
Return the number of items of the list, in constant time.
constexpr bool is_empty() const noexcept
Precomputed plans for NTT transforms.
Array< uint64_t > multiply(const Array< uint64_t > &a, const Array< uint64_t > &b) const
Multiply two polynomials using this plan size.
size_t size() const noexcept
Return the transform size bound to the plan.
Array< uint64_t > transformed(const Array< uint64_t > &input, const bool invert=false) const
Transform an input array and return the result.
Number Theoretic Transform over Z / MOD Z.
Naive compressed suffix tree (didactic implementation).
Array< size_t > find_all(const std::string_view pattern) const
Return all occurrences of a pattern.
size_t node_count() const noexcept
Return the number of nodes in the tree.
void build(const std::string_view text)
Build or rebuild the suffix tree for text.
size_t text_size() const noexcept
Return the text size (without terminal marker).
bool contains(const std::string_view pattern) const
Return true if the pattern appears in the text.
const Array< Node > & nodes() const noexcept
Return the internal node array for inspection/debugging.
Represents a point with rectangular coordinates in a 2D plane.
Static 2D range tree for orthogonal range queries.
bool is_empty() const noexcept
DynList< Point > query(const Geom_Number &xmin, const Geom_Number &xmax, const Geom_Number &ymin, const Geom_Number &ymax) const
Query: return all points inside [xmin,xmax] × [ymin,ymax].
size_t size() const noexcept
void build(const DynList< Point > &points)
Build the range tree from a point set.
DebugSnapshot debug_snapshot() const
Return structural snapshot for visualization/debug.
An axis-aligned rectangle.
const Geom_Number & get_xmin() const
Gets the minimum x-coordinate.
Collector that stores accepted solutions in an Aleph list.
size_t size() const noexcept
Number of collected solutions.
const Container_Type & solutions() const noexcept
Access the collected solutions.
bool is_empty() const noexcept
Return true if no solution has been collected.
void clear() noexcept
Remove all collected solutions.
Suffix automaton (SAM) over byte alphabet.
std::string longest_common_substring(const std::string_view other) const
Find the longest common substring between the built SAM text and other.
void build(const std::string_view text)
Build the SAM from an entire string.
bool contains(const std::string_view pattern) const
Return true if pattern is a substring of the built text.
const Array< State > & states() const noexcept
Access the internal states array for testing/inspection.
size_t distinct_substring_count() const
Count the number of distinct substrings in the built text.
size_t state_count() const noexcept
Return the number of states in the SAM.
void clear()
Reset the automaton to its initial empty state (root only).
void extend(const char ch)
Extend the SAM with a single character.
A reusable thread pool for efficient parallel task execution.
Minimal std::expected-style result type for C++20.
The typed suite of the moved-from tests.
Fast Fourier Transform (FFT) and Digital Signal Processing (DSP) toolkit.
Computational geometry algorithms.
The pattern test of the moved-from objects.
INSTANTIATE_TYPED_TEST_SUITE_P(Numeric, MovedFrom, Numeric)
::testing::Types< F::Plan, F::OverlapAdd, F::OverlapAddBank, F::OverlapSave, F::PartitionedConvolver, F::STFTProcessor, F::ISTFTProcessor, F::LFilter, F::SOSFilter, N::Plan, Aho_Corasick, Suffix_Automaton, Naive_Suffix_Tree, RangeTree2D, AABBTree, Collector > Numeric
Main namespace for Aleph-w library functions.
size_t size(Node *root) noexcept
See compute_cardinality_rec(Node * root).
Itor2 copy(Itor1 sourceBeg, const Itor1 &sourceEnd, Itor2 destBeg)
Copy elements from one range to another.
std::decay_t< typename HeadC::Item_Type > T
and
Check uniqueness with explicit hash + equality functors.
T product(const Container &container, const T &init=T{1})
Compute product of all elements.
bool none(const Container &container, Operation &operation)
Return true if no element satisfies operation.
static struct argp_option options[]
Industrial-grade Number Theoretic Transform core for modular polynomial multiplication.
static void section(const string &title)
Common infrastructure for implicit state-space search.
Array< DebugNode > nodes
Array of all nodes in debug format.
One match occurrence in the searched text.
Array< Point > x_sorted_points
The underlying x-sorted point array.
static void use(AABBTree &t)
static AABBTree make(const size_t n)
static bool is_empty(const AABBTree &t)
static Aho_Corasick make(const size_t n)
static bool is_empty(const Aho_Corasick &ac)
static void use(Aho_Corasick &ac)
static Collector make(const size_t n)
static bool is_empty(const Collector &c)
static void use(Collector &c)
static F::ISTFTProcessor make(const size_t n)
static Array< Array< Complex > > spectrogram(const size_t frame, const size_t hop, const size_t fft, const size_t n)
static F::ISTFTOptions options(const size_t hop)
static void use(F::ISTFTProcessor &p)
static Array< double > fingerprint(const F::ISTFTProcessor &p)
static bool is_empty(const F::ISTFTProcessor &p)
static Array< double > fingerprint(const F::LFilter &f)
static void use(F::LFilter &f)
static F::LFilter make(const size_t n)
static bool is_empty(const F::LFilter &f)
static bool is_empty(const F::OverlapAddBank &b)
static void use(F::OverlapAddBank &b)
static F::OverlapAddBank make(const size_t n)
static Array< Array< double > > signals(const size_t channels, const size_t n)
static void use(F::OverlapAdd &c)
static F::OverlapAdd make(const size_t n)
static bool is_empty(const F::OverlapAdd &c)
static void use(F::OverlapSave &c)
static F::OverlapSave make(const size_t n)
static bool is_empty(const F::OverlapSave &c)
static F::PartitionedConvolver make(const size_t n)
static void use(F::PartitionedConvolver &c)
static bool is_empty(const F::PartitionedConvolver &c)
static void use(F::Plan &p)
static F::Plan make(const size_t n)
static bool is_empty(const F::Plan &p)
static bool is_empty(const F::SOSFilter &f)
static F::BiquadSection section()
static F::SOSFilter make(const size_t n)
static void use(F::SOSFilter &f)
static Array< double > fingerprint(const F::SOSFilter &f)
static F::STFTProcessor make(const size_t n)
static Array< Array< Complex > > fingerprint(const F::STFTProcessor &s)
static bool is_empty(const F::STFTProcessor &s)
static void use(F::STFTProcessor &s)
static N::Plan make(const size_t n)
static void use(N::Plan &p)
static bool is_empty(const N::Plan &p)
static bool is_empty(const Naive_Suffix_Tree &t)
static void use(Naive_Suffix_Tree &t)
static Naive_Suffix_Tree make(const size_t n)
static RangeTree2D make(const size_t n)
static void use(RangeTree2D &t)
static bool is_empty(const RangeTree2D &t)
static void use(Suffix_Automaton &sam)
static Suffix_Automaton make(const size_t n)
static bool is_empty(const Suffix_Automaton &sam)
How the moved-from tests build, check and use objects of a class.
FooMap m(5, fst_unit_pair_hash, snd_unit_pair_hash)