andishgar commented on code in PR #47586:
URL: https://github.com/apache/arrow/pull/47586#discussion_r2410189058
##########
cpp/src/arrow/tensor/converter.h:
##########
@@ -63,5 +66,56 @@ Result<std::shared_ptr<Tensor>>
MakeTensorFromSparseCSCMatrix(
Result<std::shared_ptr<Tensor>> MakeTensorFromSparseCSFTensor(
MemoryPool* pool, const SparseCSFTensor* sparse_tensor);
+template <typename Converter>
+struct ConverterVisitor {
+ explicit ConverterVisitor(Converter& converter) : converter(converter) {}
+ template <typename ValueType, typename IndexType>
+ Status operator()(const ValueType& value, const IndexType& index_type) {
+ return converter.Convert(value, index_type);
+ }
+
+ Converter& converter;
+};
+
+struct ValueTypeVisitor {
+ template <typename ValueType, typename IndexType, typename Function>
+ enable_if_number<ValueType, Status> Visit(const ValueType& value_type,
+ const IndexType& index_type,
+ Function&& function) {
+ return function(value_type, index_type);
+ }
+
+ template <typename IndexType, typename Function>
+ Status Visit(const DataType& value_type, const IndexType&, Function&&) {
+ return Status::Invalid("Invalid value type: ", value_type.name(),
+ ". Expected a number.");
+ }
+};
+
+struct IndexAndValueTypeVisitor {
+ template <typename IndexType, typename Function>
+ enable_if_integer<IndexType, Status> Visit(const IndexType& index_type,
+ const std::shared_ptr<DataType>&
value_type,
+ Function&& function) {
+ ValueTypeVisitor visitor;
+ return VisitTypeInline(*value_type, &visitor, index_type,
+ std::forward<Function>(function));
+ }
+
+ template <typename Function>
+ Status Visit(const DataType& type, const std::shared_ptr<DataType>&,
Function&&) {
+ return Status::Invalid("Invalid index type: ", type.name(), ". Expected
integer.");
+ }
+};
+
+template <typename Function>
+Status VisitValueAndIndexType(const std::shared_ptr<DataType>& value_type,
+ const std::shared_ptr<DataType>& index_type,
Review Comment:
Yes, that’s okay; using const DataType& works for me.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]