Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .JuliaFormatter.toml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/CompatHelper.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: "CompatHelper"

on:
schedule:
- cron: 0 0 * * *
- cron: '0 0 * * *'
workflow_dispatch:
permissions:
contents: write
Expand Down
13 changes: 8 additions & 5 deletions .github/workflows/FormatCheck.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
name: "Format Check"

on:
push:
branches:
- 'main'
tags: '*'
pull_request:
pull_request_target:
paths: ['**/*.jl']
types: [opened, synchronize, reopened, ready_for_review]

permissions:
contents: read
actions: write
pull-requests: write

jobs:
format-check:
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
.vscode/
Manifest.toml
benchmark/*.json
dev/
docs/LocalPreferences.toml
docs/Manifest.toml
docs/build/
docs/src/index.md
examples/LocalPreferences.toml
test/LocalPreferences.toml
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ci:
skip: [julia-formatter]
skip: [runic]

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
Expand All @@ -11,7 +11,7 @@ repos:
- id: end-of-file-fixer
exclude_types: [markdown] # incompatible with Literate.jl

- repo: "https://github.com/domluna/JuliaFormatter.jl"
rev: v2.1.6
- repo: https://github.com/fredrikekre/runic-pre-commit
rev: v2.0.1
hooks:
- id: "julia-formatter"
- id: runic
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "UnspecifiedTypes"
uuid = "42b3faec-625b-4613-8ddc-352bf9672b8d"
authors = ["ITensor developers <support@itensor.org> and contributors"]
version = "0.1.6"
version = "0.1.7"

[compat]
julia = "1.10"
22 changes: 11 additions & 11 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@ using UnspecifiedTypes: UnspecifiedTypes
using Documenter: Documenter, DocMeta, deploydocs, makedocs

DocMeta.setdocmeta!(
UnspecifiedTypes, :DocTestSetup, :(using UnspecifiedTypes); recursive=true
UnspecifiedTypes, :DocTestSetup, :(using UnspecifiedTypes); recursive = true
)

include("make_index.jl")

makedocs(;
modules=[UnspecifiedTypes],
authors="ITensor developers <support@itensor.org> and contributors",
sitename="UnspecifiedTypes.jl",
format=Documenter.HTML(;
canonical="https://itensor.github.io/UnspecifiedTypes.jl",
edit_link="main",
assets=["assets/favicon.ico", "assets/extras.css"],
),
pages=["Home" => "index.md", "Reference" => "reference.md"],
modules = [UnspecifiedTypes],
authors = "ITensor developers <support@itensor.org> and contributors",
sitename = "UnspecifiedTypes.jl",
format = Documenter.HTML(;
canonical = "https://itensor.github.io/UnspecifiedTypes.jl",
edit_link = "main",
assets = ["assets/favicon.ico", "assets/extras.css"],
),
pages = ["Home" => "index.md", "Reference" => "reference.md"],
)

deploydocs(;
repo="github.com/ITensor/UnspecifiedTypes.jl", devbranch="main", push_preview=true
repo = "github.com/ITensor/UnspecifiedTypes.jl", devbranch = "main", push_preview = true
)
16 changes: 8 additions & 8 deletions docs/make_index.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ using Literate: Literate
using UnspecifiedTypes: UnspecifiedTypes

function ccq_logo(content)
include_ccq_logo = """
include_ccq_logo = """
```@raw html
<img class="display-light-only" src="assets/CCQ.png" width="20%" alt="Flatiron Center for Computational Quantum Physics logo."/>
<img class="display-dark-only" src="assets/CCQ-dark.png" width="20%" alt="Flatiron Center for Computational Quantum Physics logo."/>
```
"""
content = replace(content, "{CCQ_LOGO}" => include_ccq_logo)
return content
content = replace(content, "{CCQ_LOGO}" => include_ccq_logo)
return content
end

Literate.markdown(
joinpath(pkgdir(UnspecifiedTypes), "examples", "README.jl"),
joinpath(pkgdir(UnspecifiedTypes), "docs", "src");
flavor=Literate.DocumenterFlavor(),
name="index",
postprocess=ccq_logo,
joinpath(pkgdir(UnspecifiedTypes), "examples", "README.jl"),
joinpath(pkgdir(UnspecifiedTypes), "docs", "src");
flavor = Literate.DocumenterFlavor(),
name = "index",
postprocess = ccq_logo,
)
16 changes: 8 additions & 8 deletions docs/make_readme.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ using Literate: Literate
using UnspecifiedTypes: UnspecifiedTypes

function ccq_logo(content)
include_ccq_logo = """
include_ccq_logo = """
<picture>
<source media="(prefers-color-scheme: dark)" width="20%" srcset="docs/src/assets/CCQ-dark.png">
<img alt="Flatiron Center for Computational Quantum Physics logo." width="20%" src="docs/src/assets/CCQ.png">
</picture>
"""
content = replace(content, "{CCQ_LOGO}" => include_ccq_logo)
return content
content = replace(content, "{CCQ_LOGO}" => include_ccq_logo)
return content
end

Literate.markdown(
joinpath(pkgdir(UnspecifiedTypes), "examples", "README.jl"),
joinpath(pkgdir(UnspecifiedTypes));
flavor=Literate.CommonMarkFlavor(),
name="README",
postprocess=ccq_logo,
joinpath(pkgdir(UnspecifiedTypes), "examples", "README.jl"),
joinpath(pkgdir(UnspecifiedTypes));
flavor = Literate.CommonMarkFlavor(),
name = "README",
postprocess = ccq_logo,
)
2 changes: 1 addition & 1 deletion examples/README.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# # UnspecifiedTypes.jl
#
#
# [![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://itensor.github.io/UnspecifiedTypes.jl/stable/)
# [![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://itensor.github.io/UnspecifiedTypes.jl/dev/)
# [![Build Status](https://github.com/ITensor/UnspecifiedTypes.jl/actions/workflows/Tests.yml/badge.svg?branch=main)](https://github.com/ITensor/UnspecifiedTypes.jl/actions/workflows/Tests.yml?query=branch%3Amain)
Expand Down
2 changes: 1 addition & 1 deletion src/unspecifiedarray.jl
Original file line number Diff line number Diff line change
@@ -1 +1 @@
struct UnspecifiedArray{ElT,N} <: AbstractArray{ElT,N} end
struct UnspecifiedArray{ElT, N} <: AbstractArray{ElT, N} end
18 changes: 9 additions & 9 deletions src/unspecifiednumber.jl
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
abstract type AbstractUnspecifiedNumber <: Number end

struct UnspecifiedNumber{T<:Number} <: AbstractUnspecifiedNumber
value::T
global @inline function _UnspecifiedNumber(value::Number)
return new{typeof(value)}(value)
end
struct UnspecifiedNumber{T <: Number} <: AbstractUnspecifiedNumber
value::T
global @inline function _UnspecifiedNumber(value::Number)
return new{typeof(value)}(value)
end
end

UnspecifiedNumber(n::Number) = _UnspecifiedNumber(n)
UnspecifiedNumber{T}(n::Number) where {T<:Number} = UnspecifiedNumber(convert(T, n))
UnspecifiedNumber{T}(n::Number) where {T <: Number} = UnspecifiedNumber(convert(T, n))

UnspecifiedNumber{T}(n::UnspecifiedNumber{T}) where {T<:Number} = n
UnspecifiedNumber{T}(n::UnspecifiedNumber{T}) where {T <: Number} = n

# Fix ambiguity error.
function UnspecifiedNumber{T}(n::Base.TwicePrecision) where {T<:Number}
return UnspecifiedNumber(convert(T, n))
function UnspecifiedNumber{T}(n::Base.TwicePrecision) where {T <: Number}
return UnspecifiedNumber(convert(T, n))
end
2 changes: 1 addition & 1 deletion src/unspecifiedzero.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Base.zero(n::UnspecifiedZero) = zero(typeof(n))

# This helps handle a lot of basic algebra, like:
# UnspecifiedZero() + 2.3 == 2.3
Base.convert(::Type{T}, x::UnspecifiedZero) where {T<:Number} = T(zero(T))
Base.convert(::Type{T}, x::UnspecifiedZero) where {T <: Number} = T(zero(T))

#Base.convert(::Type{Complex{UnspecifiedZero}}, x::UnspecifiedZero) = complex(x)

Expand Down
76 changes: 39 additions & 37 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,58 +6,60 @@ using Suppressor: Suppressor
const pat = r"(?:--group=)(\w+)"
arg_id = findfirst(contains(pat), ARGS)
const GROUP = uppercase(
if isnothing(arg_id)
get(ENV, "GROUP", "ALL")
else
only(match(pat, ARGS[arg_id]).captures)
end,
if isnothing(arg_id)
get(ENV, "GROUP", "ALL")
else
only(match(pat, ARGS[arg_id]).captures)
end,
)

"match files of the form `test_*.jl`, but exclude `*setup*.jl`"
function istestfile(fn)
return endswith(fn, ".jl") && startswith(basename(fn), "test_") && !contains(fn, "setup")
return endswith(fn, ".jl") && startswith(basename(fn), "test_") && !contains(fn, "setup")
end
"match files of the form `*.jl`, but exclude `*_notest.jl` and `*setup*.jl`"
function isexamplefile(fn)
return endswith(fn, ".jl") && !endswith(fn, "_notest.jl") && !contains(fn, "setup")
return endswith(fn, ".jl") && !endswith(fn, "_notest.jl") && !contains(fn, "setup")
end

@time begin
# tests in groups based on folder structure
for testgroup in filter(isdir, readdir(@__DIR__))
if GROUP == "ALL" || GROUP == uppercase(testgroup)
for file in filter(istestfile, readdir(joinpath(@__DIR__, testgroup); join=true))
@eval @safetestset $file begin
include($file)
# tests in groups based on folder structure
for testgroup in filter(isdir, readdir(@__DIR__))
if GROUP == "ALL" || GROUP == uppercase(testgroup)
for file in filter(istestfile, readdir(joinpath(@__DIR__, testgroup); join = true))
@eval @safetestset $file begin
include($file)
end
end
end
end
end
end

# single files in top folder
for file in filter(istestfile, readdir(@__DIR__))
(file == basename(@__FILE__)) && continue # exclude this file to avoid infinite recursion
@eval @safetestset $file begin
include($file)
# single files in top folder
for file in filter(istestfile, readdir(@__DIR__))
(file == basename(@__FILE__)) && continue # exclude this file to avoid infinite recursion
@eval @safetestset $file begin
include($file)
end
end
end

# test examples
examplepath = joinpath(@__DIR__, "..", "examples")
for (root, _, files) in walkdir(examplepath)
contains(chopprefix(root, @__DIR__), "setup") && continue
for file in filter(isexamplefile, files)
filename = joinpath(root, file)
@eval begin
@safetestset $file begin
$(Expr(
:macrocall,
GlobalRef(Suppressor, Symbol("@suppress")),
LineNumberNode(@__LINE__, @__FILE__),
:(include($filename)),
))
# test examples
examplepath = joinpath(@__DIR__, "..", "examples")
for (root, _, files) in walkdir(examplepath)
contains(chopprefix(root, @__DIR__), "setup") && continue
for file in filter(isexamplefile, files)
filename = joinpath(root, file)
@eval begin
@safetestset $file begin
$(
Expr(
:macrocall,
GlobalRef(Suppressor, Symbol("@suppress")),
LineNumberNode(@__LINE__, @__FILE__),
:(include($filename)),
)
)
end
end
end
end
end
end
end
2 changes: 1 addition & 1 deletion test/test_aqua.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ using Aqua: Aqua
using Test: @testset

@testset "Code quality (Aqua.jl)" begin
Aqua.test_all(UnspecifiedTypes)
Aqua.test_all(UnspecifiedTypes)
end
28 changes: 14 additions & 14 deletions test/test_basics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ using UnspecifiedTypes: UnspecifiedZero
using Test: @testset, @test

@testset "UnspecifiedTypes (eltype=$elt)" for elt in (
Float32, Float64, Complex{Float32}, Complex{Float64}
)
for x in (elt(2) + UnspecifiedZero(), UnspecifiedZero() + elt(2))
@test x isa elt
@test x === elt(2)
end
Float32, Float64, Complex{Float32}, Complex{Float64},
)
for x in (elt(2) + UnspecifiedZero(), UnspecifiedZero() + elt(2))
@test x isa elt
@test x === elt(2)
end

for x in (elt(2) * UnspecifiedZero(), UnspecifiedZero() * elt(2))
@test x isa UnspecifiedZero
@test x === UnspecifiedZero()
end
for x in (elt(2) * UnspecifiedZero(), UnspecifiedZero() * elt(2))
@test x isa UnspecifiedZero
@test x === UnspecifiedZero()
end

# Normally, any number type takes precedence over
# `Bool`, check this isn't the case with `UnspecifiedZero`.
@test promote_type(UnspecifiedZero, Bool) === Bool
@test promote_type(Bool, UnspecifiedZero) === Bool
# Normally, any number type takes precedence over
# `Bool`, check this isn't the case with `UnspecifiedZero`.
@test promote_type(UnspecifiedZero, Bool) === Bool
@test promote_type(Bool, UnspecifiedZero) === Bool
end
Loading