• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

kunzaatko / TransferFunctions.jl / 16677608671

01 Aug 2025 02:26PM UTC coverage: 66.449% (-4.0%) from 70.433%
16677608671

push

github

kunzaatko
fix: free InterfaceFunctions.jl

305 of 459 relevant lines covered (66.45%)

1840350.53 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

75.0
/src/types/sampled-array.jl
1
using Base: CartesianIndices
2
# TODO: This should instead be defined in some package like MicroscopyCore.jl or similar <30-07-25> 
3
"""
4
    SampledArray{T,ST,N,AA<:AbstractArray} <: AbstractArray{T,N}
5

6
An `N`-dimensional sampled array with data of type `T` sample __single__ spacing of type `ST`.
7

8
The restriction of `ST` being a single type means that `SampledArray` is not able to represent arrays that have
9
different dimensions in each direction.
10

11
See also [`SampledMatrix`](@ref), [`SampledVector`](@ref), [`SpatialArray`](@ref)
12
"""
13
struct SampledArray{T,ST,N,AA<:AbstractArray{T}} <: AbstractArray{T,N}
14
    parent::AA
15
    sampling::NTuple{N,ST}
16
    function SampledArray(parent::AbstractArray{T, N}, sampling::NTuple{N, Number}) where {T,N}
45✔
17
        # PERF: Method defined on `Number` abstract type but it promotes to a single type for 
18
        sampling = promote(sampling...)
108✔
19
        return new{T,eltype(sampling),ndims(parent),typeof(parent)}(parent, sampling)
108✔
20
    end
21
    SampledArray(parent::AbstractArray{<:Any,0}, sampling::NTuple{0}) = new{eltype(parent),Any,0,typeof(parent)}(parent, sampling)
5✔
22
end
23
SampledArray(parent::AbstractArray{<:Any, N}, sampling::Number) where {N} = SampledArray(parent, ntuple(_ -> sampling, Val(N)))
12✔
24

25
Base.size(a::SampledArray) = (@inline; size(a.parent))
391✔
26
Base.axes(a::SampledArray) = (@inline; axes(a.parent))
2,053✔
27
Base.parent(a::SampledArray) = a.parent
2,641✔
28
Base.similar(a::SampledArray{T,ST,N}, ::Type{S}, dims::Dims{N}) where {T,ST,N,S}  = SampledArray(similar(parent(a), S, dims), a.sampling)
12✔
29
Base.getindex(a::SampledArray, i) = (@inline; getindex(parent(a), i))
2,386✔
30
Base.setindex!(A::SampledArray, v, i::Int) = (@inline; setindex!(parent(A), v, i))
245✔
31
Base.IndexStyle(::Type{<:SampledArray{T,ST,N,AA}}) where {T,ST,N,AA} = IndexStyle(AA)
1,787✔
32
@inline sampling(a::SampledArray) = a.sampling
30✔
33

34
# FIX: Instead should be `location_bins` which give a vector of rectangles that are the bin location corners of the
35
# samples <30-07-25> 
36
@inline posgrid(a::SampledArray) = posgrid(size(a), sampling(a); center=(1,1))
×
37
@inline sample_vertices(a::SampledArray) = map(posgrid(a)...) do x,y 
×
38
    (x,y)
×
39
end
40

41
"""
42
    SampledMatrix{T, ST} <: AbstractMatrix{T}
43

44
Two-dimensional array with elements of type `T` with a given sample spacing of type `ST`. Alias for
45
`SampledArray{T,ST,2}`.
46
"""
47
const SampledMatrix{T,ST} = SampledArray{T,ST,2}
48

49

50
"""
51
    SampledVector{T, ST} <: AbstractVector{T}
52

53
One-dimensional array with elements of type `T` with a given sample spacing of type `ST`. Alias for
54
`SampledArray{T,ST,1}`.
55
"""
56
const SampledVector{T,ST} = SampledArray{T,ST,1}
57

58
"""
59
    SpatialArray{T,N} <: AbstractArray{T,N}
60

61
An `N`-dimensional array representing values sampled uniformly in space. Alias for `SampledArray{T,<:Length,N}`.
62

63
See also [`SpatialMatrix`](@ref), [`SpatialVector`](@ref), [`SampledArray`](@ref)
64
"""
65
const SpatialArray{T,N} = SampledArray{T,<:Length,N}
66

67
"""
68
    SpatialArray(A, (Δx, Δy,...))
69
    SpatialArray(A, Δ::Length)
70

71
Construct a `SpatialArray` with values `A` and sampling `(Δx, Δy, ...)`. For a single `Δ` uses uniform sampling with
72
distance `Δ` in every direction.
73
"""
74
SpatialArray(A::AbstractArray, Δ) = SampledArray(A, Δ)
78✔
75
SpatialArray(A::AbstractArray{<:Any,N}, Δ::Length) where {N} = SampledArray(A, fillsize(Δ, N))
25✔
76

77
"""
78
    SpatialMatrix{T} <: AbstractMatrix{T}
79

80
Two-dimensional array with elements of type `T` with a given sampling distance in both directions. Alias for
81
`SpatialArray{T,2}`.
82
"""
83
const SpatialMatrix{T} = SpatialArray{T,2}
84

85
"""
86
    SpatialMatrix(M, (Δx, Δy))
87
    SpatialMatrix(M, Δ::Length)
88

89
Construct a `SpatialMatrix` with values `M` and sampling `(Δx, Δy)`. For a single `Δ` uses uniform sampling with the
90
distance `Δ` in both directions.
91
"""
92
SpatialMatrix(A::AbstractMatrix, Δ) = SpatialArray(A, Δ)
×
93

94
"""
95
    SpatialVector{T} <: AbstractVector{T}
96
One-dimensional array with elements of type `T` with a given sampling distance. Alias for `SpatialArray{T,1}`.
97
"""
98
const SpatialVector{T} = SpatialArray{T,1}
99

100
"""
101
    SpatialVector(V, Δ::Length)
102

103
Construct a `SpatialVector` with values `V` and sampling `Δ`.
104
"""
105
SpatialVector(A::AbstractVector, Δ::Length) = SpatialArray(A, (Δ,))
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc