Utilities
Numerical helper routines shared across the high-level and low-level interfaces.
KIM_API.add_forces — Methodadd_forces(idx::AbstractArray{<:Integer}, src::AbstractArray)Perform a scatter-add operation to accumulate forces. This function is specifically designed to accumulate forces from multiple atoms into a single destination array based on the provided indices.
Arguments
src::AbstractArray: Source array containing forces to be added.idx::AbstractArray{<:Integer}: Indices in the destination array where forces will be accumulated.
Returns
- A new array containing the accumulated forces at the specified indices.
Note
- This function assumes that
idxcontains valid indices for the destination array. - The destination array is initialized to zero before accumulation.
```
KIM_API.scatter_add! — Methodscatter_add!(dst::AbstractArray, src::AbstractArray, idx::AbstractArray; dims=1)Perform a scatter-add operation in-place. This function adds elements from src to dst at the indices specified by idx. It is useful for accumulating results in a pre-allocated destination vector.
Arguments
dst::AbstractArray: Destination vector where elements will be added.src::AbstractArray: Source vector whose elements are added todst.idx::AbstractArray{<:Integer}: Indices indstwheresrcelements will be added.dims::Int: Dimension along which to scatter-add. Default is 1.
Returns
- The modified
dstvector with accumulated results.