This page describes the most important changes in TypeUtils. The format is based on
Keep a Changelog, and this project adheres to
Semantic Versioning.
- Minimal Julia version is 1.0. This bound is imposed by the
InverseFunctionspackage.
This new minor version essentially provides lazymap (see below).
B = lazymap([T::Type,], f, A[, f_inv])yields an objectBthat lazily maps functionfto array or iteratorA. Optional argumentTis the element-type ofBwhich is automatically inferred if not specified. IfAis an (abstract) array,f_invmay be provided to specify the inverse off. Related type aliasLazyMap{T,N,F,typeof(A)}can be used to specialize on the typeBwithN = ndims(A)andF = typeof(f).
-
The former function
as_eltype(T,A)is now a shortcut forlazymap(T,identity,A)unlessT == eltype(A)holds in which caseAis returned. -
Private type
TypeUtils.AsEltype(formerly used byas_eltytpe) no longer exists.
units_of(x)andunits_of(typeof(x))yield the units of the numberx. The units are a trait which only depends on the type of the argument. This function is a replacement forUnitful.unitwhen this package is not yet loaded.
get_precisionon n-tuples yields a correct result and is inferable.
get_precision()yieldsAbtractFloatinstead of throwing aMethodError.
-
Fix tests for Julia 1.12 and above.
-
Syntax
@public a, b, cis allowed.
-
With multiple arguments,
get_precision(x, y...)yields the best precision of all the given arguments. -
nearest(T, x)can deal with dimensionful numbers and types.
This new minor version adds methods to deal with the numerical precision of numbers and objects.
-
get_precision(x)yields the numerical precision ofx. -
adapt_precision(T, x)yields a version ofxwith numerical precisionT. -
destructure(Vector, x)anddestructure(Vector{T}, x)yield a vector whiledestructure(Tuple, x)yields a tuple asdestructure(x).
-
convert_eltype(T,A)forAan instance ofLinearAgebra.Factorization. -
Tests with
Aqua.jl.
-
A few minor things detected by
Aqua.jlhave been fixed. -
Better rule for element type conversion of
AbstractUnitRangeinstances. -
Fix specialization of
Base.return_typeswhich shall return a vector of types.
is_signed(x)is false ifxis a complex number with unsigned rational parts.
-
New
is_signedmethod to infer whether a value of a given numeric type can be negated while retaining the same type. -
Extend
similarfor the type of arrays returned byas_eltype.
-
Macro
@assert_floating_pointto assert whether arguments or variables of a function do use floating-point for storing their value(s). -
New function
assert_floating_pointto assert whether an object does use floating-point for storing its value(s). This method is a trait: its result only depend on the type of its argument and this type may be directly specified.
@publiccan take macro names (prefixed by@) as argument.
- Relax type restriction on
Tinconvert_bare_type(T, x),convert_real_type(T, x), andconvert_floating_point_type(T, x).
- Fix
new_array(T)andnew_array(T,())to yield a 0-dimensional array.
-
Non-exported public constructor
c = TypeUtils.Converter(f,T::Type)such thatcis callable andc(x)yieldsf(T,x)for anyx. This replaces and generalizes private typeAs. -
Methods
as(T),nearest(T),convert_bare_type(T),convert_real_type(T),convert_floating_point_type(T), andconvert_eltype(T)yield converters to typeT.
- Inference works for more than 3 arguments for
bare_type(args...),real_type(args...), andfloating_point_type(args...).
- New
nearest(T,x)method to return the value of typeTthat is the nearest tox. ForTinteger andxreal, it can be seen as rounding with clamping.
- Non-exported
TypeUtils.@publicmacro is now public.
-
New macro
TypeUtils.@publicused to declare non-exported public symbols. Does nothing for Julia versions older than 1.11. -
For other packages, it may be sufficient to extend
convert_eltype(T, X)to a given typeXto haveconvert_eltype(T, x::X)work for instancesxof that type.
-
AbstractUnitRange{<:Integer}has been replaced byAbstractRange{<:Integer}as the eligible type for specifying an array axis. Methodsas_array_axis,as_array_axes, andas_array_shapeconvert index ranges toAbstractUnitRange{Int}throwing an exception if any range does not have unit step. The downside is that this must be explicitly checked for non-AbstractUnitRange{<:Integer}ranges while it can be inferred by type (it is a trait) forAbstractUnitRange{<:Integer}ranges. -
The exported alias
RelaxedArrayShape{N}reflects the above change. Exported aliasArrayShape{N}is restricted to integers and integer-valued unit-ranges which better correspond to Julia's way of representing anN-dimensional array shape.
TypeStableFunction(f, argtypes...)better tries to infer a suitable concrete type forfwith arguments of typesargtypes....
-
Non-exported type
TypeUtils.Unsupportedmay be used to provide a fallback implementation of a method for given types of arguments that is only supported when some extension is loaded. -
new_array(T, inds...)creates an array with elements of typeTand shape defined byinds.... The returned array is anOffsetArray{T}ifinds...contains any index range other thanBase.OneToand anArray{T}otherwise. In the former case, an exception is thrown if the packageOffsetArrayshas not been loaded.
Add a few types and methods related to array size and axes:
-
ArrayAxis = AbstractUnitRange{eltype(Dims)}is an alias to the possible canonical types representing a single array index range. -
ArrayAxes{N} = NTuple{N,ArrayAxis}is an alias to the possible canonical types representingN-dimensional array axes. -
ArrayShape{N}is an alias to theN-tuple of array dimensions and/or index ranges to whichas_array_shape,as_array_size, oras_array_axesare applicable. -
as_array_shapeconverts its argument(s) to canonical array axes or to canonical array size. -
as_array_axesconverts its argument(s) to canonical array axes, that is aN-tuple of typeArrayAxes{N}.as_array_axisconverts its argument to a single array axis of typeArrayAxis. -
as_array_sizeconverts its argument(s) to a canonical array size, that is aN-tuple of typeDims{N}.as_array_dimconverts its argument to a single array dimension length of typeeltype(Dims).
-
to_same_type(x...)is a substitute topromote(x...)that warrants that returned instances have the same type and that callsas(T,x), notconvert(T,x), if any conversion is needed. -
to_same_concrete_type(T...)is a substitute topromote_type(T...)that throws an exception if typesT...cannot be promoted to a common concrete type.
convert_eltypecan be applied to a number.
- All methods and types formerly provided by
Unitlessare now provided byTypeUtilswhich supersedesUnitless.
TwoDimensionalis no longer an extension becauseTwoDimensionalversion 0.5 directly extendsconvertas expected byTypeUtils.
- Method
as_return(T, f)builds an instance ofTypeStableFunction{T}which is a sub-type ofAbstractTypeStableFunction{T}. These two types are both exported.
- Methods
destructure,destructure!, andrestructureare inlined.
- Methods
destructure,destructure!,restructure, andstruct_lengthcan deal with tuples.
-
New methods
vals = destructure(obj)ordestructure!(vals, obj), andobj = restructure(T, vals)to destructure and objectobjas a tuple or vector of its values and, conversely, to rebuild an object of typeTfrom its values. -
New method
struct_lengthyields the number of values needed to destructure an object.
- Fix
convert_eltype(T,A)whenAis a range.
parameterlessis now implemented asconstructorofinConstructionBase.
convert_eltype(T,A)yields a tuple ifAis a tuple.
convert_eltype(T,A)yields a range ifAis a range.
This is the first version as an official Julia package.
- Fix a typo causing
as_returnto fail when applied to anAsReturnobject.
-
New method
as_return(T, f)yields a callable object that behaves likefwhen called as a function except that it lazily converts the value returned byfto typeT. -
New method
return_type(f, argtypes...)to infer the type of the result returned by the callable objectfwhen called with arguments of typesargtypes....
-
New method
promote_eltype(args...)to yield the promoted element type ofargs.... -
New method
convert_eltype(T,A)to convert the element type ofAto beT. -
New method
as_eltype(T,A)to lazily convert the element type ofAto beT.
-
Method
parameterless(T)to get the typeTwithout parameter specifications. For example:julia> parameterless(Vector{Float32}) Array
-
Methods
as(T,x)to convertxto typeT. -
Call
f = as(T)to build a callable object such thatf(x)is the same asas(T,x). -
Extension for
TwoDimensonal.
- Package was previously named
AsTypeandCastType.