Skip to content

Commit fc2ad24

Browse files
authored
Merge pull request #218 from ReactiveBayes/214-documentation-for-resizablearray-is-missing
add docs for resizablearray
2 parents 1f86a0f + aaa2f60 commit fc2ad24

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

docs/src/developers_guide.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,14 @@ node = context[Normal, 1]
101101
nothing # hide
102102
```
103103

104+
## ResizableArrays
105+
106+
`GraphPPL` uses `ResizableArrays` to store arrays of random variables. A `ResizableArray` is a mutable array that can grow dynamically when data is assigned to it. This is why the `x[i] ~ Normal(0, 1)` syntax is allowed in `GraphPPL`; the `ResizableArray` `x` will check if `i` is a valid index and grow the array if necessary.
107+
```@docs
108+
GraphPPL.ResizableArray
109+
```
110+
`ResizableArray` is a subtype of `AbstractArray`, and implements all the functions that are expected from an array. Note that `size` returns the largest size of the array across each dimension, so an array of size `(2, 3)` does not necessarily has to have an element stored at index `(2, 3)`, instead there exists a vector of length 3 along the second dimension.
111+
104112
## Model creation engine internal
105113

106114
```@docs

src/resizable_array.jl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
import Base: size, setindex!, getindex, show, vec
22

3+
"""
4+
ResizableArray{T, V, N} <: AbstractArray{T, N}
5+
6+
A ResizableArray is an array that can grow in any dimension. It handles like a regular AbstractArray when calling `getindex`, but for `setindex!`
7+
it will automatically resize the array if the index is out of bounds. It is also possible to iterate over the array in the same way as for a regular array.
8+
The data is stored internally as a recursive vector. The depth of the recursion is fixed at construction time and cannot be changed.
9+
10+
# Constructor
11+
- `ResizableArray(::Type{T})`: Create an empty resizable array of type `T` with depth 1, similar to a vector.
12+
- `ResizableArray(::Type{T}, ::Val{N})`: Create an empty resizable array of type `T` with depth `N`, similar to AbstractArray{T, N}.
13+
"""
314
struct ResizableArray{T, V <: AbstractVector, N} <: AbstractArray{T, N}
415
data::V
516
end
@@ -28,8 +39,6 @@ function ResizableArray(array::AbstractVector{T}) where {T}
2839
return ResizableArray{V, Vector{T}, get_recursive_depth(array)}(array)
2940
end
3041

31-
# ResizableArray(A::AbstractArray{T, N}) where {T, N} = ResizableArray{T, typeof(A), N}(A)
32-
3342
function make_recursive_vector(::Type{T}, ::Val{1}) where {T}
3443
return T[]
3544
end

0 commit comments

Comments
 (0)