particula.util.machine_limit
Machine max or min overflow protection.
Attributes
| Name | Description |
|---|---|
MAX_NEGATIVE_VALUE | No description. |
MAX_POSITIVE_VALUE | No description. |
MIN_POSITIVE_VALUE | No description. |
Functions
| Name | Description |
|---|---|
get_safe_exp | Compute the exponential of each element in the input array, with overflow |
get_safe_log | Compute the natural logarithm of each element in the input array, with |
get_safe_log10 | Compute the base-10 logarithm of each element in the input array, with |
get_safe_power | Compute the power (base ** exponent) with overflow protection. |
MAX_NEGATIVE_VALUEattributemodule attribute#
MAX_NEGATIVE_VALUE = np.finfo(np.float64).minMAX_POSITIVE_VALUEattributemodule attribute#
MAX_POSITIVE_VALUE = np.finfo(np.float64).maxMIN_POSITIVE_VALUEattributemodule attribute#
MIN_POSITIVE_VALUE = np.nextafter(0, 1, dtype=np.float64)get_safe_expfunction#
def get_safe_exp(value: ArrayLike) -> np.ndarrayCompute the exponential of each element in the input array, with overflow protection.
Parameters
| Name | Type | Description |
|---|---|---|
value | ArrayLike | Array-like of values to exponentiate. |
Returns
np.ndarray- np.ndarray of exponentiated values, with machine-level clipping.
Examples
import numpy as npimport particula as par
arr = np.array([0, 10, 1000])print(par.get_safe_exp(arr))# Output: [1.00000000e+000 2.20264658e+004 1.79769313e+308]get_safe_logfunction#
def get_safe_log(value: ArrayLike) -> np.ndarrayCompute the natural logarithm of each element in the input array, with underflow protection.
Parameters
| Name | Type | Description |
|---|---|---|
value | ArrayLike | Array-like of values for logarithm calculation. |
Returns
np.ndarray- np.ndarray of natural logarithms, with machine-level clipping.
Examples
import numpy as npimport particula as par
arr = np.array([1e-320, 1.0, 10.0])print(get_safe_log(arr))# Output: [-7.40545337e+02 0.00000000e+00 2.30258509e+00]get_safe_log10function#
def get_safe_log10(value: ArrayLike) -> np.ndarrayCompute the base-10 logarithm of each element in the input array, with underflow protection.
Parameters
| Name | Type | Description |
|---|---|---|
value | ArrayLike | Array-like of values for base-10 logarithm calculation. |
Returns
np.ndarray- np.ndarray of base-10 logarithms, with machine-level clipping.
Examples
import numpy as npimport particula as par
arr = np.array([1e-320, 1.0, 1000.0])print(par.get_safe_log10(arr))# Output: [-320. 0. 3. ]get_safe_powerfunction#
def get_safe_power(base: ArrayLike, exponent: ArrayLike) -> np.ndarrayCompute the power (base ** exponent) with overflow protection.
The power is computed as: result = exp(exponent * log(base))
where the intermediate value is clipped to avoid overflow beyond the
machine limits. This function assumes that base contains positive values.
The behavior for non-positive bases is undefined.
Parameters
| Name | Type | Description |
|---|---|---|
base | ArrayLike | Array-like of positive base values. |
exponent | ArrayLike | Array-like of exponents. |
Returns
np.ndarray- np.ndarray of power values, computed with machine-level clipping.
Examples
import numpy as npimport particula as par
base = np.array([1, 2, 3])exponent = np.array([1, 2, 3])print(par.get_safe_power(base, exponent))# Output: [ 1. 4. 27.]