Uni20
Asynchronous tensor and runtime library.
Loading...
Searching...
No Matches
blas_int.hpp
Go to the documentation of this file.
1#pragma once
2
9#include <uni20/config.hpp>
10
11#include <concepts>
12#include <cstddef>
13#include <stdexcept>
14#include <type_traits>
15#include <utility>
16
17namespace uni20::blas
18{
19
20static_assert(std::is_signed_v<blas_int>, "BLAS/LAPACK integer ABI type must be signed");
21
22inline constexpr blas_int invalid_blas_int = blas_int{-1};
23
25constexpr bool is_valid_blas_int(blas_int value) noexcept { return value >= 0; }
26
28template <std::integral Value> constexpr blas_int try_blas_int(Value value) noexcept
29{
30 if (!std::in_range<blas_int>(value))
31 {
32 return invalid_blas_int;
33 }
34
35 auto const converted = static_cast<blas_int>(value);
36 return converted >= 0 ? converted : invalid_blas_int;
37}
38
40inline blas_int checked_blas_int(std::size_t value)
41{
42 blas_int const converted = try_blas_int(value);
43 if (!is_valid_blas_int(converted))
44 {
45 throw std::overflow_error("dense dimension does not fit BLAS integer type");
46 }
47 return converted;
48}
49
50} // namespace uni20::blas
locale_t value
Definition data_table.cpp:49
Definition blas_int.hpp:18
constexpr blas_int try_blas_int(Value value) noexcept
Convert a non-negative integer to blas_int, or return the negative invalid sentinel.
Definition blas_int.hpp:28
constexpr blas_int invalid_blas_int
Definition blas_int.hpp:22
constexpr bool is_valid_blas_int(blas_int value) noexcept
Return whether a non-throwing BLAS integer conversion succeeded.
Definition blas_int.hpp:25
blas_int checked_blas_int(std::size_t value)
Convert a dense dimension to blas_int or throw on overflow.
Definition blas_int.hpp:40