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

[Question]: Possible to provide floats as single instead of double precision? #666

Closed
varon opened this issue Jan 31, 2020 · 2 comments
Closed

Comments

@varon
Copy link
Contributor

varon commented Jan 31, 2020

Description

I'm working with a lot of data that eventually gets computed on the GPU, so using float32 in the application side is preferable.

Because the data comes back as double, the automatic mapping via MapTo<T> fails.

Is it possible to set some kind of global option that returns all floats as System.Single intead of System.Double?

@varon varon changed the title [Question]: Possible to provide floats as single instead of double? [Question]: Possible to provide floats as single instead of double precision? Jan 31, 2020
@Thorium
Copy link
Member

Thorium commented Jan 31, 2020

There are no current support for this out-of-the-box.
I guess people just do "select (float mycol1, float mycol2)"

I will accept PR to just make MapTo not fail when casting. There is already a conversion-trial-system for procedure returns or something:

let rec convertTypes (itm:obj) (returnType:Type) =

I would be interested how do you use MapTo as I never used it myself, and people complain some features of it, but there are no unit-tests, so I cannot fix what I don't know it should work in the first place.

I guess what could also be doable, is configurable mapping of SQL-types (varies per database) to .NET types (1 (int), 1u (uint32), 1L (int64), 1UL (uint64), 1s (int16), 1y (sbyte), 1uy (byte), 1.0 (float), 1.0f (float32), 1.0m (decimal), 1I (BigInteger)), e.g. via static parameter, but this is not a lot requested feature.

However, what I would really also like is kind of language level #pragma keyword to set your types:
fsharp/fslang-suggestions#737

@Thorium
Copy link
Member

Thorium commented Feb 4, 2020

You can already provide optional type mapping parameter for MapTo-method.

Example to map EmployeeId from int64 database column to Int32 record:

type Employee = {
    EmployeeId : int32
    FirstName : string
    LastName : string
    HireDate : DateTime
}
let example() =
    query {
        for emp in dc.Main.Employees do
        select emp
        skip 2
        take 5
    } 
    |> Seq.map (fun e ->
        e.MapTo<Employee>(
            function
            | "EmployeeId", (:? int64 as id) -> Convert.ToInt32(id) |> box
            | k,v -> v))
    |> Seq.toList 

...and this is duplicate of #525

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