Template Numerical Library: TNL Namespace Reference

Template Numerical Library version\ main:16b9213d5

Loading...
Searching...
No Matches
Namespaces | Classes | Typedefs | Functions | Variables
TNL Namespace Reference

The main TNL namespace. More...

## Namespaces
namespace | Algorithms
| Namespace for fundamental TNL algorithms.
namespace | Allocators
| Namespace for TNL allocators.
namespace | Assert
| Internal namespace for helper classes used in the TNL_ASSERT_* macros.
namespace | Backend
| Internal namespace for CUDA/HIP backend support.
namespace | base64
| Namespace for base64 encoding and decoding functions.
namespace | CFD
| Namespace for Computational Fluid Dynamics utilities in TNL.
namespace | Containers
| Namespace for TNL containers.
namespace | Devices
| Namespace for TNL execution models.
namespace | Exceptions
| Namespace for TNL exceptions.
namespace | Graphs
| Graph algorithms and data structures.
namespace | Matrices
| Namespace for matrix formats.
namespace | Meshes
| Namespace for numerical meshes and related objects.
namespace | Pointers
| Namespace for TNL pointers.
namespace | Solvers
| Namespace for solvers.

## Classes
struct | allocates_host_accessible_data
| A trait-class that determines if an allocator allocates data that are directly accessible from the host code without the need for explicit copy operations. More...
struct | allocates_host_accessible_data< Allocators::Cuda< T > >
struct | allocates_host_accessible_data< Allocators::Hip< T > >
struct | AnyWithArg
| Function object implementing argany(x, y, i, j), i.e. returning the first true value and its index. More...
class | Atomic
class | Atomic< T, Devices::Cuda >
class | Atomic< T, Devices::Host >
class | Atomic< T, Devices::Sequential >
struct | BitAnd
| Extension of std::bit_and<void> for use with TNL::Algorithms::reduce. More...
struct | BitOr
| Extension of std::bit_or<void> for use with TNL::Algorithms::reduce. More...
struct | BitXor
| Extension of std::bit_xor<void> for use with TNL::Algorithms::reduce. More...
struct | Cast
struct | copy_const
| Copy const qualifier from Source type to Target type. More...
struct | CPUCacheSizes
| CPU cache sizes. More...
struct | CPUInfo
| CPU information. More...
struct | enable_if_type
class | File
| This class serves for binary IO. It allows to do IO even for data allocated on GPU together with on-the-fly data type conversion. More...
struct | GetValueType
| Get the underlying value type of T. More...
class | HasAddAssignmentOperator
| Type trait for checking if T has operator+= taking one argument of type T. More...
struct | HasConstexprGetSizeMethod
| Type trait for checking if T has a constexpr getSize method. More...
class | HasCountMember
| Type trait for checking if T has count member. More...
class | HasGetArrayDataMethod
| Type trait for checking if T has getArrayData method. More...
class | HasGetCommunicatorMethod
| Type trait for checking if T has getCommunicator method. More...
class | HasGetSizeMethod
| Type trait for checking if T has getSize method. More...
class | HasSetSizeMethod
| Type trait for checking if T has setSize method. More...
class | HasSubscriptOperator
| Type trait for checking if T has operator[] taking one index argument. More...
struct | Hypre
| A simple RAII wrapper for Hypre's initialization and finalization. More...
struct | is_complex
struct | is_complex< Arithmetics::Complex< T > >
struct | is_complex< const T >
struct | is_complex< std::complex< T > >
struct | is_complex< volatile const T >
struct | is_complex< volatile T >
struct | IsArrayType
| Type trait for checking if T is an array type, e.g. Containers::Array or Containers::Vector. More...
struct | IsScalarType
| Type trait for checking if T is a scalar type (in the mathematical sense). Not to be confused with std::is_scalar. More...
struct | IsStaticArrayType
| Type trait for checking if T is a static array type. More...
struct | IsVectorType
| Type trait for checking if T is a vector type, e.g. Containers::Vector or Containers::VectorView. More...
struct | IsViewType
| Type trait for checking if T is a view type. More...
class | Logger
| Creates calculations log in the form of a table. More...
struct | LogicalAnd
| Function object implementing x && y. More...
struct | LogicalOr
| Function object implementing x || y. More...
struct | Max
| Function object implementing max(x, y). More...
struct | MaxWithArg
| Function object implementing argmax(x, y, i, j), i.e. returning the maximum value and its index. More...
struct | Min
| Function object implementing min(x, y). More...
struct | MinWithArg
| Function object implementing argmin(x, y, i, j), i.e. returning the minimum value and its index. More...
struct | Multiplies
| Function object implementing x * y. More...
struct | PerformanceCounters
| Performance counter for measuring CPU cycles. More...
struct | Plus
| Function object implementing x + y. More...
class | String
| Class for managing strings. More...
class | Timer
| Class for real time, CPU time and CPU cycles measuring. More...
struct | UnaryPlus
| Function object implementing +x. More...

