From 82f34d05ecf2dd541bd4346e6943375670ab7c5e Mon Sep 17 00:00:00 2001 From: Richard Barnes Date: Thu, 9 Jan 2025 13:07:49 -0800 Subject: [PATCH] c10::optional -> std::optional --- csrc/cpu/scatter_cpu.cpp | 8 +++--- csrc/cpu/scatter_cpu.h | 6 ++--- csrc/cpu/segment_coo_cpu.cpp | 10 ++++---- csrc/cpu/segment_coo_cpu.h | 8 +++--- csrc/cpu/segment_csr_cpu.cpp | 8 +++--- csrc/cpu/segment_csr_cpu.h | 6 ++--- csrc/cuda/scatter_cuda.cu | 8 +++--- csrc/cuda/scatter_cuda.h | 6 ++--- csrc/cuda/segment_coo_cuda.cu | 10 ++++---- csrc/cuda/segment_coo_cuda.h | 8 +++--- csrc/cuda/segment_csr_cuda.cu | 8 +++--- csrc/cuda/segment_csr_cuda.h | 6 ++--- csrc/scatter.cpp | 48 +++++++++++++++++------------------ csrc/scatter.h | 48 +++++++++++++++++------------------ csrc/segment_coo.cpp | 48 +++++++++++++++++------------------ csrc/segment_csr.cpp | 28 ++++++++++---------- 16 files changed, 132 insertions(+), 132 deletions(-) diff --git a/csrc/cpu/scatter_cpu.cpp b/csrc/cpu/scatter_cpu.cpp index b7dc82d2..64b8ac3b 100644 --- a/csrc/cpu/scatter_cpu.cpp +++ b/csrc/cpu/scatter_cpu.cpp @@ -4,10 +4,10 @@ #include "reducer.h" #include "utils.h" -std::tuple> +std::tuple> scatter_cpu(torch::Tensor src, torch::Tensor index, int64_t dim, - torch::optional optional_out, - torch::optional dim_size, std::string reduce) { + std::optional optional_out, + std::optional dim_size, std::string reduce) { CHECK_CPU(src); CHECK_CPU(index); if (optional_out.has_value()) @@ -36,7 +36,7 @@ scatter_cpu(torch::Tensor src, torch::Tensor index, int64_t dim, out = torch::empty(sizes, src.options()); } - torch::optional arg_out = torch::nullopt; + std::optional arg_out = std::nullopt; int64_t *arg_out_data = nullptr; if (reduce2REDUCE.at(reduce) == MIN || reduce2REDUCE.at(reduce) == MAX) { arg_out = torch::full_like(out, src.size(dim), index.options()); diff --git a/csrc/cpu/scatter_cpu.h b/csrc/cpu/scatter_cpu.h index 286394c1..eb279c50 100644 --- a/csrc/cpu/scatter_cpu.h +++ b/csrc/cpu/scatter_cpu.h @@ -2,7 +2,7 @@ #include "../extensions.h" -std::tuple> +std::tuple> scatter_cpu(torch::Tensor src, torch::Tensor index, int64_t dim, - torch::optional optional_out, - torch::optional dim_size, std::string reduce); + std::optional optional_out, + std::optional dim_size, std::string reduce); diff --git a/csrc/cpu/segment_coo_cpu.cpp b/csrc/cpu/segment_coo_cpu.cpp index 179ce6fa..64f975dd 100644 --- a/csrc/cpu/segment_coo_cpu.cpp +++ b/csrc/cpu/segment_coo_cpu.cpp @@ -5,10 +5,10 @@ #include "utils.h" #include -std::tuple> +std::tuple> segment_coo_cpu(torch::Tensor src, torch::Tensor index, - torch::optional optional_out, - torch::optional dim_size, std::string reduce) { + std::optional optional_out, + std::optional dim_size, std::string reduce) { CHECK_CPU(src); CHECK_CPU(index); if (optional_out.has_value()) @@ -45,7 +45,7 @@ segment_coo_cpu(torch::Tensor src, torch::Tensor index, out = torch::empty(sizes, src.options()); } - torch::optional arg_out = torch::nullopt; + std::optional arg_out = std::nullopt; int64_t *arg_out_data = nullptr; if (reduce2REDUCE.at(reduce) == MIN || reduce2REDUCE.at(reduce) == MAX) { arg_out = torch::full_like(out, src.size(dim), index.options()); @@ -141,7 +141,7 @@ segment_coo_cpu(torch::Tensor src, torch::Tensor index, } torch::Tensor gather_coo_cpu(torch::Tensor src, torch::Tensor index, - torch::optional optional_out) { + std::optional optional_out) { CHECK_CPU(src); CHECK_CPU(index); if (optional_out.has_value()) diff --git a/csrc/cpu/segment_coo_cpu.h b/csrc/cpu/segment_coo_cpu.h index 425cfb8b..e0501209 100644 --- a/csrc/cpu/segment_coo_cpu.h +++ b/csrc/cpu/segment_coo_cpu.h @@ -2,10 +2,10 @@ #include "../extensions.h" -std::tuple> +std::tuple> segment_coo_cpu(torch::Tensor src, torch::Tensor index, - torch::optional optional_out, - torch::optional dim_size, std::string reduce); + std::optional optional_out, + std::optional dim_size, std::string reduce); torch::Tensor gather_coo_cpu(torch::Tensor src, torch::Tensor index, - torch::optional optional_out); + std::optional optional_out); diff --git a/csrc/cpu/segment_csr_cpu.cpp b/csrc/cpu/segment_csr_cpu.cpp index 2411e516..18be4023 100644 --- a/csrc/cpu/segment_csr_cpu.cpp +++ b/csrc/cpu/segment_csr_cpu.cpp @@ -5,9 +5,9 @@ #include "utils.h" #include -std::tuple> +std::tuple> segment_csr_cpu(torch::Tensor src, torch::Tensor indptr, - torch::optional optional_out, + std::optional optional_out, std::string reduce) { CHECK_CPU(src); CHECK_CPU(indptr); @@ -38,7 +38,7 @@ segment_csr_cpu(torch::Tensor src, torch::Tensor indptr, out = torch::empty(sizes, src.options()); } - torch::optional arg_out = torch::nullopt; + std::optional arg_out = std::nullopt; int64_t *arg_out_data = nullptr; if (reduce2REDUCE.at(reduce) == MIN || reduce2REDUCE.at(reduce) == MAX) { arg_out = torch::full(out.sizes(), src.size(dim), indptr.options()); @@ -92,7 +92,7 @@ segment_csr_cpu(torch::Tensor src, torch::Tensor indptr, } torch::Tensor gather_csr_cpu(torch::Tensor src, torch::Tensor indptr, - torch::optional optional_out) { + std::optional optional_out) { CHECK_CPU(src); CHECK_CPU(indptr); if (optional_out.has_value()) diff --git a/csrc/cpu/segment_csr_cpu.h b/csrc/cpu/segment_csr_cpu.h index 716f6890..7b4da0a2 100644 --- a/csrc/cpu/segment_csr_cpu.h +++ b/csrc/cpu/segment_csr_cpu.h @@ -2,10 +2,10 @@ #include "../extensions.h" -std::tuple> +std::tuple> segment_csr_cpu(torch::Tensor src, torch::Tensor indptr, - torch::optional optional_out, + std::optional optional_out, std::string reduce); torch::Tensor gather_csr_cpu(torch::Tensor src, torch::Tensor indptr, - torch::optional optional_out); + std::optional optional_out); diff --git a/csrc/cuda/scatter_cuda.cu b/csrc/cuda/scatter_cuda.cu index 6dabad59..83db7ccd 100644 --- a/csrc/cuda/scatter_cuda.cu +++ b/csrc/cuda/scatter_cuda.cu @@ -55,10 +55,10 @@ scatter_arg_kernel(const scalar_t *src_data, } } -std::tuple> +std::tuple> scatter_cuda(torch::Tensor src, torch::Tensor index, int64_t dim, - torch::optional optional_out, - torch::optional dim_size, std::string reduce) { + std::optional optional_out, + std::optional dim_size, std::string reduce) { CHECK_CUDA(src); CHECK_CUDA(index); if (optional_out.has_value()) @@ -89,7 +89,7 @@ scatter_cuda(torch::Tensor src, torch::Tensor index, int64_t dim, out = torch::empty(sizes, src.options()); } - torch::optional arg_out = torch::nullopt; + std::optional arg_out = std::nullopt; int64_t *arg_out_data = nullptr; if (reduce2REDUCE.at(reduce) == MIN || reduce2REDUCE.at(reduce) == MAX) { arg_out = torch::full_like(out, src.size(dim), index.options()); diff --git a/csrc/cuda/scatter_cuda.h b/csrc/cuda/scatter_cuda.h index 92bdfa8d..a0496793 100644 --- a/csrc/cuda/scatter_cuda.h +++ b/csrc/cuda/scatter_cuda.h @@ -2,7 +2,7 @@ #include "../extensions.h" -std::tuple> +std::tuple> scatter_cuda(torch::Tensor src, torch::Tensor index, int64_t dim, - torch::optional optional_out, - torch::optional dim_size, std::string reduce); + std::optional optional_out, + std::optional dim_size, std::string reduce); diff --git a/csrc/cuda/segment_coo_cuda.cu b/csrc/cuda/segment_coo_cuda.cu index ea73e418..29610dfc 100644 --- a/csrc/cuda/segment_coo_cuda.cu +++ b/csrc/cuda/segment_coo_cuda.cu @@ -149,10 +149,10 @@ __global__ void segment_coo_arg_broadcast_kernel( } } -std::tuple> +std::tuple> segment_coo_cuda(torch::Tensor src, torch::Tensor index, - torch::optional optional_out, - torch::optional dim_size, std::string reduce) { + std::optional optional_out, + std::optional dim_size, std::string reduce) { CHECK_CUDA(src); CHECK_CUDA(index); if (optional_out.has_value()) @@ -191,7 +191,7 @@ segment_coo_cuda(torch::Tensor src, torch::Tensor index, out = torch::zeros(sizes, src.options()); } - torch::optional arg_out = torch::nullopt; + std::optional arg_out = std::nullopt; int64_t *arg_out_data = nullptr; if (reduce2REDUCE.at(reduce) == MIN || reduce2REDUCE.at(reduce) == MAX) { arg_out = torch::full_like(out, src.size(dim), index.options()); @@ -325,7 +325,7 @@ __global__ void gather_coo_broadcast_kernel( } torch::Tensor gather_coo_cuda(torch::Tensor src, torch::Tensor index, - torch::optional optional_out) { + std::optional optional_out) { CHECK_CUDA(src); CHECK_CUDA(index); if (optional_out.has_value()) diff --git a/csrc/cuda/segment_coo_cuda.h b/csrc/cuda/segment_coo_cuda.h index f401faea..93f2aee6 100644 --- a/csrc/cuda/segment_coo_cuda.h +++ b/csrc/cuda/segment_coo_cuda.h @@ -2,10 +2,10 @@ #include "../extensions.h" -std::tuple> +std::tuple> segment_coo_cuda(torch::Tensor src, torch::Tensor index, - torch::optional optional_out, - torch::optional dim_size, std::string reduce); + std::optional optional_out, + std::optional dim_size, std::string reduce); torch::Tensor gather_coo_cuda(torch::Tensor src, torch::Tensor index, - torch::optional optional_out); + std::optional optional_out); diff --git a/csrc/cuda/segment_csr_cuda.cu b/csrc/cuda/segment_csr_cuda.cu index 9e6426f5..7061ba69 100644 --- a/csrc/cuda/segment_csr_cuda.cu +++ b/csrc/cuda/segment_csr_cuda.cu @@ -94,9 +94,9 @@ __global__ void segment_csr_broadcast_kernel( } } -std::tuple> +std::tuple> segment_csr_cuda(torch::Tensor src, torch::Tensor indptr, - torch::optional optional_out, + std::optional optional_out, std::string reduce) { CHECK_CUDA(src); CHECK_CUDA(indptr); @@ -128,7 +128,7 @@ segment_csr_cuda(torch::Tensor src, torch::Tensor indptr, out = torch::empty(sizes, src.options()); } - torch::optional arg_out = torch::nullopt; + std::optional arg_out = std::nullopt; int64_t *arg_out_data = nullptr; if (reduce2REDUCE.at(reduce) == MIN || reduce2REDUCE.at(reduce) == MAX) { arg_out = torch::full(out.sizes(), src.size(dim), indptr.options()); @@ -217,7 +217,7 @@ __global__ void gather_csr_broadcast_kernel( } torch::Tensor gather_csr_cuda(torch::Tensor src, torch::Tensor indptr, - torch::optional optional_out) { + std::optional optional_out) { CHECK_CUDA(src); CHECK_CUDA(indptr); if (optional_out.has_value()) diff --git a/csrc/cuda/segment_csr_cuda.h b/csrc/cuda/segment_csr_cuda.h index c59f5401..8014e766 100644 --- a/csrc/cuda/segment_csr_cuda.h +++ b/csrc/cuda/segment_csr_cuda.h @@ -2,10 +2,10 @@ #include "../extensions.h" -std::tuple> +std::tuple> segment_csr_cuda(torch::Tensor src, torch::Tensor indptr, - torch::optional optional_out, + std::optional optional_out, std::string reduce); torch::Tensor gather_csr_cuda(torch::Tensor src, torch::Tensor indptr, - torch::optional optional_out); + std::optional optional_out); diff --git a/csrc/scatter.cpp b/csrc/scatter.cpp index cda6785f..0c986c00 100644 --- a/csrc/scatter.cpp +++ b/csrc/scatter.cpp @@ -32,10 +32,10 @@ torch::Tensor broadcast(torch::Tensor src, torch::Tensor other, int64_t dim) { return src; } -std::tuple> +std::tuple> scatter_fw(torch::Tensor src, torch::Tensor index, int64_t dim, - torch::optional optional_out, - torch::optional dim_size, std::string reduce) { + std::optional optional_out, + std::optional dim_size, std::string reduce) { if (src.device().is_cuda()) { #ifdef WITH_CUDA return scatter_cuda(src, index, dim, optional_out, dim_size, reduce); @@ -55,8 +55,8 @@ class ScatterSum : public torch::autograd::Function { public: static variable_list forward(AutogradContext *ctx, Variable src, Variable index, int64_t dim, - torch::optional optional_out, - torch::optional dim_size) { + std::optional optional_out, + std::optional dim_size) { dim = dim < 0 ? src.dim() + dim : dim; ctx->saved_data["dim"] = dim; ctx->saved_data["src_shape"] = src.sizes(); @@ -84,8 +84,8 @@ class ScatterMul : public torch::autograd::Function { public: static variable_list forward(AutogradContext *ctx, Variable src, Variable index, int64_t dim, - torch::optional optional_out, - torch::optional dim_size) { + std::optional optional_out, + std::optional dim_size) { dim = dim < 0 ? src.dim() + dim : dim; ctx->saved_data["dim"] = dim; ctx->saved_data["src_shape"] = src.sizes(); @@ -116,8 +116,8 @@ class ScatterMean : public torch::autograd::Function { public: static variable_list forward(AutogradContext *ctx, Variable src, Variable index, int64_t dim, - torch::optional optional_out, - torch::optional dim_size) { + std::optional optional_out, + std::optional dim_size) { dim = dim < 0 ? src.dim() + dim : dim; ctx->saved_data["dim"] = dim; ctx->saved_data["src_shape"] = src.sizes(); @@ -131,7 +131,7 @@ class ScatterMean : public torch::autograd::Function { auto ones = torch::ones(old_index.sizes(), src.options()); result = scatter_fw(ones, old_index, old_index.dim() <= dim ? old_index.dim() - 1 : dim, - torch::nullopt, out.size(dim), "sum"); + std::nullopt, out.size(dim), "sum"); auto count = std::get<0>(result); count.masked_fill_(count < 1, 1); count = broadcast(count, out, dim); @@ -164,8 +164,8 @@ class ScatterMin : public torch::autograd::Function { public: static variable_list forward(AutogradContext *ctx, Variable src, Variable index, int64_t dim, - torch::optional optional_out, - torch::optional dim_size) { + std::optional optional_out, + std::optional dim_size) { dim = dim < 0 ? src.dim() + dim : dim; ctx->saved_data["dim"] = dim; ctx->saved_data["src_shape"] = src.sizes(); @@ -200,8 +200,8 @@ class ScatterMax : public torch::autograd::Function { public: static variable_list forward(AutogradContext *ctx, Variable src, Variable index, int64_t dim, - torch::optional optional_out, - torch::optional dim_size) { + std::optional optional_out, + std::optional dim_size) { dim = dim < 0 ? src.dim() + dim : dim; ctx->saved_data["dim"] = dim; ctx->saved_data["src_shape"] = src.sizes(); @@ -234,37 +234,37 @@ class ScatterMax : public torch::autograd::Function { SCATTER_API torch::Tensor scatter_sum(torch::Tensor src, torch::Tensor index, int64_t dim, - torch::optional optional_out, - torch::optional dim_size) { + std::optional optional_out, + std::optional dim_size) { return ScatterSum::apply(src, index, dim, optional_out, dim_size)[0]; } SCATTER_API torch::Tensor scatter_mul(torch::Tensor src, torch::Tensor index, int64_t dim, - torch::optional optional_out, - torch::optional dim_size) { + std::optional optional_out, + std::optional dim_size) { return ScatterMul::apply(src, index, dim, optional_out, dim_size)[0]; } SCATTER_API torch::Tensor scatter_mean(torch::Tensor src, torch::Tensor index, int64_t dim, - torch::optional optional_out, - torch::optional dim_size) { + std::optional optional_out, + std::optional dim_size) { return ScatterMean::apply(src, index, dim, optional_out, dim_size)[0]; } SCATTER_API std::tuple scatter_min(torch::Tensor src, torch::Tensor index, int64_t dim, - torch::optional optional_out, - torch::optional dim_size) { + std::optional optional_out, + std::optional dim_size) { auto result = ScatterMin::apply(src, index, dim, optional_out, dim_size); return std::make_tuple(result[0], result[1]); } SCATTER_API std::tuple scatter_max(torch::Tensor src, torch::Tensor index, int64_t dim, - torch::optional optional_out, - torch::optional dim_size) { + std::optional optional_out, + std::optional dim_size) { auto result = ScatterMax::apply(src, index, dim, optional_out, dim_size); return std::make_tuple(result[0], result[1]); } diff --git a/csrc/scatter.h b/csrc/scatter.h index b1c497e9..f5d9eaaf 100644 --- a/csrc/scatter.h +++ b/csrc/scatter.h @@ -12,69 +12,69 @@ SCATTER_INLINE_VARIABLE int64_t _cuda_version = cuda_version(); SCATTER_API torch::Tensor scatter_sum(torch::Tensor src, torch::Tensor index, int64_t dim, - torch::optional optional_out, - torch::optional dim_size); + std::optional optional_out, + std::optional dim_size); SCATTER_API torch::Tensor scatter_mul(torch::Tensor src, torch::Tensor index, int64_t dim, - torch::optional optional_out, - torch::optional dim_size); + std::optional optional_out, + std::optional dim_size); SCATTER_API torch::Tensor scatter_mean(torch::Tensor src, torch::Tensor index, int64_t dim, - torch::optional optional_out, - torch::optional dim_size); + std::optional optional_out, + std::optional dim_size); SCATTER_API std::tuple scatter_min(torch::Tensor src, torch::Tensor index, int64_t dim, - torch::optional optional_out, - torch::optional dim_size); + std::optional optional_out, + std::optional dim_size); SCATTER_API std::tuple scatter_max(torch::Tensor src, torch::Tensor index, int64_t dim, - torch::optional optional_out, - torch::optional dim_size); + std::optional optional_out, + std::optional dim_size); SCATTER_API torch::Tensor segment_sum_coo(torch::Tensor src, torch::Tensor index, - torch::optional optional_out, - torch::optional dim_size); + std::optional optional_out, + std::optional dim_size); SCATTER_API torch::Tensor segment_mean_coo(torch::Tensor src, torch::Tensor index, - torch::optional optional_out, - torch::optional dim_size); + std::optional optional_out, + std::optional dim_size); SCATTER_API std::tuple segment_min_coo(torch::Tensor src, torch::Tensor index, - torch::optional optional_out, - torch::optional dim_size); + std::optional optional_out, + std::optional dim_size); SCATTER_API std::tuple segment_max_coo(torch::Tensor src, torch::Tensor index, - torch::optional optional_out, - torch::optional dim_size); + std::optional optional_out, + std::optional dim_size); SCATTER_API torch::Tensor gather_coo(torch::Tensor src, torch::Tensor index, - torch::optional optional_out); + std::optional optional_out); SCATTER_API torch::Tensor segment_sum_csr(torch::Tensor src, torch::Tensor indptr, - torch::optional optional_out); + std::optional optional_out); SCATTER_API torch::Tensor segment_mean_csr(torch::Tensor src, torch::Tensor indptr, - torch::optional optional_out); + std::optional optional_out); SCATTER_API std::tuple segment_min_csr(torch::Tensor src, torch::Tensor indptr, - torch::optional optional_out); + std::optional optional_out); SCATTER_API std::tuple segment_max_csr(torch::Tensor src, torch::Tensor indptr, - torch::optional optional_out); + std::optional optional_out); SCATTER_API torch::Tensor gather_csr(torch::Tensor src, torch::Tensor indptr, - torch::optional optional_out); + std::optional optional_out); diff --git a/csrc/segment_coo.cpp b/csrc/segment_coo.cpp index 055dab87..e59877a8 100644 --- a/csrc/segment_coo.cpp +++ b/csrc/segment_coo.cpp @@ -22,10 +22,10 @@ PyMODINIT_FUNC PyInit__segment_coo_cpu(void) { return NULL; } #endif #endif -std::tuple> +std::tuple> segment_coo_fw(torch::Tensor src, torch::Tensor index, - torch::optional optional_out, - torch::optional dim_size, std::string reduce) { + std::optional optional_out, + std::optional dim_size, std::string reduce) { if (src.device().is_cuda()) { #ifdef WITH_CUDA return segment_coo_cuda(src, index, optional_out, dim_size, reduce); @@ -38,7 +38,7 @@ segment_coo_fw(torch::Tensor src, torch::Tensor index, } torch::Tensor gather_coo_fw(torch::Tensor src, torch::Tensor index, - torch::optional optional_out) { + std::optional optional_out) { if (src.device().is_cuda()) { #ifdef WITH_CUDA return gather_coo_cuda(src, index, optional_out); @@ -58,8 +58,8 @@ class SegmentSumCOO : public torch::autograd::Function { public: static variable_list forward(AutogradContext *ctx, Variable src, Variable index, - torch::optional optional_out, - torch::optional dim_size) { + std::optional optional_out, + std::optional dim_size) { ctx->saved_data["src_shape"] = src.sizes(); auto result = segment_coo_fw(src, index, optional_out, dim_size, "sum"); auto out = std::get<0>(result); @@ -84,8 +84,8 @@ class SegmentMeanCOO : public torch::autograd::Function { public: static variable_list forward(AutogradContext *ctx, Variable src, Variable index, - torch::optional optional_out, - torch::optional dim_size) { + std::optional optional_out, + std::optional dim_size) { ctx->saved_data["src_shape"] = src.sizes(); auto result = segment_coo_fw(src, index, optional_out, dim_size, "mean"); auto out = std::get<0>(result); @@ -104,7 +104,7 @@ class SegmentMeanCOO : public torch::autograd::Function { auto src_shape = list2vec(ctx->saved_data["src_shape"].toIntList()); auto grad_in = torch::empty(src_shape, grad_out.options()); gather_coo_fw(grad_out, index, grad_in); - count = gather_coo_fw(count, index, torch::nullopt); + count = gather_coo_fw(count, index, std::nullopt); for (auto i = 0; i < grad_out.dim() - index.dim(); i++) count = count.unsqueeze(-1); grad_in.true_divide_(count); @@ -116,8 +116,8 @@ class SegmentMinCOO : public torch::autograd::Function { public: static variable_list forward(AutogradContext *ctx, Variable src, Variable index, - torch::optional optional_out, - torch::optional dim_size) { + std::optional optional_out, + std::optional dim_size) { ctx->saved_data["src_shape"] = src.sizes(); auto result = segment_coo_fw(src, index, optional_out, dim_size, "min"); auto out = std::get<0>(result); @@ -148,8 +148,8 @@ class SegmentMaxCOO : public torch::autograd::Function { public: static variable_list forward(AutogradContext *ctx, Variable src, Variable index, - torch::optional optional_out, - torch::optional dim_size) { + std::optional optional_out, + std::optional dim_size) { ctx->saved_data["src_shape"] = src.sizes(); auto result = segment_coo_fw(src, index, optional_out, dim_size, "max"); auto out = std::get<0>(result); @@ -180,7 +180,7 @@ class GatherCOO : public torch::autograd::Function { public: static variable_list forward(AutogradContext *ctx, Variable src, Variable index, - torch::optional optional_out) { + std::optional optional_out) { ctx->saved_data["src_shape"] = src.sizes(); auto out = gather_coo_fw(src, index, optional_out); ctx->save_for_backward({index}); @@ -196,44 +196,44 @@ class GatherCOO : public torch::autograd::Function { auto src_shape = list2vec(ctx->saved_data["src_shape"].toIntList()); auto grad_in = torch::zeros(src_shape, grad_out.options()); - segment_coo_fw(grad_out, index, grad_in, torch::nullopt, "sum"); + segment_coo_fw(grad_out, index, grad_in, std::nullopt, "sum"); return {grad_in, Variable(), Variable()}; } }; SCATTER_API torch::Tensor segment_sum_coo(torch::Tensor src, torch::Tensor index, - torch::optional optional_out, - torch::optional dim_size) { + std::optional optional_out, + std::optional dim_size) { return SegmentSumCOO::apply(src, index, optional_out, dim_size)[0]; } SCATTER_API torch::Tensor segment_mean_coo(torch::Tensor src, torch::Tensor index, - torch::optional optional_out, - torch::optional dim_size) { + std::optional optional_out, + std::optional dim_size) { return SegmentMeanCOO::apply(src, index, optional_out, dim_size)[0]; } SCATTER_API std::tuple segment_min_coo(torch::Tensor src, torch::Tensor index, - torch::optional optional_out, - torch::optional dim_size) { + std::optional optional_out, + std::optional dim_size) { auto result = SegmentMinCOO::apply(src, index, optional_out, dim_size); return std::make_tuple(result[0], result[1]); } SCATTER_API std::tuple segment_max_coo(torch::Tensor src, torch::Tensor index, - torch::optional optional_out, - torch::optional dim_size) { + std::optional optional_out, + std::optional dim_size) { auto result = SegmentMaxCOO::apply(src, index, optional_out, dim_size); return std::make_tuple(result[0], result[1]); } SCATTER_API torch::Tensor gather_coo(torch::Tensor src, torch::Tensor index, - torch::optional optional_out) { + std::optional optional_out) { return GatherCOO::apply(src, index, optional_out)[0]; } diff --git a/csrc/segment_csr.cpp b/csrc/segment_csr.cpp index b8f366eb..5f913c21 100644 --- a/csrc/segment_csr.cpp +++ b/csrc/segment_csr.cpp @@ -22,9 +22,9 @@ PyMODINIT_FUNC PyInit__segment_csr_cpu(void) { return NULL; } #endif #endif -std::tuple> +std::tuple> segment_csr_fw(torch::Tensor src, torch::Tensor indptr, - torch::optional optional_out, + std::optional optional_out, std::string reduce) { if (src.device().is_cuda()) { #ifdef WITH_CUDA @@ -38,7 +38,7 @@ segment_csr_fw(torch::Tensor src, torch::Tensor indptr, } torch::Tensor gather_csr_fw(torch::Tensor src, torch::Tensor indptr, - torch::optional optional_out) { + std::optional optional_out) { if (src.device().is_cuda()) { #ifdef WITH_CUDA return gather_csr_cuda(src, indptr, optional_out); @@ -58,7 +58,7 @@ class SegmentSumCSR : public torch::autograd::Function { public: static variable_list forward(AutogradContext *ctx, Variable src, Variable indptr, - torch::optional optional_out) { + std::optional optional_out) { ctx->saved_data["src_shape"] = src.sizes(); auto out = std::get<0>(segment_csr_fw(src, indptr, optional_out, "sum")); ctx->save_for_backward({indptr}); @@ -82,7 +82,7 @@ class SegmentMeanCSR : public torch::autograd::Function { public: static variable_list forward(AutogradContext *ctx, Variable src, Variable indptr, - torch::optional optional_out) { + std::optional optional_out) { ctx->saved_data["src_shape"] = src.sizes(); auto out = std::get<0>(segment_csr_fw(src, indptr, optional_out, "mean")); ctx->save_for_backward({indptr}); @@ -102,7 +102,7 @@ class SegmentMeanCSR : public torch::autograd::Function { auto indptr1 = indptr.narrow(-1, 0, indptr.size(-1) - 1); auto indptr2 = indptr.narrow(-1, 1, indptr.size(-1) - 1); auto count = (indptr2 - indptr1).to(grad_in.options()); - count = gather_csr_fw(count, indptr, torch::nullopt); + count = gather_csr_fw(count, indptr, std::nullopt); for (auto i = 0; i < grad_out.dim() - indptr.dim(); i++) count = count.unsqueeze(-1); grad_in.true_divide_(count); @@ -115,7 +115,7 @@ class SegmentMinCSR : public torch::autograd::Function { public: static variable_list forward(AutogradContext *ctx, Variable src, Variable indptr, - torch::optional optional_out) { + std::optional optional_out) { ctx->saved_data["src_shape"] = src.sizes(); auto result = segment_csr_fw(src, indptr, optional_out, "min"); auto out = std::get<0>(result); @@ -146,7 +146,7 @@ class SegmentMaxCSR : public torch::autograd::Function { public: static variable_list forward(AutogradContext *ctx, Variable src, Variable indptr, - torch::optional optional_out) { + std::optional optional_out) { ctx->saved_data["src_shape"] = src.sizes(); auto result = segment_csr_fw(src, indptr, optional_out, "max"); auto out = std::get<0>(result); @@ -177,7 +177,7 @@ class GatherCSR : public torch::autograd::Function { public: static variable_list forward(AutogradContext *ctx, Variable src, Variable indptr, - torch::optional optional_out) { + std::optional optional_out) { ctx->saved_data["src_shape"] = src.sizes(); auto out = gather_csr_fw(src, indptr, optional_out); ctx->save_for_backward({indptr}); @@ -200,33 +200,33 @@ class GatherCSR : public torch::autograd::Function { SCATTER_API torch::Tensor segment_sum_csr(torch::Tensor src, torch::Tensor indptr, - torch::optional optional_out) { + std::optional optional_out) { return SegmentSumCSR::apply(src, indptr, optional_out)[0]; } SCATTER_API torch::Tensor segment_mean_csr(torch::Tensor src, torch::Tensor indptr, - torch::optional optional_out) { + std::optional optional_out) { return SegmentMeanCSR::apply(src, indptr, optional_out)[0]; } SCATTER_API std::tuple segment_min_csr(torch::Tensor src, torch::Tensor indptr, - torch::optional optional_out) { + std::optional optional_out) { auto result = SegmentMinCSR::apply(src, indptr, optional_out); return std::make_tuple(result[0], result[1]); } SCATTER_API std::tuple segment_max_csr(torch::Tensor src, torch::Tensor indptr, - torch::optional optional_out) { + std::optional optional_out) { auto result = SegmentMaxCSR::apply(src, indptr, optional_out); return std::make_tuple(result[0], result[1]); } SCATTER_API torch::Tensor gather_csr(torch::Tensor src, torch::Tensor indptr, - torch::optional optional_out) { + std::optional optional_out) { return GatherCSR::apply(src, indptr, optional_out)[0]; }