-
Notifications
You must be signed in to change notification settings - Fork 4
/
ScientificTypesBase.jl
115 lines (86 loc) · 3.16 KB
/
ScientificTypesBase.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
module ScientificTypesBase
# Type exports
export Convention
# re-export-able types and methods
export Scientific, Found, Unknown, Known, Finite, Infinite,
OrderedFactor, Multiclass, Count, Continuous,
ScientificTimeType, ScientificDate, ScientificDateTime,
ScientificTime,
Textual, Binary,
ColorImage, GrayImage, Image, Table,
Density, Sampleable,
ManifoldPoint,
Annotated, AnnotationOf, Multiset, Iterator,
Compositional
export elscitype, nonmissing
# -------------------------------------------------------------------
# Scientific Types
abstract type Found end
abstract type Known <: Found end
abstract type Unknown <: Found end
abstract type Annotated{S} <: Known end
abstract type AnnotationOf{S} <: Known end
abstract type Multiset{S} <: Known end
# for iterators over objects with scitype Ω that do not have some
# AbstractVector scitype:
abstract type Iterator{Ω} end
abstract type Infinite <: Known end
abstract type Finite{N} <: Known end
abstract type Image{W,H} <: Known end
abstract type ScientificTimeType <: Known end
abstract type Textual <: Known end
abstract type Table{K} <: Known end
abstract type Continuous <: Infinite end
abstract type Count <: Infinite end
abstract type Multiclass{N} <: Finite{N} end
abstract type OrderedFactor{N} <: Finite{N} end
abstract type ScientificDate <: ScientificTimeType end
abstract type ScientificTime <: ScientificTimeType end
abstract type ScientificDateTime <: ScientificTimeType end
abstract type GrayImage{W,H} <: Image{W,H} end
abstract type ColorImage{W,H} <: Image{W,H} end
# when sampled, objects with these scitypes return objects of scitype Ω:
abstract type Sampleable{Ω} end
abstract type Density{Ω} <: Sampleable{Ω} end
abstract type ManifoldPoint{M} <: Known end
# compositional data with D components, see CoDa.jl
abstract type Compositional{D} <: Known end
# aliases:
const Binary = Finite{2}
const Scientific = Union{Missing,Found} # deprecated (no longer publicized)
# for internal use
const Arr = AbstractArray
const TUPLE_SPECIALIZATION_THRESHOLD = 20
# ------------------------------------------------------------------
# Convention
abstract type Convention end
# -----------------------------------------------------------------
# nonmissing
if VERSION < v"1.3"
# see also discourse.julialang.org/t/get-non-missing-type-in-the-case-of-parametric-type/29109
"""
nonmissingtype(TT)
Return the type `T` if `TT = Union{Missing,T}` for some `T` and return `TT`
otherwise.
"""
function nonmissingtype(::Type{T}) where T
return T isa Union ? ifelse(T.a == Missing, T.b, T.a) : T
end
end
const nonmissing = nonmissingtype
# -----------------------------------------------------------------
# Constructor for table scientific type
"""
Table(...)
Constructor for the `Table` scientific type with:
```
Table(S1, S2, ..., Sn) <: Table
```
where `S1, ..., Sn` are the scientific type of the table's columns which
are expected to be represented by abstract vectors.
"""
Table(Ts::Type...) = Table{<:Union{(Arr{<:T,1} for T in Ts)...}}
# -----------------------------------------------------------------
# scitype
include("scitype.jl")
end # module