MCPcopy Create free account
hub / github.com/MrNeRF/LichtFeld-Studio / create_sequential_tensor

Function create_sequential_tensor

tests/test_tensor_broadcast.cpp:69–87  ·  view source on GitHub ↗

Helper to create a tensor with sequential values

Source from the content-addressed store, hash-verified

67
68 // Helper to create a tensor with sequential values
69 Tensor create_sequential_tensor(TensorShape shape, Device device = Device::CUDA) {
70 auto tensor = Tensor::empty(shape, device);
71 size_t n = tensor.numel();
72
73 if (device == Device::CUDA) {
74 std::vector<float> data(n);
75 for (size_t i = 0; i < n; ++i) {
76 data[i] = static_cast<float>(i);
77 }
78 cudaMemcpy(tensor.ptr<float>(), data.data(), n * sizeof(float), cudaMemcpyHostToDevice);
79 } else {
80 float* data = tensor.ptr<float>();
81 for (size_t i = 0; i < n; ++i) {
82 data[i] = static_cast<float>(i);
83 }
84 }
85
86 return tensor;
87 }
88
89 // Helper to create PyTorch sequential tensor
90 torch::Tensor create_torch_sequential(const std::vector<int64_t>& shape,

Callers 1

TEST_FFunction · 0.85

Calls 3

numelMethod · 0.80
emptyFunction · 0.50
dataMethod · 0.45

Tested by

no test coverage detected