---
title: "SparseMultiplyAdd(_:_:_:)"
framework: accelerate
role: symbol
role_heading: Function
path: "accelerate/sparsemultiplyadd(_:_:_:)-7iuo9"
---

# SparseMultiplyAdd(_:_:_:)

Performs the multiply operation y += Ax on a vector of double-precision, floating-point values.

## Declaration

```swift
func SparseMultiplyAdd(_ A: SparseMatrix_Double, _ x: DenseVector_Double, _ y: DenseVector_Double)
```

## Parameters

- `A`: The sparse matrix A in y += Ax.
- `x`: The dense vector x in y += Ax.
- `y`: The dense vector y in y += Ax.

## Discussion

Discussion Use this function to multiply a sparse matrix by a dense vector and accumulate the result. The following equation is an example of a matrix-vector multiplication where the matrix is sparse:

Call SparseMultiplyAdd(_:_:_:) to calculate the result. let rowCount = Int32(4) let columnCount = Int32(4) let blockCount = 4 let blockSize = UInt8(1) let rowIndices: [Int32] = [0, 3, 0, 3] let columnIndices: [Int32] = [0, 0, 3, 3] let data = [1.0, 4.0, 13.0, 16.0]

/// The _A_ in _y+=Ax_. let A = SparseConvertFromCoordinate(rowCount, columnCount,                                     blockCount, blockSize,                                     SparseAttributes_t(),                                     rowIndices, columnIndices,                                     data) defer {     SparseCleanup(A) }

/// The values for _x_ in _y+=Ax_. var xValues = [10.0, -1.0, -1.0, 10.0]

var yValues = [1.0, 1.0, 1.0, 1.0]

/// The values for _y_ in _y+=Ax_. yValues.withUnsafeMutableBufferPointer { yValuesPtr in

xValues.withUnsafeMutableBufferPointer { xValuesPtr in         /// The _x_ in _y+=Ax_.         let x = DenseVector_Double(count: 4,                                    data: xValuesPtr.baseAddress!)                  /// The _y_ in _y+=Ax_.         let y = DenseVector_Double(count: 4,                                    data: yValuesPtr.baseAddress!)                  SparseMultiplyAdd(A, x, y)     } }

/// On return, `yValues` contains: ///      `[ 141.0, 1.0, 1.0, 201.0 ]`

## See Also

### Multiply-add functions

- [SparseMultiplyAdd(_:_:_:)](accelerate/sparsemultiplyadd(_:_:_:)-ineu.md)
- [SparseMultiplyAdd(_:_:_:_:)](accelerate/sparsemultiplyadd(_:_:_:_:)-3oa6n.md)
- [SparseMultiplyAdd(_:_:_:_:)](accelerate/sparsemultiplyadd(_:_:_:_:)-8n6xy.md)
