question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DOC: complex conjugation in BLAS functions

See original GitHub issue

Is your feature request related to a problem? Please describe.

I have a very large complex array A and I want to apply its adjoint (conjugate transpose) to a vector y. If I use A.conj().T @ y then A.conj() is allocated explicitly. That consumes too much memory. It’s possible to bypass allocation by calling scipy.linalg.blas.zgemv(1.0, A, y, trans=2).

The trouble is: the meaning of the trans parameter isn’t specified in SciPy’s zgemv documentation. I only learned of this solution by guessing the behavior of trans and trying it out.

Describe the solution you’d like.

SciPy’s documentation for complex BLAS functions should indicate how to perform the conjugate-transpose operation. I.e., explain the meanings of trans = 0, 1, or 2 in documentation for the relevant functions.

I think the change is reasonable because people who are familiar with common C or FORTRAN BLAS interfaces expect trans to be a character (N, T, or H).

Describe alternatives you’ve considered.

N/A

Additional context (e.g. screenshots, GIFs)

Code snippet showing undocumented functionality:

import numpy as np
import scipy.linalg as la
import scipy.linalg.blas as blas

A = np.random.randn(3,2) + 1j*np.random.randn(3,2)
y = np.random.randn(3) + 1j

inefficient = A.T.conj() @ y
efficient = blas.zgemv(1.0, A, y, trans=2)
print(la.norm(inefficient - efficient))

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
melissawmcommented, Dec 6, 2021

I am taking a look into this - the difficulty is that these are autogenerated modules, and the documentation is also autogenerated from the wrappers, without any extra info about the parameters that f2py can parse. I don’t see any immediate solutions other than being able to use a comment as extra info for the docstring.

0reactions
rileyjmurraycommented, Dec 3, 2021

Great. So, what are some possibilities for moving forward here? Is there a brute-force option where someone (e.g., me) could expand a couple dozen documentation files with a suitable phrase for complex conjugation? I’d suggest something like “Here, setting trans = 0, 1, 2 correspond to trans = ‘N’, ‘T’, ‘H’ in the Netlib LAPACK implementation.” You seem to also suggest that modifying f2py might work. Who could we talk to to figure out if that’s actually viable?

Read more comments on GitHub >

github_iconTop Results From Across the Web

BLAS Support — GSL 2.7 documentation - GNU.org
These functions compute the complex conjugate scalar product x^H y for the vectors x and y , returning the result in dotc.
Read more >
BLAS (Basic Linear Algebra Subprograms) - The Netlib
The BLAS (Basic Linear Algebra Subprograms) are routines that provide standard building blocks for performing basic vector and matrix operations.
Read more >
BLAS — Chapel Documentation 1.16
This module provides higher-level wrappers around the BLAS functions. ... B**H is the conjugate transpose of B , conjg(alpha) is the complex conjugate...
Read more >
zgemm's conjugate transpose option does not seem to work
I am trying to multiply a complex vector to a complex matrix using the zgemm function of the BLAS library in C. This...
Read more >
Intel clBLAS: BLAS Level 1 Complex
Function Documentation. ◇ iclblasCaxpy() ... Where x and y are complex n element vectors; and H - complex conjugation on elements of x....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found