Skip to content

Commit 51da3fe

Browse files
author
rokke
committed
add docstrings
1 parent a207ed7 commit 51da3fe

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

src/array_partition.jl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,5 +723,27 @@ function Adapt.adapt_structure(to, ap::ArrayPartition)
723723
return ArrayPartition(map(x -> Adapt.adapt(to, x), ap.x)...)
724724
end
725725

726+
"""
727+
```julia
728+
AP[ matrices, ]
729+
```
730+
731+
Create an `ArrayPartition` using vector syntax. Equivalent to `ArrayPartition(matrices)`, but looks nicer with nesting.
732+
733+
# Examples:
734+
735+
Simple examples:
736+
```julia
737+
ArrayPartition([1,2,3], [1 2;3 4]) == AP[[1,2,3], [1 2;3 4]] # true
738+
AP[1u"m/s^2", 1u"m/s", 1u"m"]
739+
```
740+
741+
With an ODEProblem:
742+
```julia
743+
func(u, p, t) = AP[5u.x[1], u.x[2]./2]
744+
ODEProblem(func, AP[ [1.,2.,3.], [1. 2.;3. 4.] ], (0, 1)) |> solve
745+
```
746+
747+
"""
726748
struct AP end
727749
Base.getindex(::Type{AP}, xs...) = ArrayPartition(xs...)

src/vector_of_array.jl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1656,5 +1656,30 @@ end
16561656
unpack_args_voa(i, args::Tuple{Any}) = (unpack_voa(args[1], i),)
16571657
unpack_args_voa(::Any, args::Tuple{}) = ()
16581658

1659+
"""
1660+
```julia
1661+
VA[ matrices, ]
1662+
```
1663+
1664+
Create an `VectorOfArray` using vector syntax. Equivalent to `VectorOfArray([matrices])`, but looks nicer with nesting.
1665+
1666+
# Simple example:
1667+
```julia
1668+
VectorOfArray([[1,2,3], [1 2;3 4]]) == VA[[1,2,3], [1 2;3 4]] # true
1669+
```
1670+
1671+
# All the layers:
1672+
```julia
1673+
nested = VA[
1674+
fill(1, 2, 3),
1675+
VA[
1676+
VA[8, [1, 2, 3], [1 2;3 4], VA[1, 2, 3]],
1677+
fill(2, 3, 4),
1678+
VA[3ones(3), zeros(3)],
1679+
],
1680+
]
1681+
```
1682+
1683+
"""
16591684
struct VA end
16601685
Base.getindex(::Type{VA}, xs...) = VectorOfArray(collect(xs))

0 commit comments

Comments
 (0)