Skip to content

Commit 62dd529

Browse files
committed
documentation clean up
1 parent 5aa808c commit 62dd529

File tree

6 files changed

+59
-13
lines changed

6 files changed

+59
-13
lines changed

src/Core/constraint.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,11 @@ end
200200
# It only returns a Bool rather than a number, but simplex! checks
201201
# if the output of the "norm" function equals 1, which is converted
202202
# to a Boolean True. Is there some way to treat this constraint better?
203-
"""all(isnonnegative, x) && sum(x) ≈ 1"""
203+
"""
204+
isnonnegative_sumtoone(x)
205+
206+
Short for `all(isnonnegative, x) && sum(x) ≈ 1`.
207+
"""
204208
isnonnegative_sumtoone(x) = all(isnonnegative, x) && sum(x) 1
205209

206210
"""

src/Core/decomposition.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,12 @@ of the decomposition.
106106
107107
Example
108108
-------
109+
```julia
109110
(op1, op2) = contractions(D)
110111
(A, B, C) = factors(D)
111112
112-
array(D) == (A op1 B) op2 C
113+
array(D) == op2(op1(A, B), C)
114+
```
113115
"""
114116
contractions(D::AbstractDecomposition) = D.contractions
115117

src/Core/factorize.jl

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ function factorize(Y; kwargs...)
3030
end
3131

3232
"""
33+
_factorize(Y; kwargs...)
34+
3335
Inner level function once keyword arguments are set
3436
"""
3537
function _factorize(Y; kwargs...)
@@ -56,6 +58,8 @@ function _factorize(Y; kwargs...)
5658
end
5759

5860
"""
61+
initialize(Y, kwargs)
62+
5963
Main initialization function for `factorize`.
6064
"""
6165
function initialize(Y, kwargs)
@@ -79,6 +83,8 @@ function initialize(Y, kwargs)
7983
end
8084

8185
"""
86+
postprocess!(decomposition, Y, previous, parameters, stats_data, updateparameters!, getstats, kwargs)
87+
8288
Any post algorithm processing that needs to be done in `factorize`.
8389
"""
8490
function postprocess!(decomposition, Y, previous, parameters, stats_data, updateparameters!, getstats, kwargs)
@@ -266,7 +272,11 @@ function finalconstrain!(decomposition; constraints, final_constraints, kwargs..
266272
return NamedTuple(kwargs) # Freeze Dict into a NamedTuple
267273
end
268274

269-
"""The decomposition model Y will be factored into"""
275+
"""
276+
initialize_decomposition(Y; decomposition, model, rank, kwargs...)
277+
278+
The decomposition model Y will be factored into
279+
"""
270280
function initialize_decomposition(Y; decomposition, model, rank, kwargs...)
271281
kwargs = Dict{Symbol,Any}(kwargs)
272282
# have to add these keyword back since it was extracted by make_update # TODO check if I can safely remove these
@@ -282,6 +292,8 @@ function initialize_decomposition(Y; decomposition, model, rank, kwargs...)
282292
end
283293

284294
"""
295+
make_update!(decomposition, Y; momentum, constraints, constrain_init, group_updates_by_factor, do_subblock_updates, kwargs...)
296+
285297
What one iteration of the algorithm looks like.
286298
One iteration is likely a full cycle through each block or factor of the model.
287299
"""
@@ -341,7 +353,11 @@ function make_update!(decomposition, Y; momentum, constraints, constrain_init, g
341353
return update!, kwargs
342354
end
343355

344-
"""The stats that will be saved every iteration"""
356+
"""
357+
initialize_stats(decomposition, Y, previous, parameters; stats, kwargs...)
358+
359+
The stats that will be saved every iteration
360+
"""
345361
function initialize_stats(decomposition, Y, previous, parameters; stats, kwargs...)
346362
stat_functions = [S(; kwargs...) for S in stats] # construct the AbstractStats
347363
#@show stat_functions
@@ -354,7 +370,11 @@ function initialize_stats(decomposition, Y, previous, parameters; stats, kwargs.
354370
return stats_data, getstats
355371
end
356372

357-
"""Keep track of one or more previous iterates"""
373+
"""
374+
initialize_previous(decomposition, Y; previous_iterates::Integer, kwargs...)
375+
376+
Keep track of one or more previous iterates
377+
"""
358378
function initialize_previous(decomposition, Y; previous_iterates::Integer, kwargs...)
359379
previous = [deepcopy(decomposition) for _ in 1:previous_iterates] # TODO check if this should be copy?
360380
if previous_iterates == 0
@@ -372,7 +392,11 @@ function initialize_previous(decomposition, Y; previous_iterates::Integer, kwarg
372392
end
373393
end
374394

375-
"""update parameters needed for the update"""
395+
"""
396+
initialize_parameters(decomposition, Y, previous; momentum::Bool, random_order, recursive_random_order, kwargs...)
397+
398+
update parameters needed for the update
399+
"""
376400
function initialize_parameters(decomposition, Y, previous; momentum::Bool, random_order, recursive_random_order, kwargs...)
377401
# parameters for the update step are symbol => value pairs
378402
# they are held in a dictionary since we may mutate these for ex. the stepsize

src/Core/multiscale.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,11 @@ function scale_constraints(Y, scale; continuous_dims, kwargs...)
221221
return kwargs[:constraints], kwargs
222222
end
223223

224-
"""Use the same initialization as factorize() to get the expanded set of constraints"""
224+
"""
225+
expand_decomposition_constraints(Y, kwargs)
226+
227+
Use the same initialization as [`factorize`](@ref) to get the expanded set of constraints.
228+
"""
225229
function expand_decomposition_constraints(Y, kwargs)
226230
kwargs_copy = deepcopy(kwargs) # Don't mess up anything since the following functions mutate kwargs
227231
kwargs_copy = default_kwargs(Y; kwargs_copy...) # TODO Is there some way to clean this up?

src/Core/tensorproducts.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,12 @@ arguments as matrices in a Tucker decomposition.
150150
151151
Example
152152
-------
153-
```
153+
```julia
154154
tuckerproduct(G, (A, B, C)) == G ×₁ A ×₂ B ×₃ C
155155
tuckerproduct(G, (A, B, C); exclude=2) == G ×₁ A ×₃ C
156156
tuckerproduct(G, (A, B, C); exclude=2, excludes_missing=false) == G ×₁ A ×₃ C
157157
tuckerproduct(G, (A, C); exclude=2, excludes_missing=true) == G ×₁ A ×₃ C
158-
````
158+
```
159159
"""
160160
function tuckerproduct(core, matrices; exclude=nothing, excludes_missing=false)
161161
N = ndims(core)

src/Core/utils.jl

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,18 @@ Base.min(A::AbstractArray, x::Number) = min.(A, x)
102102

103103
# ( (x-1) % 4 +1, (x-1) ÷ 4 % 3 + 1, (x-1) ÷ 4 ÷ 3 % 2 + 1)
104104

105-
"""Like `getindex` but returns the compliment to the index or indices requested."""
106105
getnotindex(A, i::Int; view=false) = view ? (@view A[eachindex(A) .!= i]) : A[eachindex(A) .!= i]
107106
getnotindex(A, I; view=false) = view ? (@view A[eachindex(A) .∉ (I,)]) : A[eachindex(A) .∉ (I,)]
108107

108+
docs = """ getnotindex(A, i::Int; view=false)
109+
getnotindex(A, I; view=false)
110+
111+
Like `getindex` but returns the compliment to the index or indices requested.
112+
"""
113+
114+
@doc docs getnotindex
115+
# Want both methods to receive this documentation
116+
109117
"""
110118
eachfibre(A::AbstractArray; n::Integer, kwargs...)
111119
@@ -145,7 +153,11 @@ end
145153

146154
#fullouter(v...) = reshape(kron(reverse(vec.(v))...),tuple(vcat(collect.(size.(v))...)...))
147155

148-
"""Makes a Tuple of length n filled with `false`."""
156+
"""
157+
false_tuple(n::Integer)
158+
159+
Makes a Tuple of length n filled with `false`.
160+
"""
149161
false_tuple(n::Integer) = Tuple(fill(false, n))
150162

151163
"""
@@ -293,7 +305,7 @@ end
293305
294306
Geometric mean of a collection: `prod(v)^(1/length(v))`.
295307
296-
If prod(v) is detected to be 0 or Inf, the safer (but slower) implementation `exp(mean(log.(v)))` is used.
308+
If `prod(v)` is detected to be `0` or `Inf`, the safer (but slower) implementation `exp(mean(log.(v)))` is used.
297309
"""
298310
function geomean(v)
299311
p = prod(v)
@@ -317,7 +329,7 @@ Like `foldl`, but with a different folding operation between each argument.
317329
318330
Example
319331
=======
320-
```
332+
```julia-repl
321333
julia> multifoldl((+,*,-), (2,3,4,5))
322334
15
323335

0 commit comments

Comments
 (0)