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

Fix tests on macOS #184

Merged
merged 4 commits into from
Oct 24, 2023
Merged

Fix tests on macOS #184

merged 4 commits into from
Oct 24, 2023

Conversation

ttytm
Copy link
Member

@ttytm ttytm commented Oct 22, 2023

Best #182 first, then C types can be updated here as well before a merge.

Apparently math works different on mac, needed to add a little tolarance for some tests.

Summary by CodeRabbit

  • Refactor: Simplified the CI/CD pipeline by removing specific test configurations, enhancing the efficiency of the testing process.
  • Test: Introduced platform-specific tolerance checks in various test functions, ensuring consistent behavior across different operating systems when comparing floating-point values.
  • New Feature: Incorporated LAPACK and CBLAS functionality into the codebase for macOS, enhancing the software's capabilities on this platform.
  • Refactor: Simplified code in several areas by using more concise syntax, improving code readability without altering functionality.
  • Test: Enhanced test failure messages to include actual and expected values along with the tolerance, providing more detailed feedback during testing.
  • Chore: Removed unused functions and updated function signatures to align with library usage, streamlining the codebase.

@coderabbitai
Copy link

coderabbitai bot commented Oct 22, 2023

Walkthrough

The changes primarily focus on platform-specific adjustments for macOS, particularly in floating-point comparisons and LAPACK library usage. The CI/CD pipeline is simplified, and test execution steps are streamlined. The codebase now incorporates LAPACK functionality for macOS, and the test assertions have been updated to use tolerance checks for floating-point comparisons.

Changes

File(s) Summary
.github/workflows/ci.yml Simplified the CI/CD pipeline by removing specific test configurations and adding the --skip-examples flag to test execution commands.
float/float64/ge_test.v, iter/ranges_test.v, la/matrix_ops_test.v Introduced platform-specific tolerance checks for floating-point comparisons in tests. Enhanced assertions with failure messages displaying actual, expected values, and tolerance.
vlas/cflags_d_cblas.v, vlas/cflags_notd_cblas.v Added header files and flags for LAPACK and CBLAS functionality on macOS.
vlas/lapack_common.v, vlas/lapack_default.c.v, vlas/lapack_macos.c.v Removed unused functions, updated function signatures, and incorporated LAPACK functionality.
vlas/conversions.v Simplified code by replacing if-else statements with conditional expressions and changing return types.

🐇
"In the land of code, where logic is the road,
Changes come and go, like a river's flow.
Tolerance in tests, for platforms at their best,
With LAPACK's zest, we're on a quest.
Simplified CI/CD, as easy as one, two, three,
Celebrate, for we are free! 🎉"


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai help to get help.

Note: For conversation with the bot, please use the review comments on code diffs or files.

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.

Review Status

Actionable comments generated: 3

Commits Files that changed from the base of the PR and between 904b61d and ceb84de.
Files selected for processing (9)
  • .github/workflows/ci.yml (2 hunks)
  • float/float64/ge_test.v (2 hunks)
  • iter/ranges_test.v (3 hunks)
  • la/matrix_ops_test.v (1 hunks)
  • vlas/cflags_d_cblas.v (1 hunks)
  • vlas/cflags_notd_cblas.v (1 hunks)
  • vlas/lapack_common.v (2 hunks)
  • vlas/lapack_default.c.v (1 hunks)
  • vlas/lapack_macos.c.v (1 hunks)
Files skipped from review due to trivial changes (5)
  • .github/workflows/ci.yml
  • la/matrix_ops_test.v
  • vlas/cflags_d_cblas.v
  • vlas/cflags_notd_cblas.v
  • vlas/lapack_common.v
Additional comments (Suppressed): 4
vlas/lapack_default.c.v (1)
  • 1-9: The function C.LAPACKE_dlange is declared but not defined. This could lead to a linker error if the function is not defined elsewhere. Please ensure that the function is defined in the linked C libraries. Also, the function dlange is using unsafe code to call C.LAPACKE_dlange. While this is sometimes necessary when interfacing with C, it's important to ensure that the inputs to the function are valid to prevent undefined behavior. Specifically, make sure that the slices a and work are not empty before accessing their first element.
