mirror of
https://github.com/ETLCPP/etl.git
synced 2026-04-30 19:09:10 +08:00
Completed maths documentation
This commit is contained in:
parent
303ba36f6d
commit
dbf0477d88
@ -1,29 +1,52 @@
|
||||
Invert
|
||||
20.9.0
|
||||
---
|
||||
title: "Invert"
|
||||
---
|
||||
|
||||
{{< callout type="info">}}
|
||||
Header: `invert.h`
|
||||
Since: `20.9.0`
|
||||
{{< /callout >}}
|
||||
|
||||
Invert an input range.
|
||||
|
||||
```cpp
|
||||
template <typename TInput>
|
||||
class invert : public etl::unary_function<TInput, TInput>
|
||||
```
|
||||
|
||||
TInput The input data type.
|
||||
____________________________________________________________________________________________________
|
||||
``TInput``` The input data type.
|
||||
|
||||
```cpp
|
||||
invert()
|
||||
offset = 0
|
||||
minuend = etl::numeric_limits<TInput>::is_signed) ? TInput(0)
|
||||
: etl::numeric_limits<TInput>::max())
|
||||
If the type is signed then the input values have their sign changed.
|
||||
i.e. 10 => -10, -10 => 10.
|
||||
```
|
||||
**Description**
|
||||
`offset` = 0
|
||||
`minuend` = `etl::numeric_limits<TInput>::is_signed) ? TInput(0)
|
||||
: etl::numeric_limits<TInput>::max())`
|
||||
|
||||
If the type is signed then the input values have their sign changed.
|
||||
i.e. `10` => `-10`, `-10` => `10`.
|
||||
If the type is unsigned then the input values are subtracted from the type's maximum value.
|
||||
|
||||
invert(TInput offset, TInput minuend)
|
||||
Sets the offset and minuend.
|
||||
____________________________________________________________________________________________________
|
||||
TInput operator()(TInput value) const
|
||||
Invert a value.
|
||||
Calculates minuend - (value - offset)
|
||||
____________________________________________________________________________________________________
|
||||
Example
|
||||
---
|
||||
|
||||
```cpp
|
||||
invert(TInput offset, TInput minuend)
|
||||
```
|
||||
**Description**
|
||||
Sets the offset and minuend.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
TInput operator()(TInput value) const
|
||||
```
|
||||
**Description**
|
||||
Invert a value.
|
||||
Calculates `minuend - (value - offset)`
|
||||
|
||||
## Example
|
||||
```cpp
|
||||
std::array<int, 10> input =
|
||||
{
|
||||
10, 11, 12, 13, 14, 15, 16, 17, 18, 19
|
||||
@ -36,4 +59,4 @@ etl::invert<int> invert(10, 100); // offset = 10, minuend = 100
|
||||
std::transform(input.begin(), input.end(), output.begin(), invert);
|
||||
|
||||
// output = 100.0, 99.0, 98.0, 97.0, 96.0, 95.0, 94.0, 93.0, 92.0, 91.0
|
||||
|
||||
```
|
||||
12
docs/maths/is_negative.md
Normal file
12
docs/maths/is_negative.md
Normal file
@ -0,0 +1,12 @@
|
||||
---
|
||||
title: "is_negative"
|
||||
---
|
||||
|
||||
Allows a parameter of type `T` to be checked for a positive or negative value, while eliminating compiler warnings for checking `< 0` for unsigned types.
|
||||
|
||||
```cpp
|
||||
template <typename T>
|
||||
ETL_CONSTEXPR bool is_negative(const T value)
|
||||
```
|
||||
**Return**
|
||||
`true` if the value is negative, otherwise `false`.
|
||||
50
docs/maths/limiter.md
Normal file
50
docs/maths/limiter.md
Normal file
@ -0,0 +1,50 @@
|
||||
---
|
||||
title: "limiter"
|
||||
---
|
||||
|
||||
{{< callout type="info">}}
|
||||
Header: `limiter.h`
|
||||
Since: `20.9.0`
|
||||
{{< /callout >}}
|
||||
|
||||
Limits an input range.
|
||||
|
||||
```cpp
|
||||
template <typename TInput, typename TCompare = etl::less<TInput> >
|
||||
class limit : public etl::unary_function<TInput, TInput>
|
||||
```
|
||||
|
||||
`TInput` The input data type.
|
||||
`TCompare` The functor type used to compare values to the threshold. The default is `etl::less`.
|
||||
|
||||
```cpp
|
||||
limit(TInput lowest, TInput highest)
|
||||
```
|
||||
**Description**
|
||||
`lowest` The lowest limit.
|
||||
`highest` The highest limit.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
TInput operator()(TInput value) const
|
||||
```
|
||||
**Return**
|
||||
The limited value.
|
||||
|
||||
```cpp
|
||||
Example
|
||||
|
||||
std::array<int, 10> input =
|
||||
{
|
||||
10, 11, 12, 13, 14, 15, 16, 17, 18, 19
|
||||
};
|
||||
|
||||
std::array<int, 10> output;
|
||||
|
||||
etl::limiter<int> limiter(13, 16);
|
||||
|
||||
std::transform(input.begin(), input.end(), output.begin(), limiter);
|
||||
|
||||
// output = 13, 13, 13, 13, 14, 15, 16, 16, 16, 16
|
||||
```
|
||||
114
docs/maths/mean.md
Normal file
114
docs/maths/mean.md
Normal file
@ -0,0 +1,114 @@
|
||||
---
|
||||
title: "mean"
|
||||
---
|
||||
|
||||
{{< callout type="info">}}
|
||||
Header: `mean.h`
|
||||
Since: `20.9.0`
|
||||
{{< /callout >}}
|
||||
|
||||
```cpp
|
||||
template <typename TInput, typename TCalc = TInput>
|
||||
class mean : public etl::unary_function<TInput, void>
|
||||
```
|
||||
|
||||
`TInput` The input data type.
|
||||
`TCalc` The type to use for internal calculations. By default, equal to `TInput`.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
mean()
|
||||
```
|
||||
**Description**
|
||||
Default constructor.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
template <typename TIterator>
|
||||
mean(TIterator first, TIterator last)
|
||||
```
|
||||
**Description**
|
||||
Construct from an iterator range.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
void add(TInput value1)
|
||||
```
|
||||
**Description**
|
||||
Add a value.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
template <typename TIterator>
|
||||
void add(TIterator first, TIterator last)
|
||||
```
|
||||
**Description**
|
||||
Add a range of values.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
void operator()(TInput value)
|
||||
```
|
||||
**Description**
|
||||
Add a values.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
template <typename TIterator>
|
||||
void operator()(TIterator first, TIterator last)
|
||||
```
|
||||
**Description**
|
||||
Add a range of values.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
double get_mean() const
|
||||
```
|
||||
**Description**
|
||||
Returns the calculated mean for the data.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
operator double() const
|
||||
```
|
||||
**Return**
|
||||
The calculated mean for the data.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
size_t count() const
|
||||
```
|
||||
**Description**
|
||||
Get the total number added entries.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
void clear()
|
||||
```
|
||||
**Description**
|
||||
Clear the mean.
|
||||
|
||||
## Example
|
||||
|
||||
```cpp
|
||||
std::array<char, 10> input
|
||||
{
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9
|
||||
};
|
||||
|
||||
etl::mean<char, int32_t> mean(input.begin(), input.end());
|
||||
|
||||
double mean_result;
|
||||
|
||||
mean_result = mean; // mean_result == 4.5
|
||||
```
|
||||
@ -1,88 +1,159 @@
|
||||
pseudo_moving_average
|
||||
---
|
||||
title: "pseudo_moving_average"
|
||||
---
|
||||
|
||||
A moving average algorithm that continuously calculates an average value from a stream of samples.
|
||||
The sample size does not affect the size of the instantiated object. There is no overhead based on the number of samples as it simulates a window of N values from the current average.
|
||||
A moving average algorithm that continuously calculates an average value from a stream of samples.
|
||||
The sample size does not affect the size of the instantiated object. There is no overhead based on the number of samples as it simulates a window of N values from the current average.
|
||||
|
||||
There are four variants of the algorithm; two for integral values and two for floating point. Each sub variant allows the selection of compile time or run time sample size.
|
||||
The integral variant allows a compile time scaling factor to emulate fixed point arithmetic.
|
||||
____________________________________________________________________________________________________
|
||||
Integral
|
||||
There are four variants of the algorithm; two for integral values and two for floating point. Each sub-variant allows the selection of compile time or run time sample size.
|
||||
The integral variant allows a compile time scaling factor to emulate fixed point arithmetic.
|
||||
|
||||
## Integral
|
||||
|
||||
```cpp
|
||||
template <typename T, const size_t SAMPLE_SIZE, const size_t SCALING>
|
||||
pseudo_moving_average;
|
||||
```
|
||||
|
||||
```cpp
|
||||
static const size_t SAMPLE_SIZE
|
||||
The number of samples averaged over.
|
||||
```
|
||||
The number of samples averaged over.
|
||||
If this value is zero, then the run time sample size specialisation is used.
|
||||
|
||||
```cpp
|
||||
static const size_t SCALING
|
||||
```
|
||||
The sample scaling factor.
|
||||
__________________________________________________________________________________________________
|
||||
pseudo_moving_average(const T initial_value)
|
||||
Constructs the object with the initial value for the average.
|
||||
__________________________________________________________________________________________________
|
||||
pseudo_moving_average(const T initial_value, const size_t sample_size)
|
||||
For runtime sample size specialisation only.
|
||||
Constructs the object with the initial value for the average and the sample size.
|
||||
__________________________________________________________________________________________________
|
||||
void clear(const T initial_value)
|
||||
Clears the object to the initial value for the average.
|
||||
__________________________________________________________________________________________________
|
||||
void add(T new_value)
|
||||
Adds a new sample value.
|
||||
__________________________________________________________________________________________________
|
||||
T value() const
|
||||
Returns the scaled value of the average.
|
||||
To unscale the returned value, use one of the rounding found in scaled_rounding.
|
||||
__________________________________________________________________________________________________
|
||||
iterator input()
|
||||
|
||||
```cpp
|
||||
pseudo_moving_average(const T initial_value)
|
||||
```
|
||||
**Description**
|
||||
Constructs the object with the initial value for the average.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
pseudo_moving_average(const T initial_value, const size_t sample_size)
|
||||
```
|
||||
**Description**
|
||||
*For runtime sample size specialisation only.*
|
||||
Constructs the object with the initial value for the average and the sample size.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
void clear(const T initial_value)
|
||||
```
|
||||
**Description**
|
||||
Clears the object to the initial value for the average.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
void add(T new_value)
|
||||
```
|
||||
**Description**
|
||||
Adds a new sample value.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
T value() const
|
||||
```
|
||||
**Description**
|
||||
Returns the scaled value of the average.
|
||||
To unscale the returned value, use one of the rounding found in scaled_rounding.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
iterator input()
|
||||
```
|
||||
**Description**
|
||||
Returns an iterator that allows the input of new values.
|
||||
|
||||
Example
|
||||
## Example
|
||||
```cpp
|
||||
std::array data{ 9, 1, 8, 2, 7, 3, 6, 4, 5 };
|
||||
etl::pseudo_moving_average<int, SAMPLE_SIZE, SCALING> cma(0);
|
||||
std::copy(data.begin(), data.end(), cma.input());
|
||||
int average = cma.value();
|
||||
__________________________________________________________________________________________________
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
void set_sample_size(const size_t sample_size)
|
||||
|
||||
For runtime sample size specialisation only.
|
||||
```
|
||||
**Description**
|
||||
For runtime sample size specialisation only.
|
||||
Sets the sample size.
|
||||
____________________________________________________________________________________________________
|
||||
Floating point
|
||||
|
||||
## Floating point
|
||||
|
||||
```cpp
|
||||
template <typename T, const size_t SAMPLE_SIZE>
|
||||
pseudo_moving_average;
|
||||
|
||||
```
|
||||
```cpp
|
||||
static const size_t SAMPLE_SIZE
|
||||
```
|
||||
The number of samples averaged over.
|
||||
__________________________________________________________________________________________________
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
pseudo_moving_average(const T initial_value)
|
||||
```
|
||||
**Description**
|
||||
Constructs the object with the initial value for the average.
|
||||
__________________________________________________________________________________________________
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
pseudo_moving_average(const T initial_value, const size_t sample_size)
|
||||
For runtime sample size specialisation only.
|
||||
```
|
||||
**Description**
|
||||
For runtime sample size specialisation only.
|
||||
Constructs the object with the initial value for the average and the sample size.
|
||||
__________________________________________________________________________________________________
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
void clear(const T initial_value)
|
||||
```
|
||||
**Description**
|
||||
Clears the object to the initial value for the average.
|
||||
__________________________________________________________________________________________________
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
void add(T new_value)
|
||||
```
|
||||
**Description**
|
||||
Adds a new sample value.
|
||||
__________________________________________________________________________________________________
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
T value() const
|
||||
```
|
||||
**Description**
|
||||
Returns the average value.
|
||||
__________________________________________________________________________________________________
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
void set_sample_size(const size_t sample_size)
|
||||
For runtime sample size specialisation only.
|
||||
```
|
||||
**Description**
|
||||
For runtime sample size specialisation only.
|
||||
Sets the sample size.
|
||||
____________________________________________________________________________________________________
|
||||
How It Works
|
||||
|
||||
If the current moving average is 5, then an equivalent sequence of samples (for a sample size of 9), that gives the same average, would be 5, 5, 5, 5, 5, 5, 5, 5, 5
|
||||
## How It Works
|
||||
|
||||
This means, to find the average when adding a new sample to a moving average that has a current value of 5, all we need to do is multiply the current average by the sample size (9), add the new sample, and divide by the sample size + 1 (10).
|
||||
|
||||
Wikipedia
|
||||
If the current moving average is 5, then an equivalent sequence of samples (for a sample size of 9), that gives the same average, would be 5, 5, 5, 5, 5, 5, 5, 5, 5
|
||||
|
||||
This means, to find the average when adding a new sample to a moving average that has a current value of 5, all we need to do is multiply the current average by the sample size (9), add the new sample, and divide by the sample size + 1 (10).
|
||||
@ -1,26 +1,47 @@
|
||||
Quantize
|
||||
20.9.0
|
||||
---
|
||||
title: "quantize"
|
||||
---
|
||||
|
||||
{{< callout type="info">}}
|
||||
Header: `quantize.h`
|
||||
Since: `20.9.0`
|
||||
{{< /callout >}}
|
||||
|
||||
Quantizes an input range.
|
||||
|
||||
```cpp
|
||||
template <typename TInput, typename TCompare = etl::less<TInput> >
|
||||
class quantize : public etl::unary_function<TInput, TInput>
|
||||
```
|
||||
|
||||
TInput The input data type.
|
||||
TCompare The functor type used to compare values to the threshold. The default is etl::less
|
||||
____________________________________________________________________________________________________
|
||||
`TInput` The input data type.
|
||||
`TCompare` The functor type used to compare values to the threshold. The default is `etl::less`.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
quantize(const TInput* p_thresholds,
|
||||
const TInput* p_quantizations,
|
||||
size_t n_quantizations,
|
||||
TCompare compare = TCompare())
|
||||
p_thresholds A pointer to the list of threshold values.
|
||||
p_quantizations A pointer to the list of quantization values. One more than the number of thresholds.
|
||||
n_quantizations The number of quantization values.
|
||||
____________________________________________________________________________________________________
|
||||
TInput operator()(TInput value) const
|
||||
Quantatize a value.
|
||||
____________________________________________________________________________________________________
|
||||
Example
|
||||
```
|
||||
**Description**
|
||||
`p_thresholds` A pointer to the list of threshold values.
|
||||
`p_quantizations` A pointer to the list of quantization values. One more than the number of thresholds.
|
||||
`n_quantizations` The number of quantization values.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
TInput operator()(TInput value) const
|
||||
```
|
||||
**Description**
|
||||
Quantatize a value.
|
||||
|
||||
---
|
||||
|
||||
## Example
|
||||
```cpp
|
||||
constexpr size_t Size = 20U;
|
||||
constexpr size_t NThresholds = 4U;
|
||||
|
||||
@ -46,4 +67,4 @@ etl::quantize<int> quantize(thresholds.data(), quantizations.data(), quantizatio
|
||||
std::transform(input.begin(), input.end(), output.begin(), quantize);
|
||||
|
||||
// output = 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 5, 5
|
||||
|
||||
```
|
||||
18
docs/maths/radix.md
Normal file
18
docs/maths/radix.md
Normal file
@ -0,0 +1,18 @@
|
||||
---
|
||||
title: "radix"
|
||||
---
|
||||
|
||||
A smart enumeration to encode radix constants.
|
||||
|
||||
```cpp
|
||||
struct radix
|
||||
```
|
||||
|
||||
**Defines the constants**
|
||||
```cpp
|
||||
undefined
|
||||
binary
|
||||
octal
|
||||
decimal
|
||||
hex
|
||||
```
|
||||
325
docs/maths/random.md
Normal file
325
docs/maths/random.md
Normal file
@ -0,0 +1,325 @@
|
||||
---
|
||||
title: "random"
|
||||
---
|
||||
|
||||
Utilities for producing random numbers.
|
||||
|
||||
## random
|
||||
The base class for all 32 bit random number generators.
|
||||
|
||||
If `ETL_POLYMORPHIC_RANDOM` is defined, then the base class will have the following members, otherwise the base is empty.
|
||||
|
||||
```cpp
|
||||
virtual ~random();
|
||||
virtual void initialise(uint32_t seed) = 0;
|
||||
virtual uint32_t operator()() = 0;
|
||||
virtual uint32_t range(uint32_t low, uint32_t high) = 0;
|
||||
```
|
||||
|
||||
## random_xorshift
|
||||
Uses a 128bit XOR shift algorithm for producing a pseudo-random sequence of integers.
|
||||
The result is a 32 bit integer between 0 and 4,294,967,295 (2^32 - 1).
|
||||
|
||||
```cpp
|
||||
random_xor_shift()
|
||||
```
|
||||
**Description**
|
||||
Constructor.
|
||||
Uses the address of the object as the seed for the sequence.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
random_xor_shift(uint32_t seed)
|
||||
```
|
||||
**Description**
|
||||
Constructor.
|
||||
Uses seed as the `seed` for the sequence.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
void initialise(uint32_t seed)
|
||||
```
|
||||
**Description**
|
||||
Sets the seed as the new seed for the sequence.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
uint32_t operator()()
|
||||
```
|
||||
**Return**
|
||||
The next number in the pseudo-random sequence.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
uint32_t range(uint32_t low, uint32_t high)
|
||||
```
|
||||
** Return**
|
||||
A number between the specified ranges, inclusive.
|
||||
|
||||
## random_lcg
|
||||
Generates a 32 bit pseudo-random number using a linear congruent generator.
|
||||
The result is a 32 bit integer between 0 and 2,147,483,647 (2^31 - 1).
|
||||
|
||||
```cpp
|
||||
random_lcg()
|
||||
```
|
||||
**Description**
|
||||
Constructor.
|
||||
Uses the address of the object as the seed for the sequence
|
||||
|
||||
---
|
||||
```cpp
|
||||
random_lcg(uint32_t seed)
|
||||
```
|
||||
**Description**
|
||||
Constructor.
|
||||
Uses seed as the seed for the sequence.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
void initialise(uint32_t seed)
|
||||
```
|
||||
**Description**
|
||||
Sets the seed as the new seed for the sequence.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
uint32_t operator()()
|
||||
```
|
||||
**Return**
|
||||
The next number in the pseudo-random sequence.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
uint32_t range(uint32_t low, uint32_t high)
|
||||
```
|
||||
**Return**
|
||||
A number between the specified ranges, inclusive.
|
||||
|
||||
## random_clcg
|
||||
Generates a 32 bit pseudo-random number using a combined linear congruent generator.
|
||||
The result is a 32 bit integer between 0 and 2,147,483,647 (2^31 - 1).
|
||||
|
||||
```cpp
|
||||
random_clcg()
|
||||
```
|
||||
**Description**
|
||||
Constructor.
|
||||
Uses the address of the object as the seed for the sequence.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
random_clcg(uint32_t seed)
|
||||
```
|
||||
**Description**
|
||||
Constructor.
|
||||
Uses seed as the seed for the sequence.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
void initialise(uint32_t seed)
|
||||
```
|
||||
**Description**
|
||||
Sets the seed as the new seed for the sequence.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
uint32_t operator()()
|
||||
```
|
||||
**Return**
|
||||
The next number in the pseudo-random sequence.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
uint32_t range(uint32_t low, uint32_t high)
|
||||
```
|
||||
**Return**
|
||||
A number between the specified ranges, inclusive.
|
||||
|
||||
## random_lsfr
|
||||
Generates a 32 bit pseudo-random number using a linear shift feedback register.
|
||||
The result is a 32 bit integer between 1 and 4,294,967,295 (2^32 - 1).
|
||||
The seed must not be zero. The output does not include zero.
|
||||
|
||||
```cpp
|
||||
random_lsfr()
|
||||
```
|
||||
**Description**
|
||||
Constructor.
|
||||
Uses the address of the object as the seed for the sequence.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
random_lsfr(uint32_t seed)
|
||||
```
|
||||
**Description**
|
||||
Constructor.
|
||||
Uses seed as the seed for the sequence.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
void initialise(uint32_t seed)
|
||||
```
|
||||
**Description**
|
||||
Sets the seed as the new seed for the sequence.
|
||||
|
||||
```cpp
|
||||
uint32_t operator()()
|
||||
```
|
||||
**Return**
|
||||
The next number in the pseudo-random sequence.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
uint32_t range(uint32_t low, uint32_t high)
|
||||
```
|
||||
**Return**
|
||||
A number between the specified ranges, inclusive.
|
||||
|
||||
## random_mwc
|
||||
Generates a 32 bit pseudo-random number using a multiply-with-carry algorithm.
|
||||
The result is a 32 bit integer between 1 and 4,294,967,295 (2^32 - 1).
|
||||
|
||||
```cpp
|
||||
random_mwc()
|
||||
```
|
||||
**Description**
|
||||
Constructor.
|
||||
Uses the address of the object as the seed for the sequence.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
random_mwc(uint32_t seed)
|
||||
```
|
||||
**Description**
|
||||
Constructor.
|
||||
Uses seed as the seed for the sequence.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
void initialise(uint32_t seed)
|
||||
```
|
||||
**Description**
|
||||
Sets the seed as the new seed for the sequence.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
uint32_t operator()()
|
||||
```
|
||||
**Return**
|
||||
The next number in the pseudo-random sequence.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
uint32_t range(uint32_t low, uint32_t high)
|
||||
```
|
||||
**Return**
|
||||
A number between the specified ranges, inclusive.
|
||||
|
||||
## random_pcg
|
||||
Generates a 32 bit pseudo-random number using a permuted congruential generator algorithm.
|
||||
The result is a 32 bit integer between 1 and 4,294,967,295 (2^32 - 1).
|
||||
|
||||
```cpp
|
||||
random_pcg()
|
||||
```
|
||||
**Description**
|
||||
Constructor.
|
||||
Uses the address of the object as the seed for the sequence.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
random_pcg(uint32_t seed)
|
||||
```
|
||||
**Description**
|
||||
Constructor.
|
||||
Uses seed as the seed for the sequence.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
void initialise(uint32_t seed)
|
||||
```
|
||||
**Description**
|
||||
Sets the seed as the new seed for the sequence.
|
||||
|
||||
```cpp
|
||||
uint32_t operator()()
|
||||
```
|
||||
**Return**
|
||||
The next number in the pseudo-random sequence.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
uint32_t range(uint32_t low, uint32_t high)
|
||||
```
|
||||
**Return**
|
||||
A number between the specified ranges, inclusive.
|
||||
|
||||
## random_hash
|
||||
|
||||
```cpp
|
||||
template <typename THash>
|
||||
```
|
||||
Generates a 32 bit pseudo-random number by applying a user supplied 32bit hash to a counter.
|
||||
The hash must implement void `add(uint8_t)` and `uint8_t value()` member functions.
|
||||
|
||||
```cpp
|
||||
random_hash()
|
||||
```
|
||||
**Description**
|
||||
Constructor.
|
||||
Uses the address of the object as the seed for the sequence.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
random_hash(uint32_t seed)
|
||||
```
|
||||
**Description**
|
||||
Constructor.
|
||||
Uses seed as the seed for the sequence.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
void initialise(uint32_t seed)
|
||||
```
|
||||
**Description**
|
||||
Sets the seed as the new seed for the sequence.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
uint32_t operator()()
|
||||
```
|
||||
**Return**
|
||||
The next number in the pseudo-random sequence.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
uint32_t range(uint32_t low, uint32_t high)
|
||||
```
|
||||
**Return**
|
||||
A number between the specified ranges, inclusive.
|
||||
@ -1,56 +1,80 @@
|
||||
ratio
|
||||
A template constant to encode ratios.
|
||||
C++11 equivalent std::ratio
|
||||
---
|
||||
title: "ratio"
|
||||
---
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
{{< callout type="info">}}
|
||||
Header: `ratio.h`
|
||||
Since: `TBC`
|
||||
Similar to: [std::ratio](https://en.cppreference.com/w/cpp/numeric/ratio/ratio)
|
||||
{{< /callout >}}
|
||||
|
||||
A template constant to encode ratios.
|
||||
|
||||
```cpp
|
||||
template <const size_t NUM, const size_t DEN = 1>
|
||||
struct ratio
|
||||
{
|
||||
static ETL_CONSTANT intmax_t num = NUM;
|
||||
static ETL_CONSTANT intmax_t den = DEN;
|
||||
};
|
||||
```
|
||||
|
||||
num : Numerator
|
||||
den : Denominator
|
||||
`num` : Numerator
|
||||
`den` : Denominator
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
Predefined ratios
|
||||
## Predefined ratios
|
||||
|
||||
If INT_MAX > INT32_MAX
|
||||
If `INT_MAX` > `INT32_MAX`
|
||||
```cpp
|
||||
typedef ratio<1, 1000000000000000000000000> yocto;
|
||||
typedef ratio<1, 1000000000000000000000> zepto;
|
||||
typedef ratio<1, 1000000000000000000> atto;
|
||||
typedef ratio<1, 1000000000000000> femto;
|
||||
typedef ratio<1, 1000000000000> pico;
|
||||
```
|
||||
|
||||
If INT_MAX >= INT32_MAX
|
||||
If `INT_MAX` >= `INT32_MAX`
|
||||
```cpp
|
||||
typedef ratio<1, 1000000000> nano;
|
||||
typedef ratio<1, 1000000> micro;
|
||||
```
|
||||
|
||||
If INT_MAX >= INT16_MAX
|
||||
If `INT_MAX` >= `INT16_MAX`
|
||||
```cpp
|
||||
typedef ratio<1, 1000> milli;
|
||||
typedef ratio<1, 100> centi;
|
||||
typedef ratio<1, 10> deci;
|
||||
typedef ratio<10, 1> deca;
|
||||
typedef ratio<100, 1> hecto;
|
||||
typedef ratio<1000, 1> kilo;
|
||||
```
|
||||
|
||||
If INT_MAX >= INT32_MAX
|
||||
If `INT_MAX` >= `INT32_MAX`
|
||||
```cpp
|
||||
typedef ratio<1000000, 1> mega;
|
||||
typedef ratio<1000000000, 1> giga;
|
||||
```
|
||||
|
||||
If INT_MAX > INT32_MAX
|
||||
If `INT_MAX` > `INT32_MAX`
|
||||
```cpp
|
||||
typedef ratio<1000000000000, 1> tera;
|
||||
typedef ratio<1000000000000000, 1> peta;
|
||||
typedef ratio<1000000000000000000, 1> exa;
|
||||
typedef ratio<1000000000000000000000, 1> zetta;
|
||||
typedef ratio<1000000000000000000000000, 1> yotta;
|
||||
```
|
||||
|
||||
An approximation of PI to 6 digits.
|
||||
```cpp
|
||||
typedef ratio<355, 113> ratio_pi;
|
||||
```
|
||||
|
||||
An approximation of root 2.
|
||||
```cpp
|
||||
typedef ratio<239, 169> ratio_root2;
|
||||
```
|
||||
|
||||
An approximation of e.
|
||||
```cpp
|
||||
typedef ratio<326, 120> ratio_e;
|
||||
```
|
||||
@ -1,23 +1,43 @@
|
||||
Rescale
|
||||
20.9.0
|
||||
---
|
||||
title: "rescale"
|
||||
---
|
||||
|
||||
{{< callout type="info">}}
|
||||
Header: `rescale.h`
|
||||
Since: `20.9.0`
|
||||
{{< /callout >}}
|
||||
|
||||
Rescales an input range.
|
||||
|
||||
```cpp
|
||||
template <typename TInput, typename TOutput>
|
||||
class rescale : public etl::unary_function<TOutput, TInput>
|
||||
```
|
||||
|
||||
TInput The input data type.
|
||||
TCompare The functor type used to compare values to the threshold. The default is etl::less
|
||||
____________________________________________________________________________________________________
|
||||
`TInput` The input data type.
|
||||
`TCompare` The functor type used to compare values to the threshold. The default is `etl::less`.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
rescale (TInput input_min_value,
|
||||
TInput input_max_value,
|
||||
TOutput output_min_value,
|
||||
TOutput output_max_value)
|
||||
____________________________________________________________________________________________________
|
||||
TOutput operator()(TInput value) const
|
||||
Rescale a value.
|
||||
____________________________________________________________________________________________________
|
||||
Example
|
||||
```
|
||||
**Description**
|
||||
Sets the rescale limits.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
TOutput operator()(TInput value) const
|
||||
```
|
||||
**Description**
|
||||
Rescale a value.
|
||||
|
||||
## Example
|
||||
```cpp
|
||||
std::array<char, 10> input =
|
||||
{
|
||||
10, 11, 12, 13, 14, 15, 16, 17, 18, 19
|
||||
@ -30,4 +50,4 @@ etl::rescale<char, int> rescale(10, 19, 40000, 41900);
|
||||
std::transform(input.begin(), input.end(), output.begin(), rescale);
|
||||
|
||||
// output = 40000, 40211, 40422, 40633, 40844, 41055, 41266, 41477, 41688, 41900
|
||||
|
||||
```
|
||||
112
docs/maths/rms.md
Normal file
112
docs/maths/rms.md
Normal file
@ -0,0 +1,112 @@
|
||||
---
|
||||
title: "RMS (Root Mean Square)"
|
||||
---
|
||||
|
||||
{{< callout type="info">}}
|
||||
Header: `rms.h`
|
||||
Since: `20.9.0`
|
||||
{{< /callout >}}
|
||||
|
||||
```cpp
|
||||
template <typename TInput, typename TCalc = TInput>
|
||||
class rms : public etl::unary_function<TInput, void>
|
||||
```
|
||||
|
||||
`TInput` The input data type.
|
||||
`TCalc` The type to use for internal calculations. By default, equal to TInput.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
rms()
|
||||
```
|
||||
**Description**
|
||||
Default constructor.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
template <typename TIterator>
|
||||
rms(TIterator first, TIterator last)
|
||||
```
|
||||
**Description**
|
||||
Construct from an iterator range.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
void add(TInput value1)
|
||||
```
|
||||
**Description**
|
||||
Add a value.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
template <typename TIterator>
|
||||
void add(TIterator first, TIterator last)
|
||||
```
|
||||
**Description**
|
||||
Add a range of values.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
void operator()(TInput value)
|
||||
```
|
||||
**Description**
|
||||
Add a values.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
template <typename TIterator>
|
||||
void operator()(TIterator first, TIterator last)
|
||||
```
|
||||
**Description**
|
||||
Add a range of values.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
double get_rms()
|
||||
```
|
||||
**Return**
|
||||
The calculated RMS for the data.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
operator double()
|
||||
```
|
||||
**Return**
|
||||
The calculated RMS value for the data.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
size_t count() const
|
||||
```
|
||||
**Description**
|
||||
Get the total number added entries.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
void clear()
|
||||
```
|
||||
Clear the mean.
|
||||
|
||||
## Example
|
||||
```cpp
|
||||
std::array<char, 10> input
|
||||
{
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9
|
||||
};
|
||||
|
||||
etl::rms<char, int32_t> rms(input.begin(), input.end());
|
||||
|
||||
double rms_result;
|
||||
|
||||
rms_result = rms; // rms_result == 5.21
|
||||
```
|
||||
@ -1,17 +1,26 @@
|
||||
Rounded integral division
|
||||
Rounded division algorithms for integral values.
|
||||
20.43.0
|
||||
---
|
||||
title: "Rounded integral division"
|
||||
---
|
||||
|
||||
{{< callout type="info">}}
|
||||
Header: `rounded_integral_division.h`
|
||||
Since: `20.9.0`
|
||||
{{< /callout >}}
|
||||
|
||||
Rounded division algorithms for integral values.
|
||||
|
||||
These algorithms perform integer division while rounding the result as though the fractional part were actually present. They do not check for a denominator of zero.
|
||||
____________________________________________________________________________________________________
|
||||
divide_round_to_ceiling
|
||||
|
||||
## divide_round_to_ceiling
|
||||
Values are rounded to the next more positive integral value.
|
||||
|
||||
```cpp
|
||||
template <typename T1, typename T2>
|
||||
ETL_CONSTEXPR14
|
||||
etl::common_type_t<T1, T2>
|
||||
divide_round_to_ceiling(T1 numerator, T2 denominator) ETL_NOEXCEPT
|
||||
|
||||
```
|
||||
```cpp
|
||||
.151 / 100 == 2
|
||||
.150 / 100 == 2
|
||||
.149 / 100 == 2
|
||||
@ -24,15 +33,18 @@ divide_round_to_ceiling(T1 numerator, T2 denominator) ETL_NOEXCEPT
|
||||
-149 / 100 == -1
|
||||
-150 / 100 == -1
|
||||
-151 / 100 == -1
|
||||
____________________________________________________________________________________________________
|
||||
divide_round_to_floor
|
||||
```
|
||||
|
||||
## divide_round_to_floor
|
||||
Values are rounded to the next more negative integral value.
|
||||
|
||||
```cpp
|
||||
template <typename T1, typename T2>
|
||||
ETL_CONSTEXPR14
|
||||
etl::common_type_t<T1, T2>
|
||||
divide_round_to_floor(T1 numerator, T2 denominator) ETL_NOEXCEPT
|
||||
|
||||
```
|
||||
```cpp
|
||||
.151 / 100 == 1
|
||||
.150 / 100 == 1
|
||||
.149 / 100 == 1
|
||||
@ -45,15 +57,18 @@ divide_round_to_floor(T1 numerator, T2 denominator) ETL_NOEXCEPT
|
||||
-149 / 100 == -2
|
||||
-150 / 100 == -2
|
||||
-151 / 100 == -2
|
||||
____________________________________________________________________________________________________
|
||||
divide_round_to_zero
|
||||
```
|
||||
|
||||
## divide_round_to_zero
|
||||
Values are rounded towards zero.
|
||||
|
||||
```cpp
|
||||
template <typename T1, typename T2>
|
||||
ETL_CONSTEXPR14
|
||||
etl::common_type_t<T1, T2>
|
||||
divide_round_to_zero(T1 numerator, T2 denominator) ETL_NOEXCEPT
|
||||
|
||||
```
|
||||
```cpp
|
||||
.151 / 100 == 1
|
||||
.150 / 100 == 1
|
||||
.149 / 100 == 1
|
||||
@ -66,15 +81,18 @@ divide_round_to_zero(T1 numerator, T2 denominator) ETL_NOEXCEPT
|
||||
-149 / 100 == -1
|
||||
-150 / 100 == -1
|
||||
-151 / 100 == -1
|
||||
____________________________________________________________________________________________________
|
||||
divide_round_to_infinity
|
||||
```
|
||||
|
||||
## divide_round_to_infinity
|
||||
Values are rounded towards infinity.
|
||||
|
||||
```cpp
|
||||
template <typename T1, typename T2>
|
||||
ETL_CONSTEXPR14
|
||||
etl::common_type_t<T1, T2>
|
||||
divide_round_to_infinity(T1 numerator, T2 denominator) ETL_NOEXCEPT
|
||||
|
||||
```
|
||||
```cpp
|
||||
.151 / 100 == 2
|
||||
.150 / 100 == 2
|
||||
.149 / 100 == 2
|
||||
@ -87,15 +105,19 @@ divide_round_to_infinity(T1 numerator, T2 denominator) ETL_NOEXCEPT
|
||||
-149 / 100 == -2
|
||||
-150 / 100 == -2
|
||||
-151 / 100 == -2
|
||||
____________________________________________________________________________________________________
|
||||
divide_round_half_up
|
||||
Values are rounded to the nearest integral value. 'Half' values are rounded up (towards infinity).
|
||||
```
|
||||
|
||||
## divide_round_half_up
|
||||
Values are rounded to the nearest integral value.
|
||||
'Half' values are rounded up (towards infinity).
|
||||
|
||||
```cpp
|
||||
template <typename T1, typename T2>
|
||||
ETL_CONSTEXPR14
|
||||
etl::common_type_t<T1, T2>
|
||||
divide_round_half_up(T1 numerator, T2 denominator) ETL_NOEXCEPT
|
||||
|
||||
```
|
||||
```cpp
|
||||
.151 / 100 == 3
|
||||
.150 / 100 == 3
|
||||
.149 / 100 == 1
|
||||
@ -108,15 +130,18 @@ divide_round_half_up(T1 numerator, T2 denominator) ETL_NOEXCEPT
|
||||
-149 / 100 == -1
|
||||
-150 / 100 == -3
|
||||
-151 / 100 == -3
|
||||
____________________________________________________________________________________________________
|
||||
divide_round_half_down
|
||||
Values are rounded to the nearest integral value. 'Half' values are rounded up (towards zero)
|
||||
```
|
||||
|
||||
## divide_round_half_down
|
||||
Values are rounded to the nearest integral value.
|
||||
'Half' values are rounded up (towards zero)
|
||||
|
||||
```cpp
|
||||
template <typename T1, typename T2>
|
||||
ETL_CONSTEXPR14
|
||||
etl::common_type_t<T1, T2>
|
||||
divide_round_half_down(T1 numerator, T2 denominator) ETL_NOEXCEPT
|
||||
|
||||
```cpp
|
||||
.151 / 100 == 3
|
||||
.150 / 100 == 2
|
||||
.149 / 100 == 1
|
||||
@ -129,16 +154,19 @@ divide_round_half_down(T1 numerator, T2 denominator) ETL_NOEXCEPT
|
||||
-149 / 100 == -1
|
||||
-150 / 100 == -2
|
||||
-151 / 100 == -3
|
||||
____________________________________________________________________________________________________
|
||||
divide_round_half_even
|
||||
(Banker's rounding)
|
||||
Values are rounded to the nearest integral value. 'Half' values are rounded to the nearest even value.
|
||||
```
|
||||
|
||||
## divide_round_half_even
|
||||
(Banker's rounding)
|
||||
Values are rounded to the nearest integral value.
|
||||
'Half' values are rounded to the nearest even value.
|
||||
```cpp
|
||||
template <typename T1, typename T2>
|
||||
ETL_CONSTEXPR14
|
||||
etl::common_type_t<T1, T2>
|
||||
divide_round_half_even(T1 numerator, T2 denominator) ETL_NOEXCEPT
|
||||
|
||||
```
|
||||
```cpp
|
||||
.151 / 100 == 2
|
||||
.150 / 100 == 2
|
||||
.149 / 100 == 1
|
||||
@ -151,15 +179,19 @@ divide_round_half_even(T1 numerator, T2 denominator) ETL_NOEXCEPT
|
||||
-149 / 100 == -1
|
||||
-150 / 100 == -2
|
||||
-151 / 100 == -2
|
||||
____________________________________________________________________________________________________
|
||||
divide_round_half_odd
|
||||
Values are rounded to the nearest integral value. 'Half' values are rounded to the nearest odd value.
|
||||
```
|
||||
|
||||
## divide_round_half_odd
|
||||
Values are rounded to the nearest integral value.
|
||||
'Half' values are rounded to the nearest odd value.
|
||||
|
||||
```cpp
|
||||
template <typename T1, typename T2>
|
||||
ETL_CONSTEXPR14
|
||||
etl::common_type_t<T1, T2>
|
||||
divide_round_half_even(T1 numerator, T2 denominator) ETL_NOEXCEPT
|
||||
|
||||
```
|
||||
```cpp
|
||||
.151 / 100 == 2
|
||||
.150 / 100 == 1
|
||||
.149 / 100 == 1
|
||||
@ -172,4 +204,4 @@ divide_round_half_even(T1 numerator, T2 denominator) ETL_NOEXCEPT
|
||||
-149 / 100 == -1
|
||||
-150 / 100 == -1
|
||||
-151 / 100 == -2
|
||||
|
||||
```
|
||||
@ -1,29 +1,35 @@
|
||||
Scaled Rounding
|
||||
Rounding algorithms for scaled integral values.
|
||||
---
|
||||
title: "Scaled Rounding"
|
||||
---
|
||||
|
||||
From 20.40.1 all scaling functions are ETL_NODISCARD and ETL_CONSTEXPR14.
|
||||
Rounding algorithms for scaled integral values.
|
||||
|
||||
It is often advantageous to use scaled integral values rather than floating point for performance reasons.
|
||||
These functions will round the supplied values according to various popular rounding algorithms.
|
||||
See http://www.clivemaxfield.com/diycalculator/sp-round.shtml
|
||||
From `20.40.1` all scaling functions are `ETL_NODISCARD` and `ETL_CONSTEXPR14`.
|
||||
|
||||
The results may be scaled or unscaled.
|
||||
Scaled : The result has the same scaling as the input value.
|
||||
Unscaled : The result has the scaling factor removed from the input value. 'Unscaled' is a little faster than 'scaled'.
|
||||
It is often advantageous to use scaled integral values rather than floating point for performance reasons.
|
||||
These functions will round the supplied values according to various popular rounding algorithms.
|
||||
See [http://www.clivemaxfield.com/diycalculator/sp-round.shtml](http://www.clivemaxfield.com/diycalculator/sp-round.shtml)
|
||||
|
||||
Assume a scaling factor of 10 for all of the examples below (simulated one decimal place).
|
||||
i.e. 5.1 => 51
|
||||
____________________________________________________________________________________________________
|
||||
Round Ceiling
|
||||
The results may be scaled or unscaled.
|
||||
**Scaled**
|
||||
The result has the same scaling as the input value.
|
||||
|
||||
**Unscaled**
|
||||
The result has the scaling factor removed from the input value. 'Unscaled' is a little faster than 'scaled'.
|
||||
|
||||
Assume a scaling factor of `10` for all of the examples below (simulated one decimal place).
|
||||
i.e. `5.1` => `51`
|
||||
|
||||
## Round Ceiling
|
||||
|
||||
Values are rounded to the next more positive integral value.
|
||||
|
||||
Scaling = 10
|
||||
Therefore 54 represents 5.4
|
||||
|
||||
```cpp
|
||||
template <size_t Scaling, typename T>
|
||||
T round_ceiling_scaled(T value)
|
||||
|
||||
```
|
||||
**Description** |
|
||||
```cpp
|
||||
-54 => -50 -5.4 => -5.0
|
||||
-55 => -50 -5.5 => -5.0
|
||||
-56 => -50 -5.6 => -5.0
|
||||
@ -31,10 +37,16 @@ T round_ceiling_scaled(T value)
|
||||
54 => 60 5.4 => 6.0
|
||||
55 => 60 5.5 => 6.0
|
||||
56 => 60 5.5 => 6.0
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
template <size_t Scaling, typename T>
|
||||
T round_ceiling_unscaled(T value)
|
||||
|
||||
```
|
||||
**Description** |
|
||||
```cpp
|
||||
-54 => -5 -5.4 => -5
|
||||
-55 => -5 -5.5 => -5
|
||||
-56 => -5 -5.6 => -5
|
||||
@ -42,17 +54,18 @@ T round_ceiling_unscaled(T value)
|
||||
54 => 6 5.4 => 6
|
||||
55 => 6 5.5 => 6
|
||||
56 => 6 5.6 => 6
|
||||
____________________________________________________________________________________________________
|
||||
Round Floor
|
||||
```
|
||||
|
||||
## Round Floor
|
||||
|
||||
Values are rounded to the next more negative integral value.
|
||||
|
||||
Scaling = 10
|
||||
Therefore 54 represents 5.4
|
||||
|
||||
```cpp
|
||||
template <size_t Scaling, typename T>
|
||||
T round_floor_scaled(T value)
|
||||
|
||||
```
|
||||
**Description** |
|
||||
```cpp
|
||||
-54 => -60 -5.4 => -6.0
|
||||
-55 => -60 -5.5 => -6.0
|
||||
-56 => -60 -5.6 => -6.0
|
||||
@ -60,10 +73,16 @@ T round_floor_scaled(T value)
|
||||
54 => 50 5.4 => 5.0
|
||||
55 => 50 5.5 => 5.0
|
||||
56 => 50 5.6 => 5.0
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
template <size_t Scaling, typename T>
|
||||
T round_floor_unscaled(T value)
|
||||
|
||||
```
|
||||
**Description** |
|
||||
```cpp
|
||||
-54 => -6 -5.4 => -6
|
||||
-55 => -6 -5.5 => -6
|
||||
-56 => -6 -5.6 => -6
|
||||
@ -71,14 +90,19 @@ T round_floor_unscaled(T value)
|
||||
54 => 5 5.4 => 5
|
||||
55 => 5 5.5 => 5
|
||||
56 => 5 5.6 => 5
|
||||
____________________________________________________________________________________________________
|
||||
Round Half Up
|
||||
```
|
||||
|
||||
Values are rounded to the nearest integral value. 'Half' values are rounded up (towards infinity).
|
||||
## Round Half Up
|
||||
|
||||
Values are rounded to the nearest integral value.
|
||||
'Half' values are rounded up (towards infinity).
|
||||
|
||||
```cpp
|
||||
template <size_t Scaling, typename T>
|
||||
T round_half_up_scaled(T value)
|
||||
|
||||
```
|
||||
**Description** |
|
||||
```cpp
|
||||
-54 => -50 -5.4 => -5.0
|
||||
-55 => -60 -5.5 => -5.0
|
||||
-56 => -60 -5.6 => -5.0
|
||||
@ -86,10 +110,16 @@ T round_half_up_scaled(T value)
|
||||
54 => 50
|
||||
55 => 60
|
||||
56 => 60
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
template <size_t Scaling, typename T>
|
||||
T round_half_up_unscaled(T value)
|
||||
|
||||
```
|
||||
**Description** |
|
||||
```cpp
|
||||
-54 => -5
|
||||
-55 => -6
|
||||
-56 => -6
|
||||
@ -97,14 +127,19 @@ T round_half_up_unscaled(T value)
|
||||
54 => 5
|
||||
55 => 6
|
||||
56 => 6
|
||||
____________________________________________________________________________________________________
|
||||
Round Half Down
|
||||
```
|
||||
|
||||
Values are rounded to the nearest integral value. 'Half' values are rounded down (towards zero).
|
||||
## Round Half Down
|
||||
|
||||
Values are rounded to the nearest integral value.
|
||||
'Half' values are rounded down (towards zero).
|
||||
|
||||
```cpp
|
||||
template <size_t Scaling, typename T>
|
||||
T round_half_down_scaled(T value)
|
||||
|
||||
```
|
||||
**Description** |
|
||||
```cpp
|
||||
-54 => -50
|
||||
-55 => -50
|
||||
-56 => -60
|
||||
@ -112,10 +147,16 @@ T round_half_down_scaled(T value)
|
||||
54 => 50
|
||||
55 => 50
|
||||
56 => 60
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
template <size_t Scaling, typename T>
|
||||
T round_half_down_unscaled(T value)
|
||||
|
||||
```
|
||||
**Description** |
|
||||
```cpp
|
||||
-54 => -5
|
||||
-55 => -5
|
||||
-56 => -6
|
||||
@ -123,14 +164,20 @@ T round_half_down_unscaled(T value)
|
||||
54 => 5
|
||||
55 => 5
|
||||
56 => 6
|
||||
____________________________________________________________________________________________________
|
||||
Round To Zero
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Round To Zero
|
||||
|
||||
Values are rounded towards zero.
|
||||
|
||||
```cpp
|
||||
template <size_t Scaling, typename T>
|
||||
T round_zero_scaled(T value)
|
||||
|
||||
```
|
||||
**Description** |
|
||||
```cpp
|
||||
-54 => -50
|
||||
-55 => -50
|
||||
-56 => -50
|
||||
@ -138,10 +185,16 @@ T round_zero_scaled(T value)
|
||||
54 => 50
|
||||
55 => 50
|
||||
56 => 50
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
template <size_t Scaling, typename T>
|
||||
T round_zero_unscaled(T value)
|
||||
|
||||
```
|
||||
**Description** |
|
||||
```cpp
|
||||
-54 => -5
|
||||
-55 => -5
|
||||
-56 => -5
|
||||
@ -149,15 +202,18 @@ T round_zero_unscaled(T value)
|
||||
54 => 5
|
||||
55 => 5
|
||||
56 => 5
|
||||
```
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
Round To Infinity
|
||||
## Round To Infinity
|
||||
|
||||
Values are rounded towards infinity.
|
||||
|
||||
```cpp
|
||||
template <size_t Scaling, typename T>
|
||||
T round_infinity_scaled(T value)
|
||||
|
||||
```
|
||||
**Description** |
|
||||
```cpp
|
||||
-54 => -60
|
||||
-55 => -60
|
||||
-56 => -60
|
||||
@ -165,10 +221,16 @@ T round_infinity_scaled(T value)
|
||||
54 => 60
|
||||
55 => 60
|
||||
56 => 60
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
template <size_t Scaling, typename T>
|
||||
T round_infinity_unscaled(T value)
|
||||
|
||||
```
|
||||
**Description** |
|
||||
```cpp
|
||||
-54 => -6
|
||||
-55 => -6
|
||||
-56 => -6
|
||||
@ -176,15 +238,19 @@ T round_infinity_unscaled(T value)
|
||||
54 => 6
|
||||
55 => 6
|
||||
56 => 6
|
||||
```
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
Round Half Even (Banker's Rounding)
|
||||
## Round Half Even (Banker's Rounding)
|
||||
|
||||
Values are rounded to the nearest integral value. 'Half' values are rounded to the nearest even value.
|
||||
Values are rounded to the nearest integral value.
|
||||
'Half' values are rounded to the nearest even value.
|
||||
|
||||
```cpp
|
||||
template <size_t Scaling, typename T>
|
||||
T round_half_even_scaled(T value)
|
||||
|
||||
```
|
||||
**Description** |
|
||||
```cpp
|
||||
-54 => -50
|
||||
-55 => -60
|
||||
-56 => -60
|
||||
@ -198,10 +264,16 @@ T round_half_even_scaled(T value)
|
||||
64 => 60
|
||||
65 => 60
|
||||
66 => 70
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
template <size_t Scaling, typename T>
|
||||
T round_half_even_unscaled(T value)
|
||||
|
||||
```
|
||||
**Description** |
|
||||
```cpp
|
||||
-54 => -5
|
||||
-55 => -6
|
||||
-56 => -6
|
||||
@ -215,15 +287,21 @@ T round_half_even_unscaled(T value)
|
||||
64 => 6
|
||||
65 => 6
|
||||
66 => 7
|
||||
```
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
Round Half Odd
|
||||
---
|
||||
|
||||
Values are rounded to the nearest integral value. 'Half' values are rounded to the nearest odd value.
|
||||
## Round Half Odd
|
||||
|
||||
Values are rounded to the nearest integral value.
|
||||
'Half' values are rounded to the nearest odd value.
|
||||
|
||||
```cpp
|
||||
template <size_t Scaling, typename T>
|
||||
T round_half_even_scaled(T value)
|
||||
|
||||
```
|
||||
**Description** |
|
||||
```cpp
|
||||
-54 => -50
|
||||
-55 => -50
|
||||
-56 => -60
|
||||
@ -237,10 +315,16 @@ T round_half_even_scaled(T value)
|
||||
64 => 60
|
||||
65 => 70
|
||||
66 => 70
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
template <size_t Scaling, typename T>
|
||||
T round_half_even_unscaled(T value)
|
||||
|
||||
```
|
||||
**Description** |
|
||||
```cpp
|
||||
-54 => -5
|
||||
-55 => -5
|
||||
-56 => -6
|
||||
@ -254,4 +338,4 @@ T round_half_even_unscaled(T value)
|
||||
64 => 6
|
||||
65 => 7
|
||||
66 => 7
|
||||
|
||||
```
|
||||
132
docs/maths/standard_deviation.md
Normal file
132
docs/maths/standard_deviation.md
Normal file
@ -0,0 +1,132 @@
|
||||
---
|
||||
title: "standard_deviation"
|
||||
---
|
||||
|
||||
{{< callout type="info">}}
|
||||
Header: `standard_deviation.h`
|
||||
Since: `20.9.0`
|
||||
{{< /callout >}}
|
||||
|
||||
```cpp
|
||||
template <bool Standard_Deviation_Type, typename TInput, typename TCalc = TInput>
|
||||
class standard_deviation : public etl::unary_function<TInput, void>
|
||||
```
|
||||
|
||||
`Standard_Deviation_Type` `Population` or `Sample`.
|
||||
`TInput` The input data type.
|
||||
`TCalc` The type to use for internal calculations. By default, equal to `TInput`.
|
||||
|
||||
**Enumeration**
|
||||
```cpp
|
||||
standard_deviation_type
|
||||
etl::standard_deviation_type::Sample
|
||||
etl::standard_deviation_type::Population
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
```cp
|
||||
standard_deviation()
|
||||
```
|
||||
**Description**
|
||||
Default constructor.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
template <typename TIterator>
|
||||
standard_deviation(TIterator first, TIterator last)
|
||||
```
|
||||
**Description**
|
||||
Construct from an iterator range.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
void add(TInput value1)
|
||||
```
|
||||
**Description**
|
||||
Add a value.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
template <typename TIterator>
|
||||
void add(TIterator first, TIterator last)
|
||||
```
|
||||
**Description**
|
||||
Add a range of values.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
void operator()(TInput value)
|
||||
```
|
||||
**Description**
|
||||
Add a values.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
template <typename TIterator>
|
||||
void operator()(TIterator first, TIterator last)
|
||||
```
|
||||
**Description**
|
||||
Add a range of values.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
double get_standard_deviation() const
|
||||
```
|
||||
**Return**
|
||||
The calculated standard deviation for the data.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
double get_variance() const
|
||||
```
|
||||
**Return**
|
||||
The calculated variance for the data.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
operator double() const
|
||||
```
|
||||
**Return**
|
||||
The calculated standard deviation for the data.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
size_t count() const
|
||||
```
|
||||
**Description**
|
||||
Get the total number added entries.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
void clear()
|
||||
```
|
||||
**Description**
|
||||
Clear the standard deviation.
|
||||
|
||||
## Example
|
||||
```cpp
|
||||
std::array<char, 10> input
|
||||
{
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9
|
||||
};
|
||||
|
||||
etl::standard_deviation<etl::standard_deviation_type::Population, char, int32_t>
|
||||
standard_deviation(input.begin(), input.end());
|
||||
|
||||
double standard_deviation_result;
|
||||
double variance_result;
|
||||
|
||||
standard_deviation_result = standard_deviation; // standard_deviation_result == 2.87
|
||||
variance_result = standard_deviation.get_variance(); // variance_result == 8.25
|
||||
```
|
||||
@ -1,23 +1,40 @@
|
||||
Threshold
|
||||
20.9.0
|
||||
---
|
||||
title: "threshold"
|
||||
---
|
||||
|
||||
{{< callout type="info">}}
|
||||
Header: `threshold.h`
|
||||
Since: `20.9.0`
|
||||
{{< /callout >}}
|
||||
|
||||
```cpp
|
||||
template <typename TInput, typename TCompare = etl::less<TInput> >
|
||||
class threshold : public etl::unary_function<TInput, TInput>
|
||||
```
|
||||
|
||||
TInput The input data type.
|
||||
TCompare The functor type used to compare values to the threshold. The default is etl::less
|
||||
____________________________________________________________________________________________________
|
||||
`TInput` The input data type.
|
||||
`TCompare` The functor type used to compare values to the threshold. The default is `etl::less`.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
threshold(TInput threshold_value,
|
||||
TInput true_value,
|
||||
TInput false_value,
|
||||
TCompare compare = TCompare())
|
||||
```
|
||||
**Description**
|
||||
Constructor.
|
||||
____________________________________________________________________________________________________
|
||||
TInput operator()(TInput value) const
|
||||
Threshold a value.
|
||||
____________________________________________________________________________________________________
|
||||
Example
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
TInput operator()(TInput value) const
|
||||
```
|
||||
Threshold a value.
|
||||
|
||||
## Example
|
||||
```cpp
|
||||
std::array<int, 10> input
|
||||
{
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9
|
||||
@ -30,4 +47,4 @@ etl::threshold<int> threshold(4, 0, 9); // Compares each value to 4 and output 0
|
||||
std::transform(input.begin(), input.end(), output.begin(), threshold);
|
||||
|
||||
// output == 0, 0, 0, 0, 9, 9, 9, 9, 9, 9
|
||||
|
||||
```
|
||||
119
docs/maths/variance.md
Normal file
119
docs/maths/variance.md
Normal file
@ -0,0 +1,119 @@
|
||||
---
|
||||
title: "variance"
|
||||
---
|
||||
|
||||
```cpp
|
||||
template <bool Variance_Type, typename TInput, typename TCalc = TInput>
|
||||
class variance : public etl::unary_function<TInput, void>
|
||||
```
|
||||
|
||||
`Variance_Type` `Population` or `Sample`.
|
||||
`TInput` The input data type.
|
||||
`TCalc` The type to use for internal calculations. By default, equal to `TInput`.
|
||||
|
||||
**Enumeration**
|
||||
```cpp
|
||||
variance_type
|
||||
etl::variance_type::Sample
|
||||
etl::variance_type::Population
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
variance()
|
||||
```
|
||||
**Description**
|
||||
Default constructor.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
template <typename TIterator>
|
||||
variance(TIterator first, TIterator last)
|
||||
```
|
||||
**Description**
|
||||
Construct from an iterator range.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
void add(TInput value1)
|
||||
```
|
||||
**Description**
|
||||
Add a value.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
template <typename TIterator>
|
||||
void add(TIterator first, TIterator last)
|
||||
```
|
||||
**Description**
|
||||
Add a range of values.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
void operator()(TInput value)
|
||||
```
|
||||
**Description**
|
||||
Add a values.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
template <typename TIterator>
|
||||
void operator()(TIterator first, TIterator last)
|
||||
```
|
||||
**Description**
|
||||
Add a range of values.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
double get_variance() const
|
||||
```
|
||||
**Return**
|
||||
The calculated variance for the data.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
operator double() const
|
||||
```
|
||||
**Return**
|
||||
The calculated variance for the data.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
size_t count() const
|
||||
```
|
||||
**Description**
|
||||
Get the total number added entries.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
void clear()
|
||||
```
|
||||
**Description**
|
||||
Clear the variance.
|
||||
|
||||
---
|
||||
|
||||
## Example
|
||||
```cpp
|
||||
std::array<char, 10> input
|
||||
{
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9
|
||||
};
|
||||
|
||||
etl::variance<etl::variance_type::Population, char, int32_t> variance(input.begin(),
|
||||
input.end());
|
||||
|
||||
double variance_result;
|
||||
|
||||
variance_result = variance; // variance_result == 8.25
|
||||
```
|
||||
5
docs/pseudo-containers/_index.md
Normal file
5
docs/pseudo-containers/_index.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
title: "Pseudo containers"
|
||||
weight: 100
|
||||
---
|
||||
|
||||
150
docs/pseudo-containers/bresenham_line.md
Normal file
150
docs/pseudo-containers/bresenham_line.md
Normal file
@ -0,0 +1,150 @@
|
||||
---
|
||||
title: "bresenham_line"
|
||||
---
|
||||
|
||||
A 'pseudo' container that generates coordinates on a line between two points using the [Bresenham line algorithm](https://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm).
|
||||
The class has an STL-like API and is a forward iterator type container.
|
||||
|
||||
**Note:** The iterator only supports pre-increment.
|
||||
|
||||
```cpp
|
||||
etl::bresenham_line<typename T>
|
||||
```
|
||||
Where `T` is the coordinate element type.
|
||||
|
||||
## Member types
|
||||
|
||||
```cpp
|
||||
value_type etl::coordinate_2d<T>
|
||||
size_type std::size_t
|
||||
difference_type std::ptrdiff_t
|
||||
const_reference const value_type&
|
||||
const_pointer const value_type*
|
||||
const_iterator Constant forward iterator
|
||||
```
|
||||
|
||||
## Constructor
|
||||
```cpp
|
||||
etl::bresenham_line<T>();
|
||||
```
|
||||
**Description**
|
||||
Default constructor.
|
||||
Creates an empty line.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
etl::bresenham_line<T>(T first_x, T first_y, T last_x, T last_y);
|
||||
```
|
||||
**Description**
|
||||
Creates a line from pairs of coordinates.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
etl::bresenham_line<T>(const etl::coordinate_2d<T>& first, const etl::coordinate_2d<T>& last);
|
||||
```
|
||||
**Description**
|
||||
Creates a line from pairs of coordinates.
|
||||
|
||||
## Initialisation
|
||||
|
||||
```cpp
|
||||
void reset(T first_x, T first_y, T last_x, T last_y);
|
||||
```
|
||||
**Description**
|
||||
Creates a line from pairs of coordinates.
|
||||
Overwrites any current coordinates.
|
||||
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
void reset(const etl::coordinate_2d<T>& first, const etl::coordinate_2d<T>& last);
|
||||
```
|
||||
**Description**
|
||||
Creates a line from pairs of coordinates.
|
||||
Overwrites any current coordinates.
|
||||
|
||||
## Element access
|
||||
|
||||
```cpp
|
||||
const_reference front() const
|
||||
```
|
||||
**Return**
|
||||
A const reference to the first coordinate in the line.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
const_reference back() const
|
||||
```
|
||||
**Return**
|
||||
A const reference to the last coordinate in the line.
|
||||
|
||||
## Iterators
|
||||
|
||||
```cpp
|
||||
const_iterator begin()
|
||||
```
|
||||
**Return**
|
||||
An iterator to the beginning of the coordinate series.
|
||||
This will reset the Bresenham line algorithm to the first coordinate.
|
||||
|
||||
```cpp
|
||||
const_iterator end() const
|
||||
```
|
||||
**Return** An iterator to the end of the coordinate series.
|
||||
|
||||
## Capacity
|
||||
|
||||
```cpp
|
||||
size_t size() const
|
||||
```
|
||||
**Return**
|
||||
The number of coordinates in the series.
|
||||
|
||||
## Non-member functions
|
||||
```cpp
|
||||
== true if the two lines are equal, otherwise false.
|
||||
!= true if the two lines are not equal, otherwise false.
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
**Plot pixels on a line**
|
||||
```cpp
|
||||
std::ostream& operator << (std::ostream& os, const etl::coordinate_2d<int>& coordinate)
|
||||
{
|
||||
os << "(" << coordinate.x << "," << coordinate.y << ")";
|
||||
return os;
|
||||
}
|
||||
|
||||
etl::coordinate_2d<int> first = { -3, 5 };
|
||||
etl::coordinate_2d<int> last = { 3, -5 };
|
||||
|
||||
etl::bresenham_line<int> line(first, last);
|
||||
|
||||
std::cout << "There are "
|
||||
<< line.size()
|
||||
<< " coordinates between "
|
||||
<< line.front()
|
||||
<< " and "
|
||||
<< line.back();
|
||||
|
||||
// Plot the pixels between first and last.
|
||||
std::for_each(line.begin(), line.end(), PlotPixel);
|
||||
```
|
||||
|
||||
**Create a vector of pixels on a line**
|
||||
```cpp
|
||||
etl::coordinate_2d<int> first = { -3, 5 };
|
||||
etl::coordinate_2d<int> last = { 3, -5 };
|
||||
|
||||
etl::bresenham_line<int> line(first, last);
|
||||
|
||||
std::vector<etl::coordinate_2d<int>> coordinates;
|
||||
|
||||
// Create the vector of points on the line between first and last.
|
||||
std::copy(line.begin(), line.end(), std::back_inserter(coordinates));
|
||||
```
|
||||
@ -1,32 +0,0 @@
|
||||
Limiter
|
||||
20.9.0
|
||||
Limits an input range.
|
||||
|
||||
template <typename TInput, typename TCompare = etl::less<TInput> >
|
||||
class limit : public etl::unary_function<TInput, TInput>
|
||||
|
||||
TInput The input data type.
|
||||
TCompare The functor type used to compare values to the threshold. The default is etl::less
|
||||
____________________________________________________________________________________________________
|
||||
limit(TInput lowest, TInput highest)
|
||||
lowest The lowest limit.
|
||||
highest The highest limit.
|
||||
____________________________________________________________________________________________________
|
||||
TInput operator()(TInput value) const
|
||||
Limit a value.
|
||||
____________________________________________________________________________________________________
|
||||
Example
|
||||
|
||||
std::array<int, 10> input =
|
||||
{
|
||||
10, 11, 12, 13, 14, 15, 16, 17, 18, 19
|
||||
};
|
||||
|
||||
std::array<int, 10> output;
|
||||
|
||||
etl::limiter<int> limiter(13, 16);
|
||||
|
||||
std::transform(input.begin(), input.end(), output.begin(), limiter);
|
||||
|
||||
// output = 13, 13, 13, 13, 14, 15, 16, 16, 16, 16
|
||||
|
||||
@ -1,55 +0,0 @@
|
||||
Mean
|
||||
20.9.0
|
||||
|
||||
template <typename TInput, typename TCalc = TInput>
|
||||
class mean : public etl::unary_function<TInput, void>
|
||||
|
||||
TInput The input data type.
|
||||
TCalc The type to use for internal calculations. By default, equal to TInput.
|
||||
____________________________________________________________________________________________________
|
||||
mean()
|
||||
Default constructor.
|
||||
|
||||
template <typename TIterator>
|
||||
mean(TIterator first, TIterator last)
|
||||
Construct from an iterator range.
|
||||
____________________________________________________________________________________________________
|
||||
void add(TInput value1)
|
||||
Add a value.
|
||||
|
||||
template <typename TIterator>
|
||||
void add(TIterator first, TIterator last)
|
||||
Add a range of values.
|
||||
____________________________________________________________________________________________________
|
||||
void operator()(TInput value)
|
||||
Add a values.
|
||||
|
||||
template <typename TIterator>
|
||||
void operator()(TIterator first, TIterator last)
|
||||
Add a range of values.
|
||||
____________________________________________________________________________________________________
|
||||
double get_mean() const
|
||||
Returns the calculated mean for the data.
|
||||
____________________________________________________________________________________________________
|
||||
operator double() const
|
||||
Returns the calculated mean for the data.
|
||||
____________________________________________________________________________________________________
|
||||
size_t count() const
|
||||
Get the total number added entries.
|
||||
____________________________________________________________________________________________________
|
||||
void clear()
|
||||
Clear the mean.
|
||||
____________________________________________________________________________________________________
|
||||
Example
|
||||
|
||||
std::array<char, 10> input
|
||||
{
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9
|
||||
};
|
||||
|
||||
etl::mean<char, int32_t> mean(input.begin(), input.end());
|
||||
|
||||
double mean_result;
|
||||
|
||||
mean_result = mean; // mean_result == 4.5
|
||||
|
||||
@ -1,56 +0,0 @@
|
||||
RMS
|
||||
(Root Mean Square)
|
||||
20.9.0
|
||||
|
||||
template <typename TInput, typename TCalc = TInput>
|
||||
class rms : public etl::unary_function<TInput, void>
|
||||
|
||||
TInput The input data type.
|
||||
TCalc The type to use for internal calculations. By default, equal to TInput.
|
||||
____________________________________________________________________________________________________
|
||||
rms()
|
||||
Default constructor.
|
||||
|
||||
template <typename TIterator>
|
||||
rms(TIterator first, TIterator last)
|
||||
Construct from an iterator range.
|
||||
____________________________________________________________________________________________________
|
||||
void add(TInput value1)
|
||||
Add a value.
|
||||
|
||||
template <typename TIterator>
|
||||
void add(TIterator first, TIterator last)
|
||||
Add a range of values.
|
||||
____________________________________________________________________________________________________
|
||||
void operator()(TInput value)
|
||||
Add a values.
|
||||
|
||||
template <typename TIterator>
|
||||
void operator()(TIterator first, TIterator last)
|
||||
Add a range of values.
|
||||
____________________________________________________________________________________________________
|
||||
double get_rms()
|
||||
Returns the calculated RMS for the data.
|
||||
____________________________________________________________________________________________________
|
||||
operator double()
|
||||
Returns the calculated RMS value for the data.
|
||||
____________________________________________________________________________________________________
|
||||
size_t count() const
|
||||
Get the total number added entries.
|
||||
____________________________________________________________________________________________________
|
||||
void clear()
|
||||
Clear the mean.
|
||||
____________________________________________________________________________________________________
|
||||
Example
|
||||
|
||||
std::array<char, 10> input
|
||||
{
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9
|
||||
};
|
||||
|
||||
etl::rms<char, int32_t> rms(input.begin(), input.end());
|
||||
|
||||
double rms_result;
|
||||
|
||||
rms_result = rms; // rms_result == 5.21
|
||||
|
||||
@ -1,67 +0,0 @@
|
||||
Standard Deviation
|
||||
20.9.0
|
||||
|
||||
template <bool Standard_Deviation_Type, typename TInput, typename TCalc = TInput>
|
||||
class standard_deviation : public etl::unary_function<TInput, void>
|
||||
|
||||
Standard_Deviation_Type Population or Sample.
|
||||
TInput The input data type.
|
||||
TCalc The type to use for internal calculations. By default, equal to TInput.
|
||||
____________________________________________________________________________________________________
|
||||
standard_deviation_type
|
||||
etl::standard_deviation_type::Sample
|
||||
etl::standard_deviation_type::Population
|
||||
____________________________________________________________________________________________________
|
||||
standard_deviation
|
||||
standard_deviation()
|
||||
Default constructor.
|
||||
|
||||
template <typename TIterator>
|
||||
standard_deviation(TIterator first, TIterator last)
|
||||
Construct from an iterator range.
|
||||
____________________________________________________________________________________________________
|
||||
void add(TInput value1)
|
||||
Add a value.
|
||||
|
||||
template <typename TIterator>
|
||||
void add(TIterator first, TIterator last)
|
||||
Add a range of values.
|
||||
____________________________________________________________________________________________________
|
||||
void operator()(TInput value)
|
||||
Add a values.
|
||||
|
||||
template <typename TIterator>
|
||||
void operator()(TIterator first, TIterator last)
|
||||
Add a range of values.
|
||||
____________________________________________________________________________________________________
|
||||
double get_standard_deviation() const
|
||||
Returns the calculated standard deviation for the data.
|
||||
____________________________________________________________________________________________________
|
||||
double get_variance() const
|
||||
Returns the calculated variance for the data.
|
||||
____________________________________________________________________________________________________
|
||||
operator double() const
|
||||
Returns the calculated standard deviation for the data.
|
||||
____________________________________________________________________________________________________
|
||||
size_t count() const
|
||||
Get the total number added entries.
|
||||
____________________________________________________________________________________________________
|
||||
void clear()
|
||||
Clear the standard deviation.
|
||||
____________________________________________________________________________________________________
|
||||
Example
|
||||
|
||||
std::array<char, 10> input
|
||||
{
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9
|
||||
};
|
||||
|
||||
etl::standard_deviation<etl::standard_deviation_type::Population, char, int32_t>
|
||||
standard_deviation(input.begin(), input.end());
|
||||
|
||||
double standard_deviation_result;
|
||||
double variance_result;
|
||||
|
||||
standard_deviation_result = standard_deviation; // standard_deviation_result == 2.87
|
||||
variance_result = standard_deviation.get_variance(); // variance_result == 8.25
|
||||
|
||||
@ -1,62 +0,0 @@
|
||||
Variance
|
||||
20.9.0
|
||||
|
||||
template <bool Variance_Type, typename TInput, typename TCalc = TInput>
|
||||
class variance : public etl::unary_function<TInput, void>
|
||||
|
||||
Variance_Type Population or Sample.
|
||||
TInput The input data type.
|
||||
TCalc The type to use for internal calculations. By default, equal to TInput.
|
||||
____________________________________________________________________________________________________
|
||||
variance_type
|
||||
etl::variance_type::Sample
|
||||
etl::variance_type::Population
|
||||
____________________________________________________________________________________________________
|
||||
variance
|
||||
variance()
|
||||
Default constructor.
|
||||
|
||||
template <typename TIterator>
|
||||
variance(TIterator first, TIterator last)
|
||||
Construct from an iterator range.
|
||||
____________________________________________________________________________________________________
|
||||
void add(TInput value1)
|
||||
Add a value.
|
||||
|
||||
template <typename TIterator>
|
||||
void add(TIterator first, TIterator last)
|
||||
Add a range of values.
|
||||
____________________________________________________________________________________________________
|
||||
void operator()(TInput value)
|
||||
Add a values.
|
||||
|
||||
template <typename TIterator>
|
||||
void operator()(TIterator first, TIterator last)
|
||||
Add a range of values.
|
||||
____________________________________________________________________________________________________
|
||||
double get_variance() const
|
||||
Returns the calculated variance for the data.
|
||||
____________________________________________________________________________________________________
|
||||
operator double() const
|
||||
Returns the calculated variance for the data.
|
||||
____________________________________________________________________________________________________
|
||||
size_t count() const
|
||||
Get the total number added entries.
|
||||
____________________________________________________________________________________________________
|
||||
void clear()
|
||||
Clear the variance.
|
||||
____________________________________________________________________________________________________
|
||||
Example
|
||||
|
||||
std::array<char, 10> input
|
||||
{
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9
|
||||
};
|
||||
|
||||
etl::variance<etl::variance_type::Population, char, int32_t> variance(input.begin(),
|
||||
input.end());
|
||||
|
||||
double variance_result;
|
||||
|
||||
variance_result = variance; // variance_result == 8.25
|
||||
|
||||
@ -1,7 +0,0 @@
|
||||
is_negative
|
||||
|
||||
Allows a parameter of type T to be checked for a positive or negative value, while eliminating compiler warnings for checking < 0 for unsigned types.
|
||||
|
||||
template <typename T>
|
||||
ETL_CONSTEXPR bool is_negative(const T value)
|
||||
|
||||
@ -1,13 +0,0 @@
|
||||
radix
|
||||
A smart enumeration to encode radix constants.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
struct radix
|
||||
|
||||
Define the constants:
|
||||
undefined
|
||||
binary
|
||||
octal
|
||||
decimal
|
||||
hex
|
||||
|
||||
@ -1,234 +0,0 @@
|
||||
random
|
||||
Utilities for producing random numbers.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
random
|
||||
The base class for all 32 bit random number generators.
|
||||
|
||||
If ETL_POLYMORPHIC_RANDOM is defined, then the base class will have the following members, otherwise the base is empty.
|
||||
|
||||
virtual ~random();
|
||||
virtual void initialise(uint32_t seed) = 0;
|
||||
virtual uint32_t operator()() = 0;
|
||||
virtual uint32_t range(uint32_t low, uint32_t high) = 0;
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
random_xorshift
|
||||
Uses a 128bit XOR shift algorithm for producing a pseudo-random sequence of integers.
|
||||
The result is a 32 bit integer between 0 and 4,294,967,295 (2^32 - 1).
|
||||
|
||||
random_xor_shift()
|
||||
|
||||
Constructor.
|
||||
Uses the address of the object as the seed for the sequence.
|
||||
|
||||
random_xor_shift(uint32_t seed)
|
||||
|
||||
Constructor.
|
||||
Uses seed as the seed for the sequence.
|
||||
|
||||
void initialise(uint32_t seed)
|
||||
|
||||
Sets the seed as the new seed for the sequence.
|
||||
|
||||
uint32_t operator()()
|
||||
|
||||
Returns the next number in the pseudo-random sequence.
|
||||
|
||||
uint32_t range(uint32_t low, uint32_t high)
|
||||
|
||||
Returns a number between the specified ranges, inclusive.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
random_lcg
|
||||
Generates a 32 bit pseudo-random number using a linear congruent generator.
|
||||
The result is a 32 bit integer between 0 and 2,147,483,647 (2^31 - 1).
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
random_lcg()
|
||||
|
||||
Constructor.
|
||||
Uses the address of the object as the seed for the sequence
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
random_lcg(uint32_t seed)
|
||||
|
||||
Constructor.
|
||||
Uses seed as the seed for the sequence.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
void initialise(uint32_t seed)
|
||||
|
||||
Sets the seed as the new seed for the sequence.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
uint32_t operator()()
|
||||
|
||||
Returns the next number in the pseudo-random sequence.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
uint32_t range(uint32_t low, uint32_t high)
|
||||
|
||||
Returns a number between the specified ranges, inclusive.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
random_clcg
|
||||
Generates a 32 bit pseudo-random number using a combined linear congruent generator.
|
||||
The result is a 32 bit integer between 0 and 2,147,483,647 (2^31 - 1).
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
random_clcg()
|
||||
|
||||
Constructor.
|
||||
Uses the address of the object as the seed for the sequence.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
random_clcg(uint32_t seed)
|
||||
|
||||
Constructor.
|
||||
Uses seed as the seed for the sequence.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
void initialise(uint32_t seed)
|
||||
|
||||
Sets the seed as the new seed for the sequence.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
uint32_t operator()()
|
||||
|
||||
Returns the next number in the pseudo-random sequence.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
uint32_t range(uint32_t low, uint32_t high)
|
||||
Returns a number between the specified ranges, inclusive.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
random_lsfr
|
||||
Generates a 32 bit pseudo-random number using a linear shift feedback register.
|
||||
The result is a 32 bit integer between 1 and 4,294,967,295 (2^32 - 1).
|
||||
The seed must not be zero. The output does not include zero.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
random_lsfr()
|
||||
|
||||
Constructor.
|
||||
Uses the address of the object as the seed for the sequence.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
random_lsfr(uint32_t seed)
|
||||
|
||||
Constructor.
|
||||
Uses seed as the seed for the sequence.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
void initialise(uint32_t seed)
|
||||
|
||||
Sets the seed as the new seed for the sequence.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
uint32_t operator()()
|
||||
|
||||
Returns the next number in the pseudo-random sequence.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
uint32_t range(uint32_t low, uint32_t high)
|
||||
|
||||
Returns a number between the specified ranges, inclusive.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
random_mwc
|
||||
Generates a 32 bit pseudo-random number using a multiply-with-carry algorithm.
|
||||
The result is a 32 bit integer between 1 and 4,294,967,295 (2^32 - 1).
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
random_mwc()
|
||||
|
||||
Constructor.
|
||||
Uses the address of the object as the seed for the sequence.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
random_mwc(uint32_t seed)
|
||||
|
||||
Constructor.
|
||||
Uses seed as the seed for the sequence.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
void initialise(uint32_t seed)
|
||||
|
||||
Sets the seed as the new seed for the sequence.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
uint32_t operator()()
|
||||
|
||||
Returns the next number in the pseudo-random sequence.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
uint32_t range(uint32_t low, uint32_t high)
|
||||
|
||||
Returns a number between the specified ranges, inclusive.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
random_pcg
|
||||
Generates a 32 bit pseudo-random number using a permuted congruential generator algorithm.
|
||||
The result is a 32 bit integer between 1 and 4,294,967,295 (2^32 - 1).
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
random_pcg()
|
||||
|
||||
Constructor.
|
||||
Uses the address of the object as the seed for the sequence.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
random_pcg(uint32_t seed)
|
||||
|
||||
Constructor.
|
||||
Uses seed as the seed for the sequence.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
void initialise(uint32_t seed)
|
||||
|
||||
Sets the seed as the new seed for the sequence.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
uint32_t operator()()
|
||||
|
||||
Returns the next number in the pseudo-random sequence.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
uint32_t range(uint32_t low, uint32_t high)
|
||||
|
||||
Returns a number between the specified ranges, inclusive.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
random_hash
|
||||
|
||||
template <typename THash>
|
||||
Generates a 32 bit pseudo-random number by applying a user supplied 32bit hash to a counter.
|
||||
The hash must implement void add(uint8_t) and uint8_t value() member functions.
|
||||
____________________________________________________________________________________________________
|
||||
random_hash()
|
||||
|
||||
Constructor.
|
||||
Uses the address of the object as the seed for the sequence.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
random_hash(uint32_t seed)
|
||||
|
||||
Constructor.
|
||||
Uses seed as the seed for the sequence.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
void initialise(uint32_t seed)
|
||||
|
||||
Sets the seed as the new seed for the sequence.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
uint32_t operator()()
|
||||
|
||||
Returns the next number in the pseudo-random sequence.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
uint32_t range(uint32_t low, uint32_t high)
|
||||
|
||||
Returns a number between the specified ranges, inclusive.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user