Skip to content

Commit

Permalink
Create Array Type property from proxy id
Browse files Browse the repository at this point in the history
  • Loading branch information
sgilmore10 committed Jul 7, 2023
1 parent fdf34ce commit bb84776
Show file tree
Hide file tree
Showing 28 changed files with 171 additions and 73 deletions.
22 changes: 13 additions & 9 deletions matlab/src/cpp/arrow/matlab/array/proxy/boolean_array.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,30 @@
#include "arrow/matlab/bit/unpack.h"
#include "arrow/matlab/proxy/extract.h"
#include "arrow/matlab/type/proxy/primitive_ctype.h"
#include "libmexclass/proxy/ProxyManager.h"

namespace arrow::matlab::array::proxy {
libmexclass::proxy::MakeResult BooleanArray::make(const libmexclass::proxy::FunctionArguments& constructor_arguments) {
namespace mda = ::matlab::data;
using BooleanTypeProxy = type::proxy::PrimitiveCType<bool>;

mda::StructArray opts = constructor_arguments[0];

// Get the mxArray from constructor arguments
const mda::TypedArray<bool> logical_mda = opts[0]["MatlabArray"];
const mda::TypedArray<bool> validity_bitmap_mda = opts[0]["Valid"];
const mda::TypedArray<uint64_t> type_proxy_id_mda = opts[0]["TypeProxyID"];

// Pack the logical data values.
MATLAB_ASSIGN_OR_ERROR(auto data_buffer, bit::pack(logical_mda), error::BITPACK_VALIDITY_BITMAP_ERROR_ID);

// Pack the validity bitmap values.
MATLAB_ASSIGN_OR_ERROR(const auto validity_bitmap_buffer, bit::packValid(validity_bitmap_mda), error::BITPACK_VALIDITY_BITMAP_ERROR_ID);

MATLAB_ASSIGN_OR_ERROR(auto data_type_proxy,
arrow::matlab::proxy::extractTypedProxy<BooleanTypeProxy>(type_proxy_id_mda[0]),
"arrow:matlab:UnknownProxyID");

// const auto data_type = arrow::boolean();
const auto array_length = logical_mda.getNumberOfElements();

auto array_data = arrow::ArrayData::Make(data_type_proxy->getType(), array_length, {validity_bitmap_buffer, data_buffer});
auto datatype = arrow::boolean();

auto array_data = arrow::ArrayData::Make(datatype, array_length, {validity_bitmap_buffer, data_buffer});
return std::make_shared<arrow::matlab::array::proxy::BooleanArray>(arrow::MakeArray(array_data));
}

Expand All @@ -60,8 +57,15 @@ namespace arrow::matlab::array::proxy {
}

void BooleanArray::createDataTypeProxy(libmexclass::proxy::method::Context& context) {
namespace mda = ::matlab::data;
using BooleanTypeProxy = type::proxy::PrimitiveCType<bool>;

}

mda::ArrayFactory factory;

const auto type = array->type();
const auto boolean_type = std::static_pointer_cast<arrow::BooleanType>(type);
auto boolean_type_proxy = std::make_shared<BooleanTypeProxy>(boolean_type);
const auto id = libmexclass::proxy::ProxyManager::manageProxy(boolean_type_proxy);
context.outputs[0] = factory.createScalar(id);
}
}
2 changes: 1 addition & 1 deletion matlab/src/cpp/arrow/matlab/array/proxy/numeric_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include "arrow/matlab/bit/unpack.h"
#include "arrow/matlab/type/proxy/primitive_ctype.h"

#include "arrow/matlab/proxy/extract.h"
#include "libmexclass/proxy/ProxyManager.h"

#include "libmexclass/proxy/Proxy.h"

Expand Down
13 changes: 13 additions & 0 deletions matlab/src/cpp/arrow/matlab/array/proxy/timestamp_array.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@
#include "arrow/matlab/bit/unpack.h"

#include "arrow/matlab/type/time_unit.h"
#include "arrow/matlab/type/proxy/timestamp_type.h"

#include "arrow/util/utf8.h"
#include "arrow/type.h"
#include "arrow/builder.h"

#include "libmexclass/proxy/ProxyManager.h"

