comparison src/LazyTensors/lazy_tensor_operations.jl @ 838:76e5682d0e52 feature/setup_documenter

Fix a bunch of docstring mistakes
author Jonatan Werpers <jonatan@werpers.com>
date Fri, 14 Jan 2022 09:19:07 +0100
parents 1c512e796c6d
children b41180efb6c2 4a9a96d51940 7829c09f8137
comparison
equal deleted inserted replaced
837:126e169bb0b7 838:76e5682d0e52
74 Base.:-(tm1::TensorMapping{T,R,D}, tm2::TensorMapping{T,R,D}) where {T,R,D} = LazyTensorMappingBinaryOperation{:-,T,R,D}(tm1,tm2) 74 Base.:-(tm1::TensorMapping{T,R,D}, tm2::TensorMapping{T,R,D}) where {T,R,D} = LazyTensorMappingBinaryOperation{:-,T,R,D}(tm1,tm2)
75 75
76 """ 76 """
77 TensorMappingComposition{T,R,K,D} 77 TensorMappingComposition{T,R,K,D}
78 78
79 Lazily compose two TensorMappings, so that they can be handled as a single TensorMapping. 79 Lazily compose two `TensorMapping`s, so that they can be handled as a single `TensorMapping`.
80 """ 80 """
81 struct TensorMappingComposition{T,R,K,D, TM1<:TensorMapping{T,R,K}, TM2<:TensorMapping{T,K,D}} <: TensorMapping{T,R,D} 81 struct TensorMappingComposition{T,R,K,D, TM1<:TensorMapping{T,R,K}, TM2<:TensorMapping{T,K,D}} <: TensorMapping{T,R,D}
82 t1::TM1 82 t1::TM1
83 t2::TM2 83 t2::TM2
84 84
163 163
164 apply(tmi::IdentityMapping{T,D}, v::AbstractArray{T,D}, I::Vararg{Any,D}) where {T,D} = v[I...] 164 apply(tmi::IdentityMapping{T,D}, v::AbstractArray{T,D}, I::Vararg{Any,D}) where {T,D} = v[I...]
165 apply_transpose(tmi::IdentityMapping{T,D}, v::AbstractArray{T,D}, I::Vararg{Any,D}) where {T,D} = v[I...] 165 apply_transpose(tmi::IdentityMapping{T,D}, v::AbstractArray{T,D}, I::Vararg{Any,D}) where {T,D} = v[I...]
166 166
167 """ 167 """
168 Base.:∘(tm, tmi) 168 Base.:∘(tm, tmi)
169 Base.:∘(tmi, tm) 169 Base.:∘(tmi, tm)
170 170
171 Composes a `Tensormapping` `tm` with an `IdentityMapping` `tmi`, by returning `tm` 171 Composes a `Tensormapping` `tm` with an `IdentityMapping` `tmi`, by returning `tm`
172 """ 172 """
173 @inline function Base.:∘(tm::TensorMapping{T,R,D}, tmi::IdentityMapping{T,D}) where {T,R,D} 173 @inline function Base.:∘(tm::TensorMapping{T,R,D}, tmi::IdentityMapping{T,D}) where {T,R,D}
174 @boundscheck check_domain_size(tm, range_size(tmi)) 174 @boundscheck check_domain_size(tm, range_size(tmi))
314 # https://github.com/JuliaLang/julia/issues/30386 314 # https://github.com/JuliaLang/julia/issues/30386
315 """ 315 """
316 slice_tuple(t, Val(l), Val(u)) 316 slice_tuple(t, Val(l), Val(u))
317 317
318 Get a slice of a tuple in a type stable way. 318 Get a slice of a tuple in a type stable way.
319 Equivalent to t[l:u] but type stable. 319 Equivalent to `t[l:u]` but type stable.
320 """ 320 """
321 function slice_tuple(t,::Val{L},::Val{U}) where {L,U} 321 function slice_tuple(t,::Val{L},::Val{U}) where {L,U}
322 return ntuple(i->t[i+L-1], U-L+1) 322 return ntuple(i->t[i+L-1], U-L+1)
323 end 323 end
324 324
325 """ 325 """
326 split_tuple(t::Tuple{...}, ::Val{M}) where {N,M} 326 split_tuple(t::Tuple{...}, ::Val{M}) where {N,M}
327 327
328 Split the tuple `t` into two parts. the first part is `M` long. 328 Split the tuple `t` into two parts. the first part is `M` long.
329 E.g 329 E.g
330 ``` 330 ```julia
331 split_tuple((1,2,3,4),Val(3)) -> (1,2,3), (4,) 331 split_tuple((1,2,3,4),Val(3)) -> (1,2,3), (4,)
332 ``` 332 ```
333 """ 333 """
334 function split_tuple(t::NTuple{N,Any},::Val{M}) where {N,M} 334 function split_tuple(t::NTuple{N,Any},::Val{M}) where {N,M}
335 return slice_tuple(t,Val(1), Val(M)), slice_tuple(t,Val(M+1), Val(N)) 335 return slice_tuple(t,Val(1), Val(M)), slice_tuple(t,Val(M+1), Val(N))
355 """ 355 """
356 flatten_tuple(t::NTuple{N, Number} where N) = t 356 flatten_tuple(t::NTuple{N, Number} where N) = t
357 flatten_tuple(t::Tuple) = ((flatten_tuple.(t)...)...,) # simplify? 357 flatten_tuple(t::Tuple) = ((flatten_tuple.(t)...)...,) # simplify?
358 flatten_tuple(ts::Vararg) = flatten_tuple(ts) 358 flatten_tuple(ts::Vararg) = flatten_tuple(ts)
359 359
360 """ 360 @doc raw"""
361 LazyOuterProduct(tms...) 361 LazyOuterProduct(tms...)
362 362
363 Creates a `TensorMappingComposition` for the outerproduct of `tms...`. 363 Creates a `TensorMappingComposition` for the outerproduct of `tms...`.
364 This is done by separating the outer product into regular products of outer products involving only identity mappings and one non-identity mapping. 364 This is done by separating the outer product into regular products of outer products involving only identity mappings and one non-identity mapping.
365 365
366 First let 366 First let
367 ```math 367 ```math
368 A = A_{I,J} 368 \begin{aligned}
369 B = B_{M,N} 369 A &= A_{I,J} \\
370 C = C_{P,Q} 370 B &= B_{M,N} \\
371 C &= C_{P,Q} \\
372 \end{aligned}
371 ``` 373 ```
372 374
373 where ``I``, ``M``, ``P`` are multi-indexes for the ranges of ``A``, ``B``, ``C``, and ``J``, ``N``, ``Q`` are multi-indexes of the domains. 375 where ``I``, ``M``, ``P`` are multi-indexes for the ranges of ``A``, ``B``, ``C``, and ``J``, ``N``, ``Q`` are multi-indexes of the domains.
374 376
375 We use ``⊗`` to denote the outer product 377 We use ``⊗`` to denote the outer product
383 ``` 385 ```
384 And that 386 And that
385 ```math 387 ```math
386 A⊗B⊗C = (A⊗I_{|M|}⊗I_{|P|})(I_{|J|}⊗B⊗I_{|P|})(I_{|J|}⊗I_{|N|}⊗C) 388 A⊗B⊗C = (A⊗I_{|M|}⊗I_{|P|})(I_{|J|}⊗B⊗I_{|P|})(I_{|J|}⊗I_{|N|}⊗C)
387 ``` 389 ```
388 where |.| of a multi-index is a vector of sizes for each dimension. ``I_v`` denotes the identity tensor of size ``v[i]`` in each direction 390 where ``|⋅|`` of a multi-index is a vector of sizes for each dimension. ``I_v`` denotes the identity tensor of size ``v[i]`` in each direction
389 To apply ``A⊗B⊗C`` we evaluate 391 To apply ``A⊗B⊗C`` we evaluate
390 392
393 ```math
391 (A⊗B⊗C)v = [(A⊗I_{|M|}⊗I_{|P|}) [(I_{|J|}⊗B⊗I_{|P|}) [(I_{|J|}⊗I_{|N|}⊗C)v]]] 394 (A⊗B⊗C)v = [(A⊗I_{|M|}⊗I_{|P|}) [(I_{|J|}⊗B⊗I_{|P|}) [(I_{|J|}⊗I_{|N|}⊗C)v]]]
395 ```
392 """ 396 """
393 function LazyOuterProduct end 397 function LazyOuterProduct end
394 export LazyOuterProduct 398 export LazyOuterProduct
395 399
396 function LazyOuterProduct(tm1::TensorMapping{T}, tm2::TensorMapping{T}) where T 400 function LazyOuterProduct(tm1::TensorMapping{T}, tm2::TensorMapping{T}) where T