float/float64/ge_test.v (2)
  • 71-72: The tolerance for floating-point comparisons has been made conditional based on the operating system. This is likely due to differences in floating-point precision between different systems. Ensure that this change does not introduce any unexpected behavior or test failures on other systems.

  • 90-90: The assertion error message has been enhanced to include the actual value, expected value, and tolerance. This will be helpful in debugging test failures.

iter/ranges_test.v (1)
  • 3-3: The math module is imported but not used in the old hunk. Ensure that it is necessary in the new hunk.

vlas/lapack_macos.c.v Outdated Show resolved Hide resolved
iter/ranges_test.v Outdated Show resolved Hide resolved
iter/ranges_test.v Outdated Show resolved Hide resolved
Comment on lines -78 to -79
run: ~/.vmodules/vsl/bin/test ${{ matrix.flags }} --use-cblas --use-gc boehm
if: ${{ matrix.os != 'ubuntu-18.04' }}
Copy link
Member Author

@ttytm ttytm Oct 22, 2023

Choose a reason for hiding this comment

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

Removes apparently obsolete

  • gc boehm is the default mode, but I might be missing something that it was called explicitly here. Else, there is no difference with the run above.
  • ubuntu-18.04 is not in the matrix, support for such runners was deprecated

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.

Review Status

Actionable comments generated: 0

Commits Files that changed from the base of the PR and between ceb84de and 90370d7.
Files selected for processing (1)
  • iter/ranges_test.v (3 hunks)
Additional comments (Suppressed): 3
iter/ranges_test.v (3)
  • 3-3: The math module is imported but was not present in the old hunk. This is likely to support the new math.tolerance function used in the tests. Ensure that this import is necessary and that the math module is available in the project's dependencies.

  • 54-65: The test assertions for FloatIter have been updated to include a platform-specific tolerance check. On macOS, a higher tolerance of 2e-15 is used, while on other platforms, the original n.eq_epsilon(expected[i][j]) check is maintained. This change is likely due to floating-point precision differences on macOS. Ensure that this change does not affect the accuracy of the tests on other platforms.

  • 94-105: Similar to the FloatIter tests, the test assertions for LinearIter have also been updated to include a platform-specific tolerance check. Ensure that this change does not affect the accuracy of the tests on other platforms.

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.

Review Status

Actionable comments generated: 1

Commits Files that changed from the base of the PR and between 1ee1419 and 345ee81.
Files selected for processing (10)
  • .github/workflows/ci.yml (2 hunks)
  • float/float64/ge_test.v (2 hunks)
  • iter/ranges_test.v (3 hunks)
  • la/matrix_ops_test.v (1 hunks)
  • vlas/cflags_d_cblas.v (1 hunks)
  • vlas/cflags_notd_cblas.v (1 hunks)
  • vlas/conversions.v (1 hunks)
  • vlas/lapack_common.v (2 hunks)
  • vlas/lapack_default.c.v (1 hunks)
  • vlas/lapack_macos.c.v (1 hunks)
Files skipped from review due to trivial changes (3)
  • .github/workflows/ci.yml
  • vlas/cflags_d_cblas.v
  • vlas/cflags_notd_cblas.v
Additional comments (Suppressed): 14
vlas/lapack_macos.c.v (1)
  • 1-7: The function dlange is a wrapper around the C function LAPACKE_dlange. It's important to ensure that the C function is correctly declared and that the types of the parameters match between the V and C versions of the function. Also, the use of unsafe should be minimized and justified. In this case, it seems necessary to call the C function, but it's worth double-checking if there's a safer alternative.
vlas/lapack_common.v (3)
  • 16-20: The function signatures for C.LAPACKE_dgeev, C.LAPACKE_dsyev, and C.LAPACKE_dgebal have been modified. Ensure that all calls to these functions throughout the codebase have been updated to match the new signatures. Also, verify that the changes are compatible with the LAPACK library being used.

  • 192-193: The function C.LAPACKE_dgeev is now being called with the job_vlr function applied to calc_vl and calc_vr and then converted to a string. Ensure that the job_vlr function returns the correct values and that the LAPACK library can handle these string inputs.

  • 189-198: The error handling for the C.LAPACKE_dgeev function call remains the same. If the function call fails, the program will panic with the message 'lapack failed'. This is a good practice as it immediately alerts the user to the failure.

la/matrix_ops_test.v (1)
  • 32-36: The new code introduces platform-specific tolerance levels for floating-point comparisons. This is a good approach to handle precision differences across platforms. However, it's important to ensure that the tolerance level la.matrix_tests_tol is appropriately set for macOS. Also, consider using math.tolerance for all platforms for consistency, as floating-point precision issues can occur on any platform, not just macOS.
