Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fully FieldVector Broadcasts Drop Names #314

Closed
ChrisRackauckas opened this issue Oct 5, 2017 · 7 comments
Closed

Fully FieldVector Broadcasts Drop Names #314

ChrisRackauckas opened this issue Oct 5, 2017 · 7 comments

Comments

@ChrisRackauckas
Copy link
Member

ChrisRackauckas commented Oct 5, 2017

Using #313 for simplicity:

a = @FVector Float64 [a,b,c] [1,2,3]
b = a.+a
c = @MFVector Float64 [a,b,c] [1,2,3]
d = c.+c

The type of b here is SVector and the type of d here is SVector as well. It would be nice if in this case where the types are all known to be the same FieldVector that it can stay that FieldVector so that the return type has the same naming.

@andyferris
Copy link
Member

You need to overload similar_type. Please note that you have exactly the same behavior in standard (non static) AbstractArrays except in Base you need to overload similar, in order to get an array of the same type out of methods in Base.

@ChrisRackauckas
Copy link
Member Author

ChrisRackauckas commented Oct 19, 2017

Should this be done on the abstract type so that way by default this works properly?

@ChrisRackauckas
Copy link
Member Author

ChrisRackauckas commented Oct 19, 2017

Overloading similar_type didn't work.

StaticArrays.similar_type(a::T) where T<:FieldVector = T
similar_type(a) # ##FVector#661
b = a.+a

3-element SVector{3,Float64}:
 2.0
 4.0
 6.0

@andyferris
Copy link
Member

Oh, sorry, the docs aren't clear enough here! For 3 vectors, please overload:

similar_type(::Type{<:MyFieldVector}, ::Type{T}, ::Size{(3,)}) where {T} = MyFieldVector{T}

The 3-argument form is what gets used in practice.

You can't overload all of FieldVector since (a) sometimes you need a matrix or different sized vector, so that won't work, and (b) some users may wish to implement a custom type which has special properties (I'm thinking Rotations.jl which has orthogonal matrices) and thus should fall back to SVector when arbitrary transformations occur.

@andyferris
Copy link
Member

Should this be done on the abstract type so that way by default this works properly?

To follow up, we copy the pattern from Base where things fall back to Array unless otherwise specified. (Generally, we also aim to follow the design of Base as closely as possible, and in this case I think this has been considered and came to the same conclusions as I mention above).

@andyferris
Copy link
Member

Did overloading that method work for you?

@ChrisRackauckas
Copy link
Member Author

It worked

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants