Skip to content

What is scaledual? #130

@kimikage

Description

@kimikage

I am working on improving the accuracy of the conversions from Normed to Float (#129), and I am interested in scaledual, which seems to be related with the conversions.

The scaledual was introduced in d1087f7.

The introduction of scaledual is a bit speculative, but it can essentially double the speed of certain operations. It has the following property:

bd, ad = scaledual(b, a)
b*a == bd*ad

but the RHS might be faster (particularly for floating-point b and an array a of fixed-point numbers).

Originally posted by @timholy in #2 (comment)

However, in the current codebase, I think scaledual does not have the property above as its test specifies. (a[1] != af8[1])

a = rand(UInt8, 10)
rfloat = similar(a, Float32)
rfixed = similar(rfloat)
af8 = reinterpret(N0f8, a)
b = 0.5
bd, eld = scaledual(b, af8[1])
@assert b*a[1] == bd*eld

I do my best for #129, but a slowdown is inevitable. If scaledual is helpful as a workaround for people who prefer speed over accuracy, I feel relieved.

@timholy , did I not understand that correctly?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions