rok commented on code in PR #8510:
URL: https://github.com/apache/arrow/pull/8510#discussion_r1089212432


##########
cpp/src/arrow/extension/tensor_array.cc:
##########
@@ -0,0 +1,103 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "arrow/extension/tensor_array.h"
+#include "arrow/tensor.h"
+
+namespace arrow {
+namespace extension {
+
+static std::string get_name(const std::shared_ptr<DataType>& type,
+                            const std::vector<int64_t>& shape,
+                            const std::vector<int64_t>& strides) {
+  std::stringstream s;
+  s << "arrow.extension.tensor<type=" << *type << ", shape=(";
+  for (uint64_t i = 0; i < shape.size(); i++) {
+    s << shape[i];
+    if (i < shape.size() - 1) {
+      s << ", ";
+    }
+  }
+  s << "), strides=(";
+  for (uint64_t i = 0; i < strides.size(); i++) {
+    s << strides[i];
+    if (i < strides.size() - 1) {
+      s << ", ";
+    }
+  }
+  s << ")>";
+  return s.str();
+}
+
+std::string TensorArrayType::extension_name() const {
+  return get_name(type(), shape(), strides());
+}
+
+const char* TensorArrayType::type_name() const {
+  std::string extension_name = get_name(type(), shape(), strides());
+  return extension_name.c_str();
+}
+
+std::shared_ptr<ExtensionType> tensor_array(const std::shared_ptr<DataType>& 
type,
+                                            const std::vector<int64_t>& shape,
+                                            const std::vector<int64_t>& 
strides) {
+  std::string type_name = get_name(type, shape, strides);
+  auto ext_type = GetExtensionType(type_name);
+  if (!ext_type) {
+    DCHECK_OK(
+        RegisterExtensionType(std::make_shared<TensorArrayType>(type, shape, 
strides)));
+  }
+  return GetExtensionType(type_name);
+}
+
+bool TensorArrayType::ExtensionEquals(const ExtensionType& other) const {
+  const auto& other_ext = static_cast<const TensorArrayType&>(other);
+  bool equals = storage_type() == other_ext.storage_type();
+  equals &= shape() == other_ext.shape();
+  equals &= strides() == other_ext.strides();
+  return equals;
+}
+
+std::string TensorArrayType::Serialize() const { return extension_name(); }

Review Comment:
   Removed.



-- 
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]

Reply via email to