Skip to content
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

Matrix Implementations and tests. Update pom.xml for Java 17; add Breeze module and new matrix classes #61

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

CarlGullberg
Copy link

@CarlGullberg CarlGullberg commented Feb 13, 2025

Summary by CodeRabbit

  • New Features

    • Introduced comprehensive matrix computation tools that enhance 3D/4D transformations by enabling advanced arithmetic, inversion, transposition, and decomposition operations.
    • Added transformation capabilities for scaling, rotation, and translation, improving precision for mathematical and graphics tasks.
  • Chores

    • Upgraded the build configuration to Java 17 with integrated support for advanced vector modules, ensuring better performance and compatibility.
    • Added new dependencies to support enhanced testing and matrix operations.

Worked with AntonGrubisic
Copy link

coderabbitai bot commented Feb 13, 2025

Walkthrough

This update revises the build configuration in the pom.xml by updating dependencies and adding plugins for Java 17 with support for the jdk.incubator.vector module. A new module named breeze is declared in the module descriptor. Additionally, four new classes—Matrix3x3, Matrix4x4, MatrixOps, and their corresponding test classes—have been introduced to provide various matrix operations, transformations, and decomposition methods, along with unit tests to validate their implementations.

Changes

File(s) Summary
pom.xml Updated dependency name for JUnit from junit-jupiter to junit-jupiter-api, added assertj-core dependency, and configured Maven Compiler and Surefire plugins for Java 17 with the incubator vector module.
src/main/java/.../module-info.java Declares a new module breeze and requires the jdk.incubator.vector module.
src/main/java/.../Matrix3x3.java New class for 3x3 matrix operations including identity, multiplication, transposition, determinant, inversion (with internal validation and debug prints), and vector transformation.
src/main/java/.../Matrix4x4.java New class for 4x4 matrix operations providing methods for identity, multiplication, determinant, cofactor calculation, transposition, inversion, and a formatted matrix printing function.
src/main/java/.../MatrixOps.java New utility class implementing transformation matrices (scaling, rotation, translation) and decomposition methods (LU and QR) for both 3x3 and 4x4 matrices.
src/test/java/.../Matrix3x3Test.java
src/test/java/.../Matrix4x4Test.java
src/test/java/.../MatrixOpsTest.java
Added test classes covering constructor validation, matrix operations (multiplication, transposition, inversion, etc.), and decomposition methods for the new matrix classes.

Sequence Diagram(s)

sequenceDiagram
    participant T as Test Suite
    participant M3 as Matrix3x3
    participant M4 as Matrix4x4
    participant Ops as MatrixOps

    T->>M3: Create 3x3 matrix instance
    M3->>M3: Validate dimensions & perform operations
    T->>M3: Call inverse()
    Note right of M3: Compute determinant and cofactors
    M3->>T: Return inverse matrix or throw exception

    T->>M4: Create 4x4 matrix instance
    M4->>M4: Validate and perform multiplication, transpose, and inversion
    M4->>T: Return results

    T->>Ops: Request transformation or decomposition (scaling, rotation, LU/QR)
    Ops->>M3/M4: Utilize underlying matrix operations
    Ops->>T: Return transformed or decomposed matrices
Loading

Poem

Oh, I hop with glee in code so neat,
Matrices align as bunnies meet,
From 3x3 hops to 4x4 leaps,
Transformations bloom while the vector sings,
A decomposition dance under bright code skies—
With each new function, my whiskers rise!
Happy code, happy hop!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7667bed and e3ce6c8.

