I’m working on a project in physics where I need to create custom types that behave like arrays but don’t necessarily inherit from AbstractArray
because I want to disable certain default functionalities. These types represent various mathematical entities in physics, such as lattices and metric tensors. I’m looking for guidance on how to design the interface for these types.
Here are the features I want to implement in these custom types:
-
Indexing Interface: I want these types to support all the basic indexing operations like
getindex
andsetindex
. -
Equality based on Parent Type: Two instances of these types should be considered equal if and only if their parent types have the same name (not necessarily the same type) and the values they contain are semantically equal. For example,
MyType{Int}
andMyType{Float64}
can be equal as long as their elements are equal. (See How to compare two vectors whose elements are equal but their types are not the same) -
Scalar Multiplication: When multiplying one of these types by a scalar, it should produce a new instance of the same type with the elements scaled by that scalar. For example,
1.0 * MyType{Int}(data)
should yield aMyType{Float64}
. -
Elementwise Addition and Subtraction: These types should support elementwise addition and subtraction, resulting in a new instance of the same type with elements added or subtracted accordingly.
-
Scalar Division: These types should allow division by a scalar, but there might not always be an inverse operation.
-
Matrix-Vector Multiplication and Linear Solve: I need these types to support matrix-vector multiplication and linear solve operations.
-
Matrix-Matrix Multiplication: These types should also support matrix-matrix multiplication.
-
No other LinearAlgebra operations: like transpose or det, etc.
-
Fixed sizes: e.g. lattices are 3 \times 3 matrices, so are metric tensors.
I’m wondering if there’s an existing package that provides this kind of functionality or if not, what interface functions I should implement to achieve these features efficiently. Essentially, I’m looking for a design that combines elements of both an indexing interface and an array interface.
Thank you!