## Typedefs
using | BitNot = std::bit_not< void >
| Function object implementing ~x.
using | Divides = std::divides< void >
| Function object implementing x / y.
using | EqualTo = std::equal_to< void >
| Function object implementing x == y.
template<typename T>
using | GetValueType_t = typename GetValueType< T >::type
using | Greater = std::greater< void >
| Function object implementing x > y.
using | GreaterEqual = std::greater_equal< void >
| Function object implementing x >= y.
using | HYPRE_Device = Devices::Host
| The device compatible with Hypre's data structures.
using | Less = std::less< void >
| Function object implementing x < y.
using | LessEqual = std::less_equal< void >
| Function object implementing x <= y.
using | LogicalNot = std::logical_not< void >
| Function object implementing !x.
using | Minus = std::minus< void >
| Function object implementing x - y.
using | Modulus = std::modulus< void >
| Function object implementing x % y.
using | NotEqualTo = std::not_equal_to< void >
| Function object implementing x != y.
using | UnaryMinus = std::negate< void >
| Function object implementing -x.

## Functions
template<typename Value>
__cuda_callable__ Value | abs (const Complex< Value > &c)
template<class T, std::enable_if_t< std::is_unsigned_v< T >, bool > = true>
__cuda_callable__ T | abs (const T &n)
| This function returns the absolute value of given unsigned number n, i.e. n.
template<class T, std::enable_if_t< std::is_arithmetic_v< T > &&! std::is_unsigned_v< T >, bool > = true>
__cuda_callable__ T | abs (const T &n)
| This function returns absolute value of given number n.
template<typename T>
__cuda_callable__ auto | acos (const T &value) -> decltype(std::acos(value))
| This function returns the arc cosine of the given value.
template<typename T>
__cuda_callable__ auto | acosh (const T &value) -> decltype(std::acosh(value))
| This function returns the inverse hyperbolic cosine of the given value.
template<typename Vector, typename ET1, typename Reduction, typename Result, std::enable_if_t< Containers::Expressions::HasEnabledDistributedExpressionTemplates< std::decay_t< ET1 > >::value, bool > = true>
Result | addAndReduce (Vector &lhs, const ET1 &expression, const Reduction &reduction, const Result &zero)
template<typename Vector, typename ET1, typename Reduction, typename Result>
std::enable_if_t< Containers::Expressions::HasEnabledExpressionTemplates< std::decay_t< ET1 > >::value, Result > | addAndReduce (Vector &lhs, const ET1 &expression, const Reduction &reduction, const Result &zero)
template<typename Vector, typename ET1, typename Reduction, typename Result, std::enable_if_t< Containers::Expressions::HasEnabledStaticExpressionTemplates< std::decay_t< ET1 > >::value, bool > = true>
__cuda_callable__ Result | addAndReduce (Vector &lhs, const ET1 &expression, const Reduction &reduction, const Result &zero)
template<typename Vector, typename ET1, typename Reduction, typename Result, std::enable_if_t< Containers::Expressions::HasEnabledDistributedExpressionTemplates< std::decay_t< ET1 > >::value, bool > = true>
Result | addAndReduceAbs (Vector &lhs, const ET1 &expression, const Reduction &reduction, const Result &zero)
template<typename Vector, typename ET1, typename Reduction, typename Result>
std::enable_if_t< Containers::Expressions::HasEnabledExpressionTemplates< std::decay_t< ET1 > >::value, Result > | addAndReduceAbs (Vector &lhs, const ET1 &expression, const Reduction &reduction, const Result &zero)
template<typename Vector, typename ET1, typename Reduction, typename Result, std::enable_if_t< Containers::Expressions::HasEnabledStaticExpressionTemplates< std::decay_t< ET1 > >::value, bool > = true>
__cuda_callable__ Result | addAndReduceAbs (Vector &lhs, const ET1 &expression, const Reduction &reduction, const Result &zero)
template<typename Value>
__cuda_callable__ Value | arg (const Complex< Value > &c)
template<typename T1, typename T2, typename ResultType = std::common_type_t< T1, T2 >>
__cuda_callable__ ResultType | argAbsMax (const T1 &a, const T2 &b)
template<typename T1, typename T2, typename ResultType = std::common_type_t< T1, T2 >>
__cuda_callable__ ResultType | argAbsMin (const T1 &a, const T2 &b)
template<typename T1, typename T2, typename ResultType = std::common_type_t< T1, T2 >>
constexpr ResultType | argMax (const T1 &a, const T2 &b)
template<typename T1, typename T2, typename ResultType = std::common_type_t< T1, T2 >>
constexpr ResultType | argMin (const T1 &a, const T2 &b)
template<typename T>
__cuda_callable__ auto | asin (const T &value) -> decltype(std::asin(value))
| This function returns the arc sine of the given value.
template<typename T>
__cuda_callable__ auto | asinh (const T &value) -> decltype(std::asinh(value))
| This function returns the inverse hyperbolic sine of the given value.
template<typename T>
__cuda_callable__ auto | atan (const T &value) -> decltype(std::atan(value))
| This function returns the arc tangent of the given value.
template<typename T>
__cuda_callable__ auto | atan2 (const T &y, const T &x) -> decltype(std::atan2(y, x))
| This function returns the arc tangent of y/x using the signs of arguments to determine the correct quadrant.
template<typename T>
__cuda_callable__ auto | atanh (const T &value) -> decltype(std::atanh(value))
| This function returns the inverse hyperbolic tangent of the given value.
template<typename Callable>
constexpr int | callableArgumentCount ()
| Returns number of arguments of a callable object.
template<typename T>
std::set< std::vector< T > > | cartesianPower (std::vector< T > array, int N)
| Calculates the cartesian power of elements in an array: array^N.
template<typename T>
__cuda_callable__ auto | cbrt (const T &value) -> decltype(std::cbrt(value))
| This function returns cubic root of the given value.
template<typename T>
__cuda_callable__ auto | ceil (const T &value) -> decltype(std::ceil(value))
| This function returns the smallest integer value not less than the given value.
template<typename Index>
constexpr Index | combinationsCount (Index k, Index n)
| Computes the number of k-combinations in set of n element.
template<typename Value>
__cuda_callable__ Complex< Value > | conj (const Complex< Value > &c)
template<>
String | convertToString (const bool &value)
| Specialization of function convertToString for boolean.
template<typename T>
String | convertToString (const T &value)
| Converts value of type T to a String.
template<typename T>
__cuda_callable__ auto | cos (const T &value) -> decltype(std::cos(value))
| This function returns cosine of the given value.
template<typename T>
__cuda_callable__ auto | cosh (const T &value) -> decltype(std::cosh(value))
| This function returns the hyperbolic cosine of the given value.
template<typename HeaderType = std::uint64_t, typename T>
std::pair< HeaderType, std::unique_ptr< T[] > > | decompress_block (const char *data)
| Decode and decompress data from a stream. The data must be in the format as produced by the write_compressed_block function.
template<typename HeaderType = std::uint64_t, typename T>
std::pair< HeaderType, std::unique_ptr< T[] > > | decompress_block (std::istream &input_stream)
| Decode and decompress data from a stream. The data must be in the format as produced by the write_compressed_block function.
template<typename T>
std::unique_ptr< T[] > | decompress_data (const std::uint8_t *decoded_data, const std::size_t decoded_data_length, const std::size_t data_size)
| Decompress data in given byte array and return an array of elements of type T and length data_size.
template<typename Index>
constexpr Index | discreteLog2 (Index value)
| Computes an integral base-2 logarithm.
template<typename Index>
constexpr Index | discretePow (Index value, Index power)
| Computes an integral power of an integer.
template<typename Index>
constexpr Index | discreteProduct (Index first, Index last)
| Computes a product of integers first * (first+1) * ... * last.
template<typename Vector, typename ET1, typename Reduction, typename Result, std::enable_if_t< Containers::Expressions::HasEnabledDistributedExpressionTemplates< std::decay_t< ET1 > >::value, bool > = true>
Result | evaluateAndReduce (Vector &lhs, const ET1 &expression, const Reduction &reduction, const Result &zero)
template<typename Vector, typename ET1, typename Reduction, typename Result>
std::enable_if_t< Containers::Expressions::HasEnabledExpressionTemplates< std::decay_t< ET1 > >::value, Result > | evaluateAndReduce (Vector &lhs, const ET1 &expression, const Reduction &reduction, const Result &zero)
template<typename Vector, typename ET1, typename Reduction, typename Result, std::enable_if_t< Containers::Expressions::HasEnabledStaticExpressionTemplates< std::decay_t< ET1 > >::value, bool > = true>
__cuda_callable__ Result | evaluateAndReduce (Vector &lhs, const ET1 &expression, const Reduction &reduction, const Result &zero)
template<typename T>
__cuda_callable__ auto | exp (const T &value) -> decltype(std::exp(value))
| This function returns the base-e exponential of the given value.
template<typename Index>
constexpr Index | firstKCombinationsSum (Index k, Index n)
| Computes the sum of all i-combinations in set of n elements for i from 0 up to k-1.
template<typename T>
__cuda_callable__ auto | floor (const T &value) -> decltype(std::floor(value))
| This function returns largest integer value not greater than the given value.
template<typename T>
T | forceBigEndian (T value)
| Function takes a value and returns its big endian representation.
std::string | getCompilerName ()
| Returns the name of the compiler.
CPUCacheSizes | getCPUCacheSizes (int cpu_id=0)
| Returns the CPU cache sizes.
CPUInfo | getCPUInfo ()
| Returns the CPU information.
int | getCPUMaxFrequency (int cpu_id=0)
| Returns the CPU cache sizes.
std::string | getCurrentTime (const char *format="%a %b %d %Y, %H:%M:%S")
| Returns the current time.
std::size_t | getFreeMemory ()
| Returns the free memory in bytes.
std::string | getHostname ()
| Returns the hostname of the system.
constexpr HYPRE_MemoryLocation | getHypreMemoryLocation ()
| Returns the memory location used by Hypre objects.
String | getObjectType (const String &fileName)
| Does the same as getObjectType but with a fileName parameter instead of file.
String | getObjectType (File &file)
| Extracts object type from a binary file.
std::string | getOnlineCPUs ()
| Returns number of online CPUs.
template<typename T, std::enable_if_t< detail::HasStaticGetSerializationType< T >::value, bool > = true>
std::string | getSerializationType ()
| Specialization of getSerializationType for types which provide a static getSerializationType method to override the default behaviour.
template<typename T, std::enable_if_t< ! detail::HasStaticGetSerializationType< T >::value, bool > = true>
std::string | getSerializationType ()
| Returns a string identifying a type for the purpose of serialization.
std::string | getSerializationType (Algorithms::Segments::ElementsOrganization Organization)
std::string | getSystemArchitecture ()
| Returns the name of the operating system.
std::string | getSystemName ()
| Returns the name of the operating system.
std::string | getSystemRelease ()
| Returns the release of the operating system.
template<typename T>
std::string | getType ()
| Returns a human-readable string representation of given type.
template<typename T>
std::string | getType (T &&obj)
| Returns a human-readable string representation of given object's type.
template<std::size_t N, typename Index>
std::set< std::array< Index, N > > | integerFactorizationTuples (Index number)
| Finds all possible integer factorizations of a positive integer into a product of N factors.
template<typename Index, std::enable_if_t< std::is_integral_v< Index >, bool > = true>
bool | integerMultiplyOverflow (Index a, Index b)
| Checks if two values of the same integral type can be multiplied without causing integer overflow or underflow.
bool | isLittleEndian ()
| Function returns true iff the system executing the program is little endian.
template<typename T>
constexpr std::enable_if_t< std::is_integral_v< T >, bool > | isPow2 (T x)
| Checks if x is an integral power of two.
template<typename Real>
constexpr bool | isSmall (const Real &v, const Real &tolerance=1.0e-5)
| This function tests whether the given real number is small.
template<typename Callable>
constexpr bool | isVariadicCallable ()
| Returns true if callable object is variadic.
template<typename T, typename I>
auto | linspace (T a, T b, I n)
template<typename T>
__cuda_callable__ auto | log (const T &value) -> decltype(std::log(value))
| This function returns the natural logarithm of the given value.
template<typename T>
__cuda_callable__ auto | log10 (const T &value) -> decltype(std::log10(value))
| This function returns the common logarithm of the given value.
template<typename T>
__cuda_callable__ auto | log2 (const T &value) -> decltype(std::log2(value))
| This function returns the binary logarithm of the given value.
template<typename T1, typename T2, typename ResultType = std::common_type_t< T1, T2 >>
constexpr ResultType | max (const T1 &a, const T2 &b)
| This function returns maximum of two numbers.
template<typename T1, typename T2, typename T3, typename... Ts>
constexpr std::common_type_t< T1, T2, T3, Ts... > | max (T1 &&val1, T2 &&val2, T3 &&val3, Ts &&... vs)
| This function returns minimum of a variadic number of inputs.
template<typename T1, typename T2, typename ResultType = std::common_type_t< T1, T2 >>
constexpr ResultType | min (const T1 &a, const T2 &b)
| This function returns minimum of two numbers.
template<typename T1, typename T2, typename T3, typename... Ts>
constexpr std::common_type_t< T1, T2, T3, Ts... > | min (T1 &&val1, T2 &&val2, T3 &&val3, Ts &&... vs)
| This function returns minimum of a variadic number of inputs.
template<typename Value>
__cuda_callable__ Value | norm (const Complex< Value > &c)
String | operator+ (char string1, const String &string2)
| Returns concatenation of string1 and string2.
String | operator+ (const char *string1, const String &string2)
| Returns concatenation of string1 and string2.
String | operator+ (const std::string &string1, const String &string2)
| Returns concatenation of string1 and string2.
File & | operator<< (File &file, const std::string &str)
| Serialization of strings.
File & | operator>> (File &file, std::string &str)
| Deserialization of strings.
std::vector< String > | parseObjectType (const String &objectType)
| Parses the object type.
template<typename T1, typename T2, typename ResultType = std::common_type_t< T1, T2 >, std::enable_if_t< std::is_arithmetic_v< T1 > &&std::is_arithmetic_v< T2 >, bool > = true>
__cuda_callable__ ResultType | pow (const T1 &base, const T2 &exp)
| This function returns the result of base to the power of exp.
template<typename Index>
std::vector< Index > | primeFactorization (Index number)
| Calculates the prime factorization of a positive integer.
constexpr int | roundToMultiple (int number, int multiple)
| Rounds up number to the nearest multiple of number multiple.
template<typename T>
constexpr std::enable_if_t< std::is_integral_v< T >, T > | roundUpDivision (const T num, const T div)
| Divides num by div and rounds up the result.
void | saveObjectType (File &file, const String &type)
| Saves object type into a binary file.
template<class T, std::enable_if_t< ! HasSubscriptOperator< T >::value, bool > = true>
constexpr T | sign (const T &value)
| This function represents the signum function.
template<typename T>
__cuda_callable__ auto | sin (const T &value) -> decltype(std::sin(value))
| This function returns sine of the given value.
template<typename T>
__cuda_callable__ auto | sinh (const T &value) -> decltype(std::sinh(value))
| This function returns the hyperbolic sine of the given value.
template<typename T>
__cuda_callable__ std::enable_if_t< is_complex_v< T >, typename T::value_type > | sqr (const T &value)
| This function returns the squared magnitude of the given complex value.
template<typename T>
__cuda_callable__ std::enable_if_t< IsScalarType< T >::value &&! is_complex_v< T >, T > | sqr (const T &value)
| This function returns the squared magnitude of the given real value.
template<typename T>
__cuda_callable__ auto | sqrt (const T &value) -> decltype(std::sqrt(value))
| This function returns square root of the given value.
template<typename Type>
__cuda_callable__ constexpr void | swap (Type &a, Type &b) noexcept
| This function swaps values of two parameters.
template<typename Index>
Index | swapBits (Index n, std::uint8_t p1, std::uint8_t p2)
| This function swaps bits at positions p1 and p2 in an integer n.
template<typename T>
T | swapEndianness (T u)
| Function takes a value and swaps its endianness.
template<typename T>
__cuda_callable__ auto | tan (const T &value) -> decltype(std::tan(value))
| This function returns tangent of the given value.
template<typename T>
__cuda_callable__ auto | tanh (const T &value) -> decltype(std::tanh(value))
| This function returns the hyperbolic tangent of the given value.
template<typename HeaderType = std::uint64_t, typename T>
void | write_compressed_block (const T *data, const std::size_t data_size, std::ostream &output_stream, const int compression_level=Z_DEFAULT_COMPRESSION)
| Use zlib to compress the data, then encode it with base64 and write the result to the given stream.