- $if macos {
-    assert math.tolerance(matrix_det(mat_b), -306, la.matrix_tests_tol)
- } $else {
-    assert matrix_det(mat_b) == -306
- }
+ assert math.tolerance(matrix_det(mat_b), -306, la.matrix_tests_tol)
float/float64/ge_test.v (2)
  • 71-72: The tolerance for floating-point comparisons in the test_ger function has been made platform-specific. This is a good approach to handle precision differences across platforms. However, ensure that the chosen tolerance values are appropriate for the precision of the calculations being performed on each platform.

  • 90-90: The assertion error message has been enhanced to include the actual value, expected value, and tolerance. This is a good practice as it provides more context when a test fails, making it easier to debug.

iter/ranges_test.v (3)
  • 3-3: The math module is imported but not used in the old hunk. Ensure that it is necessary for the new hunk.

  • 54-65: The new hunk introduces platform-specific tolerance levels for floating-point comparisons in the test_float_iter() function. This is a good approach to account for precision differences across platforms. However, the tolerance for macOS is set to 2e-15, which is quite high. If this value is not carefully chosen, it could lead to false positives in the tests. Please verify that this tolerance level is appropriate for the precision of the calculations being tested.

  • 94-105: Similar to the previous comment, the new hunk introduces platform-specific tolerance levels for floating-point comparisons in the test_linear_iter() function. The same considerations apply: ensure that the tolerance level is appropriate for the precision of the calculations being tested.

vlas/conversions.v (4)
  • 9-11: The refactoring from if-else statements to conditional expressions improves readability and conciseness of the code. This change is consistent with the best practices for the V language.

  • 13-15: The refactoring from if-else statements to conditional expressions improves readability and conciseness of the code. This change is consistent with the best practices for the V language.

  • 17-19: The refactoring from if-else statements to conditional expressions improves readability and conciseness of the code. This change is consistent with the best practices for the V language.

  • 21-23: The return type of job_vlr function has been changed from &char to rune. Ensure that this change does not break any existing code that relies on the old return type. Also, the refactoring from if-else statements to conditional expressions improves readability and conciseness of the code.

Comment on lines +1 to +11
module vlas

import vsl.vlas.internal.vblas

fn C.LAPACKE_dlange(matrix_layout vblas.MemoryLayout, norm &char, m int, n int, a &f64, lda int, work &f64) f64

pub fn dlange(norm rune, m int, n int, a []f64, lda int, work []f64) f64 {
return unsafe {
C.LAPACKE_dlange(.row_major, &char(norm.str().str), m, n, &a[0], lda, &work[0])
}
}
Copy link

Choose a reason for hiding this comment

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

The function dlange is a wrapper around the C function LAPACKE_dlange. It's good to see that you're using the unsafe block to call the C function, which is a good practice in V language when dealing with C interop. However, it's important to ensure that the parameters passed to the C function are valid and won't cause any undefined behavior. For instance, you're passing the address of the first element of the a and work arrays to the C function. If these arrays are empty, this will result in undefined behavior. You should add a check to ensure these arrays are not empty before calling the C function.

pub fn dlange(norm rune, m int, n int, a []f64, lda int, work []f64) f64 {
+	if a.len == 0 || work.len == 0 {
+		return 0.0
+	}
	return unsafe {
		C.LAPACKE_dlange(.row_major, &char(norm.str().str), m, n, &a[0], lda, &work[0])
	}
}

- name: Execute Tests using Pure V Backend with Pure C Blas and Garbage Collection enabled
continue-on-error: true
run: ~/.vmodules/vsl/bin/test --use-cblas --use-gc boehm
run: ~/.vmodules/vsl/bin/test --use-cblas --skip-examples
Copy link
Member

Choose a reason for hiding this comment

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

why are we using the flag --skip-examples? 👀

Copy link
Member Author

Choose a reason for hiding this comment

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

Tests work, but not all examples build on mac currently.

Thought we can re-enable it when they do.

@ulises-jeremias ulises-jeremias merged commit 7d5ee50 into vlang:main Oct 24, 2023
9 checks passed
@ttytm ttytm deleted the fix/macos-tests branch October 24, 2023 23:30
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.

2 participants