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 fbe5f641d3 GH-35558: [MATLAB] Add signed integer array MATLAB classes 
(i.e. `Int8Array`, `Int16Array`, `Int32Array`, `Int64Array`) (#35561)
fbe5f641d3 is described below

commit fbe5f641d327ee81db00ce5f056940a69f4d8603
Author: Kevin Gurney <[email protected]>
AuthorDate: Mon May 22 17:21:53 2023 -0400

    GH-35558: [MATLAB] Add signed integer array MATLAB classes (i.e. 
`Int8Array`, `Int16Array`, `Int32Array`, `Int64Array`) (#35561)
    
    ### Rationale for this change
    
    Followup to https://github.com/apache/arrow/pull/35495 in which we added 
the MATLAB class `Float32Array`.
    
    This pull request adds support for round tripping signed integer between 
`arrow.array.<Array>` classes and associated MATLAB types (e.g. `int8`, 
`int16`, `int32`, `int64`).
    
    | Arrow Array Type | MATLAB Type |
    | ------------------------- | -------------------- |
    | `Int8Array`             | `int8`                |
    | `Int16Array`             | `int16`                |
    | `Int32Array`             | `int32`                |
    | `Int64Array`             | `int64`                |
    
    Example of round-tripping `int8` data:
    
    ```matlab
    >> int8MatlabArray = int8([1, 2, 3]')
    
    int8MatlabArray =
    
      3x1 int8 column vector
    
       1
       2
       3
    
    >> int8ArrowArray = arrow.array.Int8Array(int8MatlabArray)
    
    int8ArrowArray =
    
    [
      1,
      2,
      3
    ]
    
    >> int8MatlabArrayRoundTripped = toMATLAB(int8ArrowArray)
    
    int8MatlabArrayRoundTripped =
    
      3x1 int8 column vector
    
       1
       2
       3
    
    >> all(int8MatlabArray == int8MatlabArrayRoundTripped)
    
    ans =
    
      logical
    
       1
    
    ```
    
    ### What changes are included in this PR?
    
    Added four new signed integer type `arrow.array.<Array>` concrete 
subclasses.
    
    1.  `arrow.array.Int8Array`
    3. `arrow.array.Int16Array`
    4. `arrow.array.Int32Array`
    5. `arrow.array.Int64Array`
    
    ### Are these changes tested?
    
    Yes, we added the following four test classes:
    
    1.  `tInt8Array.m`
    2. `tInt16Array.m`
    3. `tInt32Array.m`
    4. `tInt64Array.m`
    
    ### Are there any user-facing changes?
    
    Yes. This change introduces 4 new publicly documented classes:
    
    1.  `arrow.array.Int8Array`
    3. `arrow.array.Int16Array`
    4. `arrow.array.Int32Array`
    5. `arrow.array.Int64Array`
    
    ### Future Directions
    
    1. Add support for null values (i.e. validity bitmap) for the signed 
integer array types.
    
    ### Notes
    
    !. Thank you to @ sgilmore10 for her help with this pull request!
    * Closes: #35558
    
    Lead-authored-by: Kevin Gurney <[email protected]>
    Co-authored-by: Sarah Gilmore <[email protected]>
    Signed-off-by: Sutou Kouhei <[email protected]>
---
 matlab/src/cpp/arrow/matlab/proxy/factory.cc | 18 ++++++++-----
 matlab/src/matlab/+arrow/+array/Int16Array.m | 40 ++++++++++++++++++++++++++++
 matlab/src/matlab/+arrow/+array/Int32Array.m | 40 ++++++++++++++++++++++++++++
 matlab/src/matlab/+arrow/+array/Int64Array.m | 40 ++++++++++++++++++++++++++++
 matlab/src/matlab/+arrow/+array/Int8Array.m  | 40 ++++++++++++++++++++++++++++
 matlab/test/arrow/array/tInt16Array.m        | 28 +++++++++++++++++++
 matlab/test/arrow/array/tInt32Array.m        | 28 +++++++++++++++++++
 matlab/test/arrow/array/tInt64Array.m        | 28 +++++++++++++++++++
 matlab/test/arrow/array/tInt8Array.m         | 28 +++++++++++++++++++
 9 files changed, 283 insertions(+), 7 deletions(-)

diff --git a/matlab/src/cpp/arrow/matlab/proxy/factory.cc 
b/matlab/src/cpp/arrow/matlab/proxy/factory.cc
index 5b3b85d33c..b7f86b9fcf 100644
--- a/matlab/src/cpp/arrow/matlab/proxy/factory.cc
+++ b/matlab/src/cpp/arrow/matlab/proxy/factory.cc
@@ -24,16 +24,20 @@
 namespace arrow::matlab::proxy {
 
 std::shared_ptr<Proxy> Factory::make_proxy(const ClassName& class_name, const 
FunctionArguments& constructor_arguments) {
-
-    // Register MATLAB Proxy classes for unsigned integer arrays
-    REGISTER_PROXY(arrow.array.proxy.UInt8Array, 
arrow::matlab::array::proxy::NumericArray<uint8_t>);
-    REGISTER_PROXY(arrow.array.proxy.UInt16Array, 
arrow::matlab::array::proxy::NumericArray<uint16_t>);
-    REGISTER_PROXY(arrow.array.proxy.UInt32Array, 
arrow::matlab::array::proxy::NumericArray<uint32_t>);
-    REGISTER_PROXY(arrow.array.proxy.UInt64Array, 
arrow::matlab::array::proxy::NumericArray<uint64_t>);
-
     // Register MATLAB Proxy classes with corresponding C++ Proxy classes.
     REGISTER_PROXY(arrow.array.proxy.Float32Array, 
arrow::matlab::array::proxy::NumericArray<float>);
     REGISTER_PROXY(arrow.array.proxy.Float64Array, 
arrow::matlab::array::proxy::NumericArray<double>);
+    // Register MATLAB Proxy classes for unsigned integer arrays
+    REGISTER_PROXY(arrow.array.proxy.UInt8Array  , 
arrow::matlab::array::proxy::NumericArray<uint8_t>);
+    REGISTER_PROXY(arrow.array.proxy.UInt16Array , 
arrow::matlab::array::proxy::NumericArray<uint16_t>);
+    REGISTER_PROXY(arrow.array.proxy.UInt32Array , 
arrow::matlab::array::proxy::NumericArray<uint32_t>);
+    REGISTER_PROXY(arrow.array.proxy.UInt64Array , 
arrow::matlab::array::proxy::NumericArray<uint64_t>);
+    // Register MATLAB Proxy classes for signed integer arrays
+    REGISTER_PROXY(arrow.array.proxy.Int8Array   , 
arrow::matlab::array::proxy::NumericArray<int8_t>);
+    REGISTER_PROXY(arrow.array.proxy.Int16Array  , 
arrow::matlab::array::proxy::NumericArray<int16_t>);
+    REGISTER_PROXY(arrow.array.proxy.Int32Array  , 
arrow::matlab::array::proxy::NumericArray<int32_t>);
+    REGISTER_PROXY(arrow.array.proxy.Int64Array  , 
arrow::matlab::array::proxy::NumericArray<int64_t>);
+
     // TODO: Decide what to do in the case that there isn't a Proxy match.
     std::cout << "Did not find a matching C++ proxy for: " + class_name << 
std::endl;
     return nullptr;
diff --git a/matlab/src/matlab/+arrow/+array/Int16Array.m 
b/matlab/src/matlab/+arrow/+array/Int16Array.m
new file mode 100644
index 0000000000..f2b7604129
--- /dev/null
+++ b/matlab/src/matlab/+arrow/+array/Int16Array.m
@@ -0,0 +1,40 @@
+classdef Int16Array < arrow.array.Array
+    % arrow.array.Int16Array
+
+    % 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.
+
+    properties (Hidden, SetAccess=private)
+        MatlabArray = int16([])
+    end
+
+    methods
+        function obj = Int16Array(data, opts)
+            arguments
+                data
+                opts.DeepCopy = false
+            end
+            validateattributes(data, "int16", ["2d", "nonsparse", "real"]);
+            if ~isempty(data), validateattributes(data, "int16", "vector"); end
+            [email protected]("Name", "arrow.array.proxy.Int16Array", 
"ConstructorArguments", {data, opts.DeepCopy});
+            % Store a reference to the array if not doing a deep copy
+            if (~opts.DeepCopy), obj.MatlabArray = data; end
+        end
+
+        function data = int16(obj)
+            data = obj.Proxy.toMATLAB();
+        end
+    end
+end
diff --git a/matlab/src/matlab/+arrow/+array/Int32Array.m 
b/matlab/src/matlab/+arrow/+array/Int32Array.m
new file mode 100644
index 0000000000..d493ee8ceb
--- /dev/null
+++ b/matlab/src/matlab/+arrow/+array/Int32Array.m
@@ -0,0 +1,40 @@
+classdef Int32Array < arrow.array.Array
+    % arrow.array.Int32Array
+
+    % 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.
+
+    properties (Hidden, SetAccess=private)
+        MatlabArray = int32([])
+    end
+
+    methods
+        function obj = Int32Array(data, opts)
+            arguments
+                data
+                opts.DeepCopy = false
+            end
+            validateattributes(data, "int32", ["2d", "nonsparse", "real"]);
+            if ~isempty(data), validateattributes(data, "int32", "vector"); end
+            [email protected]("Name", "arrow.array.proxy.Int32Array", 
"ConstructorArguments", {data, opts.DeepCopy});
+            % Store a reference to the array if not doing a deep copy
+            if (~opts.DeepCopy), obj.MatlabArray = data; end
+        end
+
+        function data = int32(obj)
+            data = obj.Proxy.toMATLAB();
+        end
+    end
+end
diff --git a/matlab/src/matlab/+arrow/+array/Int64Array.m 
b/matlab/src/matlab/+arrow/+array/Int64Array.m
new file mode 100644
index 0000000000..85e9f2e62f
--- /dev/null
+++ b/matlab/src/matlab/+arrow/+array/Int64Array.m
@@ -0,0 +1,40 @@
+classdef Int64Array < arrow.array.Array
+    % arrow.array.Int64Array
+
+    % 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.
+
+    properties (Hidden, SetAccess=private)
+        MatlabArray = int64([])
+    end
+
+    methods
+        function obj = Int64Array(data, opts)
+            arguments
+                data
+                opts.DeepCopy = false
+            end
+            validateattributes(data, "int64", ["2d", "nonsparse", "real"]);
+            if ~isempty(data), validateattributes(data, "int64", "vector"); end
+            [email protected]("Name", "arrow.array.proxy.Int64Array", 
"ConstructorArguments", {data, opts.DeepCopy});
+            % Store a reference to the array if not doing a deep copy
+            if (~opts.DeepCopy), obj.MatlabArray = data; end
+        end
+
+        function data = int64(obj)
+            data = obj.Proxy.toMATLAB();
+        end
+    end
+end
diff --git a/matlab/src/matlab/+arrow/+array/Int8Array.m 
b/matlab/src/matlab/+arrow/+array/Int8Array.m
new file mode 100644
index 0000000000..3452dd2d0f
--- /dev/null
+++ b/matlab/src/matlab/+arrow/+array/Int8Array.m
@@ -0,0 +1,40 @@
+classdef Int8Array < arrow.array.Array
+    % arrow.array.Int8Array
+
+    % 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.
+
+    properties (Hidden, SetAccess=private)
+        MatlabArray = int8([])
+    end
+
+    methods
+        function obj = Int8Array(data, opts)
+            arguments
+                data
+                opts.DeepCopy = false
+            end
+            validateattributes(data, "int8", ["2d", "nonsparse", "real"]);
+            if ~isempty(data), validateattributes(data, "int8", "vector"); end
+            [email protected]("Name", "arrow.array.proxy.Int8Array", 
"ConstructorArguments", {data, opts.DeepCopy});
+            % Store a reference to the array if not doing a deep copy
+            if (~opts.DeepCopy), obj.MatlabArray = data; end
+        end
+
+        function data = int8(obj)
+            data = obj.Proxy.toMATLAB();
+        end
+    end
+end
diff --git a/matlab/test/arrow/array/tInt16Array.m 
b/matlab/test/arrow/array/tInt16Array.m
new file mode 100644
index 0000000000..7ae3a5ead7
--- /dev/null
+++ b/matlab/test/arrow/array/tInt16Array.m
@@ -0,0 +1,28 @@
+classdef tInt16Array < hNumericArray
+    % Tests for arrow.array.Int16Array
+
+    % 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.
+    
+    properties
+        ArrowArrayClassName = "arrow.array.Int16Array"
+        ArrowArrayConstructor = @arrow.array.Int16Array
+        MatlabConversionFcn = @int16 % int16 method on class
+        MatlabArrayFcn = @int16 % int16 function
+        MaxValue = intmax("int16")
+        MinValue = intmin("int16")
+    end
+
+end
diff --git a/matlab/test/arrow/array/tInt32Array.m 
b/matlab/test/arrow/array/tInt32Array.m
new file mode 100644
index 0000000000..7b63c5c57c
--- /dev/null
+++ b/matlab/test/arrow/array/tInt32Array.m
@@ -0,0 +1,28 @@
+classdef tInt32Array < hNumericArray
+    % Tests for arrow.array.Int32Array
+
+    % 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.
+    
+    properties
+        ArrowArrayClassName = "arrow.array.Int32Array"
+        ArrowArrayConstructor = @arrow.array.Int32Array
+        MatlabConversionFcn = @int32 % int32 method on class
+        MatlabArrayFcn = @int32 % int32 function
+        MaxValue = intmax("int32")
+        MinValue = intmin("int32")
+    end
+
+end
diff --git a/matlab/test/arrow/array/tInt64Array.m 
b/matlab/test/arrow/array/tInt64Array.m
new file mode 100644
index 0000000000..41270ef240
--- /dev/null
+++ b/matlab/test/arrow/array/tInt64Array.m
@@ -0,0 +1,28 @@
+classdef tInt64Array < hNumericArray
+    % Tests for arrow.array.Int64Array
+
+    % 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.
+    
+    properties
+        ArrowArrayClassName = "arrow.array.Int64Array"
+        ArrowArrayConstructor = @arrow.array.Int64Array
+        MatlabConversionFcn = @int64 % int64 method on class
+        MatlabArrayFcn = @int64 % int64 function
+        MaxValue = intmax("int64")
+        MinValue = intmin("int64")
+    end
+
+end
diff --git a/matlab/test/arrow/array/tInt8Array.m 
b/matlab/test/arrow/array/tInt8Array.m
new file mode 100644
index 0000000000..76f96f01e4
--- /dev/null
+++ b/matlab/test/arrow/array/tInt8Array.m
@@ -0,0 +1,28 @@
+classdef tInt8Array < hNumericArray
+    % Tests for arrow.array.Int8Array
+
+    % 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.
+    
+    properties
+        ArrowArrayClassName = "arrow.array.Int8Array"
+        ArrowArrayConstructor = @arrow.array.Int8Array
+        MatlabConversionFcn = @int8 % int8 method on class
+        MatlabArrayFcn = @int8 % int8 function
+        MaxValue = intmax("int8")
+        MinValue = intmin("int8")
+    end
+
+end

Reply via email to