Some Mathematical functions used in the library.
More...
#include <cmath>
#include <Eigen/Core>
Go to the source code of this file.
|
| constexpr size_t | jsa::cicuetea::nextPow2 (size_t x) |
| | Computes the next power of 2 greater than or equal to the given number.
|
| size_t | jsa::cicuetea::constrain (size_t idx, size_t size) |
| | Constrains an index to fit within the bounds of a given size by wrapping it around.
|
| double | jsa::cicuetea::square (double x) |
| | Computes the square of a given number.
|
| Eigen::ArrayXd | jsa::cicuetea::regspace (Eigen::Index num) |
| | Generates a linearly spaced array of values from 0 to num-1.
|
| Eigen::ArrayXd | jsa::cicuetea::regspace (Eigen::Index low, Eigen::Index high) |
| | Generates a linearly spaced array of values between a specified range.
|
| Eigen::ArrayXd | jsa::cicuetea::logspace (double start, double end, Eigen::Index num) |
| | Generates a logarithmically spaced array.
|
Some Mathematical functions used in the library.
- Author
- Juan Sierra
- Date
- 3/23/25
- Copyright
- MIT License
◆ constrain()
| size_t jsa::cicuetea::constrain |
( |
size_t | idx, |
|
|
size_t | size ) |
|
inline |
Constrains an index to fit within the bounds of a given size by wrapping it around.
This function ensures that the provided index remains within the range [0, size - 1] by using the modulo operation. It is useful for cyclic or circular indexing.
- Parameters
-
| idx | The index to be constrained. |
| size | The size of the range within which the index should be constrained. |
- Returns
- The constrained index within the range [0, size - 1].
◆ logspace()
| Eigen::ArrayXd jsa::cicuetea::logspace |
( |
double | start, |
|
|
double | end, |
|
|
Eigen::Index | num ) |
|
inline |
Generates a logarithmically spaced array.
This function creates an array of num elements, logarithmically spaced between start and end. The values are computed using the natural logarithm and then exponentiated to return the final array.
- Parameters
-
| start | The starting value of the sequence (must be positive). |
| end | The ending value of the sequence (must be positive). |
| num | The number of elements in the sequence. |
- Returns
- Eigen::ArrayXd A logarithmically spaced array of size num.
- Note
- The start and end parameters must be greater than zero, as the logarithm of non-positive numbers is undefined.
◆ nextPow2()
| size_t jsa::cicuetea::nextPow2 |
( |
size_t | x | ) |
|
|
inlineconstexpr |
Computes the next power of 2 greater than or equal to the given number.
This function calculates the smallest power of 2 that is greater than or equal to the input value x. If x is 0, the function returns 1.
- Parameters
-
| x | The input value for which the next power of 2 is to be computed. |
- Returns
- The next power of 2 greater than or equal to x.
- Note
- This function uses bitwise operations to efficiently compute the result. It assumes that the input is within the range of a 64-bit unsigned integer.
◆ regspace() [1/2]
| Eigen::ArrayXd jsa::cicuetea::regspace |
( |
Eigen::Index | low, |
|
|
Eigen::Index | high ) |
|
inline |
Generates a linearly spaced array of values between a specified range.
This function creates an Eigen::ArrayXd containing evenly spaced values starting from low and ending at high, inclusive. The number of elements in the array is determined by the difference between high and low plus one.
- Parameters
-
| low | The starting value of the range (inclusive). |
| high | The ending value of the range (inclusive). |
- Returns
- Eigen::ArrayXd A 1D array of linearly spaced values from low to high.
◆ regspace() [2/2]
| Eigen::ArrayXd jsa::cicuetea::regspace |
( |
Eigen::Index | num | ) |
|
|
inline |
Generates a linearly spaced array of values from 0 to num-1.
- Parameters
-
| num | The number of elements in the resulting array. |
- Returns
- Eigen::ArrayXd A 1D array containing linearly spaced values from 0 to num-1.
◆ square()
| double jsa::cicuetea::square |
( |
double | x | ) |
|
|
inline |
Computes the square of a given number.
This function takes a double-precision floating-point number as input and returns its square (the number multiplied by itself).
- Parameters
-
| x | The number to be squared. |
- Returns
- The square of the input number.