|
5 | 5 | [](https://buildkite.com/julialang/recursivearraytools-dot-jl) |
6 | 6 |
|
7 | 7 | RecursiveArrayTools.jl is a set of tools for dealing with recursive arrays like |
8 | | -arrays of arrays. The current functionality includes: |
9 | | - |
10 | | -### Types |
11 | | - |
12 | | -#### VectorOfArray |
13 | | - |
14 | | -```julia |
15 | | -VectorOfArray(u::AbstractVector) |
16 | | -``` |
17 | | - |
18 | | -A `VectorOfArray` is an array which has the underlying data structure `Vector{AbstractArray{T}}` |
19 | | -(but, hopefully, concretely typed!). This wrapper over such data structures allows one to lazily |
20 | | -act like it's a higher-dimensional vector, and easily convert to different forms. The indexing |
21 | | -structure is: |
22 | | - |
23 | | -```julia |
24 | | -A[i] # Returns the ith array in the vector of arrays |
25 | | -A[j,i] # Returns the jth component in the ith array |
26 | | -A[j1,...,jN,i] # Returns the (j1,...,jN) component of the ith array |
27 | | -``` |
28 | | - |
29 | | -which presents itself as a column-major matrix with the columns being the arrays from the vector. |
30 | | -The `AbstractArray` interface is implemented, giving access to `copy`, `push`, `append!`, etc. functions, |
31 | | -which act appropriately. Points to note are: |
32 | | - |
33 | | -- The length is the number of vectors, or `length(A.u)` where `u` is the vector of arrays. |
34 | | -- Iteration follows the linear index and goes over the vectors |
35 | | - |
36 | | -Additionally, the `convert(Array,VA::AbstractVectorOfArray)` function is provided, which transforms |
37 | | -the `VectorOfArray` into a matrix/tensor. Also, `vecarr_to_vectors(VA::AbstractVectorOfArray)` |
38 | | -returns a vector of the series for each component, that is, `A[i,:]` for each `i`. |
39 | | -A plot recipe is provided, which plots the `A[i,:]` series. |
40 | | - |
41 | | -#### DiffEqArray |
42 | | - |
43 | | -Related to the `VectorOfArray` is the `DiffEqArray` |
44 | | - |
45 | | -```julia |
46 | | -DiffEqArray(u::AbstractVector,t::AbstractVector) |
47 | | -``` |
48 | | - |
49 | | -This is a `VectorOfArray`, which stores `A.t` that matches `A.u`. This will plot |
50 | | -`(A.t[i],A[i,:])`. The function `tuples(diffeq_arr)` returns tuples of `(t,u)`. |
51 | | - |
52 | | -To construct a DiffEqArray |
53 | | -```julia |
54 | | -t = 0.0:0.1:10.0 |
55 | | -f(t) = t - 1 |
56 | | -f2(t) = t^2 |
57 | | -vals = [[f(tval) f2(tval)] for tval in t] |
58 | | -A = DiffEqArray(vals, t) |
59 | | -A[1,:] # all time periods for f(t) |
60 | | -A.t |
61 | | -``` |
62 | | - |
63 | | -#### ArrayPartition |
64 | | - |
65 | | -```julia |
66 | | -ArrayPartition(x::AbstractArray...) |
67 | | -``` |
68 | | - |
69 | | -An `ArrayPartition` `A` is an array, which is made up of different arrays `A.x`. |
70 | | -These index like a single array, but each subarray may have a different type. |
71 | | -However, broadcast is overloaded to loop in an efficient manner, meaning that |
72 | | -`A .+= 2.+B` is type-stable in its computations, even if `A.x[i]` and `A.x[j]` |
73 | | -do not match types. A full array interface is included for completeness, which |
74 | | -allows this array type to be used in place of a standard array where |
75 | | -such a type stable broadcast may be needed. One example is in heterogeneous |
76 | | -differential equations for [DifferentialEquations.jl](https://github.com/JuliaDiffEq/DifferentialEquations.jl). |
77 | | - |
78 | | -An `ArrayPartition` acts like a single array. `A[i]` indexes through the first |
79 | | -array, then the second, etc., all linearly. But `A.x` is where the arrays are stored. |
80 | | -Thus, for: |
81 | | - |
82 | | -```julia |
83 | | -using RecursiveArrayTools |
84 | | -A = ArrayPartition(y,z) |
85 | | -``` |
86 | | - |
87 | | -we would have `A.x[1]==y` and `A.x[2]==z`. Broadcasting like `f.(A)` is efficient. |
88 | | - |
89 | | -### Functions |
90 | | - |
91 | | -```julia |
92 | | -recursivecopy!(b::Array{T,N},a::Array{T,N}) |
93 | | -``` |
94 | | - |
95 | | -A recursive `copy!` function. Acts like a `deepcopy!` on arrays of arrays, but |
96 | | -like `copy!` on arrays of scalars. |
97 | | - |
98 | | -```julia |
99 | | -convert(Array,vecvec) |
100 | | -``` |
101 | | - |
102 | | -Technically, just a Base fallback that works well. Takes in a vector of arrays, |
103 | | -returns an array of dimension one greater than the original elements. |
104 | | -Works on `AbstractVectorOfArray`. If the `vecvec` is ragged, i.e., not all of the |
105 | | -elements are the same, then it uses the size of the first element to determine |
106 | | -the conversion. |
107 | | - |
108 | | -```julia |
109 | | -vecvecapply(f::Base.Callable,v) |
110 | | -``` |
111 | | - |
112 | | -Calls `f` on each element of a vecvec `v`. |
113 | | - |
114 | | -```julia |
115 | | -copyat_or_push!{T}(a::AbstractVector{T},i::Int,x) |
116 | | -``` |
117 | | - |
118 | | -If `i<length(x)`, it's simply a `recursivecopy!` to the `i`th element. Otherwise, it will |
119 | | -`push!` a `deepcopy`. |
120 | | - |
121 | | -```julia |
122 | | -recursive_one(a) |
123 | | -``` |
124 | | - |
125 | | -Calls `one` on the bottom container to get the "true element one type". |
126 | | - |
127 | | -```julia |
128 | | -mean{T<:AbstractArray}(vecvec::Vector{T}) |
129 | | -mean{T<:AbstractArray}(matarr::Matrix{T},region=0) |
130 | | -``` |
131 | | - |
132 | | -Generalized mean functions for vectors of arrays and a matrix of arrays. |
| 8 | +arrays of arrays. |
0 commit comments