From a1ec5f49c007afe5573e33ebd85ba157116d32dc Mon Sep 17 00:00:00 2001 From: "Documenter.jl" Date: Fri, 19 Apr 2024 16:16:40 +0000 Subject: [PATCH] build based on cb2ae25 --- dev/.documenter-siteinfo.json | 2 +- dev/api/index.html | 82 +++++++++++++++++++++++++ dev/index.html | 109 +++++++++++----------------------- dev/objects.inv | Bin 298 -> 344 bytes dev/search_index.js | 2 +- 5 files changed, 119 insertions(+), 76 deletions(-) create mode 100644 dev/api/index.html diff --git a/dev/.documenter-siteinfo.json b/dev/.documenter-siteinfo.json index d5887235..15d6cee4 100644 --- a/dev/.documenter-siteinfo.json +++ b/dev/.documenter-siteinfo.json @@ -1 +1 @@ -{"documenter":{"julia_version":"1.10.2","generation_timestamp":"2024-04-19T15:07:54","documenter_version":"1.3.0"}} \ No newline at end of file +{"documenter":{"julia_version":"1.10.2","generation_timestamp":"2024-04-19T16:16:38","documenter_version":"1.4.0"}} \ No newline at end of file diff --git a/dev/api/index.html b/dev/api/index.html new file mode 100644 index 00000000..82556910 --- /dev/null +++ b/dev/api/index.html @@ -0,0 +1,82 @@ + +API Reference · SparseConnectivityTracer.jl

API Reference

Interface

SparseConnectivityTracer.connectivityFunction
connectivity(f, x)

Enumerates inputs x and primal outputs y=f(x) and returns sparse connectivity matrix C of size (m, n) where C[i, j] is true if the compute graph connects the i-th entry in y to the j-th entry in x.

Example

julia> x = rand(3);
+
+julia> f(x) = [x[1]^2, 2 * x[1] * x[2]^2, sin(x[3])];
+
+julia> connectivity(f, x)
+3×3 SparseArrays.SparseMatrixCSC{Bool, UInt64} with 4 stored entries:
+ 1  ⋅  ⋅
+ 1  1  ⋅
+ ⋅  ⋅  1
source
connectivity(f!, y, x)

Enumerates inputs x and primal outputs y after f!(y, x) and returns sparse connectivity matrix C of size (m, n) where C[i, j] is true if the compute graph connects the i-th entry in y to the j-th entry in x.

source

Internals

SparseConnectivityTracer works by pushing a Number type called Tracer through generic functions:

SparseConnectivityTracer.TracerType
Tracer(indexset) <: Number

Number type keeping track of input indices of previous computations.

See also the convenience constructor tracer. For a higher-level interface, refer to connectivity.

Examples

By enumerating inputs with tracers, we can keep track of input connectivities:

julia> xt = [tracer(1), tracer(2), tracer(3)]
+3-element Vector{Tracer}:
+ Tracer(1,)
+ Tracer(2,)
+ Tracer(3,)
+
+julia> f(x) = [x[1]^2, 2 * x[1] * x[2]^2, sin(x[3])];
+
+julia> yt = f(xt)
+3-element Vector{Tracer}:
+   Tracer(1,)
+ Tracer(1, 2)
+   Tracer(3,)

This works by overloading operators to either keep input connectivities constant, compute unions or set connectivities to zero:

julia> x = tracer(1, 2, 3)
+Tracer(1, 2, 3)
+
+julia> sin(x)  # Most operators don't modify input connectivities.
+Tracer(1, 2, 3)
+
+julia> 2 * x^3
+Tracer(1, 2, 3)
+
+julia> zero(x) # Tracer is strictly operator overloading... 
+Tracer()
+
+julia> 0 * x   # ...and doesn't look at input values.
+Tracer(1, 2, 3)
+
+julia> y = tracer(3, 5)
+Tracer(3, 5)
+
+julia> x + y   # Operations on two Tracers construct union sets
+Tracer(1, 2, 3, 5)
+
+julia> x ^ y
+Tracer(1, 2, 3, 5)

Tracer also supports random number generation and pre-allocations:

julia> M = rand(Tracer, 3, 2)
+3×2 Matrix{Tracer}:
+ Tracer()  Tracer()
+ Tracer()  Tracer()
+ Tracer()  Tracer()
+
+julia> similar(M)
+3×2 Matrix{Tracer}:
+ Tracer()  Tracer()
+ Tracer()  Tracer()
+ Tracer()  Tracer()
+
+julia> M * [x, y]
+3-element Vector{Tracer}:
+ Tracer(1, 2, 3, 5)
+ Tracer(1, 2, 3, 5)
+ Tracer(1, 2, 3, 5)
source
SparseConnectivityTracer.trace_inputFunction
trace_input(x)

Enumerates input indices and constructs Tracers.

Example

julia> x = rand(3);
+
+julia> f(x) = [x[1]^2, 2 * x[1] * x[2]^2, sin(x[3])];
+
+julia> xt = trace_input(x)
+3-element Vector{Tracer}:
+ Tracer(1,)
+ Tracer(2,)
+ Tracer(3,)
+
+julia> yt = f(xt)
+3-element Vector{Tracer}:
+   Tracer(1,)
+ Tracer(1, 2)
+   Tracer(3,)
source

The following utilities can be used to extract input indices from Tracers:

SparseConnectivityTracer.inputsFunction
inputs(tracer)

Return raw UInt64 input indices of a Tracer.

Example

julia> t = tracer(1, 2, 4)
+Tracer(1, 2, 4)
+
+julia> inputs(t)
+3-element Vector{Int64}:
+ 1
+ 2
+ 4
source
diff --git a/dev/index.html b/dev/index.html index c42da64b..355e81e1 100644 --- a/dev/index.html +++ b/dev/index.html @@ -1,5 +1,7 @@ -Home · SparseConnectivityTracer.jl

SparseConnectivityTracer

Documentation for SparseConnectivityTracer.

API reference

Interface

SparseConnectivityTracer.connectivityFunction
connectivity(f, x)

Enumerates inputs x and primal outputs y=f(x) and returns sparse connectivity matrix C of size (m, n) where C[i, j] is true if the compute graph connects the i-th entry in y to the j-th entry in x.

Example

julia> x = rand(3);
+Home · SparseConnectivityTracer.jl

SparseConnectivityTracer.jl

Stable Dev Build Status Coverage Aqua

Fast sparsity detection via operator-overloading.

Will soon include Jacobian sparsity detection (#19) and Hessian sparsity detection (#20).

Installation

To install this package, open the Julia REPL and run

julia> ]add SparseConnectivityTracer

Examples

julia> using SparseConnectivityTracer
+
+julia> x = rand(3);
 
 julia> f(x) = [x[1]^2, 2 * x[1] * x[2]^2, sin(x[3])];
 
@@ -7,76 +9,35 @@
 3×3 SparseArrays.SparseMatrixCSC{Bool, UInt64} with 4 stored entries:
  1  ⋅  ⋅
  1  1  ⋅
- ⋅  ⋅  1
source
connectivity(f!, y, x)

Enumerates inputs x and primal outputs y after f!(y, x) and returns sparse connectivity matrix C of size (m, n) where C[i, j] is true if the compute graph connects the i-th entry in y to the j-th entry in x.

source

Internals

SparseConnectivityTracer works by pushing a Number type called Tracer through generic functions:

SparseConnectivityTracer.TracerType
Tracer(indexset) <: Number

Number type keeping track of input indices of previous computations.

See also the convenience constructor tracer. For a higher-level interface, refer to connectivity.

Examples

By enumerating inputs with tracers, we can keep track of input connectivities:

julia> xt = [tracer(1), tracer(2), tracer(3)]
-3-element Vector{Tracer}:
- Tracer(1,)
- Tracer(2,)
- Tracer(3,)
-
-julia> f(x) = [x[1]^2, 2 * x[1] * x[2]^2, sin(x[3])];
-
-julia> yt = f(xt)
-3-element Vector{Tracer}:
-   Tracer(1,)
- Tracer(1, 2)
-   Tracer(3,)

This works by overloading operators to either keep input connectivities constant, compute unions or set connectivities to zero:

julia> x = tracer(1, 2, 3)
-Tracer(1, 2, 3)
-
-julia> sin(x)  # Most operators don't modify input connectivities.
-Tracer(1, 2, 3)
-
-julia> 2 * x^3
-Tracer(1, 2, 3)
-
-julia> zero(x) # Tracer is strictly operator overloading... 
-Tracer()
-
-julia> 0 * x   # ...and doesn't look at input values.
-Tracer(1, 2, 3)
-
-julia> y = tracer(3, 5)
-Tracer(3, 5)
-
-julia> x + y   # Operations on two Tracers construct union sets
-Tracer(1, 2, 3, 5)
-
-julia> x ^ y
-Tracer(1, 2, 3, 5)

Tracer also supports random number generation and pre-allocations:

julia> M = rand(Tracer, 3, 2)
-3×2 Matrix{Tracer}:
- Tracer()  Tracer()
- Tracer()  Tracer()
- Tracer()  Tracer()
-
-julia> similar(M)
-3×2 Matrix{Tracer}:
- Tracer()  Tracer()
- Tracer()  Tracer()
- Tracer()  Tracer()
-
-julia> M * [x, y]
-3-element Vector{Tracer}:
- Tracer(1, 2, 3, 5)
- Tracer(1, 2, 3, 5)
- Tracer(1, 2, 3, 5)
source
SparseConnectivityTracer.trace_inputFunction
trace_input(x)

Enumerates input indices and constructs Tracers.

Example

julia> x = rand(3);
-
-julia> f(x) = [x[1]^2, 2 * x[1] * x[2]^2, sin(x[3])];
-
-julia> xt = trace_input(x)
-3-element Vector{Tracer}:
- Tracer(1,)
- Tracer(2,)
- Tracer(3,)
-
-julia> yt = f(xt)
-3-element Vector{Tracer}:
-   Tracer(1,)
- Tracer(1, 2)
-   Tracer(3,)
source

The following utilities can be used to extract input indices from Tracers:

SparseConnectivityTracer.inputsFunction
inputs(tracer)

Return raw UInt64 input indices of a Tracer.

Example

julia> t = tracer(1, 2, 4)
-Tracer(1, 2, 4)
-
-julia> inputs(t)
-3-element Vector{Int64}:
- 1
- 2
- 4
source
+ ⋅ ⋅ 1

As a larger example, let's compute the sparsity pattern from a convolutional layer from Flux.jl:

julia> using SparseConnectivityTracer, Flux
+
+julia> x = rand(28, 28, 3, 1);
+
+julia> layer = Conv((3, 3), 3 => 8);
+
+julia> connectivity(layer, x)
+5408×2352 SparseArrays.SparseMatrixCSC{Bool, UInt64} with 146016 stored entries:
+⎡⠙⢶⣄⠀⠀⠀⠈⠻⣦⡀⠀⠀⠀⠘⢷⣄⠀⠀⠀⠀⠀⎤
+⎢⠀⠀⠙⢷⣄⠀⠀⠀⠈⠻⣦⡀⠀⠀⠀⠙⢷⣄⠀⠀⠀⎥
+⎢⠀⠀⠀⠀⠙⢷⣄⠀⠀⠀⠈⠻⣦⡀⠀⠀⠀⠉⠳⣦⡀⎥
+⎢⠙⢷⣄⠀⠀⠀⠉⠻⣦⡀⠀⠀⠈⠙⢷⣄⠀⠀⠀⠈⠁⎥
+⎢⠀⠀⠙⢷⣄⠀⠀⠀⠈⠻⣦⡀⠀⠀⠀⠉⠳⣦⡀⠀⠀⎥
+⎢⠀⠀⠀⠀⠙⢷⣄⠀⠀⠀⠈⠻⣦⡀⠀⠀⠀⠈⠻⣦⡀⎥
+⎢⠙⢷⣄⠀⠀⠀⠉⠻⣦⡀⠀⠀⠈⠙⠷⣤⡀⠀⠀⠈⠁⎥
+⎢⠀⠀⠙⢷⣄⠀⠀⠀⠈⠻⣦⡀⠀⠀⠀⠈⠻⣦⡀⠀⠀⎥
+⎢⠀⠀⠀⠀⠙⢷⣄⠀⠀⠀⠈⠻⢦⣄⠀⠀⠀⠈⠻⣦⡀⎥
+⎢⠙⢷⣄⠀⠀⠀⠉⠻⣦⡀⠀⠀⠀⠉⠻⣦⡀⠀⠀⠈⠁⎥
+⎢⠀⠀⠙⢷⣄⠀⠀⠀⠈⠻⢦⣀⠀⠀⠀⠈⠻⣦⡀⠀⠀⎥
+⎢⠀⠀⠀⠀⠙⢷⣄⠀⠀⠀⠀⠙⢷⣄⠀⠀⠀⠈⠻⣦⡀⎥
+⎢⠙⢷⣄⠀⠀⠀⠈⠻⣦⡀⠀⠀⠀⠈⠻⣦⡀⠀⠀⠀⠀⎥
+⎢⠀⠀⠙⢷⣄⠀⠀⠀⠈⠙⢶⣄⠀⠀⠀⠈⠻⣦⡀⠀⠀⎥
+⎢⣀⠀⠀⠀⠙⢷⣄⡀⠀⠀⠀⠙⢷⣄⡀⠀⠀⠈⠻⣦⡀⎥
+⎢⠙⢷⣄⠀⠀⠀⠈⠛⢶⣄⠀⠀⠀⠈⠻⣦⡀⠀⠀⠀⠀⎥
+⎢⠀⠀⠙⢷⣄⠀⠀⠀⠀⠙⢷⣄⠀⠀⠀⠈⠻⣦⡀⠀⠀⎥
+⎢⣀⠀⠀⠀⠙⠳⣦⣀⠀⠀⠀⠙⢷⣄⡀⠀⠀⠈⠻⣦⡀⎥
+⎢⠙⢷⣄⠀⠀⠀⠀⠙⢷⣄⠀⠀⠀⠈⠻⣦⡀⠀⠀⠀⠀⎥
+⎢⠀⠀⠙⠷⣄⡀⠀⠀⠀⠙⢷⣄⠀⠀⠀⠈⠻⣦⡀⠀⠀⎥
+⎢⣀⠀⠀⠀⠈⠻⣦⣀⠀⠀⠀⠙⢷⣄⡀⠀⠀⠈⠻⣦⡀⎥
+⎢⠙⠷⣄⡀⠀⠀⠀⠙⢷⣄⠀⠀⠀⠈⠻⣦⡀⠀⠀⠀⠀⎥
+⎢⠀⠀⠈⠻⣦⡀⠀⠀⠀⠙⢷⣄⠀⠀⠀⠈⠻⣦⡀⠀⠀⎥
+⎣⠀⠀⠀⠀⠈⠻⣦⠀⠀⠀⠀⠙⢷⣄⠀⠀⠀⠈⠻⢦⡀⎦