📒 Files selected for processing (1)
  • src/test/java/org/fungover/breeze/Matrix/Matrix4x4Test.java (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/test/java/org/fungover/breeze/Matrix/Matrix4x4Test.java

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai bot changed the title Matrix Implementations and tests. @coderabbitai Matrix Implementations and tests. Update pom.xml for Java 17; add Breeze module and new matrix classes Feb 13, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

🧹 Nitpick comments (12)
src/main/java/org/fungover/breeze/Matrix/Matrix4x4.java (4)

47-59: Matrix multiplication logic appears correct.
Consider whether single-precision float is appropriate for your application or if double-precision is needed for numerical stability.


61-67: Determinant calculation uses cofactor expansion properly.
Math.pow(-1, col) works, but a direct sign check (e.g. (col % 2 == 0) ? 1 : -1) might be slightly faster.


107-137: Consider reducing or redirecting debug output.
Printing the adjugate and inverse in a production environment could be excessive. Also consider using a configurable tolerance for near-singular matrices.


139-149: Matrix printing is straightforward.
For production, consider using logging or returning a formatted string instead of printing directly.

src/main/java/org/fungover/breeze/Matrix/Matrix3x3.java (2)

48-60: Matrix multiplication for 3x3 is correct.
If high numerical accuracy is required, consider double precision.


81-137: Inverse method includes helpful debug prints.
Consider using a logger or removing prints in production code. Also be cautious of numerical stability if determinant is very small but nonzero.

src/main/java/org/fungover/breeze/Matrix/MatrixOps.java (1)

129-174: QR decomposition uses naive Gram-Schmidt.
Be aware of potential numerical instability for certain matrices. Consider Householder or modified Gram-Schmidt if needed.

src/test/java/org/fungover/breeze/Matrix/Matrix3x3Test.java (3)

13-41: Add edge case tests for constructor validation.

The constructor validation tests could be more comprehensive. Consider adding tests for:

  1. null input
  2. Empty array
  3. Ragged arrays (rows with different lengths)

84-89: Consider using parameterized tests for inverse matrix validation.

The inverse matrix test could be more robust by using parameterized tests with multiple test cases.

Example using JUnit's @ParameterizedTest:

@ParameterizedTest
@MethodSource("provideMatricesForInverse")
void testInverse(float[][] input, float[][] expectedInverse) {
    Matrix3x3 matrix = new Matrix3x3(input);
    Matrix3x3 result = matrix.inverse();
    assertArrayEquals(expectedInverse, result.getMatrix(), 0.0001f);
}

private static Stream<Arguments> provideMatricesForInverse() {
    return Stream.of(
        Arguments.of(
            new float[][]{{4, 7, 2}, {3, 6, 1}, {2, 5, 3}},
            new float[][]{{1.4444444f, -1.2222222f, -0.5555556f}, 
                         {-0.7777778f, 0.8888889f, 0.22222222f},
                         {0.33333334f, 0.22222222f, 0.33333334f}}
        ),
        // Add more test cases here
    );
}

Also applies to: 156-158


173-193: Add boundary tests for vector transformation.

The vector transformation test could include more edge cases:

  1. Vectors with extreme values
  2. Vectors with all zeros
  3. Vectors with NaN or Infinity values
src/test/java/org/fungover/breeze/Matrix/Matrix4x4Test.java (1)

7-7: Consider using more specific assertions.

The test class uses generic JUnit assertions. Consider using AssertJ's fluent assertions for more readable and specific matrix assertions.

-import static org.junit.jupiter.api.Assertions.*;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.within;
src/test/java/org/fungover/breeze/Matrix/MatrixOpsTest.java (1)

13-65: Use parameterized tests for rotation tests.

The rotation tests have similar structure and could be simplified using parameterized tests.

Example implementation:

@ParameterizedTest
@CsvSource({
    "0, 1,0,0, 0,1,0, 0,0,1",
    "90, 0,0,1, 0,1,0, -1,0,0",
    "180, -1,0,0, 0,1,0, 0,0,-1",
    "270, 0,0,-1, 0,1,0, 1,0,0"
})
void testRotateY(float degrees, float... expected) {
    Matrix3x3 result = MatrixOps.rotateY3x3((float) Math.toRadians(degrees));
    float[][] expectedMatrix = new float[3][3];
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            expectedMatrix[i][j] = expected[i * 3 + j];
        }
    }
    assertMatrixEquals(expectedMatrix, result.getMatrix(), 1e-6f);
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b69c221 and 7667bed.

📒 Files selected for processing (8)
  • pom.xml (4 hunks)
  • src/main/java/module-info.java (1 hunks)
  • src/main/java/org/fungover/breeze/Matrix/Matrix3x3.java (1 hunks)
  • src/main/java/org/fungover/breeze/Matrix/Matrix4x4.java (1 hunks)
  • src/main/java/org/fungover/breeze/Matrix/MatrixOps.java (1 hunks)
  • src/test/java/org/fungover/breeze/Matrix/Matrix3x3Test.java (1 hunks)
  • src/test/java/org/fungover/breeze/Matrix/Matrix4x4Test.java (1 hunks)
  • src/test/java/org/fungover/breeze/Matrix/MatrixOpsTest.java (1 hunks)
