tpapp / TransformVariables.jl
Showing 1 of 6 files from the diff.
Newly tracked file
src/experimental.jl created.
Other files ignored by Codecov

@@ -0,0 +1,82 @@
Loading
1 +
"""
2 +
This is an in-progress rewrite of the package that will be released, primarily for testing
3 +
it in production.
4 +
5 +
For the purposes of SemVer, this is **not** part of the API. Changes will be reflected as
6 +
patch releases until it is merged.
7 +
"""
8 +
module Experimental
9 +
10 +
using ArgCheck: @argcheck
11 +
using StaticArrays: SArray
12 +
using TransformVariables: LogJacFlag, LogJac, NoLogJac,
13 +
    LOGJAC, NOLOGJAC, logjac_zero, AbstractTransform
14 +
import TransformVariables: as, dimension, transform, transform_with
15 +
16 +
####
17 +
#### generic
18 +
####
19 +
20 +
# NOTE: it is fortunate that we mispelled the abstract type name previously ;-)
21 +
abstract type AbstractTransformation <: AbstractTransform end
22 +
23 +
"""
24 +
_transform(flag::LogJacFlag, transformation::AbstractTransformation, x::AbstractVector)
25 +
26 +
Transform elements of `x` using `transformation`.
27 +
28 +
Return `(y, logjac)′`, where
29 +
30 +
- `y` is the result of the transformation,
31 +
32 +
- `logjac` is the the log Jacobian determinant or a placeholder, depending on `flag`,
33 +
34 +
**Internal function**. Methods can assume that `length(x) == dimension(transformation)`.
35 +
"""
36 +
function _transform end
37 +
38 +
# hook into existing API
39 +
function transform_with(flag::LogJacFlag, transformation::AbstractTransformation,
40 +
                        x::AbstractVector, index::Int)
41 +
    d = dimension(transformation)
42 +
    y, lj = _transform(flag, transformation, view(x, index:(index+d-1)))
43 +
    y, lj, index + d
44 +
end
45 +
46 +
function transform(transformation::AbstractTransformation, x::AbstractVector)
47 +
    first(_transform(NOLOGJAC, transformation, x))
48 +
end
49 +
50 +
function transform_and_logjac(transformation::AbstractTransformation, x::AbstractVector)
51 +
    _transform(LOGJAC, transformation, x)
52 +
end
53 +
54 +
####
55 +
#### transformations
56 +
####
57 +
58 +
# struct asArrayView{N,S<:NTuple{N,Int}}
59 +
#     dimension::S
60 +
# end
61 +
62 +
# function as_array_view(dimension::NTuple{N,Int}) where N
63 +
#     @argcheck all(x -> x ≥ 1, dimension)
64 +
#     asArrayView{N,typeof(dimension)}(dimension)
65 +
# end
66 +
67 +
struct asStaticArray{D,S} <: AbstractTransformation end
68 +
69 +
function as(::Type{<:SArray{S}}) where S
70 +
    dim = fieldtypes(S)
71 +
    @argcheck all(x -> x ≥ 1, dim)
72 +
    asStaticArray{prod(dim),S}()
73 +
end
74 +
75 +
dimension(transformation::asStaticArray{D}) where D = D
76 +
77 +
function _transform(flag::LogJacFlag, transformation::asStaticArray{D,S},
78 +
                    x::AbstractVector{T}) where {D,S,T}
79 +
    SArray{S}(x), logjac_zero(flag, T)
80 +
end
81 +
82 +
end
Files Coverage
src 97.90%
Project Totals (8 files) 97.90%
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading