I am interested in speeding up as much as possible the dot product in the specific case of a multiplication of a $n\times n$ sparse hermitian matrix $H$ (where $n$ is typically large, let's say $\approx 10^4$) and a vector $v$ with $n$ complex entries. Obviously, H.v
does the job using the function Dot[], but I am not sure that this is the fastest way to go (or is it?). For example, can I create a compiled function with the list of indexes and values of $H$ and $v$ as inputs and do better?
EDIT As suggested in the comments, here's a code to generate randomly defined $H$ and $v$:
n = 10000;(* dimension of matrix H *)
m = 50000;(* number of non-vanishing entries *)
pos = RandomInteger[{1, n}, {m,
2}];(* list of positions of non-vanishing entries *)
vals = RandomComplex[{-1.0 - 1.0*I, 1.0 + 1.0*I},
m];(* list of values *)
H = SparseArray[
Thread[pos -> vals]
, {n, n}];(* make a non-hermitian sparse array *)
H += ConjugateTranspose[H];(* make it hermitian *)
HermitianMatrixQ[H] (* check if it's hermitian *)
v = RandomComplex[{-1.0 - 1.0*I, 1.0 + 1.0*I}, n];
H . v //
RepeatedTiming // First (* time taken by the function Dot[] (4 ms \
on my machine) *)
CUDALink
that works on real dense matrices. However, I tried this and found it slower than just a CPU A.B in Mathematica. $\endgroup$