## Variables
template<typename Allocator>
constexpr bool | allocates_host_accessible_data_v = allocates_host_accessible_data< Allocator >::value
| A helper variable template for allocates_host_accessible_data.
template<class T>
constexpr bool | is_complex_v = is_complex< T >::value
constexpr double | pi = 3.14159265358979323846
| Value of the pi constant.

## Detailed Description

The main TNL namespace.

## Function Documentation

## ◆ cartesianPower()

template<typename T>

std::set< std::vector< T > > TNL::cartesianPower | ( | std::vector< T > | array,
|  | int | N )

Calculates the cartesian power of elements in an array: array^N.

For example, cartesianPower(std::vector<int>{0,1}, 2) returns the following set (written in pseudo-code): { { 0, 0 }, { 0, 1 }, { 1, 0 }, { 1, 1 } }.

Template Parameters

  T | is the type of elements in the array.

Parameters

  array | is the input array/vector of elements.
  N | is the power of the cartesian product.

Returns
  A set of vectors of elements, where each vector contains N elements from array.

## ◆ combinationsCount()

template<typename Index>

Index TNL::combinationsCount | ( | Index | k,
|  | Index | n )
| constexpr

Computes the number of k-combinations in set of n element.

See Wikipedia.

Template Parameters

  Index | is an integral type used for the evaluation of the number of combinations.

