Add range-based slicing to tensor view. (#7453)
This commit is contained in:
@@ -413,7 +413,7 @@ void CopyTensorInfoImpl(Json arr_interface, linalg::Tensor<T, D>* p_out) {
|
||||
}
|
||||
p_out->Reshape(array.shape);
|
||||
auto t = p_out->View(GenericParameter::kCpuId);
|
||||
CHECK(t.Contiguous());
|
||||
CHECK(t.CContiguous());
|
||||
// FIXME(jiamingy): Remove the use of this default thread.
|
||||
linalg::ElementWiseKernelHost(t, common::OmpGetNumThreads(0), [&](auto i, auto) {
|
||||
return linalg::detail::Apply(TypedIndex<T, D>{array}, linalg::UnravelIndex<D>(i, t.Shape()));
|
||||
@@ -531,8 +531,8 @@ void MetaInfo::SetInfo(const char* key, const void* dptr, DataType dtype, size_t
|
||||
using T = std::remove_pointer_t<decltype(cast_d_ptr)>;
|
||||
auto t =
|
||||
linalg::TensorView<T, 1>(common::Span<T>{cast_d_ptr, num}, {num}, GenericParameter::kCpuId);
|
||||
CHECK(t.Contiguous());
|
||||
Json interface { t.ArrayInterface() };
|
||||
CHECK(t.CContiguous());
|
||||
Json interface { linalg::ArrayInterface(t) };
|
||||
assert(ArrayInterface<1>{interface}.is_contiguous);
|
||||
return interface;
|
||||
};
|
||||
|
||||
@@ -61,9 +61,9 @@ class FileIterator {
|
||||
row_block_ = parser_->Value();
|
||||
using linalg::MakeVec;
|
||||
|
||||
indptr_ = MakeVec(row_block_.offset, row_block_.size + 1).ArrayInterfaceStr();
|
||||
values_ = MakeVec(row_block_.value, row_block_.offset[row_block_.size]).ArrayInterfaceStr();
|
||||
indices_ = MakeVec(row_block_.index, row_block_.offset[row_block_.size]).ArrayInterfaceStr();
|
||||
indptr_ = ArrayInterfaceStr(MakeVec(row_block_.offset, row_block_.size + 1));
|
||||
values_ = ArrayInterfaceStr(MakeVec(row_block_.value, row_block_.offset[row_block_.size]));
|
||||
indices_ = ArrayInterfaceStr(MakeVec(row_block_.index, row_block_.offset[row_block_.size]));
|
||||
|
||||
size_t n_columns = *std::max_element(row_block_.index,
|
||||
row_block_.index + row_block_.offset[row_block_.size]);
|
||||
|
||||
Reference in New Issue
Block a user