77Package ` TypeUtils ` provides useful methods to deal with types in
88[ Julia] ( https://www.julialang.org ) and facilitate coding with numbers whether they have
99units or not. The package provides methods to strip units from numbers or numeric types,
10- convert the numeric type of quantities (not their units), determine appropriate numeric
11- type to carry computations mixing numbers with different types and/or units. These methods
12- make it easy to write code that works consistently for numbers with any units (including
13- none). The intention is that the ` TypeUtils ` package automatically extends its exported
14- methods when packages such as [ ` Unitful ` ] ( https://github.com/PainterQubits/Unitful.jl ) are
15- loaded.
10+ convert the numeric type of quantities (preserving their units if any ), determine
11+ appropriate numeric type to carry computations mixing numbers with different types and/or
12+ units. These methods make it easy to write code that works consistently for numbers with
13+ any units (including none). The intention is that the ` TypeUtils ` package automatically
14+ extends its exported methods when packages such as
15+ [ ` Unitful ` ] ( https://github.com/PainterQubits/Unitful.jl ) are loaded.
1616
1717
1818## Cast value to type
@@ -27,9 +27,9 @@ A first usage is:
2727as(T, x)
2828```
2929
30- which yields ` x ` converted to type ` T ` . This behaves like a lazy version of
31- ` convert(T,x)::T ` doing nothing if ` x ` is already of type ` T ` and performing the
32- conversion and the type assertion otherwise.
30+ which yields ` x ` converted to type ` T ` . This behaves like ` convert(T,x)::T ` doing nothing
31+ if ` x ` is already of type ` T ` and performing the conversion and the type assertion
32+ otherwise.
3333
3434By default, the ` as ` method calls ` convert ` only if needed but also implements a number of
3535conversions not supported by ` convert ` . The ` as ` method is therefore a bit more versatile
@@ -160,7 +160,7 @@ The `TypeUtils` package provides the following types for array shape, size, and
160160Note that ` Dims{N} ` is the same as ` NTuple{N,Int} ` in Julia and represents the result of
161161` size(A) ` for the ` N ` -dimensional array ` A ` , so ` eltype(Dims) = Int ` .
162162
163- Given a list ` inds... ` of array dimension lenghts (integers) and/or index ranges
163+ Given a list ` inds... ` of array dimension lengths (integers) and/or index ranges
164164(integer-valued unit ranges), the following methods from ` TypeUtils ` are applicable:
165165
166166- ` as_array_shape(inds...) ` yields canonical array axes (if ` inds... ` contains any index
@@ -173,8 +173,8 @@ Given a list `inds...` of array dimension lenghts (integers) and/or index ranges
173173- ` as_array_size(inds...) ` yields canonical array size, that is a ` N ` -tuple of type
174174 ` Dims{N} ` .
175175
176- Of course, these methods also accept that their arguments be sopecified by a tuple of
177- array dimension lenghts and/or index ranges, that is ` (inds...,) ` instead of ` inds... ` in
176+ Of course, these methods also accept that their arguments be specified by a tuple of
177+ array dimension lengths and/or index ranges, that is ` (inds...,) ` instead of ` inds... ` in
178178the above example.
179179
180180To deal with individual array dimension length and/or index range:
@@ -315,7 +315,7 @@ julia> map(real_type, (u"3.2km/s", u"5GHz", typeof((0+1im)*u"Hz")))
315315
316316The following example shows a first attempt to use ` bare_type ` to implement efficient
317317in-place multiplication of an array (whose element may have units) by a real factor (which
318- must be unitless in this context):
318+ must be dimensionless in this context):
319319
320320``` julia
321321function scale!(A:: AbstractArray , α:: Number )
@@ -365,11 +365,11 @@ end
365365```
366366
367367The restriction ` α::Union{Real,Complex} ` accounts for the fact that in-place
368- multiplication imposes a unitless multiplier. Since the test leading to the expression
369- used for ` alpha ` is based on the types of the arguments, the branch is eliminated at
370- compile time and the type of ` alpha ` is known by the compiler. The ` InexactConversion `
371- exception may then only be thrown by the call to ` convert ` in the first branch of the
372- test.
368+ multiplication imposes a dimensionless multiplier. Since the test leading to the
369+ expression used for ` alpha ` is based on the types of the arguments, the branch is
370+ eliminated at compile time and the type of ` alpha ` is known by the compiler. The
371+ ` InexactConversion ` exception may then only be thrown by the call to ` convert ` in the
372+ first branch of the test.
373373
374374This seemingly very specific case was in fact the key point to allow for packages such as
375375[ LazyAlgebra] ( https://github.com/emmt/LazyAlgebra.jl ) or
0 commit comments