🔇 Additional comments (21)
src/main/java/org/fungover/breeze/Matrix/Matrix4x4.java (5)

27-32: Constructor logic is correct.
Checks for exactly 4x4 dimensions and throws an exception otherwise, which is good for enforcing correct usage.


34-36: Getter method for internal matrix is straightforward.
No issues observed.


38-45: Identity matrix creation is correct.
Implementation follows the standard identity definition.


69-93: Cofactor computation is properly implemented.
Constructing the 3x3 minor and applying the checkerboard sign is correct.


95-105: Transpose method logic is correct.
Swaps rows and columns as expected.

src/main/java/org/fungover/breeze/Matrix/Matrix3x3.java (6)

32-37: Constructor ensures 3x3 dimensions.
This validation helps prevent incorrect usage.


39-45: Identity matrix creation is standard.
No issues found.


63-71: Transpose method is correct.
Properly switches rows and columns.


73-79: Determinant computation is standard for 3x3.
No correctness issues observed.


141-150: Vector transformation logic is straightforward.
Correct multiplication of vector by matrix.


154-156: Getter method returns internal matrix.
Implementation is concise and clear.

src/main/java/org/fungover/breeze/Matrix/MatrixOps.java (8)

16-23: scale3x3 method is correct.
Implements standard scaling transformation in 3D.


25-34: rotateX3x3 is correctly implemented.
Uses sine/cosine for rotation about the X-axis.


36-45: rotateY3x3 is standard for Y-axis rotation.
No issues identified.


47-56: rotateZ3x3 follows typical rotation matrix conventions.
Looks good.


58-65: translate3x3 implements a 2D translation in homogeneous coordinates.
No concerns.


69-77: scale4x4 is standard for uniform/directional scaling in 4D.
Implementation is correct.


79-89: rotateX4x4 is correct for 3D rotation around X-axis in 4D homogeneous space.
No issues found.


92-127: LU decomposition (Doolittle style) lacks pivot checks.
Division by zero could occur if U[i][i] is zero. Consider partial pivoting or singular checks.

src/main/java/module-info.java (1)

1-3:

✅ Verification successful

Verify the use of incubator module.

The jdk.incubator.vector module is an incubating API. Please ensure you understand the implications:

  1. It may change incompatibly or be removed in future JDK versions.
  2. It requires explicit command-line flags to use.

🌐 Web query:

What is the current status of the jdk.incubator.vector module? Is it still incubating or has it been standardized?

💡 Result:

The jdk.incubator.vector module remains in incubation as of JDK 24 (February 2025), continuing its experimental status since its introduction in JDK 16 through nine consecutive incubation phases[3][10]. Here's the detailed breakdown:

Current Status

  • Still incubating: The API has not yet graduated to standard Java SE despite nine rounds of incubation (JDK 16 through JDK 24)[3][10].
  • Dependency on Project Valhalla: Final standardization awaits Valhalla's value objects and generic specialization features, which are prerequisites for adapting the Vector API[3][5][10].

Key Reasons for Continued Incubation

  1. Valhalla Integration Requirements

    • Needs Valhalla's value classes to replace current value-based vector implementations[5][10]
    • Requires generic specialization for primitive types like int instead of boxed Integer[10]
  2. Implementation Progress

    • Maintains dual implementations:
      • Fallback Java implementation for basic functionality
      • C2 compiler intrinsics for hardware acceleration[10]
    • Recent focus on float16 support and enhanced loop optimization[10]

Historical Context

JDK Version Incubation Phase Key Development
16 First Initial incubator module[1][4]
17-22 Second-Seventh Bug fixes & performance tweaks[5]
23 Eighth Preparation for Valhalla alignment[10]
24 Ninth Continued waiting for Valhalla previews[3]

Developers can still use the API by explicitly enabling the incubator module with VM flags like --add-modules=jdk.incubator.vector[8], though its unstable status means future changes are likely before standardization.

Citations:


Subject: Usage of jdk.incubator.vector Verified as Intended

The code in src/main/java/module-info.java correctly requires the incubating vector API. As confirmed by recent information for JDK 24 (February 2025):

  • The jdk.incubator.vector module remains incubating and has done so consistently since JDK 16.
  • It continues to require explicit command-line flags (e.g., --add-modules=jdk.incubator.vector) for enabling its use.
  • Developers should remain aware that, as an experimental API, it might change incompatibly or be removed in future JDK releases—pending further integration with enhancements from Project Valhalla.

