6#ifndef DEEPLIMA_SRC_INFERENCE_TORCH_VECTORIZER_H
7#define DEEPLIMA_SRC_INFERENCE_TORCH_VECTORIZER_H
9#include <torch/torch.h>
39 assert(
m_max_feat < std::numeric_limits<int64_t>::max());
42 TorchMatrix(torch::Tensor input, int64_t start_time, int64_t max_time)
52 assert(
m_max_feat < std::numeric_limits<int64_t>::max());
55 void init(int64_t max_time, int64_t max_feat)
60 assert(max_feat < std::numeric_limits<int64_t>::max());
68 inline void set(int64_t time, uint64_t feat, T value)
70 assert(feat < std::numeric_limits<uint64_t>::max());
71 assert(time < std::numeric_limits<int64_t>::max() -
m_start_time);
79 inline uint64_t
get(uint64_t time, uint64_t feat)
81 assert(feat < std::numeric_limits<uint64_t>::max());
82 assert(time < std::numeric_limits<uint64_t>::max() -
m_start_time);
87 inline uint64_t
size()
const
102 void to(torch::Device& device)
112 return torch::zeros({0, 0}, torch::TensorOptions().dtype(torch::kInt64));
127 assert(max_time > 0);
130 return torch::zeros({max_time, max_feat}, torch::TensorOptions().dtype(torch::kInt64));
136 assert(max_time > 0);
137 assert(max_feat > 0);
139 return torch::zeros({max_time, max_feat}, torch::TensorOptions().dtype(torch::kFloat32));
142template <
class D,
class Matrix>
149 inline void set(Matrix& target, uint64_t time, uint64_t feat,
const typename D::value_t value)
152 int k =
m_dicts[feat]->get_idx(value);
153 target.set(time, feat, k);
163 assert(m_max_time > 0);
164 assert(m_max_feat > 0);
166 m_tensor = torch::zeros({m_max_time, m_max_feat}, torch::TensorOptions().dtype(torch::kInt64));
167 m_accessor = m_tensor.accessor<int64_t, 2>();
173 assert(m_max_time > 0);
174 assert(m_max_feat > 0);
176 m_tensor = torch::zeros({m_max_time, m_max_feat}, torch::TensorOptions().dtype(torch::kFloat32));
177 m_accessor = m_tensor.accessor<float, 2>();
std::vector< D * > m_dicts
void set(Matrix &target, uint64_t time, uint64_t feat, const typename D::value_t value)
uint64_t get_max_feat() const
TorchMatrix(torch::Tensor input, int64_t start_time, int64_t max_time)
uint64_t get(uint64_t time, uint64_t feat)
const torch::Tensor & get_tensor() const
torch::Tensor create_tensor(int64_t max_time, int64_t max_feat)
TorchMatrix(int64_t max_time, int64_t max_feat)
void init(int64_t max_time, int64_t max_feat)
torch::Tensor create_empty_tensor()
void to(torch::Device &device)
torch::TensorAccessor< T, 2 > m_accessor
void set(int64_t time, uint64_t feat, T value)