PTYQoL.jl
PTYQoL.fields
— Method@generated fields(::Type{T}) where T = fieldnames(T)
The same as fieldnames
, but is @generated
so is fast.
PTYQoL.fracpochhammer
— Methodfracpochhammer(a, b, n)
Calculate the fraction of two Pochhammer symbols $\frac{(a)_n}{(b)_n}$ by multiplying the fractions. This approach reduces the risk of overflow/underflow when $n$ is large.
Examples
julia> fracpochhammer(1, 2, 3) # (1 * 2 * 3) / (2 * 3 * 4)
0.25
fracpochhammer(a, b, stepa, stepb, n)
Similar to fracpochhammer(a, b, n)
, except that the steps of the Pochhammer symbols are not necessarily $1$.
Examples
julia> fracpochhammer(1, 2, 0.5, 1, 3) # (1 * 1.5 * 2) / (2 * 3 * 4)
0.125
PTYQoL.isalias
— Methodisalias(type)
Check if a type is alias.
Examples
julia> isalias(Vector)
true
julia> isalias(Array)
false
PTYQoL.ln
— Functionconst ln = Fix1(log,ℯ)
Natural logarithm.
PTYQoL.seealso
— Methodseealso(s...)
Produce the "See also" parts of docstrings.
julia> seealso(sin)
"See also [`sin`](@ref)."
julia> seealso(sin, cos)
"See also [`sin`](@ref) and [`cos`](@ref)."
julia> seealso(sin, cos, tan)
"See also [`sin`](@ref), [`cos`](@ref) and [`tan`](@ref)."
PTYQoL.@Vararg1
— Macro@Vararg1
Use before a function definition to let x::T...
means at least one (instead of zero by Julia default) of type T
. This can be used to avoid ambiguity as all Vararg{T}
overlap at zero argument.
Example
julia> mysum1(x::Int...) = x
mysum1 (generic function with 1 method)
julia> mysum1() # works for 0 argument
()
julia> mysum1(x::Float64...) = x
mysum1 (generic function with 2 methods)
julia> mysum1()
ERROR: MethodError: mysum1() is ambiguous.
julia> @Vararg1 mysum2(x::Int...) = x
mysum2 (generic function with 1 method)
julia> @Vararg1 mysum2(x::Float64...) = x
mysum2 (generic function with 2 methods)
julia> mysum2()
ERROR: MethodError: no method matching mysum2()
PTYQoL.@struct_all
— Macro@struct_all(TYP, op)
@struct_all(TYP, ops...)
Define the operator of the type TYP
by applying the operator to each field and return true only when all the results are true. See also @struct_any
, @struct_copy
and @struct_map
.
Example
julia> struct Foo
a
b
end
julia> x = Foo(1,1)
Foo(1, 1)
julia> y = Foo(1.0,1.0)
Foo(1.0, 1.0)
julia> x==y, isequal(x,y)
(false, false)
julia> isapprox(x,y)
ERROR: MethodError: no method matching isapprox(::Foo, ::Foo)
julia> isfinite(x)
ERROR: MethodError: no method matching isfinite(::Foo)
julia> @struct_all Foo Base.:(==) Base.isequal Base.isapprox Base.isfinite
julia> x==y, isequal(x,y), isapprox(x,y), isfinite(x)
(true, true, true, true)
PTYQoL.@struct_any
— Macro@struct_any(TYP, op)
@struct_any(TYP, ops...)
Define the binary operator of the type TYP
by applying the operator to each field and return true when any of the results is true. See also @struct_all
, @struct_copy
and @struct_map
.
Example
julia> struct Foo
a
b
end
julia> x = Foo(Inf, NaN)
Foo(Inf, NaN)
julia> isinf(x)
ERROR: MethodError: no method matching isinf(::Foo)
julia> isnan(x)
ERROR: MethodError: no method matching isnan(::Foo)
julia> @struct_any Foo Base.isinf Base.isnan
julia> isinf(x), isnan(x)
(true, true)
PTYQoL.@struct_copy
— Macro@struct_copy(TYP)
Generate Base.copy
for copying structs of type TYP
. See also @struct_all
, @struct_any
and @struct_map
.
Example
julia> struct Foo
a
b
end
julia> x = Foo(1,1)
Foo(1, 1)
julia> y = copy(x)
ERROR: MethodError: no method matching copy(::Foo)
julia> @struct_copy Foo;
julia> y = copy(x)
Foo(1, 1)
PTYQoL.@struct_map
— Macro@struct_map(TYP, op)
@struct_map(TYP, ops...)
Define the function(s) of the type TYP
by applying the function(s) to each field and generate a new TYP
with the values. The generated function(s) are somehow faster than the naive implementation. See also @struct_all
, @struct_any
and @struct_copy
.
Example
julia> struct Foo
a
b
end
julia> x = Foo(1,1)
Foo(1, 1)
julia> @struct_map(Foo, Base.exp, Base.sin, Base.:+)
julia> exp(x), sin(x), x+x
(Foo(2.718281828459045, 2.718281828459045), Foo(0.8414709848078965, 0.8414709848078965), Foo(2, 2))