Treelite
Enumerations | Functions
typeinfo.h File Reference

Defines TypeInfo class and utilities. More...

#include <cstdint>
#include <typeinfo>
#include <string>
#include <unordered_map>
#include <sstream>
#include <utility>
#include <type_traits>
Include dependency graph for typeinfo.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Enumerations

enum  TypeInfo : uint8_t { kInvalid = 0, kUInt32 = 1, kFloat32 = 2, kFloat64 = 3 }
 Types used by thresholds and leaf outputs.
 

Functions

TypeInfo GetTypeInfoByName (const std::string &str)
 conversion table from string to TypeInfo, defined in tables.cc
 
std::string TypeInfoToString (treelite::TypeInfo type)
 Get string representation of type info. More...
 
template<typename T >
TypeInfo TypeToInfo ()
 Convert a template type into a type info. More...
 
template<template< class > class Dispatcher, typename ... Args>
auto DispatchWithTypeInfo (TypeInfo type, Args &&...args)
 Given a TypeInfo, dispatch a function with the corresponding template arg. More precisely, we shall call Dispatcher<T>::Dispatch() where the template arg T corresponds to the type parameter. More...
 
template<template< class, class > class Dispatcher, typename ... Args>
auto DispatchWithModelTypes (TypeInfo threshold_type, TypeInfo leaf_output_type, Args &&...args)
 Given the types for thresholds and leaf outputs, validate that they consist of a valid combination for a model and then dispatch a function with the corresponding template args. More precisely, we shall call Dispatcher<ThresholdType, LeafOutputType>::Dispatch() where the template args ThresholdType and LeafOutputType correspond to the parameters threshold_type and leaf_output_type, respectively. More...
 

Detailed Description

Defines TypeInfo class and utilities.

Copyright (c) 2017-2020 by Contributors

Author
Hyunsu Cho

Definition in file typeinfo.h.

Function Documentation

◆ DispatchWithModelTypes()

auto treelite::DispatchWithModelTypes ( TypeInfo  threshold_type,
TypeInfo  leaf_output_type,
Args &&...  args 
)
inline

Given the types for thresholds and leaf outputs, validate that they consist of a valid combination for a model and then dispatch a function with the corresponding template args. More precisely, we shall call Dispatcher<ThresholdType, LeafOutputType>::Dispatch() where the template args ThresholdType and LeafOutputType correspond to the parameters threshold_type and leaf_output_type, respectively.

Template Parameters
DispatcherFunction object that takes in two template args. It must have a Dispatch() static function.
Parameterpack, to forward an arbitrary number of args to Dispatcher::Dispatch()
Parameters
threshold_typeTypeInfo indicating the type of thresholds
leaf_output_typeTypeInfo indicating the type of leaf outputs
argsOther extra parameters to pass to Dispatcher::Dispatch()
Returns
Whatever that's returned by the dispatcher

Definition at line 117 of file typeinfo.h.

◆ DispatchWithTypeInfo()

auto treelite::DispatchWithTypeInfo ( TypeInfo  type,
Args &&...  args 
)
inline

Given a TypeInfo, dispatch a function with the corresponding template arg. More precisely, we shall call Dispatcher<T>::Dispatch() where the template arg T corresponds to the type parameter.

Template Parameters
DispatcherFunction object that takes in one template arg. It must have a Dispatch() static function.
Parameterpack, to forward an arbitrary number of args to Dispatcher::Dispatch()
Parameters
typeTypeInfo corresponding to the template arg T with which Dispatcher<T>::Dispatch() is called.
argsOther extra parameters to pass to Dispatcher::Dispatch()
Returns
Whatever that's returned by the dispatcher

Definition at line 87 of file typeinfo.h.

◆ TypeInfoToString()

std::string treelite::TypeInfoToString ( treelite::TypeInfo  type)
inline

Get string representation of type info.

Parameters
infoa type info
Returns
string representation

Definition at line 39 of file typeinfo.h.

◆ TypeToInfo()

TypeInfo treelite::TypeToInfo ( )
inline

Convert a template type into a type info.

Template Parameters
templatetype to be converted
Returns
TypeInfo corresponding to the template type arg

Definition at line 61 of file typeinfo.h.