Parameters

  k | denotes the number of elements in one combination.
  n | denotes the number of all elements in the set.

Returns
  Number of all k-combinations in set of n elements.

## ◆ convertToString() [1/2]

template<>

String TNL::convertToString | ( | const bool & | value | ) |
| inlinenodiscard

Specialization of function convertToString for boolean.

The boolean type is converted to 'true' or 'false'.

## ◆ convertToString() [2/2]

template<typename T>

String TNL::convertToString | ( | const T & | value | ) |
| nodiscard

Converts value of type T to a String.

Template Parameters

  T | can be any type fir which operator << is defined.

## ◆ decompress_block() [1/2]

template<typename HeaderType = std::uint64_t, typename T>

std::pair< HeaderType, std::unique_ptr< T[] > > TNL::decompress_block | ( | const char * | data | ) |

Decode and decompress data from a stream. The data must be in the format as produced by the write_compressed_block function.

The function returns a pair of the resulting data size and a std::unique_ptr to the data.

## ◆ decompress_block() [2/2]

template<typename HeaderType = std::uint64_t, typename T>

std::pair< HeaderType, std::unique_ptr< T[] > > TNL::decompress_block | ( | std::istream & | input_stream | ) |

Decode and decompress data from a stream. The data must be in the format as produced by the write_compressed_block function.

