Tool Functions

Quiqbox.flattenMethod
flatten(a::Tuple) -> Tuple

flatten(a::AbstractVector) -> AbstractVector

Flatten a::Union{AbstractVector, Tuple} that contains AbstractArrays and/or Tuples. Only operate on the outermost container.

≡≡≡ Example(s) ≡≡≡

julia> flatten((:one, 2, [3, 4.0], ([5], "six"), "7"))
(:one, 2, 3.0, 4.0, [5], "six", "7")

julia> flatten([:one, 2, [3, 4.0], ([5], "six"), "7"])
7-element Vector{Any}:
  :one
 2
 3.0
 4.0
  [5]
  "six"
  "7"
source
Quiqbox.getAtolDigitsMethod
getAtolDigits(::Type{T}) where {T<:Real} -> Int

Return the maximal number of digits kept after rounding of the input real number type T.

source
Quiqbox.getAtolValMethod
getAtolVal(::Type{T}) where {T<:Real} -> Real

Return the absolute precision tolerance of the input real number type T.

source
Quiqbox.getUnique!Method
getUnique!(arr::AbstractVector, args...; compareFunction::Function = hasEqual, 
           kws...) -> 
AbstractVector

Similar to markUnique but instead, directly return the modified arr so that the repeated entries are deleted.

≡≡≡ Example(s) ≡≡≡

julia> arr = [1, [1, 2],"s", [1, 2]]
4-element Vector{Any}:
 1
  [1, 2]
  "s"
  [1, 2]

julia> getUnique!(arr);

julia> arr
3-element Vector{Any}:
 1
  [1, 2]
  "s"
source
Quiqbox.hasApproxMethod
hasApprox(obj1, obj2, obj3...; ignoreFunction::Bool=false, ignoreContainer::Bool=false,
          decomposeNumberCollection::Bool=false, atol::Real=1e-15) -> 
Bool

Similar to hasEqual, except it does not require the Number-typed fields (e.g. Float64) of the compared containers to have the exact same values, but rather the approximate values within an error threshold determined by atol, like in isapprox.

source
Quiqbox.hasBoolRelationMethod
hasBoolRelation(boolOp::Function, obj1, obj2, obj3...; 
                ignoreFunction::Bool=false, 
                ignoreContainer::Bool=false,
                decomposeNumberCollection::Bool=false) -> 
Bool

Method for more than 2 objects. If returns true if and only if hasBoolRelation returns true for every unique combination of two objects from the all the input objects under the transitive relation. E.g.: hasBoolRelation(>, a, b, c) is equivalent to hasBoolRelation(>, a, b) && hasBoolRelation(>, b, c).

≡≡≡ Example(s) ≡≡≡

begin
    struct S
        a::Int
        b::Float64
    end

    a = S(1, 1.0)
    b = S(2, 0.5)
    c = S(2, 1.5)
    d = S(3, 2.0)

    Quiqbox.hasBoolRelation(>=, c, b, a) |> println
    Quiqbox.hasBoolRelation(>=, d, c, b) |> println
end

# output
false
true
source
Quiqbox.hasBoolRelationMethod
hasBoolRelation(boolOp::Function, obj1, obj2; ignoreFunction::Bool=false, 
                ignoreContainer::Bool=false, decomposeNumberCollection::Bool=false) -> 
Bool

Recursively apply the specified boolean operator boolOp to all the fields inside two objects (e.g., two structs of the same type). It returns true if and only if all comparisons performed return true. Note that the boolean operator should have method(s) defined for all the possible fields inside the compared objects.

If ignoreFunction = true, comparisons between Function-type fields will be ignored.

If ignoreContainer = true, the difference of the container(s) will be ignored as long as the boolean operator returns true for the field(s)/entry(s) from two objects respectively.

If decomposeNumberCollection = true, Tuple{Vararg{Number}} and Array{<:Number} will be treated as decomposable containers.

≡≡≡ Example(s) ≡≡≡

begin
    struct S
        a::Int
        b::Float64
    end

    a = S(1, 1.0)
    b = S(2, 0.5)
    c = S(2, 1.5)

    Quiqbox.hasBoolRelation(>, a, b) |> println
    Quiqbox.hasBoolRelation(>, b, a) |> println
    Quiqbox.hasBoolRelation(>, c, a) |> println
end

