Closed
Description
Steps To Reproduce
In /src/sage/data_structures/blas_dict.pyx
:
cpdef dict linear_combination(dict_factor_iter, bint factor_on_left=True):
r"""
Return the pointwise addition of dictionaries with coefficients.
INPUT:
- ``dict_factor_iter`` -- iterator of pairs ``D``, ``coeff``, where
* the ``D``'s are dictionaries with values in a common ring
* the ``coeff``'s are coefficients in this ring
- ``factor_on_left`` -- boolean (default: ``True``); if ``True``,
the coefficients are multiplied on the left, otherwise they are
multiplied on the right
OUTPUT:
- a dictionary containing all keys of dictionaries in ``dict_list``
with values being the sum of the values in the different
dictionaries and each one first multiplied by the given factor
(keys with zero value are omitted)
EXAMPLES::
sage: import sage.data_structures.blas_dict as blas
sage: D = { 0:1, 1:1 }; D
{0: 1, 1: 1}
sage: blas.linear_combination( (D,i) for i in range(5) )
{0: 10, 1: 10}
sage: blas.linear_combination( [(D,1), (D,-1)] )
{}
"""
cdef dict result = {}
cdef dict D
for D, a in dict_factor_iter:
if not a: # We multiply by 0, so nothing to do
continue
if not result and a == 1:
result = D.copy()
else:
iaxpy(a, D, result, remove_zeros=False)
return remove_zeros(result)
Looks like a bug that factor_on_left
is unused.
Expected Behavior
Actual Behavior
Additional Information
No response
Environment
- OS:
- Sage Version:
Checklist
- I have searched the existing issues for a bug report that matches the one I want to file, without success.
- I have read the documentation and troubleshoot guide