aoclsparse_?dotci() - 5.2 English - 68552

AOCL API Guide (68552)

Document ID
68552
Release Date
2025-12-29
Version
5.2 English
aoclsparse_status aoclsparse_cdotci(const aoclsparse_int nnz, const void *x, const aoclsparse_int *indx, const void *y, void *dot)#
aoclsparse_status aoclsparse_zdotci(const aoclsparse_int nnz, const void *x, const aoclsparse_int *indx, const void *y, void *dot)#

Sparse conjugate dot product for single and double data precision complex types.

aoclsparse_cdotci() (complex float) and aoclsparse_zdotci() (complex double) compute the dot product of the conjugate of a complex vector stored in a compressed format and a complex dense vector. Let \(x\) and \(y\) be respectively a sparse and dense vectors in \(C^m\) with indx ( \(I_x\)) the nonzero indices array of x of length at least nnz that is used to index into the entries of dense vector \(y\), then these functions return

\[ {\bf\mathsf{dot}} = \sum_{i=0}^{{\bf\mathsf{nnz}}-1} \overline{\,x_i\,} \cdot y_{I_{x_i}}. \]

 1/* ************************************************************************
 2 * Copyright (c) 2023 Advanced Micro Devices, Inc.
 3 *
 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
 5 * of this software and associated documentation files (the "Software"), to deal
 6 * in the Software without restriction, including without limitation the rights
 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 8 * copies of the Software, and to permit persons to whom the Software is
 9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 *
22 * ************************************************************************ */
23
24#include <complex>
25#include <iostream>
26#include <vector>
27
28/* One can use std::complex<double> instead of aoclsparse_double_complex
29#define STD_CMPLX  (or pass it as a compilation flag -DSTD_CMPLX)
30#ifdef STD_CMPLX
31#define aoclsparse_double_complex std::complex<double>
32#endif
33*/
34
35#include "aoclsparse.h"
36
37int main(void)
38{
39    aoclsparse_status                      status;
40    const aoclsparse_int                   nnz  = 3;
41    std::vector<aoclsparse_int>            indx = {0, 1, 2};
42    std::vector<aoclsparse_double_complex> x{{1, 1}, {2, 2}, {3, 3}};
43    std::vector<aoclsparse_double_complex> y{
44        {1, 1}, {1, 2}, {2, 3}, {1, 0}, {4, 1}, {1.2, -1}, {7, -1}, {0, 2}, {-2, 3}};
45    aoclsparse_double_complex dot_exp{-5, 23};
46    aoclsparse_double_complex dotc_exp{23, 5};
47    aoclsparse_double_complex dotp;
48    bool                      ok;
49
50    std::cout << "Invoking aoclsparse_zdotui...\n";
51
52    //Invoke complex double dot product
53    status = aoclsparse_zdotui(nnz, x.data(), indx.data(), y.data(), &dotp);
54    if(status != aoclsparse_status_success)
55    {
56        std::cerr << "Error returned from aoclsparse_cdotui, status = " << status << "."
57                  << std::endl;
58        return 1;
59    }
60
61#ifdef STD_CMPLX
62    std::cout << "Dot product: " << dotp << ", Expected dot product: " << dot_exp << std::endl;
63    ok = (dotp == dot_exp);
64#else
65    std::cout << "Dot product: (" << dotp.real << ", " << dotp.imag << "), Expected dot product: ("
66              << dot_exp.real << ", " << dot_exp.imag << ")" << std::endl;
67    ok = ((dotp.real == dot_exp.real) && (dotp.imag == dot_exp.imag));
68#endif
69
70    std::cout << "Invoking aoclsparse_zdotci...\n";
71
72    //Invoke complex double dot product
73    status = aoclsparse_zdotci(nnz, x.data(), indx.data(), y.data(), &dotp);
74    if(status != aoclsparse_status_success)
75    {
76        std::cerr << "Error returned from aoclsparse_cdotci, status = " << status << "."
77                  << std::endl;
78        return 2;
79    }
80#ifdef STD_CMPLX
81    std::cout << "Conjugated dot product: " << dotp
82              << ", Expected conjugated dot product: " << dotc_exp << std::endl;
83    ok &= (dotp == dotc_exp);
84    return ok ? 0 : 3;
85
86#else
87    std::cout << "Dot product: (" << dotp.real << ", " << dotp.imag << "), Expected dot product: ("
88              << dotc_exp.real << ", " << dotc_exp.imag << ")" << std::endl;
89    ok &= ((dotp.real == dotc_exp.real) && (dotp.imag == dotc_exp.imag));
90    return ok ? 0 : 4;
91#endif
92}

Note

The contents of the vectors are not checked for NaNs.

Parameters:
  • nnz[in] The number of elements (length) of vectors x and indx.

  • x[in] Array of at least nnz complex elements.

  • indx[in] Nonzero indices set, \(I_x\), of x described by this array of length at least nnz. Each entry must contain a valid index into y and be unique. The entries of indx are not checked for validity.

  • y[in] Array of at least \(\max(I_{x_i}, i \in \{ 1,\ldots,{\bf\mathsf{nnz}}\})\) complex elements.

  • dot[out] The dot product of the conjugate of \(x\) and \(y\) when nnz \(> 0\). If nnz \(\le 0\), dot is set to 0.

Return values:
  • aoclsparse_status_success – The operation completed successfully.

  • aoclsparse_status_invalid_pointer – At least one of the pointers x, indx, y, dot is invalid.

  • aoclsparse_status_invalid_size – Indicates that the provided nnz is not positive.