(j3.2006) I think this is possible, but....
Van Snyder
Van.Snyder
Tue Jan 23 17:00:20 EST 2018
I think this is possible, but it might have high overhead, be difficult
to explain in the standard, or difficult to implement.
I have a derived type that has a component that's an allocatable array
of derived type. Alternatively, its bounds could depend upon length
parameters.
In an extension of the type, I'd like that component to be an extension
of its type. That is, I'd like to be able to override components, not
just procedure bindings.
Here's a concrete example.
I developed a sparse matrix representation. One component is a rank-one
array of the nonzero matrix elements. Each element has five components:
its row, its column, the index of the next element in the same row, the
index of the next element in the same column, and the value. Each row
or column is a circular list.
Another component is an array of indices of the last element in each
row. Another component is an array of indices of the last element in
each column.
I'm using this type to represent interpolation coefficients from state
vectors that represent the temperature and composition of the
atmosphere. Each row of the matrix corresponds to a point on the path
of integration through the atmosphere.
There is a lot of other path-related information that is unrelated to
the low-level sparse-matrix abstraction. For example, the temperature
at a point on the path, or the mixing ratio of the species, for which
the matrix is a representation of the interpolation coefficients.
In the base type, I'd like the object that contains the index of the
last element in each row to be an array of a derived type that has one
integer component. In an extension of the type, I'd like to extend that
object to include, for example, the temperature or mixing ratio. I'd
like to do something similar for the array that contains the index of
the last element in each column, for example to include a logical
variable that indicates whether I need derivatives with respect to the
corresponding element of the state vector. I'd like to do something
similar to the component that represents the array elements. In
addition to an interpolation coefficient, I want to record a quantity
related to a derivative with respect to the corresponding element of the
state vector.
I can work around this by adding components in an extension of the type,
but then those components need to be allocated (either explicitly, or
under the covers if their extents are specified by length parameters).
The quantities related to a particular point on the path of integration
would not be near each other, so cache locality would suffer.
There would probably be usage overhead because each extensible component
would need to be accessed by way of a descriptor. For example, if all
you want is the array of temperatures along the path, you don't know the
stride betweem them at compile time if the component that represents
that is component of a component of extensible type.
As I said, this might be difficult to explain, might be difficult to
implement, and might be expensive to use. But it is sort of clean, and
it generalizes the idea of procedure-binding overriding to overriding
components.
Is it worth pondering?
More information about the J3
mailing list