The function returns a pair of the resulting data size and a std::unique_ptr to the data.

## ◆ discreteLog2()

template<typename Index>

Index TNL::discreteLog2 | ( | Index | value | ) |
| constexpr

Computes an integral base-2 logarithm.

Parameters

  value | is the argument of the log2 function.

## ◆ discretePow()

template<typename Index>

Index TNL::discretePow | ( | Index | value,
|  | Index | power )
| constexpr

Computes an integral power of an integer.

Parameters

  value | is the argument of the power function.
  power | is the exponent in the power function.

## ◆ discreteProduct()

template<typename Index>

Index TNL::discreteProduct | ( | Index | first,
|  | Index | last )
| constexpr

Computes a product of integers first * (first+1) * ... * last.

Template Parameters

  Index | is an integral type used for evaluation of the product.

Parameters

  first | is the first number of the product
  last | is the last number of the product.

## ◆ firstKCombinationsSum()

template<typename Index>

Index TNL::firstKCombinationsSum | ( | Index | k,
|  | Index | n )
| constexpr

Computes the sum of all i-combinations in set of n elements for i from 0 up to k-1.

Template Parameters

  Index | is an integral type used for the evaluation of the sum.

Parameters

  k | denotes the number of terms in the sum.
  n | denotes the number of elements in the set.

