ONE - On-device Neural Engine
Loading...
Searching...
No Matches
souschef Namespace Reference

This file provides string <-> number cast helpers. More...

Data Structures

struct  Arguments
 Read-only string sequence view. More...
 
class  ConstantDataChef
 
struct  ConstantDataChefFactory
 
class  ConstantInt4DataChef
 
struct  ConstantInt4DataChefFactory
 
class  ConstantUint4DataChef
 
struct  ConstantUint4DataChefFactory
 
struct  DataChef
 Data Generator. More...
 
struct  DataChefFactory
 Data Generator Factory. More...
 
class  Dataset
 
class  ExplicitDataChef
 
class  ExplicitDataChef< std::string >
 
struct  ExplicitDataChefFactory
 
class  ExplicitFloat16DataChef
 
struct  ExplicitFloat16DataChefFactory
 
class  ExplicitInt4DataChef
 
struct  ExplicitInt4DataChefFactory
 
class  ExplicitUint4DataChef
 
struct  ExplicitUint4DataChefFactory
 
class  GaussianFloat16DataChef
 
struct  GaussianFloat16DataChefFactory
 
class  GaussianFloat32DataChef
 Generate a sequence of random values according to the gaussian(=normal) distribution. More...
 
struct  GaussianFloat32DataChefFactory
 
class  GaussianInt16DataChef
 
struct  GaussianInt16DataChefFactory
 
class  GaussianInt32DataChef
 
struct  GaussianInt32DataChefFactory
 
class  GaussianInt8DataChef
 
struct  GaussianInt8DataChefFactory
 
class  GaussianUint8DataChef
 
struct  GaussianUint8DataChefFactory
 
class  RangedArguments
 
class  Registry
 
class  TensorFiller
 

Typedefs

using Data = std::vector< uint8_t >
 
template<typename T >
using Dims = std::vector< T >
 

Functions

template<typename T >
std::vector< T > as_vector (const ::google::protobuf::RepeatedPtrField< T > &field)
 
template<typename T >
Dataset< T > as_dataset (const ::google::protobuf::RepeatedPtrField< T > &field)
 
template<typename SHAPETYPE >
Dims< int32_t > as_dims (const SHAPETYPE &shape)
 
int32_t element_count (const Dims< int32_t > &dims)
 
template<typename Number >
Number to_number (const std::string &s)
 Return a numeric value that corresponds to a given string.
 
template<typename InputIt >
RangedArguments< InputIt > ranged_arguments (InputIt beg, InputIt end)
 
template<>
float to_number (const std::string &s)
 
template<>
int to_number (const std::string &s)
 
template<>
int16_t to_number (const std::string &s)
 
template<>
int64_t to_number (const std::string &s)
 
template<>
uint8_t to_number (const std::string &s)
 
template<>
int8_t to_number (const std::string &s)
 
template<>
bool to_number (const std::string &s)
 
template<>
std::string to_number (const std::string &s)
 

Detailed Description

This file provides string <-> number cast helpers.

Typedef Documentation

◆ Data

using souschef::Data = typedef std::vector<uint8_t>

Definition at line 29 of file DataChef.h.

◆ Dims

template<typename T >
using souschef::Dims = typedef std::vector<T>

Definition at line 28 of file Dims.h.

Function Documentation

◆ as_dataset()

template<typename T >
Dataset< T > souschef::as_dataset ( const ::google::protobuf::RepeatedPtrField< T > &  field)

Definition at line 72 of file Dataset.h.

73{
74 return Dataset<T>(as_vector<T>(field));
75}

◆ as_dims()

template<typename SHAPETYPE >
Dims< int32_t > souschef::as_dims ( const SHAPETYPE &  shape)

Definition at line 30 of file Dims.h.

31{
32 std::vector<int32_t> res;
33
34 for (auto &dim : shape.dim())
35 {
36 res.emplace_back(static_cast<int32_t>(dim));
37 }
38
39 return res;
40}

◆ as_vector()

template<typename T >
std::vector< T > souschef::as_vector ( const ::google::protobuf::RepeatedPtrField< T > &  field)

Definition at line 62 of file Dataset.h.

63{
64 std::vector<T> res;
65 for (const auto &elem : field)
66 {
67 res.emplace_back(elem);
68 }
69 return res;
70}

◆ element_count()

int32_t souschef::element_count ( const Dims< int32_t > &  dims)

Definition at line 42 of file Dims.h.

43{
44 return std::accumulate(dims.begin(), dims.end(), 1, std::multiplies<int32_t>());
45}

◆ ranged_arguments()

template<typename InputIt >
RangedArguments< InputIt > souschef::ranged_arguments ( InputIt  beg,
InputIt  end 
)

Definition at line 46 of file RangedArguments.h.

◆ to_number() [1/9]

template<typename Number >
Number souschef::to_number ( const std::string &  s)

Return a numeric value that corresponds to a given string.

Note
This function will throw an exception on casting failure

◆ to_number() [2/9]

template<>
float souschef::to_number ( const std::string &  s)

Definition at line 27 of file LexicalCast.cpp.

27{ return std::stof(s); }

◆ to_number() [3/9]

template<>
int souschef::to_number ( const std::string &  s)

Definition at line 28 of file LexicalCast.cpp.

28{ return std::stoi(s); }

◆ to_number() [4/9]

template<>
int16_t souschef::to_number ( const std::string &  s)

Definition at line 29 of file LexicalCast.cpp.

30{
31 // There are no standard function to parse int16_t or short int
32 // This function simulates behavior similar stoi, stol and stoll
33 int res = std::stol(s);
34 // standard does not specify string in error message, this is arbitrary
35 if (res < std::numeric_limits<int16_t>::min() || res > std::numeric_limits<int16_t>::max())
36 {
37 throw std::out_of_range("to_number<int16_t>");
38 }
39 return res;
40}

◆ to_number() [5/9]

template<>
int64_t souschef::to_number ( const std::string &  s)

Definition at line 41 of file LexicalCast.cpp.

41{ return std::stoll(s); }

◆ to_number() [6/9]

template<>
uint8_t souschef::to_number ( const std::string &  s)

Definition at line 42 of file LexicalCast.cpp.

43{
44 int temp = std::stoi(s);
45 assert(temp >= 0);
46 assert(temp <= std::numeric_limits<uint8_t>::max());
47 return static_cast<uint8_t>(temp);
48}

◆ to_number() [7/9]

template<>
int8_t souschef::to_number ( const std::string &  s)

Definition at line 49 of file LexicalCast.cpp.

50{
51 int temp = std::stoi(s);
52 assert(temp >= std::numeric_limits<int8_t>::min());
53 assert(temp <= std::numeric_limits<int8_t>::max());
54 return static_cast<int8_t>(temp);
55}

◆ to_number() [8/9]

template<>
bool souschef::to_number ( const std::string &  s)

Definition at line 56 of file LexicalCast.cpp.

57{
58 if (s == "T" || s == "t" || s == "TRUE" || s == "true" || s == "1")
59 return true;
60 if (s == "F" || s == "f" || s == "FALSE" || s == "false" || s == "0")
61 return false;
62 throw std::invalid_argument("Unsupported boolean argument");
63}

◆ to_number() [9/9]

template<>
std::string souschef::to_number ( const std::string &  s)

Definition at line 64 of file LexicalCast.cpp.

64{ return s; }