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
(*){T<:AbstractFloat}(x::T, y::Vector{T}) should work #17544
Comments
Make |
I left out the supertype -- edited above. this error occurs julia> immutable FP <: AbstractFloat
val::Float64
end
julia> import Base:*
julia> (*)(a::FP, b::FP) = FP(a.val * b.val)
* (generic function with 151 methods)
julia> afp=FP(1.5); fps=[FP(1.0),FP(2.0)];
julia> afp * fps
ERROR: MethodError: Cannot `convert` an object of type Int64 to an object of type FP
This may have arisen from a call to the constructor FP(...),
since type constructors fall back to convert methods.
in promote_op(::Base.#.*, ::Type{FP}, ::Type{FP}) at ./number.jl:73
in .*(::FP, ::Array{FP,1}) at ./arraymath.jl:71
in *(::FP, ::Array{FP,1}) at ./abstractarraymath.jl:54
in eval(::Module, ::Any) at ./boot.jl:234
in macro expansion at ./REPL.jl:92 [inlined]
in (::Base.REPL.##1#2{Base.REPL.REPLBackend})() at ./event.jl:46 version 0.5- |
Basically dup of #17314 |
I may be missing the core of #17314. Importing |
julia> immutable FP <: AbstractFloat
val::Float64
end
julia> import Base: *
julia> *(a::FP, b::FP) = FP(a.val * b.val)
* (generic function with 151 methods)
julia> Base.one(::Type{FP}) = FP(1.0)
julia> afp = FP(1.5); fps = [FP(1.0), FP(2.0)]
2-element Array{FP,1}:
FP(1.0)
FP(2.0)
julia> afp * fps
2-element Array{FP,1}:
FP(1.5)
FP(3.0) |
fancy that -- thank you, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There should be fallback definitions that support arithmetic functions where the type of the args is AbstractFloat (or maybe Real) and one or both args is a Vector (or an Array) of the same type, where the arithmetic operator is supported for two elements of that type.
The text was updated successfully, but these errors were encountered: