Skip to content

Refactor datatype mapping #94

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 29, 2025
Merged

Refactor datatype mapping #94

merged 4 commits into from
May 29, 2025

Conversation

krisfed
Copy link
Member

@krisfed krisfed commented May 27, 2025

Move the logic of mapping between datatypes into a separate class, ZarrDatatype (instead of using dictionaries in Zarr class)

Fixes #14

@krisfed krisfed marked this pull request as ready for review May 27, 2025 14:06
@krisfed krisfed requested review from jm9176 and jhughes-mw May 27, 2025 14:06

function obj = fromTensorstoreType(tensorstoreType)
% Create a datatype object based on Tensorstore datatype name
arguments
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need the arguments block and validatestrings. You could either remove the args block (which BTW means you will accept any inputs that are convertable to string, like double and datetime) or use the mustBeMember validator function. Nothing specifically wrong with this pattern, but it's a mix of two paradigms and feels weird. I'd prefer the more modern approach.

Copy link
Member Author

@krisfed krisfed May 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was my initial impulse as well! Unfortunately there seems to be a limitation:

MATLABType (1,1) string {mustBeMember(MATLABType, ZarrDatatype.MATLABTypes)} results in:

Line 59: For input arguments, validation functions must only use previously declared positional arguments, the argument being validated, or literals.

And it felt worse to me to have to re-list valid types again as a literal

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooof.

You can call mustBeMember directly. You could write a local function in the class that calls it with the right arguments.

function mustBeMATLABType(type)
mustBeMember(type, ZarrDatatype.MATLABTypes);
end

And then use
MATLABType (1,1) string {mustBeTextScalar, mustBeMATLABType}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point!

Copy link
Member

@jm9176 jm9176 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make sure that the changes have been qualified locally before merging the same.

classdef ZarrDatatype
%ZARRDATATYPE Datatype of Zarr data
% Represents the datatype mapping between MATLAB, Tensorstore, and Zarr

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing copyright

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added!

@krisfed
Copy link
Member Author

krisfed commented May 28, 2025

Please make sure that the changes have been qualified locally before merging the same.

Yup, ran the tests when creating the PR and now with the new changes too!

@krisfed krisfed merged commit 5f5f954 into main May 29, 2025
@krisfed krisfed deleted the test-branch-datatypeMapping branch May 30, 2025 16:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace dictionaries with string matching
3 participants