apytypes_common.h

Typedefs

using Rnd64Func_t = std::uint64_t()

Uniform 64-bit random number generator function type.

using Rnd64FuncPtr_t = Rnd64Func_t*

Uniform 64-bit random number generator function pointer type.

template<typename ...NB_ARGS>
using ThirdPartyArray = std::variant<nanobind::ndarray<nanobind::numpy, NB_ARGS...>, nanobind::ndarray<nanobind::pytorch, NB_ARGS...>, nanobind::ndarray<nanobind::tensorflow, NB_ARGS...>, nanobind::ndarray<nanobind::jax, NB_ARGS...>, nanobind::ndarray<nanobind::cupy, NB_ARGS...>>

Type of a third-party array library. Returning this to Python will.

Enums

enum class QuantizationMode

Values:

enumerator TRN
enumerator TRN_INF
enumerator TRN_ZERO
enumerator TRN_AWAY
enumerator TRN_MAG
enumerator RND
enumerator RND_ZERO
enumerator RND_INF
enumerator RND_MIN_INF
enumerator RND_CONV
enumerator RND_CONV_ODD
enumerator JAM
enumerator JAM_UNBIASED
enumerator STOCH_WEIGHTED
enumerator STOCH_EQUAL
enum class OverflowMode

Values:

enumerator WRAP
enumerator SAT
enumerator NUMERIC_STD
enum class ConvolutionMode

Values:

enumerator FULL
enumerator SAME
enumerator VALID
enum class ThirdPartyArrayLibrary

Enum for the supported third-party array libraries.

Values:

enumerator NUMPY
enumerator PYTORCH
enumerator TENSORFLOW
enumerator JAX
enumerator CUPY

Functions

std::uint64_t rnd64_fx()

Draw a 64-bit uniform random number from the RNG.

std::uint64_t rnd64_fp()
std::uint64_t get_rnd64_fx_seed()

Retrieve the seed that was used to initialize the active RNG.

std::uint64_t get_rnd64_fp_seed()
std::mt19937_64 get_rnd64_fx_engine()

Retrieve a copy of the current mt19937 RNG.

std::mt19937_64 get_rnd64_fp_engine()
void set_rnd64_fx_engine(const std::mt19937_64 &engine)

Set the current mt19937 RNG engine.

void set_rnd64_fp_engine(const std::mt19937_64 &engine)
void set_rnd64_fx_seed(std::uint64_t seed)

Overwrite which seed value that was used to initialize the current RNG.

void set_rnd64_fp_seed(std::uint64_t seed)
void rst_default_rnd64_fx(std::uint64_t seed)

Reset the default stochastic quantization RNG.

void rst_default_rnd64_fp(std::uint64_t seed)
QuantizationMode get_float_quantization_mode()

Return the global quantization mode for APyFloat.

void set_float_quantization_mode(QuantizationMode mode)

Set the global quantization mode for APyFloat.

APyFixedCastOption get_fixed_cast_mode()

Return the global cast mode for APyFixed.

void set_fixed_cast_mode(const APyFixedCastOption &mode)

Set the global cast mode for APyFixed.

std::optional<APyFixedAccumulatorOption> get_accumulator_mode_fixed()

Return the global accumulator mode for APyFixed.

void set_accumulator_mode_fixed(const std::optional<APyFixedAccumulatorOption> &mode)

Return the global accumulator mode for APyFixed.

std::optional<APyFloatAccumulatorOption> get_accumulator_mode_float()

Return the global accumulator mode for APyFloat.

void set_accumulator_mode_float(const std::optional<APyFloatAccumulatorOption> &mode)

Set the global accumulator mode for APyFloat.

void set_array_library_from_str(const std::string &array_lib)

Python-exported set preferred array library function.

void set_array_library(ThirdPartyArrayLibrary array_lib)

Set the preferred third-party array library.

ThirdPartyArrayLibrary get_array_library()

Return the currently set preferred third-party array library.

std::string get_array_library_as_str()

Return the currently set preferred third-party array library as a string.

template<typename ...NB_ARGS>
ThirdPartyArray<NB_ARGS...> make_third_party_ndarray(const nanobind::ndarray<NB_ARGS...> &array_ref, ThirdPartyArrayLibrary array_lib)

Convert an un-tagged nb::ndarray (Python capsule around void *) to a third-party array-library specific array.

Variables

ThreadPool thread_pool

The global APyTypes threadpool.

ThreadPoolSettings thread_pool_settings

Threadpool settings.

Threadpool settings.

struct APyFixedCastOption

Public Members

QuantizationMode quantization
OverflowMode overflow

Quantization mode to use for cast operations.

struct APyFixedAccumulatorOption

Public Members

int bits
int int_bits

Total number of bits to use for accumulator.

QuantizationMode quantization

Number of integer bits to use for accumulator.

OverflowMode overflow

Quantization mode to use for multiplication.

struct APyFloatAccumulatorOption
#include <apytypes_common.h>

Accumulator mode type for APyFloat.

Public Functions

inline APyFloatSpec get_spec(exp_t backup_bias) const noexcept

Public Members

std::uint8_t exp_bits

Number of exponent bits.

std::uint8_t man_bits

Number of mantissa bits.

std::optional<exp_t> bias

Exponent bias.

QuantizationMode quantization

Quantization mode.

std::uint64_t seed

Psueod RNG seed.

std::mt19937_64 rng_engine

RNG engine.

struct ArrayThreadSetting
#include <apytypes_common.h>

Array-specific thread settings class.

Public Members

std::size_t n_mac_threshold
struct ThreadPoolSettings
#include <apytypes_common.h>

Threadpool settings class.

Public Members

ArrayThreadSetting apyfixedarray = {10'000}
ArrayThreadSetting apycfixedarray = {2'500}
ArrayThreadSetting apyfloatarray = {5'000}
ArrayThreadSetting apycfloatarray = {1'000}