Skip to content

Commit 39ee021

Browse files
committed
update docs
1 parent 2891cd6 commit 39ee021

File tree

2 files changed

+42
-25
lines changed

2 files changed

+42
-25
lines changed

docs/src/matrix_fields.md

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -153,28 +153,45 @@ and
153153
nt_fieldmatrix[(@name(a.bar), @name(b))]
154154
```
155155

156-
If the key `(@name(name1), @name(name2))` corresponds to an entry, then
157-
`(@name(foo.bar.buz), @name(biz.bop.fud))` would be the internal key for the key
158-
`(@name(name1.foo.bar.buz), @name(name2.biz.bop.fud))`.
156+
### Further Indexing Details
159157

160-
Currently, internal values cannot be extracted in all situations. Extracting interal values
161-
works when indexing an object of type `eltype(entry)` with the
162-
second key of the internal key pair appended to the first results in a scalar.
163-
If the internal keys index to a non-scalar `Field`, a broadcasted object is returned.
158+
Let key `(@name(name1), @name(name2))` correspond to entry `sample_entry` in `FieldMatrix` `A`.
159+
An example of this is:
164160

165-
When the entry is a `Field` of `Axis2Tensor`s, and both internal names are numbers that would index
166-
an `Axis2Tensor` with the same axis.
167-
168-
This does not work when the internal keys index to a `Field` of sliced tensors.
169-
170-
Extracting internal values from a `DiagonalMatrixRow` works in all cases, except when
171-
172-
If the `FieldMatrix` represents a Jacobian, then extracting internal values works when an entry represents:
173-
174-
- The partial derrivative of an `AxisVector`, `Tuple`, or `NamedTuple` with respect to a scalar.
175-
176-
- The partial derrivative of a scalar with respect to an `AxisVector`.
177-
178-
- The partial derrivative of a `Tuple`, or `NamedTuple` with respect to an `AxisVector`. In this case, the first name of the internal key must index into the tuple and result in a scalar.
161+
```julia
162+
A = MatrixFields.FieldMatrix((@name(name1), @name(name2)) => sample_entry)
163+
```
179164

180-
- The partial derrivative of an `AxisVector` with respect to an `AxisVector`. In this case, the partial derrivative of a component of the first `AxisVector` with respect to a component of the second `AxisVector` can be extracted, but not an entire `AxisVector` with respect to a component, or a component with respect to an entire `AxisVector`
165+
Now consider what happens indexing `A` with the key `(@name(name1.foo.bar.buz), @name(name2.biz.bop.fud))`.
166+
167+
First, a function searches the keys of `A` for a key that `(@name(foo.bar.buz), @name(biz.bop.fud))`
168+
is a child of. In this example, `(@name(foo.bar.buz), @name(biz.bop.fud))` is a child of
169+
the key `(@name(name1), @name(name2))`, and
170+
`(@name(foo.bar.buz), @name(biz.bop.fud))` is referred to as the internal key.
171+
172+
Next, the entry that `(@name(name1), @name(name2))` is paired with is recursively indexed
173+
by the internal key.
174+
175+
The recursive indexing of an internal entry given some entry `entry` and internal_key `internal_name_pair`
176+
works as follows:
177+
178+
1. If the `internal_name_pair` is blank, return `entry`
179+
2. If each row of `entry` contains an `Axis2Tensor`, and `internal_name_pair` is of the form
180+
`(@name(components.data.1...), @name(components.data.2...))` (potentially with different numbers),
181+
then extract the specified component, and recurse on it with the remaining `internal_name_pair`. Note that if
182+
`entry` is not a `DiagonalMatrixRow`, then `internal_name_pair` cannot slice the tensor.
183+
3. If each row of `entry` is a `Geometry.AdjointAxisVector`, then recurse on the parent of the adjoint.
184+
4. If `internal_name_pair[1]` is not empty, and the first name in it is a field of the element type of each row of `entry`,
185+
extract that field from `entry`, and recurse on the it with the remaining names of `internal_name_pair[1]` and all of `internal_name_pair[2]`
186+
5. If `internal_name_pair[2]` is not empty, and the first name in it is a field of the element type of each row of `entry`,
187+
extract that field from `entry`, and recurse on the it with all of `internal_name_pair[1]` and the remaining names of `internal_name_pair[2]`
188+
6. At this point, if none of the previous cases are true, both `internal_name_pair[1]` and `internal_name_pair[2]` should be
189+
non-empty, and it is assumed that `entry` is being used to implicitally represent some tensor structure. If the first name in
190+
`internal_name_pair[1]` is equivalent to ``internal_name_pair[2]`, then both the first names are dropped, and entry is recursed onto.
191+
If the first names are different, both the first names are dropped, and the zero of entry is recursed onto.
192+
193+
When the entry is a `ColumnWiseBandMatrixField`, indexing it will return a broadcasted object in
194+
the following situations:
195+
196+
1. The internal key indexes to a type different than the basetype of the entry
197+
2. The internal key indexes to a zero-ed value

src/MatrixFields/field_name_dict.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ function get_internal_entry(
183183
entry[row_index, col_index],
184184
(drop_first(internal_row_name), drop_first(internal_col_name)),
185185
key_error,
186-
)
186+
) #TODO: should further indexing be allowed here
187187
elseif T <: Geometry.AdjointAxisVector # bypass parent for adjoint vectors
188188
return get_internal_entry(
189189
getfield(entry, :parent),
@@ -427,7 +427,7 @@ end
427427
get_scalar_keys(dict::FieldMatrix)
428428
429429
Returns a `FieldMatrixKeys` object that contains the keys that result in
430-
a `ScalingFieldMatrixEntry{<:Number}` or a `ColumnwiseBandMatrixField` with bands of eltype `< :Number`
430+
a `ScalingFieldMatrixEntry{<:Number}` or a `ColumnwiseBandMatrixField` with bands of eltype `<: Number`
431431
when indexing `dict`.
432432
"""
433433
function get_scalar_keys(dict::FieldMatrix)
@@ -446,7 +446,7 @@ end
446446
get_scalar_keys(T::Type)
447447
448448
Returns a tuple of `FieldNamePair` objects that correspond to any children
449-
of `T` that are of type `FT`.
449+
of `T` that are of type `<: Number`.
450450
"""
451451
function get_scalar_keys(::Type{T}) where {T}
452452
if T <: Number # TODO: is this tight enough of a Type? what about complex and duals and plushalfs

0 commit comments

Comments
 (0)