ONE - On-device Neural Engine
Loading...
Searching...
No Matches
luci::SparseIndexVector Class Reference

#include <SparsityParam.h>

Public Member Functions

 SparseIndexVector ()=default
 
 SparseIndexVector (const SparseIndexVectorType &type, const std::vector< int32_t > &sparse_index_vec)
 
 SparseIndexVector (SparseIndexVectorType type, const void *sparse_index_vec)
 
 SparseIndexVector (const SparseIndexVector &sparse_index_vec)
 
 SparseIndexVector (SparseIndexVector &&sparse_index_vec)
 
SparseIndexVectoroperator= (const SparseIndexVector &sparse_index_vec)
 
SparseIndexVectoroperator= (SparseIndexVector &&sparse_index_vector)
 
 ~SparseIndexVector ()
 
SparseIndexVectorType type (void) const
 
const std::vector< int32_t > * as_int32_vector (void) const
 
const std::vector< uint16_t > * as_uint16_vector (void) const
 
const std::vector< uint8_t > * as_uint8_vector (void) const
 

Detailed Description

Definition at line 42 of file SparsityParam.h.

Constructor & Destructor Documentation

◆ SparseIndexVector() [1/5]

luci::SparseIndexVector::SparseIndexVector ( )
default

Referenced by operator=().

◆ SparseIndexVector() [2/5]

luci::SparseIndexVector::SparseIndexVector ( const SparseIndexVectorType type,
const std::vector< int32_t > &  sparse_index_vec 
)
inline

Definition at line 46 of file SparsityParam.h.

47 : _type{type}
48 {
49 switch (type)
50 {
52 break;
54 {
55 _vec_ptr = static_cast<void *>(
56 new std::vector<int32_t>(sparse_index_vec.begin(), sparse_index_vec.end()));
57 break;
58 }
60 {
61 auto new_vec = new std::vector<uint16_t>(sparse_index_vec.size());
62 for (uint32_t idx = 0; idx < sparse_index_vec.size(); idx++)
63 {
64 new_vec->at(idx) = static_cast<uint16_t>(sparse_index_vec.at(idx));
65 }
66 _vec_ptr = static_cast<void *>(new_vec);
67 break;
68 }
70 {
71 auto new_vec = new std::vector<uint8_t>(sparse_index_vec.size());
72 for (uint32_t idx = 0; idx < sparse_index_vec.size(); idx++)
73 {
74 new_vec->at(idx) = static_cast<uint8_t>(sparse_index_vec.at(idx));
75 }
76 _vec_ptr = static_cast<void *>(new_vec);
77 break;
78 }
79 default:
80 std::runtime_error("Invalid SparseIndexVectorType");
81 }
82 }
SparseIndexVectorType type(void) const

References luci::I32, luci::NONE, type(), luci::U16, and luci::U8.

◆ SparseIndexVector() [3/5]

luci::SparseIndexVector::SparseIndexVector ( SparseIndexVectorType  type,
const void *  sparse_index_vec 
)
inline

Definition at line 84 of file SparsityParam.h.

84 : _type{type}
85 {
86 switch (type)
87 {
89 break;
91 {
92 const std::vector<int32_t> *vec =
93 static_cast<const std::vector<int32_t> *>(sparse_index_vec);
94 _vec_ptr = static_cast<void *>(new std::vector<int32_t>(vec->begin(), vec->end()));
95 break;
96 }
98 {
99 const std::vector<uint16_t> *vec =
100 static_cast<const std::vector<uint16_t> *>(sparse_index_vec);
101 _vec_ptr = static_cast<void *>(new std::vector<uint16_t>(vec->begin(), vec->end()));
102 break;
103 }
105 {
106 const std::vector<uint8_t> *vec =
107 static_cast<const std::vector<uint8_t> *>(sparse_index_vec);
108 _vec_ptr = static_cast<void *>(new std::vector<uint8_t>(vec->begin(), vec->end()));
109 break;
110 }
111 default:
112 std::runtime_error("Invalid SparseIndexVectorType");
113 }
114 }

