/
no_transform.jl
58 lines (44 loc) · 1.5 KB
/
no_transform.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
"""
NoTransform()
Identity transform.
Specifies that no transformation should be applied.
"""
struct NoTransform <: AbstractTransform end
"""
NoTransform!()
In-place version of [`NoTransform`](@ref).
"""
struct NoTransform! <: AbstractTransform end
const AnyNoTransform = Union{NoTransform, NoTransform!}
is_inplace(::NoTransform) = false
is_inplace(::NoTransform!) = true
binv(::T, d) where {T <: AnyNoTransform} = T()
length_output(::AnyNoTransform, length_in::Integer) = length_in
eltype_output(::AnyNoTransform, ::Type{T}) where T = T
eltype_input(::AnyNoTransform, ::Type) = nothing
scale_factor(::AnyNoTransform, A, dims) = 1
plan(::NoTransform, A, dims; kwargs...) = IdentityPlan()
plan(::NoTransform!, A, dims; kwargs...) = IdentityPlan!()
"""
IdentityPlan
Type of plan associated to [`NoTransform`](@ref).
"""
struct IdentityPlan <: AbstractCustomPlan end
LinearAlgebra.mul!(y, ::IdentityPlan, x) = (y === x) ? y : copy!(y, x)
LinearAlgebra.ldiv!(y, ::IdentityPlan, x) = mul!(y, IdentityPlan(), x)
Base.:*(::IdentityPlan, x) = copy(x)
Base.:\(::IdentityPlan, x) = copy(x)
"""
IdentityPlan!
Type of plan associated to [`NoTransform!`](@ref).
"""
struct IdentityPlan! <: AbstractCustomPlan end
function LinearAlgebra.mul!(y, ::IdentityPlan!, x)
if x !== y
throw(ArgumentError("in-place IdentityPlan applied to out-of-place data"))
end
y
end
LinearAlgebra.ldiv!(y, ::IdentityPlan!, x) = mul!(y, IdentityPlan!(), x)
Base.:*(::IdentityPlan!, x) = x
Base.:\(::IdentityPlan!, x) = x