You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by we...@apache.org on 2019/02/01 05:10:12 UTC

[arrow] branch master updated: ARROW-4397: [C++] Add dim_names in Tensor and SparseTensor

This is an automated email from the ASF dual-hosted git repository.

wesm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/master by this push:
     new caa3a92  ARROW-4397: [C++] Add dim_names in Tensor and SparseTensor
caa3a92 is described below

commit caa3a92d9f810fae35cea6f12f3af5e9c2444e60
Author: Kenta Murata <mr...@mrkn.jp>
AuthorDate: Thu Jan 31 23:10:09 2019 -0600

    ARROW-4397: [C++] Add dim_names in Tensor and SparseTensor
    
    Along with [ARROW-4388](https://issues.apache.org/jira/browse/ARROW-4388), it would be useful to introduce dim_names in Tensor and SparseTensor of C++ library.
    
    Author: Kenta Murata <mr...@mrkn.jp>
    
    Closes #3507 from mrkn/cpp_tensor_dim_names and squashes the following commits:
    
    f529ee27 <Kenta Murata>  Add dim_names in Tensor and SparseTensor
---
 cpp/src/arrow/sparse_tensor-test.cc | 8 ++++++++
 cpp/src/arrow/sparse_tensor.h       | 1 +
 cpp/src/arrow/tensor-test.cc        | 3 +++
 cpp/src/arrow/tensor.h              | 1 +
 4 files changed, 13 insertions(+)

diff --git a/cpp/src/arrow/sparse_tensor-test.cc b/cpp/src/arrow/sparse_tensor-test.cc
index ed51f03..0a3e986 100644
--- a/cpp/src/arrow/sparse_tensor-test.cc
+++ b/cpp/src/arrow/sparse_tensor-test.cc
@@ -60,10 +60,12 @@ TEST(TestSparseCOOTensor, CreationEmptyTensor) {
   ASSERT_EQ(24, st1.size());
   ASSERT_EQ(24, st2.size());
 
+  ASSERT_EQ(std::vector<std::string>({"foo", "bar", "baz"}), st2.dim_names());
   ASSERT_EQ("foo", st2.dim_name(0));
   ASSERT_EQ("bar", st2.dim_name(1));
   ASSERT_EQ("baz", st2.dim_name(2));
 
+  ASSERT_EQ(std::vector<std::string>({}), st1.dim_names());
   ASSERT_EQ("", st1.dim_name(0));
   ASSERT_EQ("", st1.dim_name(1));
   ASSERT_EQ("", st1.dim_name(2));
@@ -85,10 +87,12 @@ TEST(TestSparseCOOTensor, CreationFromNumericTensor) {
   ASSERT_EQ(12, st1.non_zero_length());
   ASSERT_TRUE(st1.is_mutable());
 
+  ASSERT_EQ(std::vector<std::string>({"foo", "bar", "baz"}), st2.dim_names());
   ASSERT_EQ("foo", st2.dim_name(0));
   ASSERT_EQ("bar", st2.dim_name(1));
   ASSERT_EQ("baz", st2.dim_name(2));
 
+  ASSERT_EQ(std::vector<std::string>({}), st1.dim_names());
   ASSERT_EQ("", st1.dim_name(0));
   ASSERT_EQ("", st1.dim_name(1));
   ASSERT_EQ("", st1.dim_name(2));
@@ -124,10 +128,12 @@ TEST(TestSparseCOOTensor, CreationFromTensor) {
   ASSERT_EQ(12, st1.non_zero_length());
   ASSERT_TRUE(st1.is_mutable());
 
+  ASSERT_EQ(std::vector<std::string>({"foo", "bar", "baz"}), st2.dim_names());
   ASSERT_EQ("foo", st2.dim_name(0));
   ASSERT_EQ("bar", st2.dim_name(1));
   ASSERT_EQ("baz", st2.dim_name(2));
 
+  ASSERT_EQ(std::vector<std::string>({}), st1.dim_names());
   ASSERT_EQ("", st1.dim_name(0));
   ASSERT_EQ("", st1.dim_name(1));
   ASSERT_EQ("", st1.dim_name(2));
@@ -192,10 +198,12 @@ TEST(TestSparseCSRMatrix, CreationFromNumericTensor2D) {
   ASSERT_EQ(12, st1.non_zero_length());
   ASSERT_TRUE(st1.is_mutable());
 
+  ASSERT_EQ(std::vector<std::string>({"foo", "bar", "baz"}), st2.dim_names());
   ASSERT_EQ("foo", st2.dim_name(0));
   ASSERT_EQ("bar", st2.dim_name(1));
   ASSERT_EQ("baz", st2.dim_name(2));
 
+  ASSERT_EQ(std::vector<std::string>({}), st1.dim_names());
   ASSERT_EQ("", st1.dim_name(0));
   ASSERT_EQ("", st1.dim_name(1));
   ASSERT_EQ("", st1.dim_name(2));
diff --git a/cpp/src/arrow/sparse_tensor.h b/cpp/src/arrow/sparse_tensor.h
index c7693d2..ded3a6d 100644
--- a/cpp/src/arrow/sparse_tensor.h
+++ b/cpp/src/arrow/sparse_tensor.h
@@ -135,6 +135,7 @@ class ARROW_EXPORT SparseTensor {
 
   int ndim() const { return static_cast<int>(shape_.size()); }
 
+  const std::vector<std::string>& dim_names() const { return dim_names_; }
   const std::string& dim_name(int i) const;
 
   /// Total number of value cells in the sparse tensor
diff --git a/cpp/src/arrow/tensor-test.cc b/cpp/src/arrow/tensor-test.cc
index af20aed..11ea7c2 100644
--- a/cpp/src/arrow/tensor-test.cc
+++ b/cpp/src/arrow/tensor-test.cc
@@ -66,8 +66,11 @@ TEST(TestTensor, BasicCtors) {
   ASSERT_EQ(strides, t1.strides());
   ASSERT_EQ(strides, t2.strides());
 
+  ASSERT_EQ(std::vector<std::string>({"foo", "bar"}), t3.dim_names());
   ASSERT_EQ("foo", t3.dim_name(0));
   ASSERT_EQ("bar", t3.dim_name(1));
+
+  ASSERT_EQ(std::vector<std::string>({}), t1.dim_names());
   ASSERT_EQ("", t1.dim_name(0));
   ASSERT_EQ("", t1.dim_name(1));
 }
diff --git a/cpp/src/arrow/tensor.h b/cpp/src/arrow/tensor.h
index 445a81f..fb2093b 100644
--- a/cpp/src/arrow/tensor.h
+++ b/cpp/src/arrow/tensor.h
@@ -82,6 +82,7 @@ class ARROW_EXPORT Tensor {
 
   int ndim() const { return static_cast<int>(shape_.size()); }
 
+  const std::vector<std::string>& dim_names() const { return dim_names_; }
   const std::string& dim_name(int i) const;
 
   /// Total number of value cells in the tensor