RecursiveArrayTools.jl icon indicating copy to clipboard operation
RecursiveArrayTools.jl copied to clipboard

Subtype ArrayPartition and NamedArrayPartition

Open htsnowden opened this issue 8 months ago • 7 comments

We want to use a NamedArrayPartition as our u0 in a problem to replace a DEDataArray which we used (for not much good reason) and NamedArrayPartitions have the functionality we really want. However we need to be able to multiple dispatch on the 'type' of u0 we build (aka the fields we have assigned) and therefore want to use NamedArrayPartition as a supertype to subtype from. Something like the below:

mutable struct test_struct <: NamedArrayPartition
    x :: Vector{Real}
    y :: Matrix{Real}
    z :: AnyothersupportedtypebyNamedArrayPartition
end 

htsnowden avatar May 02 '25 14:05 htsnowden

It's not clear how this would work, since the interface only expects x and x should be a tuple. We can write up what the AbstractArrayPartition interface should be but this type doesn't seem like it would match it.

ChrisRackauckas avatar May 02 '25 15:05 ChrisRackauckas

I could possibly change the need so that it has one field instead of 3 but our main need is the NamedTuple type character of NamedArrayPartitions, in a type that is both multiple dispatchable and usable as an initial condition of an ODEProblem. I don't think NamedTuple's or similar work

htsnowden avatar May 02 '25 15:05 htsnowden

Step one would be to do a code overhaul to make a bunch of functions that use an abstract type. Right now it wouldn't do much because all of the dispatches are on the concrete types.

ChrisRackauckas avatar May 03 '25 02:05 ChrisRackauckas

I could try to make a new type similar to ArrayPartitions, and somewhat copy the code and then if it works provide it as a pull request directly into RecursiveArrayTools if that is considered acceptable by yourselves.

htsnowden avatar May 06 '25 07:05 htsnowden

yes

ChrisRackauckas avatar May 06 '25 12:05 ChrisRackauckas

I have a fork with the corrections to the ArrayInterface.zeromatrix within it as well as a new type structure for NamedArrayPartitions which adds an abstract type to allow for subtyping with the same structure as NamedArrayPartition. I was wondering if I could create a pull request for this onto here so someone can review the changes but I can't create a branch here to do so.

htsnowden avatar May 15 '25 09:05 htsnowden

If you create a pull request from your fork then it can be reviewed?

ChrisRackauckas avatar May 15 '25 09:05 ChrisRackauckas