Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion matlab/src/cpp/arrow/matlab/array/proxy/array.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}
}
2 changes: 2 additions & 0 deletions matlab/src/cpp/arrow/matlab/array/proxy/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
51 changes: 51 additions & 0 deletions matlab/src/matlab/+arrow/+array/Array.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
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
% 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 (Access=protected)
Proxy
end

properties (Dependent)
Length
end

methods
function obj = Array(varargin)
obj.Proxy = libmexclass.proxy.Proxy(varargin{:});
end

function numElements = get.Length(obj)
numElements = obj.Proxy.Length();
end
end

methods (Access = private)
function str = ToString(obj)
str = obj.Proxy.ToString();
end
end

methods (Access=protected)
function displayScalarObject(obj)
disp(obj.ToString());
end
end
end

20 changes: 2 additions & 18 deletions matlab/src/matlab/+arrow/+array/Float64Array.m
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -16,10 +16,6 @@
% 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
Expand All @@ -33,25 +29,13 @@

validateattributes(data, "double", ["2d", "nonsparse", "real"]);
if ~isempty(data), validateattributes(data, "double", "vector"); end
obj@arrow.array.Array("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
17 changes: 17 additions & 0 deletions matlab/test/arrow/array/tFloat64Array.m
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,22 @@ function ErrorIfSparse(testCase, MakeDeepCopy)
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