Skip to content

construct_seeds for types where typeof(one(T)) !=T is broken #651

New issue

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

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

Already on GitHub? # to your account

Open
longemen3000 opened this issue Jun 7, 2023 · 1 comment · May be fixed by #665, #664 or #750
Open

construct_seeds for types where typeof(one(T)) !=T is broken #651

longemen3000 opened this issue Jun 7, 2023 · 1 comment · May be fixed by #665, #664 or #750

Comments

@longemen3000
Copy link

longemen3000 commented Jun 7, 2023

as far as i understand, the type of one(T) is not necessarily T (JuliaPhysics/Measurements.jl#134 for example). but construct_seeds uses this:

@generated function single_seed(::Type{Partials{N,V}}, ::Val{i}) where {N,V,i}
ex = Expr(:tuple, [ifelse(i === j, :(one(V)), :(zero(V))) for j in 1:N]...)
return :(Partials($(ex)))
end

Maybe using oneunit there is more correct?

@stevengj
Copy link
Contributor

stevengj commented Sep 18, 2023

If you want to get something of the same type, you should use oneunit, that's what it's for.

(e.g. for a dimensionful type, one must be dimensionless, i.e. of a different type, as otherwise it will not be a multiplicative identity.)

# for free to join this conversation on GitHub. Already have an account? # to comment