3#include "lamppp/tensor/scalar.hpp"
6namespace lmp::autograd {
18Variable zeros(
const std::vector<size_t>& shape, tensor::DeviceType device,
19 tensor::DataType dtype,
bool requires_grad);
29Variable ones(
const std::vector<size_t>& shape, tensor::DeviceType device,
30 tensor::DataType dtype,
bool requires_grad);
40Variable rand(
const std::vector<size_t>& shape, tensor::DeviceType device,
41 tensor::DataType dtype,
bool requires_grad);
53Variable randn(tensor::Scalar mean, tensor::Scalar var,
const std::vector<size_t>& shape, tensor::DeviceType device,
54 tensor::DataType dtype,
bool requires_grad);
59template <
typename U,
typename Alloc>
60struct IsVector<std::vector<U, Alloc>> : std::true_type {};
65 std::vector<tensor::Scalar> data;
66 std::vector<size_t> shape;
68 void unroll(
const std::vector<T>& tensor,
size_t depth = 0) {
69 if (depth >= shape.size()) {
70 shape.push_back(tensor.size());
72 LMP_CHECK(tensor.size() == shape[depth]) <<
73 "Dimensions along axis must be consistent.";
75 for (
const T& t : tensor) {
79 data.insert(data.end(), tensor.begin(), tensor.end());
97Variable tensor(
const std::vector<V>& data, tensor::DeviceType device,
98 tensor::DataType dtype,
bool requires_grad) {
Definition variable.hpp:48
Main tensor object for Lamppp.
Definition tensor.hpp:29
Definition constructor.hpp:58
Definition constructor.hpp:64