References luci::I32, luci::NONE, type(), luci::U16, and luci::U8.

◆ SparseIndexVector() [4/5]

luci::SparseIndexVector::SparseIndexVector ( const SparseIndexVector sparse_index_vec)
inline

Definition at line 116 of file SparsityParam.h.

117 : SparseIndexVector(sparse_index_vec._type, sparse_index_vec._vec_ptr)
118 {
119 }

◆ SparseIndexVector() [5/5]

luci::SparseIndexVector::SparseIndexVector ( SparseIndexVector &&  sparse_index_vec)
inline

Definition at line 121 of file SparsityParam.h.

122 : _type{sparse_index_vec._type}, _vec_ptr{std::exchange(sparse_index_vec._vec_ptr, nullptr)}
123 {
124 }

◆ ~SparseIndexVector()

luci::SparseIndexVector::~SparseIndexVector ( )
inline

Definition at line 138 of file SparsityParam.h.

139 {
140 switch (_type)
141 {
143 break;
145 {
146 auto vec_ptr = static_cast<std::vector<int32_t> *>(_vec_ptr);
147 delete vec_ptr;
148 break;
149 }
151 {
152 auto vec_ptr = static_cast<std::vector<uint16_t> *>(_vec_ptr);
153 delete vec_ptr;
154 break;
155 }
157 {
158 auto vec_ptr = static_cast<std::vector<uint8_t> *>(_vec_ptr);
159 delete vec_ptr;
160 break;
161 }
162 default:
163 break;
164 }
165 _vec_ptr = nullptr;
167 }

References luci::I32, luci::NONE, luci::U16, and luci::U8.

Member Function Documentation

◆ as_int32_vector()

const std::vector< int32_t > * luci::SparseIndexVector::as_int32_vector ( void  ) const
inline

Definition at line 173 of file SparsityParam.h.

174 {
175 return _type == SparseIndexVectorType::I32 ? static_cast<const std::vector<int32_t> *>(_vec_ptr)
176 : nullptr;
177 }

References luci::I32.

Referenced by luci::to_circle_sparse_index_vector().

◆ as_uint16_vector()

const std::vector< uint16_t > * luci::SparseIndexVector::as_uint16_vector ( void  ) const
inline

Definition at line 178 of file SparsityParam.h.

179 {
180 return _type == SparseIndexVectorType::U16
181 ? static_cast<const std::vector<uint16_t> *>(_vec_ptr)
182 : nullptr;
183 }

References luci::U16.

Referenced by luci::to_circle_sparse_index_vector().

◆ as_uint8_vector()

const std::vector< uint8_t > * luci::SparseIndexVector::as_uint8_vector ( void  ) const
inline

Definition at line 184 of file SparsityParam.h.

185 {
186 return _type == SparseIndexVectorType::U8 ? static_cast<const std::vector<uint8_t> *>(_vec_ptr)
187 : nullptr;
188 }

References luci::U8.

Referenced by luci::to_circle_sparse_index_vector().

◆ operator=() [1/2]

SparseIndexVector & luci::SparseIndexVector::operator= ( const SparseIndexVector sparse_index_vec)
inline

Definition at line 126 of file SparsityParam.h.

127 {
128 return *this = SparseIndexVector(sparse_index_vec);
129 }

References SparseIndexVector().

◆ operator=() [2/2]

SparseIndexVector & luci::SparseIndexVector::operator= ( SparseIndexVector &&  sparse_index_vector)
inline

Definition at line 131 of file SparsityParam.h.

132 {
133 std::swap(_vec_ptr, sparse_index_vector._vec_ptr);
134 std::swap(_type, sparse_index_vector._type);
135 return *this;
136 }

◆ type()

SparseIndexVectorType luci::SparseIndexVector::type ( void  ) const
inline

Definition at line 170 of file SparsityParam.h.

170{ return _type; }

Referenced by SparseIndexVector(), SparseIndexVector(), and luci::to_circle_sparse_index_vector().


The documentation for this class was generated from the following file: