Skip to content

stdlib_dot_product and stdlib_dot_product_kahan return erroneous results for complex vectors #1016

@loiseaujc

Description

@loiseaujc

Description

The implementations of the improved dot_product kernels work like a charm for real vectors but return erroneous results for complex ones. It seems like the complex versions are missing a complex-conjugate operation. See the following code snippet for reproducibility.

program main
   use stdlib_linalg_constants
   use stdlib_intrinsics
   implicit none

   integer(ilp), parameter :: n = 128
   complex(dp), dimension(n) :: x, y
   real(dp), dimension(n, 2) :: z

   call random_number(z); x%re = z(:, 1); x%im = z(:, 2)
   call random_number(z); y%re = z(:, 1); y%im = z(:, 2)

   print *, dot_product(x, y)
   print *, stdlib_dot_product(x, y)
   print *, stdlib_dot_product_kahan(x, y)
end program main

Expected Behaviour

Results between stdlib_dot_product, stdlib_dot_product_kahan and the Fortran intrinsic dot_product should be identical (up to a multiple of the machine precision).

Version of stdlib

latest

Platform and Architecture

Ubuntu 22.04

Additional Information

Ping @perazz, @jalvesz

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions