You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "rok (via GitHub)" <gi...@apache.org> on 2023/02/01 03:11:32 UTC

[GitHub] [arrow] rok commented on a diff in pull request #8510: GH-15483: [C++] Add a Tensor logical value type with constant dimensions, implemented using ExtensionType

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


##########
cpp/src/arrow/extension/tensor_array.cc:
##########
@@ -0,0 +1,161 @@
+// 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/extension_type.h"
+
+#include "arrow/json/rapidjson_defs.h"  // IWYU pragma: keep
+#include "arrow/tensor.h"
+#include "arrow/util/logging.h"
+
+#include <rapidjson/rapidjson.h>
+#include <rapidjson/document.h>
+#include <rapidjson/stringbuffer.h>
+#include <rapidjson/writer.h>
+
+namespace rj = arrow::rapidjson;
+
+namespace arrow {
+namespace extension {
+
+std::string TensorArrayType::extension_name() const { return "arrow.fixed_size_tensor"; }
+
+size_t TensorArrayType::ndim() const { return shape_.size(); }
+
+std::vector<int64_t> TensorArrayType::shape() const { return shape_; }
+
+std::vector<int64_t> TensorArrayType::strides() const {
+  std::vector<int64_t> strides;
+  const auto& element_type =
+      internal::checked_cast<const FixedWidthType&>(*storage_type());
+
+  if (is_row_major_) {
+    DCHECK_OK(internal::ComputeRowMajorStrides(element_type, shape_, &strides));
+  } else {
+    DCHECK_OK(internal::ComputeColumnMajorStrides(element_type, shape_, &strides));
+  }
+
+  return strides;
+}
+
+std::shared_ptr<DataType> TensorArrayType::storage_type() const { return storage_type_; }
+
+std::string TensorArrayType::order() const { return is_row_major_ ? "C" : "F"; }
+
+bool TensorArrayType::ExtensionEquals(const ExtensionType& other) const {
+  if (extension_name() != other.extension_name()) {
+    return false;
+  }
+
+  const auto& other_ext = static_cast<const TensorArrayType&>(other);
+  bool equals = storage_type()->Equals(other_ext.storage_type());
+  equals &= shape() == other_ext.shape();
+  equals &= strides() == other_ext.strides();

Review Comment:
   Removed and switched to `dim_names` to try that API option.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org