Skip to content

Unitless typeof and eltype #22216

Open
Open
@ChrisRackauckas

Description

@ChrisRackauckas

A very common operation when trying to write package which works with unitful quantities is getting the unitless element-type. This is required to find the right eps or set the tolerance to the correct Number type. However, I am not sure of a completely generic way to handle this. typeof(first(one(u))) works well in a pinch, but I am noticing an issue with GPUArrays which do not have indexing and thus don't have first defined. So the only way I know of to always get the unitless element type is eltype(u./u), which has an extra operation just to grab the type.

Is there a generic function to strip the units off of a type? Some unitless(T) to get whatever the type of the non-unit part is? That would be a clear way to implement this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureIndicates new feature / enhancement requeststypes and dispatchTypes, subtyping and method dispatch

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions