Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
Namespaces | Classes | Typedefs | Enumerations | Functions | Variables
shambase Namespace Reference

namespace for basic c++ utilities More...

Namespaces

namespace  logs
 Namespace containing logs utils.
 

Classes

struct  arg_group
 A context group containing a section name and a list of arguments. More...
 
struct  args_info
 An argument containing a name and a value. More...
 
struct  BenchmarkResult
 Structure to store the results of a benchmark. More...
 
struct  context
 A context containing a list of argument groups. More...
 
class  DistributedData
 Represents a collection of objects distributed across patches identified by a u64 id. More...
 
class  DistributedDataShared
 Container for objects shared between two distributed data elements. More...
 
struct  FixedStack
 Fixed-capacity stack container with compile-time size determination. More...
 
class  FortranIOFile
 Class for reading and writing Fortran-style binary files. More...
 
class  FunctionTimer
 Class FunctionTimer measures the time it takes to execute a function. More...
 
struct  has_bitlen
 Check if a type has a certain number of bits. More...
 
class  has_operator_self_geq
 Checks if the type T has an operator ">=" defined for self-comparison. More...
 
class  has_operator_self_greater_than
 Checks if the type T has an operator ">" defined for self-comparison. More...
 
class  has_operator_self_leq
 Checks if the type T has an operator "<=" defined for self-comparison. More...
 
class  has_operator_self_less_than
 Checks if the type T has an operator "<" defined for self-comparison. More...
 
struct  OddEvenTransposeSortT
 
struct  OddEvenTransposeSortT< I, I >
 
struct  primitive_type_info
 Struct containing information about primitive types. More...
 
class  scoped_exception_gen_callback
 Scoped exception generator callback. More...
 
class  StorageComponent
 Helper class for Storage Module of any solver. More...
 
struct  table
 
class  Timer
 Class Timer measures the time elapsed since the timer was started. More...
 
struct  TypeNameInfo
 
struct  TypeNameInfo< f32 >
 
struct  TypeNameInfo< f64 >
 
struct  TypeNameInfo< i16 >
 
struct  TypeNameInfo< i32 >
 
struct  TypeNameInfo< i64 >
 
struct  TypeNameInfo< i8 >
 
struct  TypeNameInfo< shammath::C2< flt_type > >
 
struct  TypeNameInfo< shammath::C4< flt_type > >
 
struct  TypeNameInfo< shammath::C6< flt_type > >
 
struct  TypeNameInfo< shammath::M10< flt_type > >
 
struct  TypeNameInfo< shammath::M4< flt_type > >
 
struct  TypeNameInfo< shammath::M4DH3< flt_type > >
 
struct  TypeNameInfo< shammath::M4DH5< flt_type > >
 
struct  TypeNameInfo< shammath::M4DH7< flt_type > >
 
struct  TypeNameInfo< shammath::M4DH< flt_type > >
 
struct  TypeNameInfo< shammath::M4Shift16< flt_type > >
 
struct  TypeNameInfo< shammath::M4Shift2< flt_type > >
 
struct  TypeNameInfo< shammath::M4Shift4< flt_type > >
 
struct  TypeNameInfo< shammath::M4Shift8< flt_type > >
 
struct  TypeNameInfo< shammath::M5< flt_type > >
 
struct  TypeNameInfo< shammath::M6< flt_type > >
 
struct  TypeNameInfo< shammath::M7< flt_type > >
 
struct  TypeNameInfo< shammath::M8< flt_type > >
 
struct  TypeNameInfo< shammath::M9< flt_type > >
 
struct  TypeNameInfo< shammath::TGauss3< flt_type > >
 
struct  TypeNameInfo< shammath::TGauss5< flt_type > >
 
struct  TypeNameInfo< sycl::vec< T, n > >
 
struct  TypeNameInfo< u16 >
 
struct  TypeNameInfo< u32 >
 
struct  TypeNameInfo< u64 >
 
struct  TypeNameInfo< u8 >
 
class  WithUUID
 A class that provides unique identifiers (UUID) to instances. More...
 

Typedefs

template<class T >
using VectorProperties = sham::VectorProperties< T >
 
template<class T >
using VecComponent = sham::VecComponent< T >
 
using exception_gen_callback_t = void(*)(std::string msg)
 type of the exception generator callback
 
template<class T >
using formatter = fmt::formatter< T >
 Formatter alias for fmt::formatter
 
template<typename T >
using opt_ref = std::optional< std::reference_wrapper< T > >
 Optional reference wrapper.
 
using printer_t = void(*)(std::string_view)
 
using flush_t = void(*)()
 

Enumerations

enum  ParallelForWrapMode { PARALLEL_FOR , PARALLEL_FOR_ROUND , ND_RANGE }
 

Functions

template<class T , int n, std::enable_if_t< std::is_integral_v< T >, int > = 0>
i32 any (sycl::vec< T, n > v)
 Fallback function for sycl::any SYCL std : Returns 1 if the most significant bit in any component of x is set; otherwise returns 0. if it is something else than the most significant bit it is UB.
 
template<class T >
void check_buffer_size (sycl::buffer< T > &buf, u64 max_range, const SourceLocation loc=SourceLocation())
 check that the size of a sycl buffer is below or equal to the value of max range throw if it is not the case
 
std::string getDevice_type (const sycl::device &Device)
 Get the Device Type Name.
 
sycl::nd_range< 1 > make_range (u32 length, const u32 group_size=32)
 Generate a sycl nd range out of a group size and length.
 
template<u32 group_size = default_gsize, ParallelForWrapMode mode = default_loop_mode, class LambdaKernel >
void parallel_for (sycl::handler &cgh, u32 length, const char *name, LambdaKernel &&ker)
 
template<u32 group_size = default_gsize_2d, ParallelForWrapMode mode = default_loop_mode, class LambdaKernel >
void parallel_for_2d (sycl::handler &cgh, u32 length_x, u32 length_y, const char *name, LambdaKernel &&ker)
 
template<u32 group_size = default_gsize_3d, ParallelForWrapMode mode = default_loop_mode, class LambdaKernel >
void parallel_for_3d (sycl::handler &cgh, u32 length_x, u32 length_y, u32 length_z, const char *name, LambdaKernel &&ker)
 
template<ParallelForWrapMode mode = default_loop_mode, class LambdaKernel >
void parallel_for_gsize (sycl::handler &cgh, u32 length, u32 group_size, const char *name, LambdaKernel &&ker)
 
void check_queue_state (sycl::queue &q, SourceLocation loc=SourceLocation())
 
template<class T , class Comp >
void ptr_insert_sort (T *data, u32 start, u32 end, Comp &&comp)
 Simple insertion sort on pointer range.
 
template<class T , int ArrSize, class Comp >
void odd_even_transpose_sort_segment_flags (T *data, const u8 *segment_boundary, Comp comp)
 Odd-even transpose sort with segment boundaries.
 
template<class T >
void stream_write (std::basic_stringstream< byte > &stream, T &obj)
 
template<class T >
void stream_read (std::basic_stringstream< byte > &stream, T &obj)
 
void stream_write_string (std::basic_stringstream< byte > &stream, std::string &s)
 
void stream_read_string (std::basic_stringstream< byte > &stream, std::string &s)
 
template<class T >
void stream_write_vector (std::basic_stringstream< byte > &stream, std::vector< T > &vec)
 write the vector into the bytestream
 
template<class T >
void stream_read_vector (std::basic_stringstream< byte > &stream, std::vector< T > &vec)
 read a vector from the bytestream Note : this appends read objects to the vector without resetting it
 
template<class T >
void stream_write_vector_trivial (std::basic_stringstream< byte > &stream, std::vector< T > &vec)
 
template<class T >
void stream_read_vector_trivial (std::basic_stringstream< byte > &stream, std::vector< T > &vec)
 read a vector from the bytestream Note : this appends read objects to the vector without resetting it
 
u64 fnv1a_hash (const char *data, size_t size)
 Compute the FNV-1a hash of a given data.
 
template<class T1 , class FuncMatch , class FuncMissing , class FuncExtra >
void on_distributeddata_ids_diff (const shambase::DistributedData< T1 > &dd, const std::vector< u64 > &ref_ids, FuncMatch &&func_missing, FuncMissing &&func_match, FuncExtra &&func_extra)
 Compare two distributed data and apply callbacks based on the difference.
 
template<class T1 , class T2 , class FuncMatch , class FuncMissing , class FuncExtra >
void on_distributeddata_diff (const shambase::DistributedData< T1 > &dd, const shambase::DistributedData< T2 > &reference, FuncMatch &&func_missing, FuncMissing &&func_match, FuncExtra &&func_extra)
 Compare two distributed data and apply callbacks based on the difference.
 
bool is_little_endian ()
 Check if the CPU is in little endian.
 
template<class T >
void endian_swap (T &a)
 Swap the endianness of the input value.
 
template<class T >
get_endian_swap (T a)
 Return a copy of the input value with the endianness swapped.
 
std::string exception_format (SourceLocation loc)
 Format the exception message with the source location information.
 
void set_exception_gen_callback (exception_gen_callback_t callback)
 Set the exception generator callback.
 
exception_gen_callback_t get_exception_gen_callback ()
 Get the current exception generator callback.
 
void exception_gen_callback (std::string msg)
 The callback called when an exception is thrown.
 
template<class ExcptTypes >
ExcptTypes make_except_with_loc (std::string message, SourceLocation loc=SourceLocation{})
 Create an exception with a message and a location.
 
template<class ExcptTypes >
void throw_with_loc (std::string message, SourceLocation loc=SourceLocation{})
 Throw an exception and append the source location to it.
 
void throw_unimplemented (SourceLocation loc=SourceLocation{})
 Throw a std::runtime_error saying that the function is unimplemented.
 
void throw_unimplemented (std::string message, SourceLocation loc=SourceLocation{})
 Throw a std::runtime_error with a message saying that the function is unimplemented.
 
template<class exception_type >
exception_type make_except_with_loc_with_ctx (std::string message, context ctx, SourceLocation loc=SourceLocation{})
 Make an exception with a message and variadic context groups.
 
template<i32 power, class T >
constexprpow_constexpr_fast_inv (T a, T a_inv) noexcept
 
FortranIOFile load_fortran_file (const std::string &fname)
 Load a Fortran formatted file from disk.
 
template<class T , std::enable_if_t< std::is_integral_v< T >, int > = 0>
constexpr bool is_pow_of_two_fast (T v) noexcept
 determine if v is a power of two Warning : this function return true if v == 0 Source : https://graphics.stanford.edu/~seander/bithacks.html
 
template<class T , std::enable_if_t< std::is_integral_v< T >, int > = 0>
constexpr bool is_pow_of_two (T v) noexcept
 determine if v is a power of two and check if v==0 Source : https://graphics.stanford.edu/~seander/bithacks.html
 
template<class T , std::enable_if_t< std::is_integral_v< T >||std::is_signed_v< T >, int > = 0>
constexpr bool sign_differ (T a, T b) noexcept
 check if the sign of the two integers differs Source : https://graphics.stanford.edu/~seander/bithacks.html
 
template<class T , std::enable_if_t< std::is_integral_v< T >, int > = 0>
void xor_swap (T &a, T &b)
 swap two values using xor Source : https://graphics.stanford.edu/~seander/bithacks.html
 
template<class T , std::enable_if_t< std::is_integral_v< T >||(!std::is_signed_v< T >), int > = 0>
constexprroundup_pow2 (T v) noexcept
 round up to the next power of two Source : https://graphics.stanford.edu/~seander/bithacks.html
 
constexpr u32 group_count (u32 len, u32 group_size)
 Calculates the number of groups based on the length and group size.
 
template<class T , std::enable_if_t< std::is_integral_v< T >, int > = 0>
select_bit (T value, T bitnum)
 Selects and returns the bit at a specific position in the given value.
 
template<class T , std::enable_if_t< std::is_integral_v< T >, int > = 0>
constexprmost_sig_bit_mask () noexcept
 Generates a mask with only the most significant bit set.
 
template<class T , std::enable_if_t< std::is_integral_v< T >, int > = 0>
constexpr bool is_most_sig_bit_set (const T x) noexcept
 Checks if the most significant bit is set in the given value.
 
template<i32 power, class T >
constexprpow_constexpr (T a) noexcept
 Calculates the power of a number at compile time.
 
template<u32 flag>
constexpr bool is_flag_on (u32 val)
 
template<class T , class AccU8 >
void store_u8 (AccU8 &acc, u64 idx_write, T a)
 Store a value of type T in a byte buffer.
 
template<class T , class AccU8 >
load_u8 (AccU8 &acc, u64 ptr_load)
 load a value of type T from a byte buffer
 
template<class T , class TAcc >
void store_conv (TAcc *acc, T a)
 pointer cast store the value
 
template<class T , class TAcc >
load_conv (TAcc *acc)
 pointer cast load from a pointer
 
template<class T >
T & get_check_ref (const std::unique_ptr< T > &ptr, SourceLocation loc=SourceLocation())
 Takes a std::unique_ptr and returns a reference to the object it holds. It throws a std::runtime_error if the std::unique_ptr does not hold anything.
 
template<class T >
T & get_check_ref (const std::shared_ptr< T > &ptr, SourceLocation loc=SourceLocation())
 Takes a std::shared_ptr and returns a reference to the object it holds. It throws a std::runtime_error if the std::shared_ptr does not hold anything.
 
template<class T >
const T & get_check_ref (const std::optional< T > &ptr, SourceLocation loc=SourceLocation())
 Get reference to object held by the unique ptr, and throw if nothing is held.
 
template<class T >
T & get_check_ref (std::optional< T > &ptr, SourceLocation loc=SourceLocation())
 Same overload but for non const case.
 
template<class T >
T & get_check_ref (T *ptr, SourceLocation loc=SourceLocation())
 Takes a raw pointer and returns a reference to the object it points to. It throws a std::runtime_error if the pointer is null.
 
template<class T >
const T & get_check_ref (const T *ptr, SourceLocation loc=SourceLocation())
 same overload but for const pointer
 
template<typename T >
auto extract_value (std::optional< T > &o, SourceLocation loc=SourceLocation()) -> T
 Extracts the content out of an optional.
 
template<typename T >
auto extract_pointer (std::unique_ptr< T > &o, SourceLocation loc=SourceLocation()) -> T
 extract content out of unique_ptr
 
template<int n, class T >
std::array< T, n > convert_to_array (std::vector< T > &in)
 Convert a vector to an array of size n.
 
template<class U , class T >
constexpr bool can_narrow (T val)
 Check if an integer value can be safely narrowed to a target type.
 
template<class U , class T >
U narrow_or_throw (T val, SourceLocation &&callsite=SourceLocation{})
 
template<class T >
constexprget_max ()
 
template<class T >
constexprget_min ()
 
template<class T >
constexprget_epsilon ()
 
template<class T >
constexprget_infty ()
 
std::string popen_fetch_output (const char *command)
 Run a command and return the output.
 
void print (std::string_view sv)
 Prints a string to the console.
 
void println (std::string_view sv)
 Prints a string to the console followed by a newline.
 
void flush ()
 Flushes the output buffer.
 
void change_printer (void(*func_printer_normal)(std::string_view), void(*func_printer_ln)(std::string_view), void(*func_flush_func)())
 Changes the behavior of the print, println and flush functions.
 
void reset_std_behavior ()
 Restores the default behavior of the print and println functions.
 
bool is_aligned (const void *ptr, size_t alignment) noexcept
 Check if a pointer is aligned with the given alignment.
 
template<class T >
bool is_aligned (const void *ptr) noexcept
 Check if a pointer is aligned with the given type.
 
template<class T , class Container1 , class Container2 >
void set_diff (Container1 &c1, Container2 &ref, std::vector< T > &missing, std::vector< T > &matching, std::vector< T > &extra)
 Compute the difference between two containers as three separate vectors.
 
std::string fmt_callstack ()
 Get the formatted callstack.
 
void set_callstack_process_identifier (std::string identifier)
 
void add_callstack_gen_info_generator (std::string(*generator)())
 
template<class T >
std::vector< T > vector_from_set (const std::set< T > &in)
 
template<class T >
std::set< T > set_from_vector (const std::vector< T > &in)
 
template<class K , class T >
std::vector< K > keys_from_map (const std::unordered_map< K, T > &in)
 
 __attribute__ ((always_inline)) auto vformat(std
 format a string using fmtlib style Cheat sheet : https://hackingcpp.com/cpp/libs/fmt.html
 
template<class It , typename... Tformat>
std::string format_array (const It &iter, u32 len, u32 column_count, fmt::format_string< Tformat... > fmt)
 Format an array of elements into a string.
 
std::string readable_sizeof (double size)
 given a sizeof value return a readble string Example : readable_sizeof(1024*1024*1024) -> "1.00 GB"
 
void write_string_to_file (std::string filename, std::string s)
 dump a string to a file
 
void replace_all (std::string &inout, std::string_view what, std::string_view with)
 replace all occurence of a search string with another
 
std::string increase_indent (std::string in, std::string delim="\n ")
 Increase indentation of a string.
 
std::string trunc_str (std::string s, u32 max_len)
 Truncate a string to a specified length, adding an ellipsis if necessary.
 
std::string trunc_str_start (std::string s, u32 max_len)
 Truncate a string to a specified length, adding an ellipsis at the start if necessary.
 
bool contain_substr (std::string str, std::string what)
 Check if a substring is present in a given string.
 
std::string shorten_string (std::string str, u32 len)
 Shortens a string by removing the last specified number of characters.
 
std::vector< std::string > split_str (std::string s, std::string delimiter)
 Splits a string into a vector of substrings according to a delimiter.
 
std::string nanosec_to_time_str (double nanosec)
 Convert nanoseconds to a human-readable string representation.
 
template<class Func >
f64 timeit (Func &&f, u32 relaunch=1)
 Measures the average time it takes to execute a function.
 
template<class Func >
f64 timeitfor (Func &&f, f64 max_duration=1)
 Measures the average time it takes to execute a function until a maximum duration is reached.
 
BenchmarkResult benchmark_pow_len (std::function< f64(u32)> func, u32 start, u32 end, f64 pow_exp)
 Benchmark a function with input values following a power law.
 
template<class T >
std::string get_type_name ()
 
template<class signature , class Func >
constexpr void check_functor_nocapture (Func &&func)
 Check if a lambda or a function has the correct signature.
 
template<class RetType , class... Targ, class Func >
constexpr void check_functor_nocapture_deduce (Func &&func, Targ...)
 Check if a callable object has the correct deduced signature.
 
template<class RetType , class... Targ, class Func >
constexpr void check_functor_signature (Func &&func)
 Check if a callable object has the correct deduced signature.
 
template<class... Targ, class Func >
constexpr void check_functor_signature_noreturn (Func &&func)
 variant of check_functor_signature that does not check the return type
 
template<class RetType , class... Targ, class Func >
constexpr void check_functor_signature_deduce (Func &&func, Targ...)
 Check if a callable object has the correct deduced signature.
 
template<class... Targ, class Func >
constexpr void check_functor_signature_deduce_noreturn (Func &&func, Targ...)
 variant of check_functor_signature_deduce that does not check the return type
 
template<class... Targ2, class... Targ, class Func >
constexpr void check_functor_signature_deduce_noreturn_add_t (Func &&func, Targ...)
 variant of check_functor_signature_deduce that does not check the return type and where some types can be specified manually
 
template<class T >
std::shared_ptr< T > to_shared (T &&t)
 

Variables

constexpr u32 default_gsize = SHAMROCK_LOOP_GSIZE
 
constexpr u32 default_gsize_2d = 16
 
constexpr u32 default_gsize_3d = 4
 
template<class T >
constexpr u64 bitsizeof = sizeof(T) * CHAR_BIT
 Number of bits in a type T.
 
template<typename T , int num>
constexpr bool has_bitlen_v = has_bitlen<T, num>::value
 Helper variable template for has_bitlen.
 
template<class >
constexpr bool always_false_v = false
 Helper variable template that is always false. Especially useful to perform static asserts based on templates.
 
template<bool val, class type >
constexpr bool typed_false_v = val
 Helper variable template that is used to associate a type to a boolean value in the compile logs.
 
void(* exception_print_callback )(std::string msg) = nullptr
 exception print callback func ptr
 
std::string _callstack_process_identifier
 
std::vector< std::function< std::string()> > _callstack_gen_info_generators
 

Detailed Description

namespace for basic c++ utilities

Typedef Documentation

◆ exception_gen_callback_t

type of the exception generator callback

Definition at line 42 of file exception.hpp.

◆ flush_t

using shambase::flush_t = typedef void (*)()

Definition at line 24 of file print.cpp.

◆ formatter

template<class T >
using shambase::formatter = typedef fmt::formatter<T>

Formatter alias for fmt::formatter

This alias is used to prevent explicit use of the fmt library in the codebase. This way, we can change the formatting library without having to modify all the code that uses it.

Template Parameters
TType to format

Definition at line 35 of file format.hpp.

◆ opt_ref

template<typename T >
using shambase::opt_ref = typedef std::optional<std::reference_wrapper<T> >

Optional reference wrapper.

Definition at line 26 of file optional.hpp.

◆ printer_t

using shambase::printer_t = typedef void (*)(std::string_view)

Definition at line 23 of file print.cpp.

◆ VecComponent

template<class T >
using shambase::VecComponent = typedef sham::VecComponent<T>

Definition at line 151 of file vec.hpp.

◆ VectorProperties

Definition at line 148 of file vec.hpp.

Enumeration Type Documentation

◆ ParallelForWrapMode

enum shambase::ParallelForWrapMode

Definition at line 80 of file sycl_utils.hpp.

Function Documentation

◆ __attribute__()

shambase::__attribute__ ( (always_inline )
inline

format a string using fmtlib style Cheat sheet : https://hackingcpp.com/cpp/libs/fmt.html

Template Parameters
T
Parameters
fmtthe format string
argsthe arguments to format agains
Returns
std::string the formatted string

format a string using C printf style https://cplusplus.com/reference/cstdio/printf/

Template Parameters
T
Parameters
fmtthe format string
argsthe arguments to format agains
Returns
std::string the formatted string

Definition at line 33 of file string.hpp.

+ Here is the call graph for this function:

◆ add_callstack_gen_info_generator()

void shambase::add_callstack_gen_info_generator ( std::string(*)()  generator)

Definition at line 229 of file stacktrace.cpp.

◆ any()

template<class T , int n, std::enable_if_t< std::is_integral_v< T >, int > = 0>
i32 shambase::any ( sycl::vec< T, n >  v)

Fallback function for sycl::any SYCL std : Returns 1 if the most significant bit in any component of x is set; otherwise returns 0. if it is something else than the most significant bit it is UB.

Template Parameters
T
n
Parameters
v
Returns
i32

Definition at line 38 of file sycl_builtins.hpp.

+ Here is the call graph for this function:

◆ benchmark_pow_len()

BenchmarkResult shambase::benchmark_pow_len ( std::function< f64(u32)>  func,
u32  start,
u32  end,
f64  pow_exp 
)
inline

Benchmark a function with input values following a power law.

This function takes a function and a range of input values, and benchmarks it by executing the function with each of the input values. The input values are generated by starting at the start value and repeatedly multiplying by pow_exp until the end value is reached.

Parameters
funcThe function to be benchmarked.
startThe starting value of the input.
endThe ending value of the input.
pow_expThe power of the exponent to increase the input value.
Returns
BenchmarkResult A structure containing the counts and times of the benchmark.

Definition at line 254 of file time.hpp.

+ Here is the call graph for this function:

◆ can_narrow()

template<class U , class T >
constexpr bool shambase::can_narrow ( val)
constexpr

Check if an integer value can be safely narrowed to a target type.

This function checks whether an integer value of type T can be represented in the target integer type U without overflow. Works with both signed and unsigned integer types for now.

Template Parameters
UThe target integer type to narrow to
TThe source integer type of the value
Parameters
valThe value to check
Returns
true if the value can be safely narrowed to type U
false if narrowing would cause overflow
i32 value = 300;
bool can_fit = can_narrow<i8>(value); // false, 300 > 127
i32 small = 100;
bool ok = can_narrow<i16>(small); // true, 100 fits in i16
i32 negative = -10;
bool unsigned_ok = can_narrow<u32>(negative); // false, negative value
std::int32_t i32
32 bit integer
void throw_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Throw an exception and append the source location to it.

Definition at line 54 of file narrowing.hpp.

+ Here is the call graph for this function:

◆ change_printer()

void shambase::change_printer ( void(*)(std::string_view)  func_printer_normal,
void(*)(std::string_view)  func_printer_ln,
void(*)()  func_flush_func 
)

Changes the behavior of the print, println and flush functions.

Parameters
func_printer_normalThe function to be used for printing a string to the console.
func_printer_lnThe function to be used for printing a string to the console followed by a newline.
func_flush_funcThe function to be used for flushing the output buffer.

Definition at line 52 of file print.cpp.

+ Here is the call graph for this function:

◆ check_buffer_size()

template<class T >
void shambase::check_buffer_size ( sycl::buffer< T > &  buf,
u64  max_range,
const SourceLocation  loc = SourceLocation() 
)

check that the size of a sycl buffer is below or equal to the value of max range throw if it is not the case

Template Parameters
T
Parameters
buf
max_range
loc

Definition at line 43 of file sycl_utils.hpp.

+ Here is the call graph for this function:

◆ check_functor_nocapture()

template<class signature , class Func >
constexpr void shambase::check_functor_nocapture ( Func &&  func)
constexpr

Check if a lambda or a function has the correct signature.

The function does nothing at runtime, but at compile time it checks if the given lambda or function has the correct signature. If the signature is wrong, the static assert will fail and the correct signature will be indicated in the signature of always_false_v<...>.

Warning
This does not work with capturing lambdas
auto func = [](int a, int b) -> int { return a + b; };

Definition at line 262 of file type_traits.hpp.

+ Here is the call graph for this function:

◆ check_functor_nocapture_deduce()

template<class RetType , class... Targ, class Func >
constexpr void shambase::check_functor_nocapture_deduce ( Func &&  func,
Targ...   
)
constexpr

Check if a callable object has the correct deduced signature.

This function deduces the signature of the callable object using the provided return type and argument types, then checks if the callable matches this signature using check_functor.

Template Parameters
RetTypeThe return type of the callable.
TargThe types of the arguments the callable takes.
FuncThe type of the callable object to check.
Parameters
funcThe callable object to be checked.

Definition at line 284 of file type_traits.hpp.

+ Here is the call graph for this function:

◆ check_functor_signature()

template<class RetType , class... Targ, class Func >
constexpr void shambase::check_functor_signature ( Func &&  func)
constexpr

Check if a callable object has the correct deduced signature.

This function deduces the signature of the callable object using the provided return type and argument types, then checks if the callable matches this signature using check_functor and also checks if the return type matches the deduced return type.

Example :

int x = 0;
auto func = [x](int a, int b) -> int { return a + b; };
Note
This function works also for lambda with captures
Template Parameters
RetTypeThe return type of the callable.
TargThe types of the arguments the callable takes.
FuncThe type of the callable object to check.
Parameters
funcThe callable object to be checked.

Definition at line 311 of file type_traits.hpp.

+ Here is the call graph for this function:

◆ check_functor_signature_deduce()

template<class RetType , class... Targ, class Func >
constexpr void shambase::check_functor_signature_deduce ( Func &&  func,
Targ...   
)
constexpr

Check if a callable object has the correct deduced signature.

This function deduces the signature of the callable object using the provided return type and argument types, then checks if the callable matches this signature using check_functor_signature.

Template Parameters
RetTypeThe return type of the callable.
TargThe types of the arguments the callable takes.
FuncThe type of the callable object to check.
Parameters
funcThe callable object to be checked.

Definition at line 355 of file type_traits.hpp.

+ Here is the call graph for this function:

◆ check_functor_signature_deduce_noreturn()

template<class... Targ, class Func >
constexpr void shambase::check_functor_signature_deduce_noreturn ( Func &&  func,
Targ...   
)
constexpr

variant of check_functor_signature_deduce that does not check the return type

Definition at line 361 of file type_traits.hpp.

+ Here is the call graph for this function:

◆ check_functor_signature_deduce_noreturn_add_t()

template<class... Targ2, class... Targ, class Func >
constexpr void shambase::check_functor_signature_deduce_noreturn_add_t ( Func &&  func,
Targ...   
)
constexpr

variant of check_functor_signature_deduce that does not check the return type and where some types can be specified manually

For example when using a type with a reference, this is not properly deduced. This functions allows to specify the type manually with the reference.

Here the function signature will be auto(sycl::handler&, <other types>)

Definition at line 383 of file type_traits.hpp.

+ Here is the call graph for this function:

◆ check_functor_signature_noreturn()

template<class... Targ, class Func >
constexpr void shambase::check_functor_signature_noreturn ( Func &&  func)
constexpr

variant of check_functor_signature that does not check the return type

Definition at line 331 of file type_traits.hpp.

+ Here is the call graph for this function:

◆ check_queue_state()

void shambase::check_queue_state ( sycl::queue &  q,
SourceLocation  loc = SourceLocation() 
)
inline

Definition at line 320 of file sycl_utils.hpp.

◆ contain_substr()

bool shambase::contain_substr ( std::string  str,
std::string  what 
)
inline

Check if a substring is present in a given string.

Parameters
strThe input string
whatThe substring to search for
Returns
true If the substring is found
false If the substring is not found

Definition at line 258 of file string.hpp.

+ Here is the call graph for this function:

◆ convert_to_array()

template<int n, class T >
std::array< T, n > shambase::convert_to_array ( std::vector< T > &  in)
inline

Convert a vector to an array of size n.

Template Parameters
nThe size of the array
TThe type of the elements in the array
Parameters
inThe input vector
Returns
std::array<T, n> The converted array
Exceptions
std::invalid_argumentIf the input vector size does not match n

Definition at line 246 of file memory.hpp.

+ Here is the call graph for this function:

◆ endian_swap()

template<class T >
void shambase::endian_swap ( T &  a)
inline

Swap the endianness of the input value.

This function will swap the endianness of the input value a.

Template Parameters
Ttype of the input value
Parameters
ainput value

Definition at line 51 of file endian.hpp.

+ Here is the call graph for this function:

◆ exception_format()

std::string shambase::exception_format ( SourceLocation  loc)

Format the exception message with the source location information.

This function formats a string that contains the source location information. It is useful to add this information to the exception message, in order to have a better understanding of where the exception was thrown.

Parameters
locThe location from where the exception was thrown
Returns
std::string The formatted exception message

Definition at line 24 of file exception.cpp.

+ Here is the call graph for this function:

◆ exception_gen_callback()

void shambase::exception_gen_callback ( std::string  msg)

The callback called when an exception is thrown.

This callback is called with the formatted exception message as argument. It is settable with set_exception_gen_callback.

Parameters
msgThe formatted exception message

Definition at line 31 of file exception.cpp.

+ Here is the call graph for this function:

◆ extract_pointer()

template<typename T >
auto shambase::extract_pointer ( std::unique_ptr< T > &  o,
SourceLocation  loc = SourceLocation() 
) -> T

extract content out of unique_ptr

Template Parameters
T
Parameters
o
Returns
T

Definition at line 227 of file memory.hpp.

+ Here is the call graph for this function:

◆ extract_value()

template<typename T >
auto shambase::extract_value ( std::optional< T > &  o,
SourceLocation  loc = SourceLocation() 
) -> T

Extracts the content out of an optional.

This function that takes an std::optional object and extracts the value from it. If the optional is empty, it throws a runtime error. The extracted value is returned, and the optional is left in an empty state.

See also
https://stackoverflow.com/questions/71980007/take-value-out-of-stdoptional
Template Parameters
Tthe type of the optional
Parameters
oreference to the optional object
locThe source location where this function is called.
Returns
T the value extracted from the optional
Exceptions
std::runtime_errorIf the std::unique_ptr does not hold anything.

Definition at line 211 of file memory.hpp.

+ Here is the call graph for this function:

◆ flush()

void shambase::flush ( )

Flushes the output buffer.

This function forces the output buffer to be written to the console immediately, rather than waiting for the buffer to fill up.

Definition at line 44 of file print.cpp.

◆ fmt_callstack()

std::string shambase::fmt_callstack ( )

Get the formatted callstack.

get the formatted callstack

This function returns a formatted string representing the current call stack.

Returns
The formatted call stack as a string.
std::string

Definition at line 238 of file stacktrace.cpp.

+ Here is the call graph for this function:

◆ fnv1a_hash()

u64 shambase::fnv1a_hash ( const char data,
size_t  size 
)
inline

Compute the FNV-1a hash of a given data.

Parameters
data
size
Returns
u64

Definition at line 31 of file checksum.hpp.

+ Here is the call graph for this function:

◆ format_array()

template<class It , typename... Tformat>
std::string shambase::format_array ( const It iter,
u32  len,
u32  column_count,
fmt::format_string< Tformat... >  fmt 
)
inline

Format an array of elements into a string.

This function takes an iterator to the first element of the array, the length of the array, the number of elements per column, and a format string. It formats each element of the array using the format string and concatenates the formatted elements into a single string.

Template Parameters
ItIterator type (deduced)
Tformatvariadic template type (deduced)
Parameters
iteriterator to the first element of the array
lenlength of the array
column_countnumber of elements per column
fmtformat string
Returns
std::string the formatted string
Exceptions
std::invalid_argumentif the format string is invalid

Definition at line 111 of file string.hpp.

+ Here is the call graph for this function:

◆ get_check_ref() [1/6]

template<class T >
const T & shambase::get_check_ref ( const std::optional< T > &  ptr,
SourceLocation  loc = SourceLocation() 
)
inline

Get reference to object held by the unique ptr, and throw if nothing is held.

Template Parameters
T
Parameters
ptr
Returns
T&

Definition at line 149 of file memory.hpp.

+ Here is the call graph for this function:

◆ get_check_ref() [2/6]

template<class T >
T & shambase::get_check_ref ( const std::shared_ptr< T > &  ptr,
SourceLocation  loc = SourceLocation() 
)
inline

Takes a std::shared_ptr and returns a reference to the object it holds. It throws a std::runtime_error if the std::shared_ptr does not hold anything.

Template Parameters
TThe type of the object held by the std::shared_ptr.
Parameters
ptrA reference to the std::shared_ptr.
locThe source location where this function is called.
Returns
A reference to the object held by the std::shared_ptr.
Exceptions
std::runtime_errorIf the std::shared_ptr does not hold anything.

Definition at line 131 of file memory.hpp.

+ Here is the call graph for this function:

◆ get_check_ref() [3/6]

template<class T >
T & shambase::get_check_ref ( const std::unique_ptr< T > &  ptr,
SourceLocation  loc = SourceLocation() 
)
inline

Takes a std::unique_ptr and returns a reference to the object it holds. It throws a std::runtime_error if the std::unique_ptr does not hold anything.

Template Parameters
TThe type of the object held by the std::unique_ptr.
Parameters
ptrA reference to the std::unique_ptr.
locThe source location where this function is called.
Returns
A reference to the object held by the std::unique_ptr.
Exceptions
std::runtime_errorIf the std::unique_ptr does not hold anything.

Definition at line 110 of file memory.hpp.

+ Here is the call graph for this function:

◆ get_check_ref() [4/6]

template<class T >
const T & shambase::get_check_ref ( const T *  ptr,
SourceLocation  loc = SourceLocation() 
)
inline

same overload but for const pointer

Definition at line 187 of file memory.hpp.

+ Here is the call graph for this function:

◆ get_check_ref() [5/6]

template<class T >
T & shambase::get_check_ref ( std::optional< T > &  ptr,
SourceLocation  loc = SourceLocation() 
)
inline

Same overload but for non const case.

Definition at line 159 of file memory.hpp.

+ Here is the call graph for this function:

◆ get_check_ref() [6/6]

template<class T >
T & shambase::get_check_ref ( T *  ptr,
SourceLocation  loc = SourceLocation() 
)
inline

Takes a raw pointer and returns a reference to the object it points to. It throws a std::runtime_error if the pointer is null.

Template Parameters
TThe type of the object pointed to by the raw pointer.
Parameters
ptrThe raw pointer.
locThe source location where this function is called.
Returns
A reference to the object pointed to by the raw pointer.
Exceptions
std::runtime_errorIf the raw pointer is null.

Definition at line 177 of file memory.hpp.

+ Here is the call graph for this function:

◆ get_endian_swap()

template<class T >
T shambase::get_endian_swap ( a)
inline

Return a copy of the input value with the endianness swapped.

This function returns a copy of its input value, with the endianness of the value swapped. The input value is not modified.

Template Parameters
TThe type of the input value.
Parameters
aThe input value whose endianness is to be swapped.
Returns
A copy of a with its endianness swapped.

Definition at line 86 of file endian.hpp.

+ Here is the call graph for this function:

◆ get_epsilon()

template<class T >
constexpr T shambase::get_epsilon ( )
constexpr

Definition at line 42 of file numeric_limits.hpp.

◆ get_exception_gen_callback()

exception_gen_callback_t shambase::get_exception_gen_callback ( )

Get the current exception generator callback.

This function returns the current exception generator callback.

Returns
exception_gen_callback_t The current exception generator callback

Definition at line 41 of file exception.cpp.

◆ get_infty()

template<class T >
constexpr T shambase::get_infty ( )
constexpr

Definition at line 52 of file numeric_limits.hpp.

◆ get_max()

template<class T >
constexpr T shambase::get_max ( )
constexpr

Definition at line 26 of file numeric_limits.hpp.

◆ get_min()

template<class T >
constexpr T shambase::get_min ( )
constexpr

Definition at line 34 of file numeric_limits.hpp.

◆ get_type_name()

template<class T >
std::string shambase::get_type_name ( )

Definition at line 35 of file type_name_info.hpp.

◆ getDevice_type()

std::string shambase::getDevice_type ( const sycl::device &  Device)
inline

Get the Device Type Name.

Parameters
Device
Returns
std::string

Definition at line 56 of file sycl_utils.hpp.

+ Here is the call graph for this function:

◆ group_count()

constexpr u32 shambase::group_count ( u32  len,
u32  group_size 
)
inlineconstexpr

Calculates the number of groups based on the length and group size.

Parameters
lenThe total length
group_sizeThe size of each group
Returns
constexpr u32 The number of groups

Definition at line 125 of file integer.hpp.

+ Here is the call graph for this function:

◆ increase_indent()

std::string shambase::increase_indent ( std::string  in,
std::string  delim = "\n    " 
)
inline

Increase indentation of a string.

Parameters
inthe input string
Returns
std::string the output string

Definition at line 197 of file string.hpp.

+ Here is the call graph for this function:

◆ is_aligned() [1/2]

template<class T >
bool shambase::is_aligned ( const void ptr)
inlinenoexcept

Check if a pointer is aligned with the given type.

Definition at line 36 of file ptr.hpp.

+ Here is the call graph for this function:

◆ is_aligned() [2/2]

bool shambase::is_aligned ( const void ptr,
size_t  alignment 
)
inlinenoexcept

Check if a pointer is aligned with the given alignment.

Parameters
[in]ptrthe pointer to check
[in]alignmentthe alignment to check for
Returns
true if the pointer is aligned, false otherwise

Definition at line 29 of file ptr.hpp.

+ Here is the call graph for this function:

◆ is_flag_on()

template<u32 flag>
constexpr bool shambase::is_flag_on ( u32  val)
inlineconstexpr

Definition at line 188 of file integer.hpp.

◆ is_little_endian()

bool shambase::is_little_endian ( )
inline

Check if the CPU is in little endian.

Check if the CPU is in little endian by checking the endianness of short int

The check is done by reinterpreting a short int with the value 0x0001 as a char array and checking the first byte of this array.

If the first byte is 1, then the CPU is in little endian, false otherwise.

Returns
true if the CPU is in little endian, false otherwise

Definition at line 36 of file endian.hpp.

+ Here is the call graph for this function:

◆ is_most_sig_bit_set()

template<class T , std::enable_if_t< std::is_integral_v< T >, int > = 0>
constexpr bool shambase::is_most_sig_bit_set ( const x)
inlineconstexprnoexcept

Checks if the most significant bit is set in the given value.

Template Parameters
TThe type of the value
Parameters
xThe value to check
Returns
constexpr bool True if the most significant bit is set, false otherwise

Definition at line 161 of file integer.hpp.

+ Here is the call graph for this function:

◆ is_pow_of_two()

template<class T , std::enable_if_t< std::is_integral_v< T >, int > = 0>
constexpr bool shambase::is_pow_of_two ( v)
inlineconstexprnoexcept

determine if v is a power of two and check if v==0 Source : https://graphics.stanford.edu/~seander/bithacks.html

Template Parameters
Tthe type
Parameters
v
Returns
true
false

Definition at line 49 of file integer.hpp.

◆ is_pow_of_two_fast()

template<class T , std::enable_if_t< std::is_integral_v< T >, int > = 0>
constexpr bool shambase::is_pow_of_two_fast ( v)
inlineconstexprnoexcept

determine if v is a power of two Warning : this function return true if v == 0 Source : https://graphics.stanford.edu/~seander/bithacks.html

Template Parameters
Tthe type
Parameters
v
Returns
true
false

Definition at line 36 of file integer.hpp.

◆ keys_from_map()

template<class K , class T >
std::vector< K > shambase::keys_from_map ( const std::unordered_map< K, T > &  in)
inline

Definition at line 44 of file StlContainerConversion.hpp.

◆ load_conv()

template<class T , class TAcc >
T shambase::load_conv ( TAcc acc)
inline

pointer cast load from a pointer

Template Parameters
T
TAcc
Parameters
acc
Returns
T

Definition at line 94 of file memory.hpp.

◆ load_fortran_file()

FortranIOFile shambase::load_fortran_file ( const std::string &  fname)
inline

Load a Fortran formatted file from disk.

Parameters
fnameFilename of the file to load
Returns
The loaded file
Exceptions
runtime_errorif the file is not found

Definition at line 404 of file fortran_io.hpp.

+ Here is the call graph for this function:

◆ load_u8()

template<class T , class AccU8 >
T shambase::load_u8 ( AccU8 acc,
u64  ptr_load 
)
inline

load a value of type T from a byte buffer

Template Parameters
T
AccU8
Parameters
acc
ptr_load
Returns
T

Definition at line 60 of file memory.hpp.

+ Here is the call graph for this function:

◆ make_except_with_loc()

template<class ExcptTypes >
ExcptTypes shambase::make_except_with_loc ( std::string  message,
SourceLocation  loc = SourceLocation{} 
)
inline

Create an exception with a message and a location.

This function creates an exception with a message that is richer, as it also contains the source location where the exception was thrown.

Template Parameters
ExcptTypesThe type of the exception to create
Parameters
messageThe message of the exception
locThe location from where the exception was thrown
Returns
ExcptTypes The exception with a message that also contains the source location.

Definition at line 105 of file exception.hpp.

◆ make_except_with_loc_with_ctx()

template<class exception_type >
exception_type shambase::make_except_with_loc_with_ctx ( std::string  message,
context  ctx,
SourceLocation  loc = SourceLocation{} 
)
inline

Make an exception with a message and variadic context groups.

This function allows to make an exception with multiple context groups. Each context group has a section name and a list of arguments.

Usage:

"The cross product is zero",
"function args",
ARG_INFO(center),
ARG_INFO(nx),
ARG_INFO(ny)},
shambase::arg_group{"internal variables", ARG_INFO(e_z)}});
#define ARG_INFO(var)
Macro to automatically capture variable name and value for exception context.
A context group containing a section name and a list of arguments.
Template Parameters
exception_typeThe type of the exception to make
Parameters
messageThe message of the exception
ctxThe context containing the arguments
locThe source location where the exception is thrown
Returns
exception_type The exception

Definition at line 108 of file exception_ctx.hpp.

◆ make_range()

sycl::nd_range< 1 > shambase::make_range ( u32  length,
const u32  group_size = 32 
)
inline

Generate a sycl nd range out of a group size and length.

Parameters
lengthmax index value
group_sizegroup size
Returns
sycl::nd_range<1> the sycl nd range

Definition at line 74 of file sycl_utils.hpp.

+ Here is the call graph for this function:

◆ most_sig_bit_mask()

template<class T , std::enable_if_t< std::is_integral_v< T >, int > = 0>
constexpr T shambase::most_sig_bit_mask ( )
inlineconstexprnoexcept

Generates a mask with only the most significant bit set.

Template Parameters
TThe type of the value
Returns
constexpr T The mask with only the most significant bit set

Definition at line 149 of file integer.hpp.

◆ nanosec_to_time_str()

std::string shambase::nanosec_to_time_str ( double  nanosec)
inline

Convert nanoseconds to a human-readable string representation.

Parameters
nanosecThe duration in nanoseconds.
Returns
std::string The duration in a human-readable format.

Definition at line 33 of file time.hpp.

+ Here is the call graph for this function:

◆ narrow_or_throw()

template<class U , class T >
U shambase::narrow_or_throw ( val,
SourceLocation &&  callsite = SourceLocation{} 
)
inline

Definition at line 83 of file narrowing.hpp.

◆ odd_even_transpose_sort_segment_flags()

template<class T , int ArrSize, class Comp >
void shambase::odd_even_transpose_sort_segment_flags ( T *  data,
const u8 segment_boundary,
Comp  comp 
)
inline

Odd-even transpose sort with segment boundaries.

Sorts array while respecting segment boundaries where comparisons are disabled.

Template Parameters
TElement type
ArrSizeCompile-time array size
CompComparator type
Parameters
dataPointer to data array
segment_boundaryFlags indicating segment boundaries (1 = boundary, 0 = no boundary)
compComparison function

Definition at line 79 of file alg_primitives.hpp.

+ Here is the call graph for this function:

◆ on_distributeddata_diff()

void shambase::on_distributeddata_diff ( const shambase::DistributedData< T1 > &  dd,
const shambase::DistributedData< T2 > &  reference,
FuncMatch &&  func_missing,
FuncMissing &&  func_match,
FuncExtra &&  func_extra 
)
inline

Compare two distributed data and apply callbacks based on the difference.

This function compares the two given distributed data and applies callbacks based on the difference.

The callbacks are:

  • func_missing: called for each id present in the reference but not in dd
  • func_match: called for each id present in both dd and the reference
  • func_extra: called for each id present in dd but not in the reference
Parameters
ddthe distributed data to compare
referencethe reference distributed data
func_missingthe callback for missing ids
func_matchthe callback for matching ids
func_extrathe callback for extra ids

Definition at line 352 of file DistributedData.hpp.

+ Here is the call graph for this function:

◆ on_distributeddata_ids_diff()

void shambase::on_distributeddata_ids_diff ( const shambase::DistributedData< T1 > &  dd,
const std::vector< u64 > &  ref_ids,
FuncMatch &&  func_missing,
FuncMissing &&  func_match,
FuncExtra &&  func_extra 
)
inline

Compare two distributed data and apply callbacks based on the difference.

This is the same as on_distributeddata_diff but where one of the distributed data is represented by a vector of its ids.

This function compares the two given distributed data and applies callbacks based on the difference.

The callbacks are:

  • func_missing: called for each id present in the reference but not in dd
  • func_match: called for each id present in both dd and the reference
  • func_extra: called for each id present in dd but not in the reference
Parameters
ddthe distributed data to compare
ref_idsthe reference ids
func_missingthe callback for missing ids
func_matchthe callback for matching ids
func_extrathe callback for extra ids

Definition at line 302 of file DistributedData.hpp.

+ Here is the call graph for this function:

◆ parallel_for()

template<u32 group_size = default_gsize, ParallelForWrapMode mode = default_loop_mode, class LambdaKernel >
void shambase::parallel_for ( sycl::handler &  cgh,
u32  length,
const char name,
LambdaKernel &&  ker 
)
inline

Definition at line 102 of file sycl_utils.hpp.

◆ parallel_for_2d()

template<u32 group_size = default_gsize_2d, ParallelForWrapMode mode = default_loop_mode, class LambdaKernel >
void shambase::parallel_for_2d ( sycl::handler &  cgh,
u32  length_x,
u32  length_y,
const char name,
LambdaKernel &&  ker 
)
inline

Definition at line 151 of file sycl_utils.hpp.

◆ parallel_for_3d()

template<u32 group_size = default_gsize_3d, ParallelForWrapMode mode = default_loop_mode, class LambdaKernel >
void shambase::parallel_for_3d ( sycl::handler &  cgh,
u32  length_x,
u32  length_y,
u32  length_z,
const char name,
LambdaKernel &&  ker 
)
inline

Definition at line 207 of file sycl_utils.hpp.

◆ parallel_for_gsize()

template<ParallelForWrapMode mode = default_loop_mode, class LambdaKernel >
void shambase::parallel_for_gsize ( sycl::handler &  cgh,
u32  length,
u32  group_size,
const char name,
LambdaKernel &&  ker 
)
inline

Definition at line 276 of file sycl_utils.hpp.

◆ popen_fetch_output()

std::string shambase::popen_fetch_output ( const char command)

Run a command and return the output.

Definition at line 23 of file popen.cpp.

+ Here is the call graph for this function:

◆ pow_constexpr()

template<i32 power, class T >
constexpr T shambase::pow_constexpr ( a)
inlineconstexprnoexcept

Calculates the power of a number at compile time.

Template Parameters
powerThe power to raise the number to
TThe type of the number
Parameters
aThe number to raise to the power
Returns
constexpr T The result of the power calculation

Definition at line 174 of file integer.hpp.

+ Here is the call graph for this function:

◆ pow_constexpr_fast_inv()

template<i32 power, class T >
constexpr T shambase::pow_constexpr_fast_inv ( a,
a_inv 
)
inlineconstexprnoexcept

Definition at line 24 of file floats.hpp.

◆ print()

void shambase::print ( std::string_view  sv)

Prints a string to the console.

Parameters
sThe string to be printed.

Definition at line 30 of file print.cpp.

◆ println()

void shambase::println ( std::string_view  sv)

Prints a string to the console followed by a newline.

Parameters
sThe string to be printed.

Definition at line 37 of file print.cpp.

◆ ptr_insert_sort()

template<class T , class Comp >
void shambase::ptr_insert_sort ( T *  data,
u32  start,
u32  end,
Comp &&  comp 
)
inline

Simple insertion sort on pointer range.

Template Parameters
TElement type
CompComparator type
Parameters
dataPointer to data array
startStarting index (inclusive)
endEnding index (exclusive)
compComparison function

Definition at line 35 of file alg_primitives.hpp.

+ Here is the call graph for this function:

◆ readable_sizeof()

std::string shambase::readable_sizeof ( double  size)
inline

given a sizeof value return a readble string Example : readable_sizeof(1024*1024*1024) -> "1.00 GB"

Parameters
sizethe size
Returns
std::string the formated string

Definition at line 139 of file string.hpp.

+ Here is the call graph for this function:

◆ replace_all()

void shambase::replace_all ( std::string &  inout,
std::string_view  what,
std::string_view  with 
)
inline

replace all occurence of a search string with another

taken from https://en.cppreference.com/w/cpp/string/basic_string/replace

Parameters
inoutthe string to modify
whatthe search string
withthe replace string

Definition at line 183 of file string.hpp.

+ Here is the call graph for this function:

◆ reset_std_behavior()

void shambase::reset_std_behavior ( )

Restores the default behavior of the print and println functions.

This function resets the behavior of the print and println functions to their default behavior, which is to print to the standard output stream.

Definition at line 61 of file print.cpp.

+ Here is the call graph for this function:

◆ roundup_pow2()

template<class T , std::enable_if_t< std::is_integral_v< T >||(!std::is_signed_v< T >), int > = 0>
constexpr T shambase::roundup_pow2 ( v)
inlineconstexprnoexcept

round up to the next power of two Source : https://graphics.stanford.edu/~seander/bithacks.html

Template Parameters
T
Parameters
v
Returns
constexpr T

Definition at line 92 of file integer.hpp.

+ Here is the call graph for this function:

◆ select_bit()

template<class T , std::enable_if_t< std::is_integral_v< T >, int > = 0>
T shambase::select_bit ( value,
bitnum 
)
inline

Selects and returns the bit at a specific position in the given value.

Template Parameters
TThe type of the value
Parameters
valueThe value from which to select the bit
bitnumThe position of the bit to select
Returns
T The selected bit

Definition at line 138 of file integer.hpp.

+ Here is the call graph for this function:

◆ set_callstack_process_identifier()

void shambase::set_callstack_process_identifier ( std::string  identifier)

Definition at line 223 of file stacktrace.cpp.

◆ set_diff()

void shambase::set_diff ( Container1 c1,
Container2 ref,
std::vector< T > &  missing,
std::vector< T > &  matching,
std::vector< T > &  extra 
)
inline

Compute the difference between two containers as three separate vectors.

Compute the difference between two containers as three separate vectors. The first vector contains the elements of the first container that are not in the second container. The second vector contains the elements of the second container that are not in the first container. The third vector contains the elements that are present in both containers.

Parameters
c1The first container.
refThe second container.
missingThe elements of the first container that are not in the second.
matchingThe elements that are present in both containers.
extraThe elements of the second container that are not in the first.

Definition at line 41 of file sets.hpp.

+ Here is the call graph for this function:

◆ set_exception_gen_callback()

void shambase::set_exception_gen_callback ( exception_gen_callback_t  callback)

Set the exception generator callback.

This function sets a callback that is called whenever an exception is thrown. The callback is called with the formatted exception message as argument.

Parameters
callbackThe callback to set

Definition at line 37 of file exception.cpp.

+ Here is the call graph for this function:

◆ set_from_vector()

template<class T >
std::set< T > shambase::set_from_vector ( const std::vector< T > &  in)
inline

Definition at line 35 of file StlContainerConversion.hpp.

◆ shorten_string()

std::string shambase::shorten_string ( std::string  str,
u32  len 
)
inline

Shortens a string by removing the last specified number of characters.

Parameters
strThe input string
lenThe number of characters to be removed from the end of the string
Exceptions
std::invalid_argumentIf the length of the input string is less than the specified length
Returns
std::string The shortened string

Definition at line 273 of file string.hpp.

+ Here is the call graph for this function:

◆ sign_differ()

template<class T , std::enable_if_t< std::is_integral_v< T >||std::is_signed_v< T >, int > = 0>
constexpr bool shambase::sign_differ ( a,
b 
)
inlineconstexprnoexcept

check if the sign of the two integers differs Source : https://graphics.stanford.edu/~seander/bithacks.html

Template Parameters
T
Parameters
a
b
Returns
true
false

Definition at line 64 of file integer.hpp.

+ Here is the call graph for this function:

◆ split_str()

std::vector< std::string > shambase::split_str ( std::string  s,
std::string  delimiter 
)
inline

Splits a string into a vector of substrings according to a delimiter.

Parameters
sThe string to be split
delimiterThe string to be used as a delimiter for splitting
Returns
std::vector<std::string> The vector of substrings

Definition at line 290 of file string.hpp.

+ Here is the call graph for this function:

◆ store_conv()

template<class T , class TAcc >
void shambase::store_conv ( TAcc acc,
a 
)
inline

pointer cast store the value

Parameters
ain the pointer
Template Parameters
T
TAcc
Parameters
acc
a

Definition at line 80 of file memory.hpp.

+ Here is the call graph for this function:

◆ store_u8()

template<class T , class AccU8 >
void shambase::store_u8 ( AccU8 acc,
u64  idx_write,
a 
)
inline

Store a value of type T in a byte buffer.

Store the given value of type T into the byte buffer at the given index. The address is the starting address of the value to store in the buffer.

Template Parameters
Ttype of the value to store
AccU8type of the byte buffer
Parameters
accbyte buffer
idx_writeindex to store the value in the byte buffer
avalue to store

Definition at line 41 of file memory.hpp.

+ Here is the call graph for this function:

◆ stream_read()

template<class T >
void shambase::stream_read ( std::basic_stringstream< byte > &  stream,
T &  obj 
)
inline

Definition at line 32 of file bytestream.hpp.

◆ stream_read_string()

void shambase::stream_read_string ( std::basic_stringstream< byte > &  stream,
std::string &  s 
)
inline

Definition at line 42 of file bytestream.hpp.

◆ stream_read_vector()

template<class T >
void shambase::stream_read_vector ( std::basic_stringstream< byte > &  stream,
std::vector< T > &  vec 
)
inline

read a vector from the bytestream Note : this appends read objects to the vector without resetting it

Template Parameters
T
Parameters
stream
vec

Definition at line 128 of file bytestream.hpp.

+ Here is the call graph for this function:

◆ stream_read_vector_trivial()

template<class T >
void shambase::stream_read_vector_trivial ( std::basic_stringstream< byte > &  stream,
std::vector< T > &  vec 
)
inline

read a vector from the bytestream Note : this appends read objects to the vector without resetting it

Template Parameters
T
Parameters
stream
vec

Definition at line 167 of file bytestream.hpp.

+ Here is the call graph for this function:

◆ stream_write()

template<class T >
void shambase::stream_write ( std::basic_stringstream< byte > &  stream,
T &  obj 
)
inline

Definition at line 27 of file bytestream.hpp.

◆ stream_write_string()

void shambase::stream_write_string ( std::basic_stringstream< byte > &  stream,
std::string &  s 
)
inline

Definition at line 36 of file bytestream.hpp.

◆ stream_write_vector()

template<class T >
void shambase::stream_write_vector ( std::basic_stringstream< byte > &  stream,
std::vector< T > &  vec 
)
inline

write the vector into the bytestream

Template Parameters
T
Parameters
stream
vec

Definition at line 104 of file bytestream.hpp.

+ Here is the call graph for this function:

◆ stream_write_vector_trivial()

template<class T >
void shambase::stream_write_vector_trivial ( std::basic_stringstream< byte > &  stream,
std::vector< T > &  vec 
)
inline

Definition at line 146 of file bytestream.hpp.

◆ throw_unimplemented() [1/2]

void shambase::throw_unimplemented ( SourceLocation  loc = SourceLocation{})
inline

Throw a std::runtime_error saying that the function is unimplemented.

This function is a convenient way to throw a std::runtime_error saying that the function is unimplemented. It also includes the source location where the exception was thrown.

Usage :

void throw_unimplemented(SourceLocation loc=SourceLocation{})
Throw a std::runtime_error saying that the function is unimplemented.
Parameters
locThe location from where the exception was thrown
Exceptions
std::runtime_errorThe exception with a message saying that the function is unimplemented, and the source location.

Definition at line 153 of file exception.hpp.

◆ throw_unimplemented() [2/2]

void shambase::throw_unimplemented ( std::string  message,
SourceLocation  loc = SourceLocation{} 
)
inline

Throw a std::runtime_error with a message saying that the function is unimplemented.

This function is a convenient way to throw a std::runtime_error saying that the function is unimplemented. It also includes the source location where the exception was thrown.

Usage :

Parameters
messageThe message to add to the exception message
locThe location from where the exception was thrown
Exceptions
std::runtime_errorThe exception with a message saying that the function is unimplemented, the given message, and the source location.

Definition at line 175 of file exception.hpp.

◆ throw_with_loc()

template<class ExcptTypes >
void shambase::throw_with_loc ( std::string  message,
SourceLocation  loc = SourceLocation{} 
)
inline

Throw an exception and append the source location to it.

This function allows to throw an exception with a message that is richer, as it also contains the source location where the exception was thrown.

Usage :

Template Parameters
ExcptTypesThe type of the exception to throw
Parameters
messageThe message of the exception
locThe location from where the exception was thrown
Exceptions
ExcptTypesThe exception with a message that also contains the source location.

Definition at line 132 of file exception.hpp.

◆ timeit()

template<class Func >
f64 shambase::timeit ( Func &&  f,
u32  relaunch = 1 
)
inline

Measures the average time it takes to execute a function.

This function measures the average time it takes to execute a function by executing it the specified number of times and dividing the total time by the number of times the function was executed.

Template Parameters
FuncThe type of the function to be executed.
Parameters
fThe function to be executed.
relaunchThe number of times the function is executed. Default is 1.
Returns
f64 The average time it takes to execute the function.

Definition at line 179 of file time.hpp.

+ Here is the call graph for this function:

◆ timeitfor()

template<class Func >
f64 shambase::timeitfor ( Func &&  f,
f64  max_duration = 1 
)
inline

Measures the average time it takes to execute a function until a maximum duration is reached.

This function measures the average time it takes to execute a function until a maximum duration is reached. It does this by executing the function in a loop until the maximum duration is reached and then dividing the total time by the number of times the function was executed.

Template Parameters
FuncThe type of the function to be executed.
Parameters
fThe function to be executed.
max_durationThe maximum time the function is allowed to take. Default is 1 second.
Returns
f64 The average time it takes to execute the function.

Definition at line 207 of file time.hpp.

+ Here is the call graph for this function:

◆ to_shared()

template<class T >
std::shared_ptr< T > shambase::to_shared ( T &&  t)

Definition at line 42 of file ExternalForces.cpp.

◆ trunc_str()

std::string shambase::trunc_str ( std::string  s,
u32  max_len 
)
inline

Truncate a string to a specified length, adding an ellipsis if necessary.

Parameters
sThe string to truncate.
max_lenThe maximum length of the string.
Returns
std::string The truncated string.
Exceptions
std::invalid_argumentIf the maximum length is less than 5.

This function truncates a string to a specified length by taking the first max_len - 5 characters and appending an ellipsis if the original string is longer than max_len. If max_len is less than 5, an std::invalid_argument exception is thrown.

Definition at line 215 of file string.hpp.

+ Here is the call graph for this function:

◆ trunc_str_start()

std::string shambase::trunc_str_start ( std::string  s,
u32  max_len 
)
inline

Truncate a string to a specified length, adding an ellipsis at the start if necessary.

Parameters
sThe input string.
max_lenThe maximum length of the string.
Returns
std::string The truncated string.
Exceptions
std::invalid_argumentIf the maximum length is less than 5.

This function truncates a string to a specified length by adding an ellipsis at the start of the string, and taking the last max_len - 4 characters if the original string is longer than max_len. If max_len is less than 5, an std::invalid_argument exception is thrown.

Definition at line 239 of file string.hpp.

+ Here is the call graph for this function:

◆ vector_from_set()

template<class T >
std::vector< T > shambase::vector_from_set ( const std::set< T > &  in)
inline

Definition at line 26 of file StlContainerConversion.hpp.

◆ write_string_to_file()

void shambase::write_string_to_file ( std::string  filename,
std::string  s 
)
inline

dump a string to a file

Parameters
filenamethe filename
sthe string to dump

Definition at line 168 of file string.hpp.

+ Here is the call graph for this function:

◆ xor_swap()

template<class T , std::enable_if_t< std::is_integral_v< T >, int > = 0>
void shambase::xor_swap ( T &  a,
T &  b 
)
inline

swap two values using xor Source : https://graphics.stanford.edu/~seander/bithacks.html

Template Parameters
T
Parameters
a
b

Definition at line 77 of file integer.hpp.

+ Here is the call graph for this function:

Variable Documentation

◆ _callstack_gen_info_generators

std::vector<std::function<std::string()> > shambase::_callstack_gen_info_generators

Definition at line 227 of file stacktrace.cpp.

◆ _callstack_process_identifier

std::string shambase::_callstack_process_identifier

Definition at line 221 of file stacktrace.cpp.

◆ always_false_v

template<class >
constexpr bool shambase::always_false_v = false
inlineconstexpr

Helper variable template that is always false. Especially useful to perform static asserts based on templates.

if constexpr(constexpr_condition(var)){
......
}else {
static_assert(shambase::always_false_v<decltype(var)>, "non-exhaustive visitor!");
}
constexpr bool always_false_v
Helper variable template that is always false. Especially useful to perform static asserts based on t...
Template Parameters
Tdummy parameter to select the right overload

Definition at line 234 of file type_traits.hpp.

◆ bitsizeof

template<class T >
constexpr u64 shambase::bitsizeof = sizeof(T) * CHAR_BIT
inlineconstexpr

Number of bits in a type T.

Template Parameters
Ttype for which the number of bits is computed

Definition at line 33 of file type_traits.hpp.

◆ default_gsize

constexpr u32 shambase::default_gsize = SHAMROCK_LOOP_GSIZE
constexpr

Definition at line 94 of file sycl_utils.hpp.

◆ default_gsize_2d

constexpr u32 shambase::default_gsize_2d = 16
constexpr

Definition at line 95 of file sycl_utils.hpp.

◆ default_gsize_3d

constexpr u32 shambase::default_gsize_3d = 4
constexpr

Definition at line 96 of file sycl_utils.hpp.

◆ exception_print_callback

void(* shambase::exception_print_callback) (std::string msg) ( std::string  msg) = nullptr

exception print callback func ptr

Definition at line 29 of file exception.cpp.

◆ has_bitlen_v

template<typename T , int num>
constexpr bool shambase::has_bitlen_v = has_bitlen<T, num>::value
inlineconstexpr

Helper variable template for has_bitlen.

This variable template is true if T has num bits.

Template Parameters
Ttype to check
numnumber of bits

Definition at line 59 of file type_traits.hpp.

◆ typed_false_v

template<bool val, class type >
constexpr bool shambase::typed_false_v = val
inlineconstexpr

Helper variable template that is used to associate a type to a boolean value in the compile logs.

Template Parameters
valboolean value to transport
typeThe dummy type to be associated with the boolean value

Definition at line 244 of file type_traits.hpp.