namespace arrow::matlab::array::proxy {

Expand Down Expand Up @@ -93,5 +96,15 @@ namespace arrow::matlab::array::proxy {
}

void TimestampArray::createDataTypeProxy(libmexclass::proxy::method::Context& context) {
namespace mda = ::matlab::data;
using TimestampTypeProxy = type::proxy::TimestampType;

mda::ArrayFactory factory;

const auto type = array->type();
const auto timestamp_type = std::static_pointer_cast<arrow::TimestampType>(type);
auto timestamp_type_proxy = std::make_shared<TimestampTypeProxy>(timestamp_type);
const auto id = libmexclass::proxy::ProxyManager::manageProxy(timestamp_type_proxy);
context.outputs[0] = factory.createScalar(id);
}
}
6 changes: 3 additions & 3 deletions matlab/src/matlab/+arrow/+array/BooleanArray.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
end
arrow.args.validateTypeAndShape(data, "logical");
validElements = arrow.args.parseValidElements(data, opts);
type = arrow.type.BooleanType;
opts = struct(MatlabArray=data, Valid=validElements, TypeProxyID=type.Proxy.ID);
opts = struct(MatlabArray=data, Valid=validElements);
[email protected]("Name", "arrow.array.proxy.BooleanArray", "ConstructorArguments", {opts});
obj.Type = type;
typeProxyID = obj.Proxy.createDataTypeProxy();
obj.Type = arrow.type.BooleanType(typeProxyID);
end

function data = logical(obj)
Expand Down
6 changes: 3 additions & 3 deletions matlab/src/matlab/+arrow/+array/Float32Array.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@

methods
function obj = Float32Array(data, varargin)
type = arrow.type.Float32Type;
[email protected](data, "single", ...
"arrow.array.proxy.Float32Array", type.Proxy.ID, varargin{:});
obj.Type = type;
"arrow.array.proxy.Float32Array", varargin{:});
typeProxyID = obj.Proxy.createDataTypeProxy();
obj.Type = arrow.type.Float32Type(typeProxyID);
end

function data = single(obj)
Expand Down
4 changes: 2 additions & 2 deletions matlab/src/matlab/+arrow/+array/Float64Array.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
function obj = Float64Array(data, varargin)
[email protected](data, "double", ...
"arrow.array.proxy.Float64Array", varargin{:});
type_proxy_id = obj.Proxy.createDataTypeProxy();
obj.Type = arrow.type.Float64Type(type_proxy_id);
typeProxyID = obj.Proxy.createDataTypeProxy();
obj.Type = arrow.type.Float64Type(typeProxyID);
end

function data = double(obj)
Expand Down
6 changes: 3 additions & 3 deletions matlab/src/matlab/+arrow/+array/Int16Array.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@

methods
function obj = Int16Array(data, varargin)
type = arrow.type.Int16Type;
[email protected](data, "int16", ...
"arrow.array.proxy.Int16Array", type.Proxy.ID, varargin{:});
obj.Type = type;
"arrow.array.proxy.Int16Array", varargin{:});
typeProxyID = obj.Proxy.createDataTypeProxy();
obj.Type = arrow.type.Int16Type(typeProxyID);
end

function data = int16(obj)
Expand Down
6 changes: 3 additions & 3 deletions matlab/src/matlab/+arrow/+array/Int32Array.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@

methods
function obj = Int32Array(data, varargin)
type = arrow.type.Int32Type;
[email protected](data, "int32", ...
"arrow.array.proxy.Int32Array", type.Proxy.ID, varargin{:});
obj.Type = type;
"arrow.array.proxy.Int32Array", varargin{:});
typeProxyID = obj.Proxy.createDataTypeProxy();
obj.Type = arrow.type.Int32Type(typeProxyID);
end

function data = int32(obj)
Expand Down
6 changes: 3 additions & 3 deletions matlab/src/matlab/+arrow/+array/Int64Array.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@

methods
function obj = Int64Array(data, varargin)
type = arrow.type.Int64Type;
[email protected](data, "int64", ...
"arrow.array.proxy.Int64Array", type.Proxy.ID, varargin{:});
obj.Type = type;
"arrow.array.proxy.Int64Array", varargin{:});
typeProxyID = obj.Proxy.createDataTypeProxy();
obj.Type = arrow.type.Int64Type(typeProxyID);
end

function data = int64(obj)
Expand Down
6 changes: 3 additions & 3 deletions matlab/src/matlab/+arrow/+array/Int8Array.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@

