// demo/tensor_range.cpp
#include "core/tensor/tensor.hpp"
#include <cassert>
#include <ranges>
using namespace venus;
// clang-format off
auto main() -> int {
auto tensor = Tensor<int, Device::CPU, 2>(3, 3); // heap alloc 3x3 Tensor
venus::ops::iota(tensor, 1); // venus::Tensor([1, 2, 3, 4, 5, 6, 7, 8, 9], shape=(3, 3))
auto pipeline =
tensor |
std::views::filter([](int x) { return x % 2 == 0; }) | // 2, 4, 6, 8
std::views::transform([](int x) { return x * x; }) | // 4, 16, 36, 64
std::views::take(2); // 4, 16
auto result = std::ranges::fold_left(pipeline, 0, std::plus{}); // 20
assert(result == 20);
}
-
Notifications
You must be signed in to change notification settings - Fork 0
Deep Learning Framework for C++23
License
AndreiMoraru123/venus
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
Deep Learning Framework for C++23
Topics
Resources
License
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published