Returns
  Sum of all i-combinations in set of n elements for i from 0 up to k-1.

## ◆ getObjectType() [1/2]

String TNL::getObjectType | ( | const String & | fileName | ) |
| nodiscard

Does the same as getObjectType but with a fileName parameter instead of file.

Throws Exceptions::FileDeserializationError if the object type cannot be detected.

Parameters

  fileName | name of a file where the object is stored

Returns
  string with the object type

## ◆ getObjectType() [2/2]

String TNL::getObjectType | ( | File & | file | ) |
| nodiscard

Extracts object type from a binary file.

Throws Exceptions::FileDeserializationError if the object type cannot be detected.

Parameters

  file | is file where the object is stored

Returns
  string with the object type

## ◆ getSerializationType()

template<typename T, std::enable_if_t< ! detail::HasStaticGetSerializationType< T >::value, bool > = true>

std::string TNL::getSerializationType | ( |  | ) |

Returns a string identifying a type for the purpose of serialization.

By default, this function returns the same string as getType. However, if a user-defined class has a static getSerializationType method, it is called instead. This is useful for overriding the default typeid name, which may be necessary e.g. for class templates which should have the same serialization type for multiple devices.

## ◆ getType() [1/2]

template<typename T>

std::string TNL::getType | ( |  | ) |