# output
false
false
true
begin
    struct S
        a::Int
        b::Float64
    end

    struct S2
        a::Int
        b::Float64
    end

    Quiqbox.hasBoolRelation(==, S(1,2), S2(1,2), ignoreContainer=true)
end

# output
true
source
Quiqbox.hasEqualMethod
hasEqual(obj1, obj2, obj3...; 
         ignoreFunction::Bool=false, 
         ignoreContainer::Bool=false,
         decomposeNumberCollection::Bool=false) -> 
Bool

Compare if two containers (e.g. struct) are equal. An instantiation of hasBoolRelation. ≡≡≡ Example(s) ≡≡≡

begin
    struct S
        a::Int
        b::Float64
    end
    a = S(1, 1.0)
    b = S(1, 1.0)
    c = S(1, 1.0)
    d = S(1, 1.1)

    hasEqual(a, b, c) |> println
    hasEqual(a, b, c, d) |> println
end

# output
true
false
source
Quiqbox.hasIdenticalMethod
hasIdentical(obj1, obj2, obj3...; 
             ignoreFunction::Bool=false, 
             ignoreContainer::Bool=false,
             decomposeNumberCollection::Bool=false) -> 
Bool

Compare if two containers (e.g. struct) are the Identical. An instantiation of hasBoolRelation.

≡≡≡ Example(s) ≡≡≡

begin
    struct S
        a::Int
        b::Vector{Float64}
    end

    a = S(1, [1.0, 1.1])
    b = a
    c = b
    d = S(1, [1.0, 1.1])

    hasIdentical(a, b, c) |> println
    hasIdentical(a, b, c, d) |> println
end

# output
true
false
source
Quiqbox.markUniqueMethod
markUnique(arr::AbstractArray{T}, args...; 
           compareFunction::Function=hasEqual, kws...) where {T} -> 
Tuple{Vector{Int}, Vector{T}}

Return a Vector{Int} whose elements are indices to mark the elements inside arr such that same element will be marked with same index, and a Vector{T} containing all the unique elements. The definition of "unique" (or "same") is based on compareFunction which is set to hasEqual in default. args and kws are placeholders for the positional arguments and keyword arguments for compareFunction respectively.

≡≡≡ Example(s) ≡≡≡

markUnique([1, [1, 2],"s", [1, 2]])

# output
([1, 2, 3, 2], Any[1, [1, 2], "s"])
begin
    struct S
        a::Int
        b::Float64
    end

    a = S(1, 2.0)
    b = S(1, 2.0)
    c = S(1, 2.1)
    d = a

    markUnique([a,b,c,d])
end

# output
([1, 1, 2, 1], S[S(1, 2.0), S(1, 2.1)])
source
Quiqbox.printStyledInfoMethod
printStyledInfo(str::String; title::String="", titleColor::Symbol=:light_blue) -> 
Nothing

Print info with colorful title and automatically highlighted code blocks enclosed by .

If you want to highlight other contents in different colors, you can also start it with "///theColorSymbolName///" and then enclose it with `. The available color names follows the values ofcolorkeyword argument in functionBase.printstyled`.

NOTE: There can only be one color in one quote.

≡≡≡ Example(s) ≡≡≡

julia> Quiqbox.printStyledInfo("This `///magenta///word` is in color magenta.")
This word is in color magenta.
source
Quiqbox.replaceSymbolMethod
replaceSymbol(sym::Symbol, pair::Pair{String, String}; count::Int=typemax(Int)) -> 
Symbol

Similar as Base.replace but for Symbols.

source
Quiqbox.checkFnameMethod
checkFname(Fname::String; showWarning::Bool=true) -> String

Check if there is a file with the same name in the current directory. If so, add a "_N" at the end of Fname. showWarning determines whether to print out the WARNING info when there is a file with the same name.

source
Quiqbox.flattenMethod
flatten(bs::AbstractVector{<:GTBasisFuncs{T, D}}) where {T, D} -> 
AbstractVector{<:GTBasisFuncs{T, D, 1}}

flatten(bs::Tuple{Vararg{GTBasisFuncs{T, D}}}) where {T, D} -> 
Tuple{Vararg{GTBasisFuncs{T, D, 1}}}

Flatten a collection of GTBasisFuncs by decomposing every GTBasisFuncs{T, D, ON} where ON > 1 into multiple GTBasisFuncs{T, D, 1}.

source