methods
function obj = Int8Array(data, varargin)
type = arrow.type.Int8Type;
[email protected](data, "int8", type.Proxy.ID, ...
[email protected](data, "int8", ...
"arrow.array.proxy.Int8Array", varargin{:});
obj.Type = type;
typeProxyID = obj.Proxy.createDataTypeProxy();
obj.Type = arrow.type.Int8Type(typeProxyID);
end

function data = int8(obj)
Expand Down
4 changes: 3 additions & 1 deletion matlab/src/matlab/+arrow/+array/TimestampArray.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@

args = struct(MatlabArray=ptime, Valid=validElements, TimeZone=timezone, TimeUnit=string(opts.TimeUnit));
[email protected]("Name", "arrow.array.proxy.TimestampArray", "ConstructorArguments", {args});
obj.Type = arrow.type.TimestampType(TimeUnit=opts.TimeUnit, TimeZone=timezone);

typeProxyID = obj.Proxy.createDataTypeProxy();
obj.Type = arrow.type.TimestampType(typeProxyID);
end

function dates = toMATLAB(obj)
Expand Down
6 changes: 3 additions & 3 deletions matlab/src/matlab/+arrow/+array/UInt16Array.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@

methods
function obj = UInt16Array(data, varargin)
type = arrow.type.UInt16Type;
[email protected](data, "uint16", ...
"arrow.array.proxy.UInt16Array", type.Proxy.ID, varargin{:});
obj.Type = type;
"arrow.array.proxy.UInt16Array", varargin{:});
typeProxyID = obj.Proxy.createDataTypeProxy();
obj.Type = arrow.type.UInt16Type(typeProxyID);
end

function data = uint16(obj)
Expand Down
6 changes: 3 additions & 3 deletions matlab/src/matlab/+arrow/+array/UInt32Array.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@

methods
function obj = UInt32Array(data, varargin)
type = arrow.type.UInt32Type;
[email protected](data, "uint32", ...
"arrow.array.proxy.UInt32Array", type.Proxy.ID, varargin{:});
obj.Type = type;
"arrow.array.proxy.UInt32Array", varargin{:});
typeProxyID = obj.Proxy.createDataTypeProxy();
obj.Type = arrow.type.UInt32Type(typeProxyID);
end

function data = uint32(obj)
Expand Down
6 changes: 3 additions & 3 deletions matlab/src/matlab/+arrow/+array/UInt64Array.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@

methods
function obj = UInt64Array(data, varargin)
type = arrow.type.UInt64Type;
[email protected](data, "uint64", ...
"arrow.array.proxy.UInt64Array", type.Proxy.ID, varargin{:});
obj.Type = type;
"arrow.array.proxy.UInt64Array", varargin{:});
typeProxyID = obj.Proxy.createDataTypeProxy();
obj.Type = arrow.type.UInt64Type(typeProxyID);
end

function data = uint64(obj)
Expand Down
6 changes: 3 additions & 3 deletions matlab/src/matlab/+arrow/+array/UInt8Array.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@

methods
function obj = UInt8Array(data, varargin)
type = arrow.type.UInt8Type;
[email protected](data, "uint8", ...
"arrow.array.proxy.UInt8Array", type.Proxy.ID, varargin{:});
obj.Type = type;
"arrow.array.proxy.UInt8Array", varargin{:});
typeProxyID = obj.Proxy.createDataTypeProxy();
obj.Type = arrow.type.UInt8Type(typeProxyID);
end

function data = uint8(obj)
Expand Down
9 changes: 7 additions & 2 deletions matlab/src/matlab/+arrow/+type/BooleanType.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@
%BOOLEANTYPE Type class for boolean data.

methods
function obj = BooleanType()
[email protected]("Name", "arrow.type.proxy.BooleanType", "ConstructorArguments", {})
function obj = BooleanType(proxyID)
arguments
proxyID = missing
end
proxyName = "arrow.type.proxy.BooleanType";
args = arrow.type.parseProxyArguments(proxyName, proxyID);
[email protected](args{:});
end
end
end
9 changes: 7 additions & 2 deletions matlab/src/matlab/+arrow/+type/Float32Type.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@
%FLOAT32TYPE Type class for float32 data.

