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

Re: [PR] GH-35623: [C++][Python] FixedShapeTensorType.ToString() should print the type's parameters [arrow]

AlenkaF commented on code in PR #36496:
URL: https://github.com/apache/arrow/pull/36496#discussion_r1342502720


##########
cpp/src/arrow/extension/fixed_shape_tensor.cc:
##########
@@ -104,6 +104,38 @@ bool FixedShapeTensorType::ExtensionEquals(const ExtensionType& other) const {
          permutation_equivalent;
 }
 
+std::string FixedShapeTensorType::ToString() const {
+  std::stringstream ss;
+  ss << "extension<" << this->extension_name()
+     << "[value_type=" << value_type_->ToString() << ", shape=[";
+  std::string separator;
+  for (auto v : shape_) {
+    ss << separator << v;
+    separator = ",";
+  }
+  ss << "]";
+  if (!permutation_.empty()) {
+    ss << ", permutation=[";
+    std::string p_separator;
+    for (auto v : permutation_) {
+      ss << p_separator << v;
+      p_separator = ",";
+    }
+    ss << "]";
+  }
+  if (!dim_names_.empty()) {
+    ss << ", dim_names=[";
+    std::string d_separator;
+    for (std::string v : dim_names_) {
+      ss << d_separator << v;
+      d_separator = ",";
+    }
+    ss << "]";
+  }
+  ss << "]>";
+  return ss.str();
+}
+

Review Comment:
   I went with the class template Ben suggested. The only change I added was due to compiler errors on my M1 (`no viable constructor or deduction guide for deduction of template arguments`).
   
   This solution seemed simpler then vendoring `fmt`. I also decided to do a new template and not to use `GenericToString` helper that Rok suggested because it didn't feel right to depend on the compute module.
   
   The change has been added here: https://github.com/apache/arrow/pull/36496/commits/796193d05b10b2a5fb5aa3e441e80780c42fe9f6



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