Option 3 – Vectors of type T where T is a subtype of Number

The third option is to take vectors of type T, where T is just a subtype of Number.

The function can be defined as follows:

sumprod_3(A::Vector{T}, B::Vector{T}) where T <: Number = sum(A .* B)

Let's try it first:

As the type parameter T can be any subtype of Number, this function comfortably handles vectors of Float64, Int64, and even Number types. Unfortunately, it cannot handle arguments of different types, but we should be able to improve it further. Let's try the next option.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.111.125