APyFloatArray
¶
-
class APyFloatArray : public APyArray<APyFloatData, APyFloatArray>¶
Public Functions
-
explicit APyFloatArray(const nanobind::sequence &sign_seq, const nanobind::sequence &exp_seq, const nanobind::sequence &man_seq, std::uint8_t exp_bits, std::uint8_t man_bits, std::optional<exp_t> bias = std::nullopt)¶
Constructor taking a sequence of signs, biased exponents, and mantissas. If no bias is given, an IEEE-like bias will be used.
-
APyFloatArray(const std::vector<std::size_t> &shape, exp_t exp_bits, std::uint8_t man_bits, std::optional<exp_t> bias = std::nullopt)¶
Constructor specifying only the shape and format of the array.
-
inline APyFloatArray create_array(const std::vector<std::size_t> &shape) const¶
-
inline bool same_type_as(const APyFloatArray &other) const noexcept¶
Test if two floating-point vectors have the same bit specifiers.
-
inline bool same_type_as(const APyFloat &other) const noexcept¶
Test if
*this
has the same bit specifiers as anotherAPyFloat
-
inline APyFloatSpec spec() const noexcept¶
Retrieve the bit specification.
-
APyFloatArray operator+(const APyFloatArray &rhs) const¶
-
APyFloatArray operator+(const APyFloat &rhs) const¶
-
APyFloatArray operator-(const APyFloatArray &rhs) const¶
-
APyFloatArray operator-(const APyFloat &rhs) const¶
-
APyFloatArray operator-() const¶
-
APyFloatArray operator*(const APyFloatArray &rhs) const¶
-
APyFloatArray operator*(const APyFloat &rhs) const¶
-
APyFloatArray operator/(const APyFloatArray &rhs) const¶
-
APyFloatArray operator/(const APyFloat &rhs) const¶
-
APyFloatArray abs() const¶
Absolute value.
-
APyFloatArray rdiv(const APyFloat &lhs) const¶
Elementwise R-division with floating-point scalar.
-
APyFloatArray rsub(const APyFloat &lhs) const¶
Elementwise R-subtraction with floating-point scalar.
-
std::variant<APyFloatArray, APyFloat> matmul(const APyFloatArray &rhs) const¶
Matrix multiplication. If both arguments are 2-D tensors, this method performs the ordinary matrix multiplication. If input dimensions are greater than 2, this method performs stacked matrix multiplications, where the dimensions of last two dimensions are treated as matrices.
-
std::string repr() const¶
Python
__repr__()
function.
-
void _set_values_from_ndarray(const nanobind::ndarray<nanobind::c_contig> &ndarray)¶
Set data fields based on an and-array of doubles.
-
APyFloatArray convolve(const APyFloatArray &other, const std::string &mode) const¶
Perform a linear convolution with
other
usingmode
-
std::variant<APyFloatArray, APyFloat> sum(std::optional<std::variant<nb::tuple, nb::int_>> axis = std::nullopt) const¶
Sum over one or more axes.
-
APyFloatArray cumsum(std::optional<nb::int_> axis = std::nullopt) const¶
Cumulative sum over one or more axes.
-
std::variant<APyFloatArray, APyFloat> nansum(std::optional<std::variant<nb::tuple, nb::int_>> axis = std::nullopt) const¶
Sum over one or more axes, treating Nan as 0.
-
APyFloatArray nancumsum(std::optional<nb::int_> axis = std::nullopt) const¶
Cumulative sum over one or more axes, treatíng Nan as 0.
-
std::variant<APyFloatArray, APyFloat> prod(std::optional<std::variant<nb::tuple, nb::int_>> axis = std::nullopt) const¶
Multiplication over one or more axes.
-
APyFloatArray cumprod(std::optional<nb::int_> axis = std::nullopt) const¶
Cumulative multiplication over one or more axes.
-
std::variant<APyFloatArray, APyFloat> nanprod(std::optional<std::variant<nb::tuple, nb::int_>> axis = std::nullopt) const¶
Multiplication over one or more axes, treating Nan as 0.
-
APyFloatArray nancumprod(std::optional<nb::int_> axis = std::nullopt) const¶
Cumulative multiplication over one or more axes, treating Nan as 0.
-
std::variant<APyFloatArray, APyFloat> max(std::optional<std::variant<nb::tuple, nb::int_>> axis = std::nullopt) const¶
Return the maximum of an array or the maximum along an axis.
-
std::variant<APyFloatArray, APyFloat> min(std::optional<std::variant<nb::tuple, nb::int_>> axis = std::nullopt) const¶
Return the minimum of an array or the minimum along an axis.
-
std::variant<APyFloatArray, APyFloat> nanmax(std::optional<std::variant<nb::tuple, nb::int_>> axis = std::nullopt) const¶
Return the maximum of an array or the maximum along an axis. Ignoring nan.
-
std::variant<APyFloatArray, APyFloat> nanmin(std::optional<std::variant<nb::tuple, nb::int_>> axis = std::nullopt) const¶
Return the minimum of an array or the minimum along an axis. Ignoring nan.
-
APyFloatArray cast(std::optional<int> exp_bits, std::optional<int> man_bits, std::optional<exp_t> bias = std::nullopt, std::optional<QuantizationMode> quantization = std::nullopt) const¶
Return a copy of the tensor with the elements resized.
-
APyFloatArray _cast(std::uint8_t exp_bits, std::uint8_t man_bits, exp_t bias, std::optional<QuantizationMode> quantization = std::nullopt) const¶
Internal cast method when format is given fully.
-
APyFloatArray _cast(std::uint8_t exp_bits, std::uint8_t man_bits, exp_t bias, QuantizationMode quantization) const¶
Internal cast method when format and quantization mode is given.
-
APyFloatArray cast_no_quant(std::uint8_t exp_bits, std::uint8_t man_bits, std::optional<exp_t> bias = std::nullopt) const¶
Change the number of mantissa and exponent bits for cases where it is known that quantization does not happen, i.e., the resulting number of bits is not shorter.
-
inline exp_t get_bias() const¶
Return the bias.
-
inline std::uint8_t get_man_bits() const¶
Return the bit width of the mantissa field.
-
inline std::uint8_t get_exp_bits() const¶
Return the bit width of the exponent field.
-
inline std::uint8_t get_bits() const¶
Return the bit width of the entire floating-point format.
-
std::variant<nb::list, nb::ndarray<nb::numpy, uint64_t>, nb::ndarray<nb::numpy, uint32_t>, nb::ndarray<nb::numpy, uint16_t>, nb::ndarray<nb::numpy, uint8_t>> to_bits(bool numpy = false) const¶
Extract bit-pattern.
-
template<typename NB_ARRAY_TYPE, typename INT_TYPE>
nb::ndarray<NB_ARRAY_TYPE, INT_TYPE> to_bits_ndarray() const¶ Create an N-dimensional array containing bit-patterns.
-
nb::list to_bits_python_recursive_descent(std::size_t dim, std::vector<APyFloatData>::const_iterator &it) const¶
Create a nested Python list containing bit-patterns as Python integers.
-
APyFloatArray cast_to_double(std::optional<QuantizationMode> quantization = std::nullopt) const¶
Convenience method when target format is known to correspond to a double-precision floating-point
-
APyFloatArray cast_to_single(std::optional<QuantizationMode> quantization = std::nullopt) const¶
Convenience method when target format is known to correspond to a single-precision floating-point
-
APyFloatArray cast_to_half(std::optional<QuantizationMode> quantization = std::nullopt) const¶
Convenience method when target format is known to correspond to a half-precision floating-point
-
APyFloatArray cast_to_bfloat16(std::optional<QuantizationMode> quantization = std::nullopt) const¶
Convenience method when target format is known to correspond to a 16-bit brain float
-
APyFloat checked_inner_product(const APyFloatArray &rhs) const¶
Evaluate the inner between two vectors. This method assumes that the the shape of both
*this
andrhs
are equally long. Anything else is undefined behaviour.
-
APyFloatArray checked_2d_matmul(const APyFloatArray &rhs) const¶
Evaluate the matrix product between two 2D matrices. This method assumes that the shape of
*this
andrhs
have been checked to match a 2D matrix multiplication.
Public Members
-
std::uint8_t exp_bits¶
Number of exponent bits.
-
std::uint8_t man_bits¶
Number of mantissa bits.
-
exp_t bias¶
Exponent bias.
Public Static Functions
-
static inline APyFloatArray create_array_static(const std::vector<std::size_t> &shape, const APyFloat &flt)¶
-
static void create_in_place(APyFloatArray *apyfloatarray, const nanobind::sequence &sign_seq, const nanobind::sequence &exp_seq, const nanobind::sequence &man_seq, int exp_bits, int man_bits, std::optional<exp_t> bias = std::nullopt)¶
Factory function for Python interface.
-
static APyFloatArray from_numbers(const nanobind::sequence &number_seq, int exp_bits, int man_bits, std::optional<exp_t> bias = std::nullopt)¶
Create an
APyFloatArray
tensor object initialized with values from a sequence of numbers
-
static APyFloatArray from_array(const nanobind::ndarray<nanobind::c_contig> &ndarray, int exp_bits, int man_bits, std::optional<exp_t> bias = std::nullopt)¶
Create an
APyFloatArray
tensor object initialized with values from an ndarray.
-
static APyFloatArray from_bits(const nb::sequence &python_bit_patterns, int exp_bits, int man_bits, std::optional<exp_t> bias = std::nullopt)¶
Create an
APyFloatArray
tensor object initialized from bit-representation.
-
static APyFloatArray zeros(const nb::tuple &shape, std::uint8_t exp_bits, std::uint8_t man_bits, std::optional<exp_t> bias = std::nullopt)¶
-
static APyFloatArray ones(const nb::tuple &shape, std::uint8_t exp_bits, std::uint8_t man_bits, std::optional<exp_t> bias = std::nullopt)¶
-
static APyFloatArray eye(const nb::int_ &N, std::uint8_t exp_bits, std::uint8_t man_bits, std::optional<nb::int_> M, std::optional<exp_t> bias = std::nullopt)¶
-
static APyFloatArray identity(const nb::int_ &N, std::uint8_t exp_bits, std::uint8_t man_bits, std::optional<exp_t> bias = std::nullopt)¶
-
static APyFloatArray arange(const nb::object &start, const nb::object &stop, const nb::object &step, std::uint8_t exp_bits, std::uint8_t man_bits, std::optional<exp_t> bias = std::nullopt)¶
Create an
APyFloatArray
with evenly spaced values within a given interval.
-
static APyFloatArray _from_bits_ndarray(const nb::ndarray<nb::c_contig> &ndarray, int exp_bits, int man_bits, std::optional<exp_t> bias = std::nullopt)¶
Create an
APyFloatArray
tensor object initialized from bit-representation.
Public Static Attributes
-
static constexpr auto ARRAY_NAME = std::string_view("APyFloatArray")¶
Name of this array type (used when throwing errors)
Friends
-
template<typename RANDOM_ACCESS_ITERATOR_IN, typename RANDOM_ACCESS_ITERATOR_INOUT, typename APYFLOAT_TYPE>
friend void float_product(RANDOM_ACCESS_ITERATOR_IN src1, RANDOM_ACCESS_ITERATOR_IN src2, RANDOM_ACCESS_ITERATOR_INOUT dst, const APYFLOAT_TYPE &x, const APYFLOAT_TYPE &y)¶
-
explicit APyFloatArray(const nanobind::sequence &sign_seq, const nanobind::sequence &exp_seq, const nanobind::sequence &man_seq, std::uint8_t exp_bits, std::uint8_t man_bits, std::optional<exp_t> bias = std::nullopt)¶