Compat.Fix
— TypeFix{N}(f, x)
A type representing a partially-applied version of a function f
, with the argument x
fixed at position N::Int
. In other words, Fix{3}(f, x)
behaves similarly to (y1, y2, y3...; kws...) -> f(y1, y2, x, y3...; kws...)
.
When nesting multiple Fix
, note that the N
in Fix{N}
is relative to the current available arguments, rather than an absolute ordering on the target function. For example, Fix{1}(Fix{2}(f, 4), 4)
fixes the first and second arg, while Fix{2}(Fix{1}(f, 4), 4)
fixes the first and third arg.
Note that Compat.Fix{1}
/Fix{2}
are not the same as Base.Fix1
/Fix2
on Julia versions earlier than 1.12.0-DEV.981
. Therefore, if you wish to use this as a way to dispatch on Fix{N}
, you may wish to declare a method for both Compat.Fix{1}
/Fix{2}
as well as Base.Fix1
/Fix2
, conditional on a @static if !isdefined(Base, :Fix); ...; end
.
Compat.Fix1
— TypeAlias for Fix{1}
. See Fix
.
Compat.Fix2
— TypeAlias for Fix{2}
. See Fix
.
Compat.LogRange
— TypeLogRange{T}(start, stop, len) <: AbstractVector{T}
A range whose elements are spaced logarithmically between start
and stop
, with spacing controlled by len
. Returned by logrange
.
Like LinRange
, the first and last elements will be exactly those provided, but intermediate values may have small floating-point errors. These are calculated using the logs of the endpoints, which are stored on construction, often in higher precision than T
.
The version of this struct in Compat.jl does not use Base.TwicePrecision{Float64}
before Julia 1.9. Therefore it has larger floating-point errors on intermediate points than shown below.
The printing of Compat.jl's version of the struct is also different, less like LinRange
and more like Vector
.
Examples
julia> logrange(1, 4, length=5)
5-element Base.LogRange{Float64, Base.TwicePrecision{Float64}}:
1.0, 1.41421, 2.0, 2.82843, 4.0
julia> Base.LogRange{Float16}(1, 4, 5)
5-element Base.LogRange{Float16, Float64}:
1.0, 1.414, 2.0, 2.828, 4.0
julia> logrange(1e-310, 1e-300, 11)[1:2:end]
6-element Vector{Float64}:
1.0e-310
9.999999999999974e-309
9.999999999999981e-307
9.999999999999988e-305
9.999999999999994e-303
1.0e-300
julia> prevfloat(1e-308, 5) == ans[2]
true
Note that integer eltype T
is not allowed. Use for instance round.(Int, xs)
, or explicit powers of some integer base:
julia> xs = logrange(1, 512, 4)
4-element Base.LogRange{Float64, Base.TwicePrecision{Float64}}:
1.0, 8.0, 64.0, 512.0
julia> 2 .^ (0:3:9) |> println
[1, 8, 64, 512]
Compat._valid_macro
— Method_valid_macro(expr)
Check if expr
is a valid macro call with no arguments.
Compat.logrange
— Functionlogrange(start, stop, length)
logrange(start, stop; length)
Construct a specialized array whose elements are spaced logarithmically between the given endpoints. That is, the ratio of successive elements is a constant, calculated from the length.
This is similar to geomspace
in Python. Unlike PowerRange
in Mathematica, you specify the number of elements not the ratio. Unlike logspace
in Python and Matlab, the start
and stop
arguments are always the first and last elements of the result, not powers applied to some base.
Examples
julia> logrange(10, 4000, length=3)
3-element Base.LogRange{Float64, Base.TwicePrecision{Float64}}:
10.0, 200.0, 4000.0
julia> ans[2] ≈ sqrt(10 * 4000) # middle element is the geometric mean
true
julia> range(10, 40, length=3)[2] ≈ (10 + 40)/2 # arithmetic mean
true
julia> logrange(1f0, 32f0, 11)
11-element Base.LogRange{Float32, Float64}:
1.0, 1.41421, 2.0, 2.82843, 4.0, 5.65685, 8.0, 11.3137, 16.0, 22.6274, 32.0
julia> logrange(1, 1000, length=4) ≈ 10 .^ (0:3)
true
See the Compat.LogRange
type for further details.
The version of this struct in Compat.jl does not use Base.TwicePrecision{Float64}
before Julia 1.9, so it sometimes has larger floating-point errors on intermediate points.
The printing of Compat.jl's version of the struct is also different, less like LinRange
and more like Vector
.