-
aoclsparse_status aoclsparse_ssctr(const aoclsparse_int nnz, const float *x, const aoclsparse_int *indx, float *y)#
-
aoclsparse_status aoclsparse_dsctr(const aoclsparse_int nnz, const double *x, const aoclsparse_int *indx, double *y)#
-
aoclsparse_status aoclsparse_csctr(const aoclsparse_int nnz, const void *x, const aoclsparse_int *indx, void *y)#
-
aoclsparse_status aoclsparse_zsctr(const aoclsparse_int nnz, const void *x, const aoclsparse_int *indx, void *y)#
Sparse scatter for single and double precision real and complex types.
aoclsparse_?sctrscatter the elements of a compressed sparse vector into a dense vector.Let \(y\in R^m\) (or \(C^m\)) be a dense vector, and \(x\) be a compressed sparse vector with \(I_x\) be its nonzero indices set of length at least
nnzand described by the arrayindx, then\[ y_{I_{x_{i}}} = x_i, \quad i\in\{1,\ldots,{\bf\mathsf{nnz}}\}. \]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 "aoclsparse.h" 25 26#include <cfloat> 27#include <cmath> 28#include <complex> 29#include <iomanip> 30#include <iostream> 31#include <vector> 32 33// Sample program to illustrate the usage of scatter of a compressed sparse vector to the full storage form (complex double precision) 34// Using other precisions are also similar to below example 35int main(void) 36{ 37 std::cout << "--------------------------------" << std::endl 38 << "---- Scatter sample program ----" << std::endl 39 << "--------------------------------" << std::endl 40 << std::endl; 41 42 // Number of non-zeros of the sparse vector 43 const aoclsparse_int nnz = 3; 44 45 // Sparse index vector (does not need to be ordered) 46 std::vector<aoclsparse_int> indx = {0, 3, 6}; 47 // Sparse value vector in compressed form 48 std::vector<std::complex<double>> x{{1.01, -1.13}, {2.4, -2.0}, {-0.3, 1.3}}; 49 50 // Output vector 51 std::vector<std::complex<double>> y{{0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}}; 52 53 // Expected output vector 54 std::vector<std::complex<double>> y_exp{ 55 {1.01, -1.13}, {0, 0}, {0, 0}, {2.4, -2.0}, {0, 0}, {0, 0}, {-0.3, 1.3}}; 56 57 aoclsparse_int ny = y.size(); 58 59 aoclsparse_status status; 60 61 std::cout << "Invoking aoclsparse_zsctr...\n"; 62 //Invoke complex scatter 63 status = aoclsparse_zsctr(nnz, x.data(), indx.data(), y.data()); 64 if(status != aoclsparse_status_success) 65 { 66 std::cerr << "Error returned from aoclsparse_zsctr, status = " << status << "." 67 << std::endl; 68 return 3; 69 } 70 71 // Check and print the result 72 std::cout << "Scatter to vector y: " << std::endl 73 << std::setw(10) << "y" 74 << " " << std::setw(17) << "expected y" << std::endl; 75 std::cout << std::fixed; 76 std::cout.precision(4); 77 bool oki, ok = true; 78 for(aoclsparse_int i = 0; i < ny; i++) 79 { 80 oki = y[i] == y_exp[i]; 81 ok &= oki; 82 std::cout << std::setw(11) << y[i] << std::setw(3) << "" << std::setw(11) << y_exp[i] 83 << std::setw(2) << (oki ? "" : " ! Error") << std::endl; 84 } 85 return (ok ? 0 : 6); 86}
Note
The contents of the vectors are not checked for NaNs.
- Parameters:
nnz – [in] The number of elements to use from \(x\) and \({\bf\mathsf{indx}}\).
x – [in] Dense array of at least size \({\bf\mathsf{nnz}}\). The first \({\bf\mathsf{nnz}}\) elements are to be scattered.
indx – [in] Nonzero index set for \(x\) of size at least \({\bf\mathsf{nnz}}\). The first \({\bf\mathsf{nnz}}\) indices are used for the scattering. The elements in this vector are only checked for non-negativity. The user should make sure that index is less than the size of
y.y – [out] Array of at least \(\max(I_{x_i}, i \in \{ 1,\ldots,{\bf\mathsf{nnz}}\})\) elements.
- Return values:
aoclsparse_status_success – The operation completed successfully.
aoclsparse_status_invalid_pointer – At least one of the pointers
x,indx,yis invalid.aoclsparse_status_invalid_size – Indicates that provided
nnzis less than zero.aoclsparse_status_invalid_index_value – At least one of the indices in indx is negative.