Performs the operation X = X + alpha * Y, where X and Y are sparse arrays.
Synopsis
g2-sparse-add
(value-array-1: class quantity-array, index-array-1: class integer-array,
value-array-2: class quantity-array, index-array-2: class integer-array,
full-array: class quantity-array, alpha: quantity, range: class integer-array,
full-array-initialized: truth-value)
Description
g2-sparse-add performs the operation X = X + alpha * Y, where X is the array represented in sparse format by value-array1 and index-array1, and Y is the array represented in sparse format by value-array2 and index-array2. The result is placed in the first sparse array (value-array1 and index-array1).g2-sparse-add follows these rules:
g2-sparse-add adds only those elements of each value array that are within the range specified for that value array. See the description of the range argument below.
g2-sparse-add adds the two elements and includes the sum as an element of the resulting array. In the resulting array, the sum has the same index value as the two elements that were added.
value-array2 to an element of value-array1, g2-sparse-add multiplies the element of value-array2 by alpha.
g2-sparse-add includes the given element in the resulting array, without performing any addition. In the resulting array, the given element keeps its original index value.
value-array2, g2-sparse-add multiplies the element by alpha before including it in the resulting array.
range argument is an integer-array containing four elements that specify the range of elements in the two value arrays that can be added:
range define the range for the first value array, by specifying the indexes in the first value array of the first and last elements to include in the range.
range define the range for the second value array, by specifying the indexes in the second value array of the first and last elements to include in the range.
range as:
0, 4, 0, 4
0, (length of value-array-1 - 1), 0, (length of value-array-2 - 1)
g2-sparse-add is called with the following arguments:
call g2-sparse-add(value-a, index-a, value-b, index-b, full, 1.0, range, true);
value-a = (4, 5, 6)
index-a = (0, 1, 2)
value-b = (1, 2)
index-b = (0, 2)
full = (1, 0, 2, 0, 0, 0)
range = (0, 1, 0, 1)
full-array-initialized = true
g2-sparse-add returns the following values to value-a:
(5, 5, 2)
g2-sparse-add does the following:
value-a, 5, in the result. g2-sparse-add does not add this element to the corresponding element of the other value array, because that corresponding element has a different index value.
value-a is 1. Thus, the second element of the result is 5.
value-b, 2, in the result. g2-sparse-add does not add this element to the corresponding element of the other value array, because the corresponding element has a different index value.
value-b is 2. Thus, the third element of the result is 2.