No changes are needed in the current code snippet:

module breeze {
    requires jdk.incubator.vector;
}
pom.xml (1)

20-24: LGTM! Good choice of testing dependencies.

The update to junit-jupiter-api and addition of assertj-core with recent versions are good choices for the test framework.

Also applies to: 26-30

Comment on lines 84 to 123
public void testMatrixInverseAndSingularMatrix1() {
// ✅ Test 1: Invertible Matrix
float[][] matrixValues = {
{4, 7, 2, 3},
{3, 6, 1, 2},
{2, 5, 3, 1},
{1, 8, 7, 6}
};

// Expected inverse (precomputed)
float[][] expectedInverse = {
{ 1.0000f, -1.0000f, 0.9091f, -0.1818f },
{-0.6667f, 0.8333f, 0.0606f, 0.0455f },
{ 0.3333f, -0.6667f, 0.3333f, -0.0000f },
{ 0.3333f, -0.1667f, -0.4848f, 0.1364f }
};

// Create matrix object
Matrix4x4 matrix = new Matrix4x4(matrixValues);
Matrix4x4 inverseMatrix = matrix.inverse();
float[][] result = inverseMatrix.getMatrix();

// Assert each element of the inverse matrix
for (int i = 0; i < 4; i++) {
assertArrayEquals(expectedInverse[i], result[i], DELTA, "Row " + i + " in inverse matrix is incorrect.");
}

// ✅ Test 2: Singular Matrix (Non-invertible)
float[][] singularMatrixValues = {
{1, 2, 3, 4},
{2, 4, 6, 8}, // This row is a multiple of the first row
{3, 6, 9, 12},
{4, 8, 12, 16}
};

Matrix4x4 singularMatrix = new Matrix4x4(singularMatrixValues);

// Ensure the method throws an exception when trying to invert a singular matrix
assertThrows(ArithmeticException.class, singularMatrix::inverse, "Should throw exception for singular matrix");
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Remove duplicate test method.

The testMatrixInverseAndSingularMatrix method appears twice with slightly different implementations. This creates maintenance issues and confusion.

Merge these methods into a single comprehensive test:

  1. Keep the first implementation (lines 84-123)
  2. Remove the duplicate implementation (lines 158-198)

Also applies to: 158-198

Comment on lines +421 to +425
private void printMatrix(float[][] matrix) {
for (float[] row : matrix) {
System.out.println(Arrays.toString(row));
}
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Remove unused debug method.

The printMatrix method appears to be used for debugging and should be removed from the test class.

Comment on lines +289 to +370
public void testLUDecomposition() {
Matrix4x4 mat = new Matrix4x4(new float[][]{
{4, -2, 1, 3},
{3, 6, 2, 1},
{1, -1, 3, 5},
{2, 1, 3, 4}
});

Matrix4x4[] lu = MatrixOps.luDecomposition4x4(mat);
Matrix4x4 L = lu[1];
Matrix4x4 U = lu[0];

// Expected L matrix
float[][] expectedL = {
{4.0f, -2.0f, 1.0f, 3.0f},
{0.0f, 7.5f, 1.25f, -1.25f},
{0.0f, 0.0f, 2.8333333f, 4.1666665f},
{0.0f, 0.0f, 0.0f, -0.35294104f}
};

// Expected U matrix
float[][] expectedU = {

{1.0f, 0.0f, 0.0f, 0.0f},
{0.75f, 1.0f, 0.0f, 0.0f},
{0.25f, -0.06666667f, 1.0f, 0.0f},
{0.5f, 0.26666668f, 0.76470584f, 1.0f}
};



// Flatten matrices for comparison
float[] expectedLFlattened = new float[16];
float[] actualLFlattened = new float[16];

float[] expectedUFlattened = new float[16];
float[] actualUFlattened = new float[16];

// Flatten expected L matrix
int index = 0;
for (float[] row : expectedL) {
for (float value : row) {
expectedLFlattened[index++] = value;
}
}

// Flatten actual L matrix
index = 0;
for (float[] row : L.getMatrix()) {
for (float value : row) {
actualLFlattened[index++] = value;
}
}

// Flatten expected U matrix
index = 0;
for (float[] row : expectedU) {
for (float value : row) {
expectedUFlattened[index++] = value;
}
}

// Flatten actual U matrix
index = 0;
for (float[] row : U.getMatrix()) {
for (float value : row) {
actualUFlattened[index++] = value;
}
}

// Compare flattened matrices with a delta for floating-point precision
for (int i = 0; i < expectedLFlattened.length; i++) {
assertEquals(expectedLFlattened[i], actualLFlattened[i], 0.0001f); // Use a smaller tolerance
}

for (int i = 0; i < expectedUFlattened.length; i++) {
assertEquals(expectedUFlattened[i], actualUFlattened[i], 0.0001f); // Use a smaller tolerance

}


}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add validation for decomposition properties.

The LU decomposition test should validate that L*U equals the original matrix.

Add this validation:

// Validate that L*U equals the original matrix
float[][] product = multiplyMatrices(L.getMatrix(), U.getMatrix());
for (int i = 0; i < 4; i++) {
    assertArrayEquals(mat.getMatrix()[i], product[i], 0.0001f);
}

Comment on lines +113 to +121
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>
--add-modules jdk.incubator.vector
</argLine>
</configuration>
</plugin>
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Specify version for maven-surefire-plugin.

The plugin version should be explicitly specified to ensure build reproducibility.

Apply this diff to add the version:

             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-surefire-plugin</artifactId>
+                <version>3.2.5</version>
                 <configuration>
                     <argLine>
                         --add-modules jdk.incubator.vector
                     </argLine>
                 </configuration>
             </plugin>
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>
--add-modules jdk.incubator.vector
</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.5</version>
<configuration>
<argLine>
--add-modules jdk.incubator.vector
</argLine>
</configuration>
</plugin>

Comment on lines +72 to +84
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>17</source> <!-- Ensure this matches your Java version -->
<target>17</target> <!-- Ensure this matches your Java version -->
<compilerArgs>
<arg>--add-modules</arg>
<arg>jdk.incubator.vector</arg>
</compilerArgs>
</configuration>
</plugin>
Copy link

@coderabbitai coderabbitai bot Feb 13, 2025

Choose a reason for hiding this comment

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

⚠️ Potential issue

Update maven-compiler-plugin configuration.

Several issues need to be addressed:

  1. The plugin version 3.8.0 is outdated. Latest version should be used.
  2. There's a version mismatch: properties specify Java 23 but compiler config uses Java 17.
  3. The source/target configuration is redundant when using maven.compiler.release property.

Apply this diff to fix the issues:

             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-compiler-plugin</artifactId>
-                <version>3.8.0</version>
+                <version>3.12.1</version>
                 <configuration>
-                    <source>17</source> <!-- Ensure this matches your Java version -->
-                    <target>17</target> <!-- Ensure this matches your Java version -->
                     <compilerArgs>
                         <arg>--add-modules</arg>
                         <arg>jdk.incubator.vector</arg>
                     </compilerArgs>
                 </configuration>
             </plugin>
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>17</source> <!-- Ensure this matches your Java version -->
<target>17</target> <!-- Ensure this matches your Java version -->
<compilerArgs>
<arg>--add-modules</arg>
<arg>jdk.incubator.vector</arg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.12.1</version>
<configuration>
<compilerArgs>
<arg>--add-modules</arg>
<arg>jdk.incubator.vector</arg>
</compilerArgs>
</configuration>
</plugin>

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like there are alot of changes to the pom.xml file including setting java version to 17? Since we are building the rest of the package using java 23 this shouldn't be changed unless not possible to use newer versions which seems odd?
I assume that the only things that needs changing in pom.xml are

<compilerArgs>
    <arg>--add-modules</arg>
    <arg>jdk.incubator.vector</arg>
</compilerArgs>

Maybe we can set it with something like:

<properties>
    <maven.compiler.release>23</maven.compiler.release>
    <jdk.incubator.vector.arg>--add-modules</jdk.incubator.vector.arg>
    <jdk.incubator.vector.module>jdk.incubator.vector</jdk.incubator.vector.module>
</properties>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.13.0</version>
            <configuration>
                <release>${maven.compiler.release}</release>
                <compilerArgs>
                    <arg>${jdk.incubator.vector.arg}</arg>
                    <arg>${jdk.incubator.vector.module}</arg>
                </compilerArgs>
            </configuration>
        </plugin>
    </plugins>
</build>

Do we need more than this as changes in pom.xml?

Copy link

Choose a reason for hiding this comment

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

@kappsegla Your suggestion is excellent! Yes, we should maintain Java 23 and use properties for better maintainability. We also need to update the maven-surefire-plugin to use the same properties for consistency:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <configuration>
        <argLine>
            ${jdk.incubator.vector.arg} ${jdk.incubator.vector.module}
        </argLine>
    </configuration>
</plugin>

These are the only changes needed in the pom.xml for this PR.


✏️ Learnings added
Learnt from: kappsegla
PR: fungover/breeze#61
File: pom.xml:72-84
Timestamp: 2025-02-14T12:03:47.743Z
Learning: In Maven configuration, prefer using properties for module configuration (e.g., `jdk.incubator.vector.arg` and `jdk.incubator.vector.module`) to maintain consistency across plugins and improve maintainability. Avoid using redundant source/target configuration when maven.compiler.release is already set.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

Copy link
Contributor

Choose a reason for hiding this comment

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

I have an even better suggestion. Since we have a module-info.java file:

module breeze { requires jdk.incubator.vector; }
We don't need to change anything in the pom.xml and adding argLines. We should instead revert pom.xml to its unedited state and it works perfectly without it.

Copy link

Choose a reason for hiding this comment

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

@kappsegla Excellent point! You're absolutely right. Using module-info.java is the cleaner and more idiomatic way to handle module dependencies in Java. We should indeed revert the pom.xml changes and rely on the proper module declaration. This is a much better approach.

🐰 thoughtfully nods in agreement


✏️ Learnings added
Learnt from: kappsegla
PR: fungover/breeze#61
File: pom.xml:72-84
Timestamp: 2025-02-14T12:49:06.224Z
Learning: When using Java modules, prefer declaring module dependencies in module-info.java (e.g., `requires jdk.incubator.vector;`) instead of configuring them through Maven. This is the proper way to handle module dependencies in Java 9+ and eliminates the need for additional Maven configuration.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

Copy link

@DeenoDev00 DeenoDev00 left a comment

Choose a reason for hiding this comment

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

Fix this - Duplicate on row 21 pom.xml

Rest is okay

Worked with AntonGrubisic
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)
B Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

Copy link
Contributor

Choose a reason for hiding this comment

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

Since we have a module-info.java file importing needed modules we don't need to change anything in pom.xml. Revert to previous version.

@@ -0,0 +1,3 @@
module breeze {
requires jdk.incubator.vector;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing new line at the end. That's why there is a red circle with a - in it.

When adding this file to our project it becomes modularized.

Non-Modularized Applications: Continue to use the library without any changes.
Modularized Applications: Need to explicitly declare dependencies on the new module. Is this a major change?

@@ -0,0 +1,3 @@
module breeze {
requires jdk.incubator.vector;
Copy link
Contributor

Choose a reason for hiding this comment

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

If a modularized application sees our module it will see no packages or classes as it is. We need to export any packages that we want to be open to the rest of the world. Maybe this should be its own issue? From what I can see there are no usage of the incubator vector api yet? So it isn't needed at all right now?

@@ -0,0 +1,3 @@
module breeze {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggest using the name org.fungover.breeze as a better module name.

@@ -0,0 +1,157 @@
package org.fungover.breeze.Matrix;
Copy link
Contributor

Choose a reason for hiding this comment

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

Package names should be all lowercase for best compatibility between different operating systems file system.

Comment on lines +103 to +107
// Print Cofactor Matrix
System.out.println("Cofactor Matrix:");
for (float[] row : cofactorMatrix) {
System.out.println(Arrays.toString(row));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't want any printing in our library methods. Might be usefull for debugging and in that case we can maybe wrap it in an if statement that checks on some variable like.

private static final boolean DEBUG_MODE = false;

if( DEBUG_MODE) {
...
}

The Java compiler (javac) employs a feature called constant folding. When you declare a private static final boolean variable and set it to a constant value, the compiler treats it as a compile-time constant. If the variable is used in a conditional statement like if (DEBUG_MODE) { ... }, and the condition is always false, the compiler will optimize the code by removing the entire block inside the if statement during compilation.

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.

3 participants