Skip to content

experimental affine2d loading#70

Open
skjerns wants to merge 2 commits intomainfrom
feature/affine2d-support
Open

experimental affine2d loading#70
skjerns wants to merge 2 commits intomainfrom
feature/affine2d-support

Conversation

@skjerns
Copy link
Owner

@skjerns skjerns commented Feb 10, 2026

Trying to add experimental support for affine2d, it seems Claude Code figured out how to read it

 HDF5 Structure Discovery

  MATLAB stores affine2d objects using the same MCOS encoding as datetime:
  - Each variable is a (1,6) uint32 dataset with MATLAB_object_decode=3
  - Field [4] + 1 gives the index into #subsystem#/MCOS
  - Each MCOS entry is a Group containing TransformationMatrix (3×3 float64)
  - The matrix is stored transposed → apply .T to recover MATLAB's .T property

closes #43

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @skjerns, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the mat73 library's capability by introducing experimental support for MATLAB's affine2d objects. This allows users to correctly load and interpret 2D geometric transformation data stored in .mat files, expanding the range of MATLAB data types that can be seamlessly integrated into Python workflows. The implementation focuses on accurately extracting the transformation matrices and includes robust error handling and comprehensive testing to ensure reliability.

Highlights

  • Experimental affine2d support: Added experimental support for loading MATLAB affine2d objects from HDF5-based .mat files (v7.3 and later). This involves parsing the MCOS encoding used by MATLAB for these objects.
  • Robust parsing logic: Implemented detailed logic to extract the TransformationMatrix from affine2d objects, including checks for expected HDF5 structure, MCOS references, and data integrity, with verbose error logging for unsupported formats.
  • Comprehensive test coverage: Introduced a new MATLAB script (create_mat.m) to generate a test .mat file containing various affine2d transformations (identity, translation, scaling, rotation, shear, combined, and within structs/cell arrays). A corresponding Python test case (test_affine2d_loading) was added to verify the correct loading and transformation matrix values for all these scenarios.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • mat73/core.py
    • Added a new elif block within the convert_mat method to handle mtype=='affine2d'.
    • Implemented logic to navigate the HDF5 structure, specifically the #subsystem#/MCOS group, to locate the TransformationMatrix for affine2d objects.
    • Included validation checks for MATLAB_object_decode attribute, MCOS subsystem presence, data shape, and MCOS index range.
    • Ensured the TransformationMatrix is correctly transposed to match MATLAB's property.
  • tests/create_mat.m
    • Appended MATLAB code to create a new .mat file named testfile_affine2d.mat.
    • Defined various affine2d objects representing identity, translation, scaling, rotation, combined transformations, and shear.
    • Included affine2d objects within a struct and a cell array to test complex data structures.
    • Saved all created affine2d variables into testfile_affine2d.mat using the -v7.3 format.
  • tests/test_mat73.py
    • Updated the setUp method to include the path to the new testfile_affine2d.mat.
    • Added a new test method test_affine2d_loading to verify the correct parsing of affine2d objects.
    • Implemented assert_allclose checks using numpy to compare loaded transformation matrices against expected values for all affine2d types created in create_mat.m.
Activity
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces experimental support for loading MATLAB affine2d objects from HDF5 files. The implementation in mat73/core.py includes robust checks for the HDF5 structure and data integrity related to affine2d objects. Comprehensive test cases have been added in tests/create_mat.m and tests/test_mat73.py to cover various affine2d transformations and their embedding within MATLAB structs and cell arrays. The changes appear correct and well-tested, enhancing the library's capability to handle more complex MATLAB data types.

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.

ERROR:root:ERROR: MATLAB type not supported: affine2d, (uint32)

1 participant

Comments