SparseConnectivityTracer enumerates inputs x and primal outputs y=f(x) and returns a sparse connectivity matrix C of size $m \times n$, where C[i, j] is true if the compute graph connects the $j$-th entry in x to the $i$-th entry in y.

For more detailled examples, take a look at the API reference.

diff --git a/dev/objects.inv b/dev/objects.inv index 02fc00a0ead48cd79fb2dd31d905ac8a29789652..20b6a7be9f975162610352470abb528586083124 100644 GIT binary patch delta 205 zcmV;;05boo0@wnOlYfq}4uU`ohIgLg5?#@_vKeC{n?ZL|k75pwa=9x8-d;c;XdscP zY5RTcuPDY+IF5rjm%`r(amq9Fz^L)CZnt884n>3sS|o{H-T6b;vKsEFdwRA0;g2O` zMx*;iYs~j92CTzFPK1)xOL29zAkl78Jwb=WXbH5NeA?|3m_`ZJ>>Y#Fz$&MS^AXl7 zjC}+036F`q9UyvOK0Y_)rpOd5QXM1($@b|e%&gm5Zn5?$jmDM1zZ4#nMW5toG$+3S H_BhO(rm$n< delta 159 zcmV;Q0AT;v0;&R#lYfsr3&JoEhWGx816@;a?ItdE6Lc>zxj-adLUI-R?@faghe&lg zxaWQD!;;1)B-Wkw3d9cJ=c N)JLl(z5p3HlFiZEPR0NL diff --git a/dev/search_index.js b/dev/search_index.js index 7064fb18..4cb17067 100644 --- a/dev/search_index.js +++ b/dev/search_index.js @@ -1,3 +1,3 @@ var documenterSearchIndex = {"docs": -[{"location":"","page":"Home","title":"Home","text":"CurrentModule = SparseConnectivityTracer","category":"page"},{"location":"#SparseConnectivityTracer","page":"Home","title":"SparseConnectivityTracer","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"Documentation for SparseConnectivityTracer.","category":"page"},{"location":"#API-reference","page":"Home","title":"API reference","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"","category":"page"},{"location":"#Interface","page":"Home","title":"Interface","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"connectivity","category":"page"},{"location":"#SparseConnectivityTracer.connectivity","page":"Home","title":"SparseConnectivityTracer.connectivity","text":"connectivity(f, x)\n\nEnumerates inputs x and primal outputs y=f(x) and returns sparse connectivity matrix C of size (m, n) where C[i, j] is true if the compute graph connects the i-th entry in y to the j-th entry in x.\n\nExample\n\njulia> x = rand(3);\n\njulia> f(x) = [x[1]^2, 2 * x[1] * x[2]^2, sin(x[3])];\n\njulia> connectivity(f, x)\n3×3 SparseArrays.SparseMatrixCSC{Bool, UInt64} with 4 stored entries:\n 1 ⋅ ⋅\n 1 1 ⋅\n ⋅ ⋅ 1\n\n\n\n\n\nconnectivity(f!, y, x)\n\nEnumerates inputs x and primal outputs y after f!(y, x) and returns sparse connectivity matrix C of size (m, n) where C[i, j] is true if the compute graph connects the i-th entry in y to the j-th entry in x.\n\n\n\n\n\n","category":"function"},{"location":"#Internals","page":"Home","title":"Internals","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"SparseConnectivityTracer works by pushing a Number type called Tracer through generic functions:","category":"page"},{"location":"","page":"Home","title":"Home","text":"Tracer\ntracer\ntrace_input","category":"page"},{"location":"#SparseConnectivityTracer.Tracer","page":"Home","title":"SparseConnectivityTracer.Tracer","text":"Tracer(indexset) <: Number\n\nNumber type keeping track of input indices of previous computations.\n\nSee also the convenience constructor tracer. For a higher-level interface, refer to connectivity.\n\nExamples\n\nBy enumerating inputs with tracers, we can keep track of input connectivities:\n\njulia> xt = [tracer(1), tracer(2), tracer(3)]\n3-element Vector{Tracer}:\n Tracer(1,)\n Tracer(2,)\n Tracer(3,)\n\njulia> f(x) = [x[1]^2, 2 * x[1] * x[2]^2, sin(x[3])];\n\njulia> yt = f(xt)\n3-element Vector{Tracer}:\n Tracer(1,)\n Tracer(1, 2)\n Tracer(3,)\n\nThis works by overloading operators to either keep input connectivities constant, compute unions or set connectivities to zero:\n\njulia> x = tracer(1, 2, 3)\nTracer(1, 2, 3)\n\njulia> sin(x) # Most operators don't modify input connectivities.\nTracer(1, 2, 3)\n\njulia> 2 * x^3\nTracer(1, 2, 3)\n\njulia> zero(x) # Tracer is strictly operator overloading... \nTracer()\n\njulia> 0 * x # ...and doesn't look at input values.\nTracer(1, 2, 3)\n\njulia> y = tracer(3, 5)\nTracer(3, 5)\n\njulia> x + y # Operations on two Tracers construct union sets\nTracer(1, 2, 3, 5)\n\njulia> x ^ y\nTracer(1, 2, 3, 5)\n\nTracer also supports random number generation and pre-allocations:\n\njulia> M = rand(Tracer, 3, 2)\n3×2 Matrix{Tracer}:\n Tracer() Tracer()\n Tracer() Tracer()\n Tracer() Tracer()\n\njulia> similar(M)\n3×2 Matrix{Tracer}:\n Tracer() Tracer()\n Tracer() Tracer()\n Tracer() Tracer()\n\njulia> M * [x, y]\n3-element Vector{Tracer}:\n Tracer(1, 2, 3, 5)\n Tracer(1, 2, 3, 5)\n Tracer(1, 2, 3, 5)\n\n\n\n\n\n","category":"type"},{"location":"#SparseConnectivityTracer.tracer","page":"Home","title":"SparseConnectivityTracer.tracer","text":"tracer(index)\ntracer(indices)\n\nConvenience constructor for Tracer from input indices.\n\n\n\n\n\n","category":"function"},{"location":"#SparseConnectivityTracer.trace_input","page":"Home","title":"SparseConnectivityTracer.trace_input","text":"trace_input(x)\n\nEnumerates input indices and constructs Tracers.\n\nExample\n\njulia> x = rand(3);\n\njulia> f(x) = [x[1]^2, 2 * x[1] * x[2]^2, sin(x[3])];\n\njulia> xt = trace_input(x)\n3-element Vector{Tracer}:\n Tracer(1,)\n Tracer(2,)\n Tracer(3,)\n\njulia> yt = f(xt)\n3-element Vector{Tracer}:\n Tracer(1,)\n Tracer(1, 2)\n Tracer(3,)\n\n\n\n\n\n","category":"function"},{"location":"","page":"Home","title":"Home","text":"The following utilities can be used to extract input indices from Tracers:","category":"page"},{"location":"","page":"Home","title":"Home","text":"inputs","category":"page"},{"location":"#SparseConnectivityTracer.inputs","page":"Home","title":"SparseConnectivityTracer.inputs","text":"inputs(tracer)\n\nReturn raw UInt64 input indices of a Tracer.\n\nExample\n\njulia> t = tracer(1, 2, 4)\nTracer(1, 2, 4)\n\njulia> inputs(t)\n3-element Vector{Int64}:\n 1\n 2\n 4\n\n\n\n\n\n","category":"function"}] +[{"location":"api/","page":"API Reference","title":"API Reference","text":"CurrentModule = Main\nCollapsedDocStrings = true","category":"page"},{"location":"api/#API-Reference","page":"API Reference","title":"API Reference","text":"","category":"section"},{"location":"api/","page":"API Reference","title":"API Reference","text":"","category":"page"},{"location":"api/#Interface","page":"API Reference","title":"Interface","text":"","category":"section"},{"location":"api/","page":"API Reference","title":"API Reference","text":"connectivity","category":"page"},{"location":"api/#SparseConnectivityTracer.connectivity","page":"API Reference","title":"SparseConnectivityTracer.connectivity","text":"connectivity(f, x)\n\nEnumerates inputs x and primal outputs y=f(x) and returns sparse connectivity matrix C of size (m, n) where C[i, j] is true if the compute graph connects the i-th entry in y to the j-th entry in x.\n\nExample\n\njulia> x = rand(3);\n\njulia> f(x) = [x[1]^2, 2 * x[1] * x[2]^2, sin(x[3])];\n\njulia> connectivity(f, x)\n3×3 SparseArrays.SparseMatrixCSC{Bool, UInt64} with 4 stored entries:\n 1 ⋅ ⋅\n 1 1 ⋅\n ⋅ ⋅ 1\n\n\n\n\n\nconnectivity(f!, y, x)\n\nEnumerates inputs x and primal outputs y after f!(y, x) and returns sparse connectivity matrix C of size (m, n) where C[i, j] is true if the compute graph connects the i-th entry in y to the j-th entry in x.\n\n\n\n\n\n","category":"function"},{"location":"api/#Internals","page":"API Reference","title":"Internals","text":"","category":"section"},{"location":"api/","page":"API Reference","title":"API Reference","text":"SparseConnectivityTracer works by pushing a Number type called Tracer through generic functions:","category":"page"},{"location":"api/","page":"API Reference","title":"API Reference","text":"Tracer\ntracer\ntrace_input","category":"page"},{"location":"api/#SparseConnectivityTracer.Tracer","page":"API Reference","title":"SparseConnectivityTracer.Tracer","text":"Tracer(indexset) <: Number\n\nNumber type keeping track of input indices of previous computations.\n\nSee also the convenience constructor tracer. For a higher-level interface, refer to connectivity.\n\nExamples\n\nBy enumerating inputs with tracers, we can keep track of input connectivities:\n\njulia> xt = [tracer(1), tracer(2), tracer(3)]\n3-element Vector{Tracer}:\n Tracer(1,)\n Tracer(2,)\n Tracer(3,)\n\njulia> f(x) = [x[1]^2, 2 * x[1] * x[2]^2, sin(x[3])];\n\njulia> yt = f(xt)\n3-element Vector{Tracer}:\n Tracer(1,)\n Tracer(1, 2)\n Tracer(3,)\n\nThis works by overloading operators to either keep input connectivities constant, compute unions or set connectivities to zero:\n\njulia> x = tracer(1, 2, 3)\nTracer(1, 2, 3)\n\njulia> sin(x) # Most operators don't modify input connectivities.\nTracer(1, 2, 3)\n\njulia> 2 * x^3\nTracer(1, 2, 3)\n\njulia> zero(x) # Tracer is strictly operator overloading... \nTracer()\n\njulia> 0 * x # ...and doesn't look at input values.\nTracer(1, 2, 3)\n\njulia> y = tracer(3, 5)\nTracer(3, 5)\n\njulia> x + y # Operations on two Tracers construct union sets\nTracer(1, 2, 3, 5)\n\njulia> x ^ y\nTracer(1, 2, 3, 5)\n\nTracer also supports random number generation and pre-allocations:\n\njulia> M = rand(Tracer, 3, 2)\n3×2 Matrix{Tracer}:\n Tracer() Tracer()\n Tracer() Tracer()\n Tracer() Tracer()\n\njulia> similar(M)\n3×2 Matrix{Tracer}:\n Tracer() Tracer()\n Tracer() Tracer()\n Tracer() Tracer()\n\njulia> M * [x, y]\n3-element Vector{Tracer}:\n Tracer(1, 2, 3, 5)\n Tracer(1, 2, 3, 5)\n Tracer(1, 2, 3, 5)\n\n\n\n\n\n","category":"type"},{"location":"api/#SparseConnectivityTracer.tracer","page":"API Reference","title":"SparseConnectivityTracer.tracer","text":"tracer(index)\ntracer(indices)\n\nConvenience constructor for Tracer from input indices.\n\n\n\n\n\n","category":"function"},{"location":"api/#SparseConnectivityTracer.trace_input","page":"API Reference","title":"SparseConnectivityTracer.trace_input","text":"trace_input(x)\n\nEnumerates input indices and constructs Tracers.\n\nExample\n\njulia> x = rand(3);\n\njulia> f(x) = [x[1]^2, 2 * x[1] * x[2]^2, sin(x[3])];\n\njulia> xt = trace_input(x)\n3-element Vector{Tracer}:\n Tracer(1,)\n Tracer(2,)\n Tracer(3,)\n\njulia> yt = f(xt)\n3-element Vector{Tracer}:\n Tracer(1,)\n Tracer(1, 2)\n Tracer(3,)\n\n\n\n\n\n","category":"function"},{"location":"api/","page":"API Reference","title":"API Reference","text":"The following utilities can be used to extract input indices from Tracers:","category":"page"},{"location":"api/","page":"API Reference","title":"API Reference","text":"inputs","category":"page"},{"location":"api/#SparseConnectivityTracer.inputs","page":"API Reference","title":"SparseConnectivityTracer.inputs","text":"inputs(tracer)\n\nReturn raw UInt64 input indices of a Tracer.\n\nExample\n\njulia> t = tracer(1, 2, 4)\nTracer(1, 2, 4)\n\njulia> inputs(t)\n3-element Vector{Int64}:\n 1\n 2\n 4\n\n\n\n\n\n","category":"function"},{"location":"#SparseConnectivityTracer.jl","page":"Home","title":"SparseConnectivityTracer.jl","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"(Image: Stable) (Image: Dev) (Image: Build Status) (Image: Coverage) (Image: Aqua)","category":"page"},{"location":"","page":"Home","title":"Home","text":"Fast sparsity detection via operator-overloading.","category":"page"},{"location":"","page":"Home","title":"Home","text":"Will soon include Jacobian sparsity detection (#19) and Hessian sparsity detection (#20).","category":"page"},{"location":"#Installation","page":"Home","title":"Installation","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"To install this package, open the Julia REPL and run ","category":"page"},{"location":"","page":"Home","title":"Home","text":"julia> ]add SparseConnectivityTracer","category":"page"},{"location":"#Examples","page":"Home","title":"Examples","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"julia> using SparseConnectivityTracer\n\njulia> x = rand(3);\n\njulia> f(x) = [x[1]^2, 2 * x[1] * x[2]^2, sin(x[3])];\n\njulia> connectivity(f, x)\n3×3 SparseArrays.SparseMatrixCSC{Bool, UInt64} with 4 stored entries:\n 1 ⋅ ⋅\n 1 1 ⋅\n ⋅ ⋅ 1","category":"page"},{"location":"","page":"Home","title":"Home","text":"As a larger example, let's compute the sparsity pattern from a convolutional layer from Flux.jl:","category":"page"},{"location":"","page":"Home","title":"Home","text":"julia> using SparseConnectivityTracer, Flux\n\njulia> x = rand(28, 28, 3, 1);\n\njulia> layer = Conv((3, 3), 3 => 8);\n\njulia> connectivity(layer, x)\n5408×2352 SparseArrays.SparseMatrixCSC{Bool, UInt64} with 146016 stored entries:\n⎡⠙⢶⣄⠀⠀⠀⠈⠻⣦⡀⠀⠀⠀⠘⢷⣄⠀⠀⠀⠀⠀⎤\n⎢⠀⠀⠙⢷⣄⠀⠀⠀⠈⠻⣦⡀⠀⠀⠀⠙⢷⣄⠀⠀⠀⎥\n⎢⠀⠀⠀⠀⠙⢷⣄⠀⠀⠀⠈⠻⣦⡀⠀⠀⠀⠉⠳⣦⡀⎥\n⎢⠙⢷⣄⠀⠀⠀⠉⠻⣦⡀⠀⠀⠈⠙⢷⣄⠀⠀⠀⠈⠁⎥\n⎢⠀⠀⠙⢷⣄⠀⠀⠀⠈⠻⣦⡀⠀⠀⠀⠉⠳⣦⡀⠀⠀⎥\n⎢⠀⠀⠀⠀⠙⢷⣄⠀⠀⠀⠈⠻⣦⡀⠀⠀⠀⠈⠻⣦⡀⎥\n⎢⠙⢷⣄⠀⠀⠀⠉⠻⣦⡀⠀⠀⠈⠙⠷⣤⡀⠀⠀⠈⠁⎥\n⎢⠀⠀⠙⢷⣄⠀⠀⠀⠈⠻⣦⡀⠀⠀⠀⠈⠻⣦⡀⠀⠀⎥\n⎢⠀⠀⠀⠀⠙⢷⣄⠀⠀⠀⠈⠻⢦⣄⠀⠀⠀⠈⠻⣦⡀⎥\n⎢⠙⢷⣄⠀⠀⠀⠉⠻⣦⡀⠀⠀⠀⠉⠻⣦⡀⠀⠀⠈⠁⎥\n⎢⠀⠀⠙⢷⣄⠀⠀⠀⠈⠻⢦⣀⠀⠀⠀⠈⠻⣦⡀⠀⠀⎥\n⎢⠀⠀⠀⠀⠙⢷⣄⠀⠀⠀⠀⠙⢷⣄⠀⠀⠀⠈⠻⣦⡀⎥\n⎢⠙⢷⣄⠀⠀⠀⠈⠻⣦⡀⠀⠀⠀⠈⠻⣦⡀⠀⠀⠀⠀⎥\n⎢⠀⠀⠙⢷⣄⠀⠀⠀⠈⠙⢶⣄⠀⠀⠀⠈⠻⣦⡀⠀⠀⎥\n⎢⣀⠀⠀⠀⠙⢷⣄⡀⠀⠀⠀⠙⢷⣄⡀⠀⠀⠈⠻⣦⡀⎥\n⎢⠙⢷⣄⠀⠀⠀⠈⠛⢶⣄⠀⠀⠀⠈⠻⣦⡀⠀⠀⠀⠀⎥\n⎢⠀⠀⠙⢷⣄⠀⠀⠀⠀⠙⢷⣄⠀⠀⠀⠈⠻⣦⡀⠀⠀⎥\n⎢⣀⠀⠀⠀⠙⠳⣦⣀⠀⠀⠀⠙⢷⣄⡀⠀⠀⠈⠻⣦⡀⎥\n⎢⠙⢷⣄⠀⠀⠀⠀⠙⢷⣄⠀⠀⠀⠈⠻⣦⡀⠀⠀⠀⠀⎥\n⎢⠀⠀⠙⠷⣄⡀⠀⠀⠀⠙⢷⣄⠀⠀⠀⠈⠻⣦⡀⠀⠀⎥\n⎢⣀⠀⠀⠀⠈⠻⣦⣀⠀⠀⠀⠙⢷⣄⡀⠀⠀⠈⠻⣦⡀⎥\n⎢⠙⠷⣄⡀⠀⠀⠀⠙⢷⣄⠀⠀⠀⠈⠻⣦⡀⠀⠀⠀⠀⎥\n⎢⠀⠀⠈⠻⣦⡀⠀⠀⠀⠙⢷⣄⠀⠀⠀⠈⠻⣦⡀⠀⠀⎥\n⎣⠀⠀⠀⠀⠈⠻⣦⠀⠀⠀⠀⠙⢷⣄⠀⠀⠀⠈⠻⢦⡀⎦","category":"page"},{"location":"","page":"Home","title":"Home","text":"SparseConnectivityTracer enumerates inputs x and primal outputs y=f(x) and returns a sparse connectivity matrix C of size m times n, where C[i, j] is true if the compute graph connects the j-th entry in x to the i-th entry in y.","category":"page"},{"location":"","page":"Home","title":"Home","text":"For more detailled examples, take a look at the API reference.","category":"page"},{"location":"#Related-packages","page":"Home","title":"Related packages","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"SparseDiffTools.jl: automatic sparsity detection via Symbolics.jl and Cassette.jl\nSparsityTracing.jl: automatic Jacobian sparsity detection using an algorithm based on SparsLinC by Bischof et al. (1996)","category":"page"}] }