Skip to content

fix: complex dot_product formulation #1017

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 3 commits into from
Jul 23, 2025
Merged

Conversation

jalvesz
Copy link
Contributor

@jalvesz jalvesz commented Jul 17, 2025

addresses #1016

cc: @loiseaujc

@jalvesz jalvesz requested a review from Copilot July 19, 2025 12:32
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes the complex dot product formulation in the stdlib intrinsics implementation to ensure compliance with the mathematical standard. The fix addresses issue #1016 by correcting the conjugation logic in complex number multiplication.

  • Modifies the complex dot product implementation to conjugate the first vector instead of the second
  • Updates both the standard and Kahan summation variants of the dot product functions
  • Adds comprehensive test coverage to verify conformance with the compiler intrinsic behavior

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/stdlib_intrinsics_dot_product.fypp Corrects conjugation order in complex dot product calculations for both standard and Kahan variants
test/intrinsics/test_intrinsics.fypp Adds test case comparing stdlib implementations against compiler intrinsic to ensure standard conformance

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@jalvesz jalvesz requested review from perazz and loiseaujc July 21, 2025 05:55
Copy link
Contributor

@loiseaujc loiseaujc left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@jalvesz jalvesz merged commit 2552c36 into fortran-lang:master Jul 23, 2025
16 checks passed
@jalvesz jalvesz deleted the fix_dot branch July 23, 2025 05:55
github-actions bot added a commit to banana-bred/stdlib that referenced this pull request Jul 23, 2025
* fix complex dot_product formulation

* smaller array and wider tolerance

* Update test/intrinsics/test_intrinsics.fypp

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
github-actions bot added a commit to banana-bred/stdlib that referenced this pull request Jul 23, 2025
* fix complex dot_product formulation

* smaller array and wider tolerance

* Update test/intrinsics/test_intrinsics.fypp

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
github-actions bot added a commit to banana-bred/stdlib that referenced this pull request Jul 23, 2025
* fix complex dot_product formulation

* smaller array and wider tolerance

* Update test/intrinsics/test_intrinsics.fypp

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
block ! test for https://github.com/fortran-lang/stdlib/issues/1016
${t}$ :: x(128), y(128)
real(${k}$) :: z(128,2)
real(${k}$), parameter :: tolerance = epsilon(1._${k}$)*100000
Copy link
Member

Choose a reason for hiding this comment

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

For a 32-bit precision dot product, this error is ~0.01, which seems a bit large? I believe using sqrt(epsilon(0.0_${k}$)) would be a more established error threshold in numerical analysis. LGTM otherwise.

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.

stdlib_dot_product and stdlib_dot_product_kahan return erroneous results for complex vectors
3 participants