Skip to content

Commit 36a822f

Browse files
authored
c10::optional -> std::optional (#394)
1 parent cdbf561 commit 36a822f

13 files changed

+75
-75
lines changed

csrc/cpu/metis_cpu.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
#include "utils.h"
1212

1313
torch::Tensor partition_cpu(torch::Tensor rowptr, torch::Tensor col,
14-
torch::optional<torch::Tensor> optional_value,
15-
torch::optional<torch::Tensor> optional_node_weight,
14+
std::optional<torch::Tensor> optional_value,
15+
std::optional<torch::Tensor> optional_node_weight,
1616
int64_t num_parts, bool recursive) {
1717
#ifdef WITH_METIS
1818
CHECK_CPU(rowptr);
@@ -66,8 +66,8 @@ torch::Tensor partition_cpu(torch::Tensor rowptr, torch::Tensor col,
6666
// --partitions64bit
6767
torch::Tensor
6868
mt_partition_cpu(torch::Tensor rowptr, torch::Tensor col,
69-
torch::optional<torch::Tensor> optional_value,
70-
torch::optional<torch::Tensor> optional_node_weight,
69+
std::optional<torch::Tensor> optional_value,
70+
std::optional<torch::Tensor> optional_node_weight,
7171
int64_t num_parts, bool recursive, int64_t num_workers) {
7272
#ifdef WITH_MTMETIS
7373
CHECK_CPU(rowptr);

csrc/cpu/metis_cpu.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
#include "../extensions.h"
44

55
torch::Tensor partition_cpu(torch::Tensor rowptr, torch::Tensor col,
6-
torch::optional<torch::Tensor> optional_value,
7-
torch::optional<torch::Tensor> optional_node_weight,
6+
std::optional<torch::Tensor> optional_value,
7+
std::optional<torch::Tensor> optional_node_weight,
88
int64_t num_parts, bool recursive);
99

1010
torch::Tensor
1111
mt_partition_cpu(torch::Tensor rowptr, torch::Tensor col,
12-
torch::optional<torch::Tensor> optional_value,
13-
torch::optional<torch::Tensor> optional_node_weight,
12+
std::optional<torch::Tensor> optional_value,
13+
std::optional<torch::Tensor> optional_node_weight,
1414
int64_t num_parts, bool recursive, int64_t num_workers);

csrc/cpu/relabel_cpu.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ std::tuple<torch::Tensor, torch::Tensor> relabel_cpu(torch::Tensor col,
4242
return std::make_tuple(out_col, out_idx);
4343
}
4444

45-
std::tuple<torch::Tensor, torch::Tensor, torch::optional<torch::Tensor>,
45+
std::tuple<torch::Tensor, torch::Tensor, std::optional<torch::Tensor>,
4646
torch::Tensor>
4747
relabel_one_hop_cpu(torch::Tensor rowptr, torch::Tensor col,
48-
torch::optional<torch::Tensor> optional_value,
48+
std::optional<torch::Tensor> optional_value,
4949
torch::Tensor idx, bool bipartite) {
5050

5151
CHECK_CPU(rowptr);
@@ -79,7 +79,7 @@ relabel_one_hop_cpu(torch::Tensor rowptr, torch::Tensor col,
7979
auto out_col = torch::empty({offset}, col.options());
8080
auto out_col_data = out_col.data_ptr<int64_t>();
8181

82-
torch::optional<torch::Tensor> out_value = torch::nullopt;
82+
std::optional<torch::Tensor> out_value = std::nullopt;
8383
if (optional_value.has_value()) {
8484
out_value = torch::empty({offset}, optional_value.value().options());
8585

csrc/cpu/relabel_cpu.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
std::tuple<torch::Tensor, torch::Tensor> relabel_cpu(torch::Tensor col,
66
torch::Tensor idx);
77

8-
std::tuple<torch::Tensor, torch::Tensor, torch::optional<torch::Tensor>,
8+
std::tuple<torch::Tensor, torch::Tensor, std::optional<torch::Tensor>,
99
torch::Tensor>
1010
relabel_one_hop_cpu(torch::Tensor rowptr, torch::Tensor col,
11-
torch::optional<torch::Tensor> optional_value,
11+
std::optional<torch::Tensor> optional_value,
1212
torch::Tensor idx, bool bipartite);

csrc/cpu/spmm_cpu.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
#include "reducer.h"
66
#include "utils.h"
77

8-
std::tuple<torch::Tensor, torch::optional<torch::Tensor>>
8+
std::tuple<torch::Tensor, std::optional<torch::Tensor>>
99
spmm_cpu(torch::Tensor rowptr, torch::Tensor col,
10-
torch::optional<torch::Tensor> optional_value, torch::Tensor mat,
10+
std::optional<torch::Tensor> optional_value, torch::Tensor mat,
1111
std::string reduce) {
1212
CHECK_CPU(rowptr);
1313
CHECK_CPU(col);
@@ -29,7 +29,7 @@ spmm_cpu(torch::Tensor rowptr, torch::Tensor col,
2929
sizes[mat.dim() - 2] = rowptr.numel() - 1;
3030
auto out = torch::empty(sizes, mat.options());
3131

32-
torch::optional<torch::Tensor> arg_out = torch::nullopt;
32+
std::optional<torch::Tensor> arg_out = std::nullopt;
3333
int64_t *arg_out_data = nullptr;
3434
if (reduce2REDUCE.at(reduce) == MIN || reduce2REDUCE.at(reduce) == MAX) {
3535
arg_out = torch::full_like(out, col.numel(), rowptr.options());

csrc/cpu/spmm_cpu.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
#include "../extensions.h"
44

5-
std::tuple<torch::Tensor, torch::optional<torch::Tensor>>
5+
std::tuple<torch::Tensor, std::optional<torch::Tensor>>
66
spmm_cpu(torch::Tensor rowptr, torch::Tensor col,
7-
torch::optional<torch::Tensor> optional_value, torch::Tensor mat,
7+
std::optional<torch::Tensor> optional_value, torch::Tensor mat,
88
std::string reduce);
99

1010
torch::Tensor spmm_value_bw_cpu(torch::Tensor row, torch::Tensor rowptr,

csrc/cpu/utils.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ inline int64_t uniform_randint(int64_t high) {
5151

5252
inline torch::Tensor
5353
choice(int64_t population, int64_t num_samples, bool replace = false,
54-
torch::optional<torch::Tensor> weight = torch::nullopt) {
54+
std::optional<torch::Tensor> weight = std::nullopt) {
5555

5656
if (population == 0 || num_samples == 0)
5757
return torch::empty({0}, at::kLong);

csrc/cuda/spmm_cuda.cu

+3-3
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ __global__ void spmm_kernel(const int64_t *rowptr_data, const int64_t *col_data,
8989
}
9090
}
9191

92-
std::tuple<torch::Tensor, torch::optional<torch::Tensor>>
92+
std::tuple<torch::Tensor, std::optional<torch::Tensor>>
9393
spmm_cuda(torch::Tensor rowptr, torch::Tensor col,
94-
torch::optional<torch::Tensor> optional_value, torch::Tensor mat,
94+
std::optional<torch::Tensor> optional_value, torch::Tensor mat,
9595
std::string reduce) {
9696

9797
CHECK_CUDA(rowptr);
@@ -115,7 +115,7 @@ spmm_cuda(torch::Tensor rowptr, torch::Tensor col,
115115
sizes[mat.dim() - 2] = rowptr.numel() - 1;
116116
auto out = torch::empty(sizes, mat.options());
117117

118-
torch::optional<torch::Tensor> arg_out = torch::nullopt;
118+
std::optional<torch::Tensor> arg_out = std::nullopt;
119119
int64_t *arg_out_data = nullptr;
120120
if (reduce2REDUCE.at(reduce) == MIN || reduce2REDUCE.at(reduce) == MAX) {
121121
arg_out = torch::full_like(out, col.numel(), rowptr.options());

csrc/cuda/spmm_cuda.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
#include "../extensions.h"
44

5-
std::tuple<torch::Tensor, torch::optional<torch::Tensor>>
5+
std::tuple<torch::Tensor, std::optional<torch::Tensor>>
66
spmm_cuda(torch::Tensor rowptr, torch::Tensor col,
7-
torch::optional<torch::Tensor> optional_value, torch::Tensor mat,
7+
std::optional<torch::Tensor> optional_value, torch::Tensor mat,
88
std::string reduce);
99

1010
torch::Tensor spmm_value_bw_cuda(torch::Tensor row, torch::Tensor rowptr,

csrc/metis.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ PyMODINIT_FUNC PyInit__metis_cpu(void) { return NULL; }
1616
#endif
1717

1818
SPARSE_API torch::Tensor partition(torch::Tensor rowptr, torch::Tensor col,
19-
torch::optional<torch::Tensor> optional_value,
19+
std::optional<torch::Tensor> optional_value,
2020
int64_t num_parts, bool recursive) {
2121
if (rowptr.device().is_cuda()) {
2222
#ifdef WITH_CUDA
@@ -25,14 +25,14 @@ SPARSE_API torch::Tensor partition(torch::Tensor rowptr, torch::Tensor col,
2525
AT_ERROR("Not compiled with CUDA support");
2626
#endif
2727
} else {
28-
return partition_cpu(rowptr, col, optional_value, torch::nullopt, num_parts,
28+
return partition_cpu(rowptr, col, optional_value, std::nullopt, num_parts,
2929
recursive);
3030
}
3131
}
3232

3333
SPARSE_API torch::Tensor partition2(torch::Tensor rowptr, torch::Tensor col,
34-
torch::optional<torch::Tensor> optional_value,
35-
torch::optional<torch::Tensor> optional_node_weight,
34+
std::optional<torch::Tensor> optional_value,
35+
std::optional<torch::Tensor> optional_node_weight,
3636
int64_t num_parts, bool recursive) {
3737
if (rowptr.device().is_cuda()) {
3838
#ifdef WITH_CUDA
@@ -47,8 +47,8 @@ SPARSE_API torch::Tensor partition2(torch::Tensor rowptr, torch::Tensor col,
4747
}
4848

4949
SPARSE_API torch::Tensor mt_partition(torch::Tensor rowptr, torch::Tensor col,
50-
torch::optional<torch::Tensor> optional_value,
51-
torch::optional<torch::Tensor> optional_node_weight,
50+
std::optional<torch::Tensor> optional_value,
51+
std::optional<torch::Tensor> optional_node_weight,
5252
int64_t num_parts, bool recursive,
5353
int64_t num_workers) {
5454
if (rowptr.device().is_cuda()) {

csrc/relabel.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ SPARSE_API std::tuple<torch::Tensor, torch::Tensor> relabel(torch::Tensor col,
2828
}
2929
}
3030

31-
SPARSE_API std::tuple<torch::Tensor, torch::Tensor, torch::optional<torch::Tensor>,
31+
SPARSE_API std::tuple<torch::Tensor, torch::Tensor, std::optional<torch::Tensor>,
3232
torch::Tensor>
3333
relabel_one_hop(torch::Tensor rowptr, torch::Tensor col,
34-
torch::optional<torch::Tensor> optional_value,
34+
std::optional<torch::Tensor> optional_value,
3535
torch::Tensor idx, bool bipartite) {
3636
if (rowptr.device().is_cuda()) {
3737
#ifdef WITH_CUDA

csrc/sparse.h

+18-18
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,28 @@ SPARSE_API torch::Tensor ptr2ind(torch::Tensor ptr, int64_t E);
1616

1717
SPARSE_API torch::Tensor
1818
partition(torch::Tensor rowptr, torch::Tensor col,
19-
torch::optional<torch::Tensor> optional_value, int64_t num_parts,
19+
std::optional<torch::Tensor> optional_value, int64_t num_parts,
2020
bool recursive);
2121

2222
SPARSE_API torch::Tensor
2323
partition2(torch::Tensor rowptr, torch::Tensor col,
24-
torch::optional<torch::Tensor> optional_value,
25-
torch::optional<torch::Tensor> optional_node_weight,
24+
std::optional<torch::Tensor> optional_value,
25+
std::optional<torch::Tensor> optional_node_weight,
2626
int64_t num_parts, bool recursive);
2727

2828
SPARSE_API torch::Tensor
2929
mt_partition(torch::Tensor rowptr, torch::Tensor col,
30-
torch::optional<torch::Tensor> optional_value,
31-
torch::optional<torch::Tensor> optional_node_weight,
30+
std::optional<torch::Tensor> optional_value,
31+
std::optional<torch::Tensor> optional_node_weight,
3232
int64_t num_parts, bool recursive, int64_t num_workers);
3333

3434
SPARSE_API std::tuple<torch::Tensor, torch::Tensor> relabel(torch::Tensor col,
3535
torch::Tensor idx);
3636

3737
SPARSE_API std::tuple<torch::Tensor, torch::Tensor,
38-
torch::optional<torch::Tensor>, torch::Tensor>
38+
std::optional<torch::Tensor>, torch::Tensor>
3939
relabel_one_hop(torch::Tensor rowptr, torch::Tensor col,
40-
torch::optional<torch::Tensor> optional_value,
40+
std::optional<torch::Tensor> optional_value,
4141
torch::Tensor idx, bool bipartite);
4242

4343
SPARSE_API torch::Tensor random_walk(torch::Tensor rowptr, torch::Tensor col,
@@ -52,25 +52,25 @@ std::tuple<torch::Tensor, torch::Tensor, torch::Tensor, torch::Tensor>
5252
sample_adj(torch::Tensor rowptr, torch::Tensor col, torch::Tensor idx,
5353
int64_t num_neighbors, bool replace);
5454

55-
SPARSE_API torch::Tensor spmm_sum(torch::optional<torch::Tensor> opt_row,
55+
SPARSE_API torch::Tensor spmm_sum(std::optional<torch::Tensor> opt_row,
5656
torch::Tensor rowptr, torch::Tensor col,
57-
torch::optional<torch::Tensor> opt_value,
58-
torch::optional<torch::Tensor> opt_colptr,
59-
torch::optional<torch::Tensor> opt_csr2csc,
57+
std::optional<torch::Tensor> opt_value,
58+
std::optional<torch::Tensor> opt_colptr,
59+
std::optional<torch::Tensor> opt_csr2csc,
6060
torch::Tensor mat);
6161

62-
SPARSE_API torch::Tensor spmm_mean(torch::optional<torch::Tensor> opt_row,
62+
SPARSE_API torch::Tensor spmm_mean(std::optional<torch::Tensor> opt_row,
6363
torch::Tensor rowptr, torch::Tensor col,
64-
torch::optional<torch::Tensor> opt_value,
65-
torch::optional<torch::Tensor> opt_rowcount,
66-
torch::optional<torch::Tensor> opt_colptr,
67-
torch::optional<torch::Tensor> opt_csr2csc,
64+
std::optional<torch::Tensor> opt_value,
65+
std::optional<torch::Tensor> opt_rowcount,
66+
std::optional<torch::Tensor> opt_colptr,
67+
std::optional<torch::Tensor> opt_csr2csc,
6868
torch::Tensor mat);
6969

7070
SPARSE_API std::tuple<torch::Tensor, torch::Tensor>
7171
spmm_min(torch::Tensor rowptr, torch::Tensor col,
72-
torch::optional<torch::Tensor> opt_value, torch::Tensor mat);
72+
std::optional<torch::Tensor> opt_value, torch::Tensor mat);
7373

7474
SPARSE_API std::tuple<torch::Tensor, torch::Tensor>
7575
spmm_max(torch::Tensor rowptr, torch::Tensor col,
76-
torch::optional<torch::Tensor> opt_value, torch::Tensor mat);
76+
std::optional<torch::Tensor> opt_value, torch::Tensor mat);

0 commit comments

Comments
 (0)