31 const torch::Tensor& values,
32 const torch::IntArrayRef& size) {
35 auto crow_indices = torch::arange(0, col_indices.size(0)+1, 1, torch::kInt64) * col_indices.size(1);
38 if (crow_indices.size(0) < size[0]) {
39 auto last = crow_indices[-1];
40 auto pad = last.repeat({size[0] - crow_indices.size(0)});
41 crow_indices = torch::cat({crow_indices, pad});
44 return torch::sparse_csr_tensor(crow_indices.flatten(),
45 col_indices.flatten(),
47 size, values.options().layout(torch::Layout::SparseCsr));
62 const std::array<int64_t, N>& nbasfuncs,
63 const torch::Tensor& values,
64 const torch::IntArrayRef& size) {
67 torch::Tensor col_indices_;
69 col_indices_ = col_indices[0];
70 else if constexpr (N == 2)
71 col_indices_ = (col_indices[0].unsqueeze(2) +
72 nbasfuncs[0]*col_indices[1].unsqueeze(1))
73 .permute({0, 2, 1}).reshape({col_indices[0].size(0), -1});
74 else if constexpr (N == 3)
75 col_indices_ = (col_indices[0].unsqueeze(2).unsqueeze(3) +
76 nbasfuncs[0]*col_indices[1].unsqueeze(1).unsqueeze(3) +
77 nbasfuncs[0]*nbasfuncs[1]*col_indices[2].unsqueeze(1).unsqueeze(2))
78 .permute({0, 3, 2, 1}).reshape({col_indices[0].size(0), -1});
80 throw std::runtime_error(
"Invalid dimension");
101 const std::array<short, N>& degrees,
102 const std::array<int64_t, N>& nbasfuncs,
103 const torch::Tensor& values,
104 const torch::IntArrayRef& size) {
107 std::array<torch::Tensor, N> col_indices;
108 for (std::size_t i = 0; i < N; ++i) {
110 (knot_indices[i].unsqueeze(0) +
111 torch::arange(-degrees[i],
113 knot_indices[i].options()
torch::Tensor to_sparseCsrTensor(const torch::Tensor &col_indices, const torch::Tensor &values, const torch::IntArrayRef &size)
Constructs a sparse-CSR matrix from the column indices, matrix values and the matrix size.
Definition matrix.hpp:30