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

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


The following commit(s) were added to refs/heads/main by this push:
     new cdefbb8f4b GH-35480: [MATLAB] Add abstract MATLAB base class called 
`arrow.array.Array` (#35491)
cdefbb8f4b is described below

commit cdefbb8f4b4183b29fbcdb014af1f6fc0030475c
Author: sgilmore10 <[email protected]>
AuthorDate: Thu May 11 17:03:33 2023 -0400

    GH-35480: [MATLAB] Add abstract MATLAB base class called 
`arrow.array.Array` (#35491)
    
    
    ### Rationale for this change
    
    It will be helpful for sharing the implementation of common functionality 
if there is an abstract base class from which the MATLAB 
`arrow.array.[Type]Array` classes can inherit.
    
    ### What changes are included in this PR?
    
    1. Added abstract base class `arrow.array.Array`
    2. Changed `arrow.array.Float64Array` to inherit from `arrow.array.Array`
    3. Added `Length` property on `arrow.array.Array`
    
    ### Are these changes tested?
    
    1. Added a test point for the `Length` property in `tFloat64Array.m`.
    2. Qualified locally on macOS and linux.
    
    ### Are there any user-facing changes?
    
    Yes, there is now a `Length` property on `arrow.array.Float64Array`
    
    ### Future Directions
    
    We will continue to build out the concrete Array subclasses.
    * Closes: #35480
    
    Lead-authored-by: Sarah Gilmore <[email protected]>
    Co-authored-by: Kevin Gurney <[email protected]>
    Signed-off-by: Sutou Kouhei <[email protected]>
---
 matlab/src/cpp/arrow/matlab/array/proxy/array.cc   |  8 ++++-
 matlab/src/cpp/arrow/matlab/array/proxy/array.h    |  2 ++
 .../+arrow/+array/{Float64Array.m => Array.m}      | 42 ++++++++++------------
 matlab/src/matlab/+arrow/+array/Float64Array.m     | 20 ++---------
 matlab/test/arrow/array/tFloat64Array.m            | 17 +++++++++
 5 files changed, 46 insertions(+), 43 deletions(-)

diff --git a/matlab/src/cpp/arrow/matlab/array/proxy/array.cc 
b/matlab/src/cpp/arrow/matlab/array/proxy/array.cc
index 865dd694b7..038eeb701c 100644
--- a/matlab/src/cpp/arrow/matlab/array/proxy/array.cc
+++ b/matlab/src/cpp/arrow/matlab/array/proxy/array.cc
@@ -24,7 +24,7 @@ namespace arrow::matlab::array::proxy {
         // Register Proxy methods.
         REGISTER_METHOD(Array, ToString);
         REGISTER_METHOD(Array, ToMatlab);
-
+        REGISTER_METHOD(Array, Length);
     }
 
     void Array::ToString(libmexclass::proxy::method::Context& context) {
@@ -34,4 +34,10 @@ namespace arrow::matlab::array::proxy {
         auto str_mda = factory.createScalar(array->ToString());
         context.outputs[0] = str_mda;
     }
+
+    void Array::Length(libmexclass::proxy::method::Context& context) {
+        ::matlab::data::ArrayFactory factory;
+        auto length_mda = factory.createScalar(array->length());
+        context.outputs[0] = length_mda;
+    }
 }
diff --git a/matlab/src/cpp/arrow/matlab/array/proxy/array.h 
b/matlab/src/cpp/arrow/matlab/array/proxy/array.h
index 8a16630348..0ca75bcce4 100644
--- a/matlab/src/cpp/arrow/matlab/array/proxy/array.h
+++ b/matlab/src/cpp/arrow/matlab/array/proxy/array.h
@@ -33,6 +33,8 @@ class Array : public libmexclass::proxy::Proxy {
 
         void ToString(libmexclass::proxy::method::Context& context);
 
+        void Length(libmexclass::proxy::method::Context& context);
+
         virtual void ToMatlab(libmexclass::proxy::method::Context& context) = 
0;
 
         std::shared_ptr<arrow::Array> array;
diff --git a/matlab/src/matlab/+arrow/+array/Float64Array.m 
b/matlab/src/matlab/+arrow/+array/Array.m
similarity index 57%
copy from matlab/src/matlab/+arrow/+array/Float64Array.m
copy to matlab/src/matlab/+arrow/+array/Array.m
index c48ee45574..259dba0cea 100644
--- a/matlab/src/matlab/+arrow/+array/Float64Array.m
+++ b/matlab/src/matlab/+arrow/+array/Array.m
@@ -1,5 +1,6 @@
-classdef Float64Array < matlab.mixin.CustomDisplay
-    % arrow.array.Float64Array
+classdef (Abstract) Array < matlab.mixin.CustomDisplay & ...
+                            matlab.mixin.Scalar
+    % arrow.array.Array
 
     % Licensed to the Apache Software Foundation (ASF) under one or more
     % contributor license agreements.  See the NOTICE file distributed with
@@ -16,30 +17,28 @@ classdef Float64Array < matlab.mixin.CustomDisplay
     % implied.  See the License for the specific language governing
     % permissions and limitations under the License.
 
-    properties (Access=private)
+    
+    properties (Access=protected)
         Proxy
     end
 
-    properties (Hidden, SetAccess=private)
-        MatlabArray
+    properties (Dependent)
+        Length
     end
-
+    
     methods
-        function obj = Float64Array(data, opts)
-            arguments
-                data
-                opts.DeepCopy = false
-            end
+        function obj = Array(varargin)
+            obj.Proxy = libmexclass.proxy.Proxy(varargin{:}); 
+        end
 
-            validateattributes(data, "double", ["2d", "nonsparse", "real"]);
-            if ~isempty(data), validateattributes(data, "double", "vector"); 
end
-            % Store a reference to the array if not doing a deep copy
-            if (~opts.DeepCopy), obj.MatlabArray = data; end
-            obj.Proxy = libmexclass.proxy.Proxy("Name", 
"arrow.array.proxy.Float64Array", "ConstructorArguments", {data, 
opts.DeepCopy});
+        function numElements = get.Length(obj)
+            numElements = obj.Proxy.Length();
         end
+    end
 
-        function data = double(obj)
-            data = obj.Proxy.ToMatlab();
+    methods (Access = private)
+        function str = ToString(obj)
+            str = obj.Proxy.ToString();
         end
     end
 
@@ -48,10 +47,5 @@ classdef Float64Array < matlab.mixin.CustomDisplay
             disp(obj.ToString());
         end
     end
-
-    methods (Access=private)
-        function str = ToString(obj)
-            str = obj.Proxy.ToString();
-        end
-    end
 end
+
diff --git a/matlab/src/matlab/+arrow/+array/Float64Array.m 
b/matlab/src/matlab/+arrow/+array/Float64Array.m
index c48ee45574..ec77ef7221 100644
--- a/matlab/src/matlab/+arrow/+array/Float64Array.m
+++ b/matlab/src/matlab/+arrow/+array/Float64Array.m
@@ -1,4 +1,4 @@
-classdef Float64Array < matlab.mixin.CustomDisplay
+classdef Float64Array < arrow.array.Array
     % arrow.array.Float64Array
 
     % Licensed to the Apache Software Foundation (ASF) under one or more
@@ -16,10 +16,6 @@ classdef Float64Array < matlab.mixin.CustomDisplay
     % implied.  See the License for the specific language governing
     % permissions and limitations under the License.
 
-    properties (Access=private)
-        Proxy
-    end
-
     properties (Hidden, SetAccess=private)
         MatlabArray
     end
@@ -33,25 +29,13 @@ classdef Float64Array < matlab.mixin.CustomDisplay
 
             validateattributes(data, "double", ["2d", "nonsparse", "real"]);
             if ~isempty(data), validateattributes(data, "double", "vector"); 
end
+            [email protected]("Name", "arrow.array.proxy.Float64Array", 
"ConstructorArguments", {data, opts.DeepCopy});
             % Store a reference to the array if not doing a deep copy
             if (~opts.DeepCopy), obj.MatlabArray = data; end
-            obj.Proxy = libmexclass.proxy.Proxy("Name", 
"arrow.array.proxy.Float64Array", "ConstructorArguments", {data, 
opts.DeepCopy});
         end
 
         function data = double(obj)
             data = obj.Proxy.ToMatlab();
         end
     end
-
-    methods (Access=protected)
-        function displayScalarObject(obj)
-            disp(obj.ToString());
-        end
-    end
-
-    methods (Access=private)
-        function str = ToString(obj)
-            str = obj.Proxy.ToString();
-        end
-    end
 end
diff --git a/matlab/test/arrow/array/tFloat64Array.m 
b/matlab/test/arrow/array/tFloat64Array.m
index 7e1a878c42..f85feb78e7 100755
--- a/matlab/test/arrow/array/tFloat64Array.m
+++ b/matlab/test/arrow/array/tFloat64Array.m
@@ -100,5 +100,22 @@ classdef tFloat64Array < matlab.unittest.TestCase
             fcn = @() arrow.array.Float64Array(sparse(ones([10 1])), 
DeepCopy=MakeDeepCopy);
             testCase.verifyError(fcn, "MATLAB:expectedNonsparse");
         end
+
+        function Length(testCase, MakeDeepCopy)
+            % Zero length array
+            A = arrow.array.Float64Array([], DeepCopy=MakeDeepCopy);
+            expectedLength = int64(0);
+            testCase.verifyEqual(A.Length, expectedLength);
+
+            % Scalar
+            A = arrow.array.Float64Array(1, DeepCopy=MakeDeepCopy);
+            expectedLength = int64(1);
+            testCase.verifyEqual(A.Length, expectedLength);
+
+            % Vector
+            A = arrow.array.Float64Array(1:100, DeepCopy=MakeDeepCopy);
+            expectedLength = int64(100);
+            testCase.verifyEqual(A.Length, expectedLength);
+        end
     end
 end

Reply via email to