Skip to content

Commit

Permalink
Fix bfloat16_t rounding functions
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleHerndon committed Feb 13, 2025
1 parent 6b3124d commit b2b7c73
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions shortfin/python/array_host_ops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,23 @@ template <>
struct is_trivially_copyable<bfloat16_t> : std::true_type {};
} // namespace std

// Math functions needed by xtensor for bfloat16_t
inline constexpr bfloat16_t round(bfloat16_t x) noexcept {
return bfloat16_t(std::round(float(x)));
}

inline constexpr bfloat16_t ceil(bfloat16_t x) noexcept {
return bfloat16_t(std::ceil(float(x)));
}

inline constexpr bfloat16_t floor(bfloat16_t x) noexcept {
return bfloat16_t(std::floor(float(x)));
}

inline constexpr bfloat16_t trunc(bfloat16_t x) noexcept {
return bfloat16_t(std::trunc(float(x)));
}

#endif // BFLOAT16_HPP

using namespace shortfin::array;
Expand Down

0 comments on commit b2b7c73

Please sign in to comment.