JuliaPhysics / JuliaPhysics/Unitful.jl

Can create dimensionless Unitful vectors, but not ranges

Open
#855 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Julia
Stars
675
Forks
124
Avg merge
3h 38m
Merged PRs (30d)
1

Description

Hi,

I'm trying to create vectors and ranges the elements of which are Unitful Quantities, but which have no units. That is, they are recognized as containing dimensionless Quantities.

I came across a surprising (to me) difference between vectors and ranges.

First note that

nounits = convert(Quantity{typeof(1),NoDims,Unitful.FreeUnits{(),NoDims,nothing}}, 1)

is a value equal to 1 that has no units. It is different from 1 itself:

1::Int64
>> 1

nounits::Quantity{Int64, NoDims, Unitful.FreeUnits{(), NoDims, nothing}}
>> 1

1::Quantity{Int64, NoDims, Unitful.FreeUnits{(), NoDims, nothing}}
>> ERROR

I can create a vector containing nondimensional Unitful Quantities

convert.(Quantity{Int64, NoDims, Unitful.FreeUnits{(), NoDims, nothing}}, collect(1:10))
>>10-element Vector{Quantity{Int64, NoDims, Unitful.FreeUnits{(), NoDims, nothing}}}:

and I can create a range containing dimensional Unitful Quantities

typeof(1*u"m":1*u"m":10*u"m")
>> StepRange{Quantity{Int64, 𝐋, Unitful.FreeUnits{(m,), 𝐋, nothing}}, Quantity{Int64, 𝐋, Unitful.FreeUnits{(m,), 𝐋, nothing}}}

typeof((1:10) .* u"m")
>> StepRange{Quantity{Int64, 𝐋, Unitful.FreeUnits{(m,), 𝐋, nothing}}, Quantity{Int64, 𝐋, Unitful.FreeUnits{(m,), 𝐋, nothing}}}

but I can't create a range containing nondimensional Unitful Quantities

typeof((1:10) .* nounits)
>> StepRangeLen{Int64, Int64, Int64, Int64}

typeof(nounits:nounits:10*nounits)
>> StepRange{Int64, Int64}

It would be good if it were possible to create non-dimensional Unitful ranges. This way, both dimensional and nondimensional vectors and ranges could be treated as containing Unitful Quantities.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reproducing the dimensionless Quantity and range examples from the issue in Julia, then trace the range construction behavior for nounits and Unitful quantities. Done means nondimensional Unitful ranges preserve their Quantity element type, consistently with dimensional Unitful ranges.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.