Why not use lookup table in SelectedRows?
Created by: yingfeng
I notice that the implementation of SelectedRows is a kind of Key-Value map actually as follows:
Vector<int64_t> rows_;
std::unique_ptr<Tensor> value_{nullptr};
together with corresponding typical map operations:
std::vector<std::pair<int64_t, int64_t>> Get(const std::vector<int64_t>& keys,ramework::Tensor* value) const;
bool Set(int64_t key, const Tensor& value);
However, all Get
and Set
rely on lookup operations of rows
, which is a linear scan actually:
int64_t Index(int64_t key) const {
auto it = std::find(rows_.begin(), rows_.end(), key);
if (it == rows_.end()) {
return static_cast<int64_t>(-1);
}
return static_cast<int64_t>(std::distance(rows_.begin(), it));
}
Why not choose some kind of lookup table to replace std::vector
within SelectedRows?