Returns a human-readable string representation of given type.

Note that since we use the typeid operator internally, the top-level cv-qualifiers are always ignored. See https://stackoverflow.com/a/8889143 for details.

## ◆ getType() [2/2]

template<typename T>

std::string TNL::getType | ( | T && | obj | ) |

Returns a human-readable string representation of given object's type.

Note that since we use the typeid operator internally, the top-level cv-qualifiers are always ignored. See https://stackoverflow.com/a/8889143 for details.

## ◆ integerFactorizationTuples()

template<std::size_t N, typename Index>

std::set< std::array< Index, N > > TNL::integerFactorizationTuples | ( | Index | number | ) |

Finds all possible integer factorizations of a positive integer into a product of N factors.

Template Parameters

  N | is the rank of the tuples (2 for pairs, 3 for triplets, etc.)
  Index | is the integral type of the input number.

Parameters

  number | is the integer to be factorized.

Returns
  A set of N-tuples, where the product of all components in each tuple is equal to number.

## ◆ integerMultiplyOverflow()

template<typename Index, std::enable_if_t< std::is_integral_v< Index >, bool > = true>

bool TNL::integerMultiplyOverflow | ( | Index | a,
|  | Index | b )

Checks if two values of the same integral type can be multiplied without causing integer overflow or underflow.

Template Parameters

  Index | is the integral type of input values.

Parameters

  a | is the first operand in the expression a * b
  b | is the second operand in the expression a * b

Returns
  true if the operation a * b results in an integer overflow or underflow, and false if the result fits into the Index type.

## ◆ isPow2()

template<typename T>

std::enable_if_t< std::is_integral_v< T >, bool > TNL::isPow2 | ( | T | x | ) |
| constexpr

Checks if x is an integral power of two.

Returns true if x is a power of two. Otherwise returns false.

Parameters

  x | Integer.

## ◆ isSmall()

template<typename Real>

bool TNL::isSmall | ( | const Real & | v,
|  | const Real & | tolerance = 1.0e-5 )
| constexpr

This function tests whether the given real number is small.

It tests whether the number v is in tolerance, in other words, whether v in absolute value is less then or equal to tolerance.

Parameters

  v | Real number.
  tolerance | Critical value which is set to 0.00001 by default.

## ◆ max()

template<typename T1, typename T2, typename T3, typename... Ts>

std::common_type_t< T1, T2, T3, Ts... > TNL::max | ( | T1 && | val1,
|  | T2 && | val2,
|  | T3 && | val3,
|  | Ts &&... | vs )
| constexpr

