- Notifications
You must be signed in to change notification settings - Fork0
Tools for easily handling objects like arrays of arrays and deeper nestings in scientific machine learning (SciML) and other applications
License
mateuszbaran/RecursiveArrayTools.jl
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
RecursiveArrayTools.jl is a set of tools for dealing with recursive arrays likearrays of arrays. The current functionality includes:
VectorOfArray(u::AbstractVector)
AVectorOfArray is an array which has the underlying data structureVector{AbstractArray{T}}(but, hopefully, concretely typed!). This wrapper over such data structures allows one to lazilyact like it's a higher-dimensional vector, and easily convert to different forms. The indexingstructure is:
A[i]# Returns the ith array in the vector of arraysA[j,i]# Returns the jth component in the ith arrayA[j1,...,jN,i]# Returns the (j1,...,jN) component of the ith array
which presents itself as a column-major matrix with the columns being the arrays from the vector.TheAbstractArray interface is implemented, giving access tocopy,push,append!, etc. functions,which act appropriately. Points to note are:
- The length is the number of vectors, or
length(A.u)whereuis the vector of arrays. - Iteration follows the linear index and goes over the vectors
Additionally, theconvert(Array,VA::AbstractVectorOfArray) function is provided, which transformstheVectorOfArray into a matrix/tensor. Also,vecarr_to_vectors(VA::AbstractVectorOfArray)returns a vector of the series for each component, that is,A[i,:] for eachi.A plot recipe is provided, which plots theA[i,:] series.
Related to theVectorOfArray is theDiffEqArray
DiffEqArray(u::AbstractVector,t::AbstractVector)
This is aVectorOfArray, which storesA.t that matchesA.u. This will plot(A.t[i],A[i,:]). The functiontuples(diffeq_arr) returns tuples of(t,u).
To construct a DiffEqArray
t=0.0:0.1:10.0f(t)= t-1f2(t)= t^2vals= [[f(tval)f2(tval)]for tvalin t]A=DiffEqArray(vals, t)A[1,:]# all time periods for f(t)A.t
ArrayPartition(x::AbstractArray...)
AnArrayPartitionA is an array, which is made up of different arraysA.x.These index like a single array, but each subarray may have a different type.However, broadcast is overloaded to loop in an efficient manner, meaning thatA .+= 2.+B is type-stable in its computations, even ifA.x[i] andA.x[j]do not match types. A full array interface is included for completeness, whichallows this array type to be used in place of a standard array wheresuch a type stable broadcast may be needed. One example is in heterogeneousdifferential equations forDifferentialEquations.jl.
AnArrayPartition acts like a single array.A[i] indexes through the firstarray, then the second, etc., all linearly. ButA.x is where the arrays are stored.Thus, for:
using RecursiveArrayToolsA=ArrayPartition(y,z)
we would haveA.x[1]==y andA.x[2]==z. Broadcasting likef.(A) is efficient.
recursivecopy!(b::Array{T,N},a::Array{T,N})
A recursivecopy! function. Acts like adeepcopy! on arrays of arrays, butlikecopy! on arrays of scalars.
convert(Array,vecvec)Technically, just a Base fallback that works well. Takes in a vector of arrays,returns an array of dimension one greater than the original elements.Works onAbstractVectorOfArray. If thevecvec is ragged, i.e., not all of theelements are the same, then it uses the size of the first element to determinethe conversion.
vecvecapply(f::Base.Callable,v)
Callsf on each element of a vecvecv.
copyat_or_push!{T}(a::AbstractVector{T},i::Int,x)
Ifi<length(x), it's simply arecursivecopy! to theith element. Otherwise, it willpush! adeepcopy.
recursive_one(a)Callsone on the bottom container to get the "true element one type".
mean{T<:AbstractArray}(vecvec::Vector{T})mean{T<:AbstractArray}(matarr::Matrix{T},region=0)
Generalized mean functions for vectors of arrays and a matrix of arrays.
About
Tools for easily handling objects like arrays of arrays and deeper nestings in scientific machine learning (SciML) and other applications
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Languages
- Julia99.0%
- TeX1.0%