Open tmigot opened 2 years ago
After #107 only obj
allocate.
Fixing obj
would require writing a function that computes x' * H * x
without allocating (for all H
types).
Isn't there a 3-arguments dot
?
help?> dot
search: dot @__dot__ stdout DEPOT_PATH adjoint Adjoint adjoint! fieldcount codepoint fieldoffset bound_constrained isdisjoint lowrankdowndate lowrankdowndate! denominator VoidListofStates add_to_list! PKGMODE_PROJECT modifyproperty!
dot(x, y)
x ⋅ y
Compute the dot product between two vectors. For complex vectors, the first vector is conjugated.
dot also works on arbitrary iterable objects, including arrays of any dimension, as long as dot is defined on the elements.
dot is semantically equivalent to sum(dot(vx,vy) for (vx,vy) in zip(x, y)), with the added restriction that the arguments must have equal lengths.
x ⋅ y (where ⋅ can be typed by tab-completing \cdot in the REPL) is a synonym for dot(x, y).
Examples
≡≡≡≡≡≡≡≡≡≡
julia> dot([1; 1], [2; 3])
5
julia> dot([im; im], [1; 1])
0 - 2im
julia> dot(1:5, 2:6)
70
julia> x = fill(2., (5,5));
julia> y = fill(3., (5,5));
julia> dot(x, y)
150.0
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
dot(x, A, y)
Compute the generalized dot product dot(x, A*y) between two vectors x and y, without storing the intermediate result of A*y. As for the two-argument dot(_,_), this acts recursively. Moreover, for complex vectors, the first vector is
conjugated.
│ Julia 1.4
│
│ Three-argument dot requires at least Julia 1.4.
Examples
≡≡≡≡≡≡≡≡≡≡
julia> dot([1; 1], [1 2; 3 4], [2; 3])
26
julia> dot(1:5, reshape(1:25, 5, 5), 2:6)
4850
julia> ⋅(1:5, reshape(1:25, 5, 5), 2:6) == dot(1:5, reshape(1:25, 5, 5), 2:6)
true
Oh I didn't know about this function. It would have to be added to SparseMatricesCOO. Also I would keep the existing behaviour in case H is a LinearOperator.
Ok, so if I understand. We should implement this 3-args dot in SparseMatricesCOO and in LinearOperators?
Yes for SparseMatricesCOO. For LinearOperators this is complicated, I would keep the existing code even though it allocates.
How about preallocating storage in the quadratic model to store H * x
? It could be reused for the gradient.
There seems to be two functions of the API allocating
obj
hess_coord
I used the following script to track allocations in QuadraticModels
and the results