From d2ffb8abf32387a11eb99b858d5e5ee8bd8018a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Mon, 8 Apr 2024 13:42:44 +0200 Subject: [PATCH] Address review comments (#274) * Address review comments * Add shortcut * Fix --- paper/paper.tex | 44 +++++++++++++++++++++++--------------------- paper/prep.rb | 2 +- paper/ref.bib | 2 +- 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/paper/paper.tex b/paper/paper.tex index 20de2e80..8397d5f1 100644 --- a/paper/paper.tex +++ b/paper/paper.tex @@ -64,7 +64,7 @@ \section{Design consideration} \subsection{May mutate} \label{sec:may_mutate} Consider the task of summing the elements of a vector. -By default, Julia's \lstinline|sum| function will compute the sum with a code equivalent to the following: +By default, Julia's \lstinline|sum| function will compute the sum with a method equivalent to the following: \jlinputlisting{code/sum.jl} If the type of the elements of \lstinline|x| is \lstinline|BigInt|, it is more efficient to replace the line \lstinline|acc = acc + el| by the line @@ -106,9 +106,9 @@ \subsection{May mutate} as well as the \lstinline|destructive_add!| function in JuMP v0.20. \subsection{Should mutate} -In situations where the correctness of a code depends on +In situations where the correctness of code depends on the mutation of the first argument of an operation, -an API that allows an implementation to silently returns the +an API that allows an implementation to silently return the result without modifying the first argument is not appropriate. To motivate this, consider the \lstinline|Rational| Julia type: @@ -117,9 +117,8 @@ \subsection{Should mutate} product of \lstinline|a::Rational| and some other rational \lstinline|b::Rational| (ignoring the simplification with \lstinline|gcd| for simplicity). -Using \lstinline|a.num = mul!!(a.num, b.num)| and -\lstinline|a.den = mul!!(a.den, b.den)| -(where \lstinline|mul!!| follows BangBang's convention) +Using \lstinline|a.num = mul!!(a.num, b.num); a.den = mul!!(a.den, b.den)| +(where \lstinline|mul!!| follows BangBang's conventioni) is not an option since the \lstinline|Rational| struct is not mutable. @@ -134,8 +133,8 @@ \subsection{Mutability} An implementation \lstinline|mul!!| (where \lstinline|mul!!| \emph{may} mutate its first argument and \lstinline|mul!| \emph{should} mutate its first argument) for rational numbers could be: \begin{jllisting} -function mul!!(a::Rational{S}, b::Rational{T}) - if # S can be mutated to `*(::S, ::T)` +function mul!!(a::Rational{S}, b::Rational{T}) where {S,T} + if # `S` can be mutated to `*(::S, ::T)` mul!(a.num, b.num) mul!(a.den, b.den) return a @@ -216,7 +215,7 @@ \subsection{May mutate fallback} \subsection{Mutability fallback} It turns out that all types considered at the moment fall into two categories. The first category is made of the types \lstinline|T| for which -\lstinline|mutability(T, ...)| always return \lstinline|IsNotMutable()|. +\lstinline|mutability(T, ...)| always returns \lstinline|IsNotMutable()|. These are typically the non-mutable types, e.g., \lstinline|Int|, \lstinline|Float64|, \lstinline|Rational{Int}|, ... In the second category are the types \lstinline|T| for which \lstinline|mutability(T, op, args...)| returns \lstinline|IsMutable()| @@ -266,8 +265,8 @@ \subsection{Minimal interface} Then \begin{unnumlist} \item \lstinline|mutability(::Foo, +, Foo, Foo)|, - \item \lstinline|operate!!(+, ::Foo, ::Foo)| and - \item \lstinline|operate_to!!(::Foo, +, ::Foo, ::Foo)| + \item \lstinline|operate!!(+, ::Foo, ::Foo)|, + \item \lstinline|operate_to!!(::Foo, +, ::Foo, ::Foo)|, \item \lstinline|add!!(::Foo, ::Foo)| and \item \lstinline|add_to!!(::Foo, ::Foo, ::Foo)| \end{unnumlist} @@ -356,19 +355,21 @@ \subsection{Matrix-vector product} \ma{} enables operations to communicate the buffers they need to allocate through the \lstinline|buffer_for| function. The buffer can then be reused between multiple occurrences of the same operation with \lstinline|buffered_operate!|. By default, \lstinline|buffer_for| returns \lstinline|nothing| -and \lstinline|buffered_operate!| has the following fallback: +and \lstinline|buffered_operate!| has the following fallback (where \lstinline|MA| is a shortcut for \lstinline|MutableArithmetics|): \begin{jllisting} -buffered_operate!(::Nothing, args...) = operate!(args...) +MA.buffered_operate!(::Nothing, args...) = operate!(args...) \end{jllisting} -The buffer can be reused by implementing: +The implementation of the following two methods in MutableArithmetics +allows the buffer to be created and reused by a generic method that is not +specific to \lstinline|BigInt|: \begin{jllisting} -function buffer_for( +function MA.buffer_for( ::typeof(add_mul), ::Type{BigInt}..., ) return BigInt() end -function buffered_operate!( +function MA.buffered_operate!( buffer::BigInt, ::typeof(add_mul), a::BigInt, @@ -379,12 +380,13 @@ \subsection{Matrix-vector product} return operate!(+, a, buffer) end \end{jllisting} -Then, the matrix multiplication can create the buffer -only once with +This is used by the implementation of matrix-vector +multiplication in MutableArithmetics to create the +buffer once with \begin{jllisting} buf = buffer_for(add_mul, eltype(c), eltype(A), eltype(b)) \end{jllisting} -and then call +and then reuse it with \begin{jllisting} buffered_operate!(buf, add_mul, c[i], A[i, j], b[j]) \end{jllisting} @@ -446,8 +448,8 @@ \subsection{Mutability layers} add_mul, typeof(c), typeof(A), typeof(b)) 0 -julia> @allocated buffered_operate!( - buf, add_mul, c, A, b) +julia> @ballocated buffered_operate!( + $buf, add_mul, $c, $A, $b) 0 \end{jllisting} diff --git a/paper/prep.rb b/paper/prep.rb index 6da32f46..ce05d191 100644 --- a/paper/prep.rb +++ b/paper/prep.rb @@ -34,7 +34,7 @@ # hypersetup f << "\\hypersetup{\n" f << "pdftitle = {#{metadata["title"]}},\n" - f << "pdfsubject = {JuliaCon 2019 Proceedings},\n" + f << "pdfsubject = {JuliaCon 2021 Proceedings},\n" author_list = metadata['authors'].map { |a| a['name'] }.join(', ') f << "pdfauthor = {#{author_list}},\n" keyword_list = metadata['keywords'].join(', ') diff --git a/paper/ref.bib b/paper/ref.bib index 533248b7..1a85ce43 100644 --- a/paper/ref.bib +++ b/paper/ref.bib @@ -120,7 +120,7 @@ @ARTICLE{BenchmarkTools.jl-2016 @Conference{weisser2019polynomial, author = {Weisser, Tillmann and Legat, Beno{\^\i}t and Coey, Chris and Kapelevich, Lea and Vielma, Juan Pablo}, - title = {Polynomial and Moment Optimization in Julia and JuMP}, + title = {{Polynomial and Moment Optimization in Julia and JuMP}}, booktitle = {JuliaCon}, year = {2019}, url = {https://pretalx.com/juliacon2019/talk/QZBKAU/},