blace.ai
blace_index.h
1#pragma once
2
3#include "ml_core/callbacks.h"
4#include <climits>
5#include <memory>
6#include <optional>
7#include <stdint.h>
8#include <vector>
9
10namespace blace {
11namespace ops {
12class BaseOp;
13typedef std::shared_ptr<blace::ops::BaseOp> OpP;
14} // namespace ops
15} // namespace blace
16
17namespace blace {
18
19namespace ml_core {
20
24struct Slice final {
25public:
35 EXPORT_OR_IMPORT Slice(std::optional<int64_t> start_index = std::nullopt,
36 std::optional<int64_t> stop_index = std::nullopt,
37 std::optional<int64_t> step_index = std::nullopt);
38
44 inline int64_t start() const { return start_; }
45
51 inline int64_t stop() const { return stop_; }
52
58 inline int64_t step() const { return step_; }
59
60private:
61 int64_t start_;
62 int64_t stop_;
63 int64_t step_;
64};
65
66enum class BlaceIndexType { None, Slice, OpP, Int };
67
72struct BlaceIndex {
77 BlaceIndex() : type_(BlaceIndexType::None) {}
78
84 BlaceIndex(int64_t integer) : integer_(integer), type_(BlaceIndexType::Int) {}
85
92 : slice_(std::move(slice)), type_(BlaceIndexType::Slice) {}
93
100 BlaceIndex(blace::ops::OpP tensor)
101 : node_op_to_eval_(std::move(tensor)), type_(BlaceIndexType::OpP) {}
102
108 bool is_none() const;
109
115 bool is_integer() const;
116
122 int64_t integer() const;
123
129 bool is_slice() const;
130
137
143 bool is_node_op() const;
144
150 const blace::ops::OpP &node_op() const;
151
158 bool operator==(const BlaceIndex &rhs) const;
159
165 BlaceIndexType getType();
166
173
179 blace::ops::OpP getNodeOp();
180
181private:
182 int64_t integer_ = 0;
184 blace::ops::OpP node_op_to_eval_;
185 BlaceIndexType type_;
186};
187
188typedef std::vector<BlaceIndex> BlaceIndexVec;
189} // namespace ml_core
190} // namespace blace
Definition: blace_index.h:72
BlaceIndex()
Definition: blace_index.h:77
BlaceIndex(int64_t integer)
Definition: blace_index.h:84
BlaceIndex(blace::ml_core::Slice slice)
Definition: blace_index.h:91
blace::ml_core::Slice getSlice()
const blace::ml_core::Slice & slice() const
bool operator==(const BlaceIndex &rhs) const
blace::ops::OpP getNodeOp()
BlaceIndexType getType()
const blace::ops::OpP & node_op() const
BlaceIndex(blace::ops::OpP tensor)
Definition: blace_index.h:100
Definition: blace_index.h:24
int64_t start() const
Definition: blace_index.h:44
int64_t step() const
Definition: blace_index.h:58
int64_t stop() const
Definition: blace_index.h:51
EXPORT_OR_IMPORT Slice(std::optional< int64_t > start_index=std::nullopt, std::optional< int64_t > stop_index=std::nullopt, std::optional< int64_t > step_index=std::nullopt)