88[ ![ version] [ version-img ]] [ version-url ]
99[ ![ pkgeval] [ pkgeval-img ]] [ pkgeval-url ]
1010
11- ** MutableArithmetics** (MA for short) is a [ Julia] ( http://julialang.org ) package which allows:
12- * for mutable types to implement mutable arithmetics;
13- * for algorithms that could exploit mutable arithmetics to exploit them while still being completely generic.
11+ ** MutableArithmetics** (MA for short) is a [ Julia] ( http://julialang.org ) package
12+ which allows:
13+ * for mutable types to implement mutable arithmetics
14+ * for algorithms that could exploit mutable arithmetics to exploit them while
15+ still being completely generic.
1416
1517While in some cases, similar features have been included in packages
16- idiosyncratically, the goal of this package is to provide a generic interface to
17- allow anyone to make use of mutability when desired.
18+ idiosyncratically, the goal of MutableArithmetics is to provide a generic
19+ interface to allow anyone to make use of mutability when desired.
1820
19- The package allows a given type to declare itself mutable through the
20- ` MA.mutability ` trait.
21- Then the user can use the ` MA.operate!! ` function to write generic code
21+ The package allows a type to declare itself mutable through the ` MA.mutability `
22+ trait. Then the user can use the ` MA.operate!! ` function to write generic code
2223that works for arbitrary type while exploiting mutability of the type
2324if possible. More precisely:
24-
25- * The ` MA.operate!!(op::Function, x, args...) ` redirects to ` op(x, args...) `
26- if ` x ` is not mutable or if the result of the operation cannot be stored in ` x ` .
27- Otherwise, it redirects to ` MA.operate!(op, x, args...) ` .
28- * ` MA.operate!(op::Function, x, args...) ` stores the result of the
29- operation in ` x ` . It is a ` MethodError ` if ` x ` is not mutable or if the
30- result of the operation cannot be stored in ` x ` .
31-
32- So from a generic code, ` MA.operate!! ` can be used when the value of ` x ` is not
33- used anywhere else to recycle it if possible. This allows the code to both
34- work for mutable and for non-mutable type.
35-
36- When the type is known to be mutable, ` MA.operate! ` can be used to make
37- sure the operation is done in-place. If it is not possible, the ` MethodError `
38- allows to easily fix the issue while ` MA.operate!! ` would have silently fallen
39- back to the non-mutating function.
40-
41- In conclusion, the distinction between ` MA.operate!! ` and ` MA.operate! `
42- allows to cover all use case while having an universal convention accross all
43- operations.
44-
45- The following types implement the MutableArithmetics API:
46- * The API is implemented for ` Base.BigInt ` in ` src/bigint.jl ` .
47- * The API is implemented for ` Base.BigFloat ` in ` src/bigfloat.jl ` .
48- * The API is implemented for ` Base.Array ` in ` src/linear_algebra.jl ` .
49- * The ` Polynomial ` type of [ Polynomials.jl] ( https://github.com/JuliaMath/Polynomials.jl ) .
50- * The interface for multivariate polynomials [ MultivariatePolynomials] ( https://github.com/JuliaAlgebra/MultivariatePolynomials.jl )
51- as well as its two implementations [ DynamicPolynomials] ( https://github.com/JuliaAlgebra/DynamicPolynomials.jl )
52- and [ TypedPolynomials] ( https://github.com/JuliaAlgebra/TypedPolynomials.jl ) .
53- * The scalar and quadratic functions used to define an Optimization Program in
54- [ MathOptInterface] ( https://github.com/jump-dev/MathOptInterface.jl ) .
55- * The scalar and quadratic expressions used to model optimization in
56- [ JuMP] ( https://github.com/jump-dev/JuMP.jl ) .
57-
58- The algorithms from the following libraries use the MutableArithmetics API
59- to exploit the mutability of the type when possible:
60- * The multivariate polynomials implemented in [ MultivariatePolynomials] ( https://github.com/JuliaAlgebra/MultivariatePolynomials.jl ) ,
61- [ DynamicPolynomials] ( https://github.com/JuliaAlgebra/DynamicPolynomials.jl )
62- and [ TypedPolynomials] ( https://github.com/JuliaAlgebra/TypedPolynomials.jl )
63- work with any type and exploit the mutability of the type through the MA API.
64-
65- In addition, the implementation of the following functionalities available from
66- ` Base ` are reimplemented on top of the MA API:
67- * Matrix-matrix, matrix-vector and array-scalar multiplication including
68- ` SparseArrays.AbstractSparseArray ` , ` LinearAlgebra.Adjoint ` ,
69- ` LinearAlgebra.Transpose ` , ` LinearAlgebra.Symmetric ` .
70- * ` Base.sum ` , ` LinearAlgebra.dot ` and ` LinearAlgebra.diagm ` .
25+ * The ` MA.operate!!(op::Function, x, args...) ` redirects to ` op(x, args...) `
26+ if ` x ` is not mutable or if the result of the operation cannot be stored in
27+ ` x ` . Otherwise, it redirects to ` MA.operate!(op, x, args...) ` .
28+ * ` MA.operate!(op::Function, x, args...) ` stores the result of the operation in
29+ ` x ` . It is a ` MethodError ` if ` x ` is not mutable or if the result of the
30+ operation cannot be stored in ` x ` .
31+
32+ So from a generic code perspective, ` MA.operate!! ` can be used when the value of
33+ ` x ` is not used anywhere else. This allows the code to both work for mutable and
34+ for non-mutable type.
35+
36+ When the type is known to be mutable, ` MA.operate! ` can be used to make sure the
37+ operation is done in-place. If it is not possible, the ` MethodError ` allows one
38+ to easily fix the issue while ` MA.operate!! ` would have silently fallen back to
39+ the non-mutating function.
40+
41+ In conclusion, the distinction between ` MA.operate!! ` and ` MA.operate! ` covers
42+ all use case while having an universal convention accross all operations.
43+
44+ ## Implementations
45+
46+ The following types and packages implement the MutableArithmetics API:
47+
48+ * ` Base.BigInt ` in ` src/interfaces/BigInt.jl ` .
49+ * ` Base.BigFloat ` in ` src/interfaces/BigFloat.jl ` .
50+ * ` Base.Array ` in ` src/interfaces/LinearAlgebra.jl ` .
51+ * [ Polynomials.jl] ( https://github.com/JuliaMath/Polynomials.jl ) uses MA for its
52+ ` Polynomial ` type
53+ * [ MultivariatePolynomials] ( https://github.com/JuliaAlgebra/MultivariatePolynomials.jl )
54+ uses MA for its multivariate polynomials, as well as its two implementations
55+ in [ DynamicPolynomials] ( https://github.com/JuliaAlgebra/DynamicPolynomials.jl )
56+ and [ TypedPolynomials] ( https://github.com/JuliaAlgebra/TypedPolynomials.jl )
57+ * [ JuMP] ( https://github.com/jump-dev/JuMP.jl ) and
58+ [ MathOptInterface] ( https://github.com/jump-dev/MathOptInterface.jl ) use
59+ MA for the scalar and quadratic functions used to define an optimization
60+ program
61+
62+ In addition, the implementation of the following ` Base ` functionalities are
63+ reimplemented using the MA API:
64+ * Matrix-matrix, matrix-vector and array-scalar multiplication including
65+ ` SparseArrays.AbstractSparseArray ` , ` LinearAlgebra.Adjoint ` ,
66+ ` LinearAlgebra.Transpose ` , ` LinearAlgebra.Symmetric ` .
67+ * ` Base.sum ` , ` LinearAlgebra.dot ` and ` LinearAlgebra.diagm ` .
7168
7269These methods are reimplemented in this package for several reasons:
7370* The implementation in ` Base ` does not exploit the mutability of the type
@@ -90,11 +87,6 @@ model are subtypes of `MA.AbstractMutable` but are not mutable.
9087The only purpose of this abstract type is to have ` Base ` methods to be dispatched
9188to the implementations of this package. See ` src/dispatch.jl ` for more details.
9289
93- ## Documentation
94-
95- - [ ** STABLE** ] [ docs-stable-url ] &mdash ; ** most recently tagged version of the documentation.**
96- - [ ** LATEST** ] [ docs-dev-url ] &mdash ; * in-development version of the documentation.*
97-
9890## Quick Example & Benchmark
9991
10092``` julia
@@ -184,8 +176,6 @@ BenchmarkTools.Trial: 4910 samples with 1 evaluation.
184176```
185177Note that there are now 0 allocations.
186178
187- > This package started out as a GSoC '19 project.
188-
189179[ docs-stable-img ] : https://img.shields.io/badge/docs-stable-blue.svg
190180[ docs-dev-img ] : https://img.shields.io/badge/docs-dev-blue.svg
191181[ docs-stable-url ] : https://jump.dev/MutableArithmetics.jl/stable
0 commit comments