methods
function obj = Float32Type()
[email protected]("Name", "arrow.type.proxy.Float32Type", "ConstructorArguments", {})
function obj = Float32Type(proxyID)
arguments
proxyID = missing
end
proxyName = "arrow.type.proxy.Float32Type";
args = arrow.type.parseProxyArguments(proxyName, proxyID);
[email protected](args{:});
end
end
end
11 changes: 4 additions & 7 deletions matlab/src/matlab/+arrow/+type/Float64Type.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,12 @@
%FLOAT64Type Type class for float64 data.

methods
function obj = Float64Type(ID)
function obj = Float64Type(proxyID)
arguments
ID = missing
end
if ismissing(ID)
args = {"Name", "arrow.type.proxy.Float64Type", "ConstructorArguments", {}};
else
args = {"Name", "arrow.type.proxy.Float64Type", "ID", ID};
proxyID = missing
end
proxyName = "arrow.type.proxy.Float64Type";
args = arrow.type.parseProxyArguments(proxyName, proxyID);
[email protected](args{:});
end
end
Expand Down
9 changes: 7 additions & 2 deletions matlab/src/matlab/+arrow/+type/Int16Type.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@
%INT16TYPE Type class for int8 data.

methods
function obj = Int16Type()
[email protected]("Name", "arrow.type.proxy.Int16Type", "ConstructorArguments", {})
function obj = Int16Type(proxyID)
arguments
proxyID = missing
end
proxyName = "arrow.type.proxy.Int16Type";
args = arrow.type.parseProxyArguments(proxyName, proxyID);
[email protected](args{:});
end
end
end
Expand Down
9 changes: 7 additions & 2 deletions matlab/src/matlab/+arrow/+type/Int32Type.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@
%INT32TYPE Type class for int32 data.

methods
function obj = Int32Type()
[email protected]("Name", "arrow.type.proxy.Int32Type", "ConstructorArguments", {})
function obj = Int32Type(proxyID)
arguments
proxyID = missing
end
proxyName = "arrow.type.proxy.Int32Type";
args = arrow.type.parseProxyArguments(proxyName, proxyID);
[email protected](args{:});
end
end
end
Expand Down
9 changes: 7 additions & 2 deletions matlab/src/matlab/+arrow/+type/Int64Type.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@
%INT64TYPE Type class for int64 data.

methods
function obj = Int64Type()
[email protected]("Name", "arrow.type.proxy.Int64Type", "ConstructorArguments", {})
function obj = Int64Type(proxyID)
arguments
proxyID = missing
end
proxyName = "arrow.type.proxy.Int64Type";
args = arrow.type.parseProxyArguments(proxyName, proxyID);
[email protected](args{:});
end
end
end
9 changes: 7 additions & 2 deletions matlab/src/matlab/+arrow/+type/Int8Type.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@
%INT8TYPE Type class for int8 data.

methods
function obj = Int8Type()
[email protected]("Name", "arrow.type.proxy.Int8Type", "ConstructorArguments", {})
function obj = Int8Type(proxyID)
arguments
proxyID = missing
end
proxyName = "arrow.type.proxy.Int8Type";
args = arrow.type.parseProxyArguments(proxyName, proxyID);
[email protected](args{:});
end
end
end
Expand Down
9 changes: 6 additions & 3 deletions matlab/src/matlab/+arrow/+type/TimestampType.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,17 @@
end

methods
function obj = TimestampType(opts)
function obj = TimestampType(proxyID, opts)
%TIMESTAMPTYPE Construct an instance of this class
arguments
proxyID = missing
opts.TimeUnit(1, 1) arrow.type.TimeUnit = arrow.type.TimeUnit.Microsecond
opts.TimeZone(1, 1) string {mustBeNonmissing} = ""
end
args = struct(TimeUnit=string(opts.TimeUnit), TimeZone=opts.TimeZone);
[email protected]("Name", "arrow.type.proxy.TimestampType", "ConstructorArguments", {args});
constructorrArgs = struct(TimeUnit=string(opts.TimeUnit), TimeZone=opts.TimeZone);
proxyName = "arrow.type.proxy.TimestampType";
args = arrow.type.parseProxyArguments(proxyName, proxyID, {constructorrArgs});
[email protected](args{:});
end

function unit = get.TimeUnit(obj)
Expand Down
Loading

0 comments on commit bb84776

Please sign in to comment.