This function returns minimum of a variadic number of inputs.

The inputs are folded with the binary max function from the left to the right.

## ◆ min()

template<typename T1, typename T2, typename T3, typename... Ts>

std::common_type_t< T1, T2, T3, Ts... > TNL::min | ( | T1 && | val1,
|  | T2 && | val2,
|  | T3 && | val3,
|  | Ts &&... | vs )
| constexpr

This function returns minimum of a variadic number of inputs.

The inputs are folded with the binary min function from the left to the right.

## ◆ parseObjectType()

std::vector< String > TNL::parseObjectType | ( | const String & | objectType | ) |
| nodiscard

Parses the object type.

Parameters

  objectType | is a string with the object type to be parsed.

Returns
  vector of strings where the first one is the object type and the next strings are the template parameters.

Example
  #include <iostream>
  #include <TNL/Object.h>
  using namespace TNL;
  int
  main()
  {
  auto parsedObjectType = parseObjectType( "MyObject< Value, Device, Index >" );
  for( auto& token : parsedObjectType )
  std::cout << token << '\n';
  }
  std::cout
  TNL
  The main TNL namespace.
  Definition AtomicOperations.h:15
  TNL::parseObjectType
  std::vector< String > parseObjectType(const String &objectType)
  Parses the object type.

Output
  MyObject
  Value
  Device
  Index

## ◆ primeFactorization()

template<typename Index>

std::vector< Index > TNL::primeFactorization | ( | Index | number | ) |

Calculates the prime factorization of a positive integer.

The function uses the simple trial division algorithm, so it is not efficient for large numbers.

Template Parameters

  Index | is the integral type of the input number.

Parameters

  number | is the integer to be factorized.

Returns
  A vector of the prime factors.

## ◆ roundToMultiple()

int TNL::roundToMultiple | ( | int | number,
|  | int | multiple )
| constexpr

Rounds up number to the nearest multiple of number multiple.

Parameters

  number | Integer we want to round.
  multiple | Integer.

## ◆ roundUpDivision()

template<typename T>

std::enable_if_t< std::is_integral_v< T >, T > TNL::roundUpDivision | ( | const T | num,
|  | const T | div )
| constexpr

Divides num by div and rounds up the result.

Parameters

  num | An integer considered as dividend.
  div | An integer considered as divisor.

## ◆ saveObjectType()

void TNL::saveObjectType | ( | File & | file,
|  | const String & | type )

Saves object type into a binary file.

Throws Exceptions::FileDeserializationError if the object type cannot be detected.

Parameters

  file | is the file where the object will be saved
  type | is the object type to be saved

## ◆ sign()

template<class T, std::enable_if_t< ! HasSubscriptOperator< T >::value, bool > = true>

T TNL::sign | ( | const T & | value | ) |
| constexpr

This function represents the signum function.

It extracts the sign of value. In other words, the signum function projects negative numbers to value -1, positive numbers to value 1 and zero to value 0.

## ◆ sqr()

template<typename T>

__cuda_callable__ std::enable_if_t< is_complex_v< T >, typename T::value_type > TNL::sqr | ( | const T & | value | ) |

This function returns the squared magnitude of the given complex value.

Note that the result is equivalent to std::norm( value ) which is equivalent to std::conj( value ) * value.

## ◆ swap()

template<typename Type>

__cuda_callable__ constexpr void TNL::swap | ( | Type & | a,
|  | Type & | b )
| constexprnoexcept

This function swaps values of two parameters.

It assigns the value of a to the parameter b and vice versa.

## ◆ swapEndianness()

template<typename T>

T TNL::swapEndianness | ( | T | u | ) |

Function takes a value and swaps its endianness.

Reference: https://stackoverflow.com/a/4956493

## ◆ write_compressed_block()

template<typename HeaderType = std::uint64_t, typename T>

void TNL::write_compressed_block | ( | const T * | data,
|  | const std::size_t | data_size,
|  | std::ostream & | output_stream,
|  | const int | compression_level = Z_DEFAULT_COMPRESSION )

Use zlib to compress the data, then encode it with base64 and write the result to the given stream.

Options for compression_level:

- Z_NO_COMPRESSION
- Z_BEST_SPEED
- Z_BEST_COMPRESSION
- Z_DEFAULT_COMPRESSION