1
1
"""
2
- MOInput (x::AbstractVector, out_dim::Integer)
2
+ MOInputIsotopicByFeatures (x::AbstractVector, out_dim::Integer)
3
3
4
- A data type to accomodate modelling multi-dimensional output data .
4
+ `MOInputIsotopicByFeatures(x, out_dim)` has length `out_dim * length(x)` .
5
5
6
- `MOInput(x, out_dim)` has length `length(x) * out_dim`.
6
+ ```jldoctest
7
+ julia> x = [1, 2, 3];
8
+
9
+ julia> KernelFunctions.MOInputIsotopicByFeatures(x, 2)
10
+ 6-element KernelFunctions.MOInputIsotopicByFeatures{Int64, Vector{Int64}}:
11
+ (1, 1)
12
+ (1, 2)
13
+ (2, 1)
14
+ (2, 2)
15
+ (3, 1)
16
+ (3, 2)
17
+ ```
18
+
19
+ Accommodates modelling multi-dimensional output data where all outputs are always observed.
20
+
21
+ As shown above, an `MOInputIsotopicByFeatures` represents a vector of tuples.
22
+ The first `out_dim` elements represent all outputs for the first input, the second
23
+ `out_dim` elements represent the outputs for the second input, etc.
24
+
25
+ See [Inputs for Multiple Outputs](@ref) in the docs for more info.
26
+ """
27
+ struct MOInputIsotopicByFeatures{S,T<: AbstractVector{S} } <: AbstractVector{Tuple{S,Int}}
28
+ x:: T
29
+ out_dim:: Integer
30
+ end
31
+
32
+ """
33
+ MOInputIsotopicByOutputs(x::AbstractVector, out_dim::Integer)
34
+
35
+ `MOInputIsotopicByOutputs(x, out_dim)` has length `length(x) * out_dim`.
7
36
8
37
```jldoctest
9
38
julia> x = [1, 2, 3];
10
39
11
- julia> MOInput (x, 2)
12
- 6-element MOInput{ Vector{Int64}}:
40
+ julia> KernelFunctions.MOInputIsotopicByOutputs (x, 2)
41
+ 6-element KernelFunctions.MOInputIsotopicByOutputs{Int64, Vector{Int64}}:
13
42
(1, 1)
14
43
(2, 1)
15
44
(3, 1)
@@ -18,40 +47,59 @@ julia> MOInput(x, 2)
18
47
(3, 2)
19
48
```
20
49
21
- As shown above, an `MOInput` represents a vector of tuples.
50
+ Accommodates modelling multi-dimensional output data where all outputs are always observed.
51
+
52
+ As shown above, an `MOInputIsotopicByOutputs` represents a vector of tuples.
22
53
The first `length(x)` elements represent the inputs for the first output, the second
23
54
`length(x)` elements represent the inputs for the second output, etc.
24
-
25
- See [Inputs for Multiple Outputs](@ref) in the docs for more info.
26
55
"""
27
- struct MOInput{ T<: AbstractVector } <: AbstractVector{Tuple{Any ,Int}}
56
+ struct MOInputIsotopicByOutputs{S, T<: AbstractVector{S} } <: AbstractVector{Tuple{S ,Int}}
28
57
x:: T
29
58
out_dim:: Integer
30
59
end
31
60
32
- Base. length (inp:: MOInput ) = inp. out_dim * length (inp. x)
33
-
34
- Base. size (inp:: MOInput , d) = d:: Integer == 1 ? inp. out_dim * size (inp. x, 1 ) : 1
35
- Base. size (inp:: MOInput ) = (inp. out_dim * size (inp. x, 1 ),)
36
-
37
- Base. lastindex (inp:: MOInput ) = length (inp)
38
- Base. firstindex (inp:: MOInput ) = 1
39
-
40
- function Base. getindex (inp:: MOInput , ind:: Integer )
41
- if ind > 0
42
- out_dim = ind ÷ length (inp. x) + 1
43
- ind = ind % length (inp. x)
44
- if ind == 0
45
- ind = length (inp. x)
46
- out_dim -= 1
47
- end
48
- return (inp. x[ind], out_dim:: Int )
49
- else
50
- throw (BoundsError (string (" Trying to access at " , ind)))
51
- end
61
+ const IsotopicMOInputs = Union{MOInputIsotopicByFeatures,MOInputIsotopicByOutputs}
62
+
63
+ function Base. getindex (inp:: MOInputIsotopicByOutputs , ind:: Integer )
64
+ @boundscheck checkbounds (inp, ind)
65
+ output_index, feature_index = fldmod1 (ind, length (inp. x))
66
+ feature = @inbounds inp. x[feature_index]
67
+ return feature, output_index
52
68
end
53
69
54
- Base. iterate (inp:: MOInput ) = (inp[1 ], 1 )
55
- function Base. iterate (inp:: MOInput , state)
56
- return (state < length (inp)) ? (inp[state + 1 ], state + 1 ) : nothing
70
+ function Base. getindex (inp:: MOInputIsotopicByFeatures , ind:: Integer )
71
+ @boundscheck checkbounds (inp, ind)
72
+ feature_index, output_index = fldmod1 (ind, inp. out_dim)
73
+ feature = @inbounds inp. x[feature_index]
74
+ return feature, output_index
57
75
end
76
+
77
+ Base. size (inp:: IsotopicMOInputs ) = (inp. out_dim * length (inp. x),)
78
+
79
+ """
80
+ MOInput(x::AbstractVector, out_dim::Integer)
81
+
82
+ A data type to accommodate modelling multi-dimensional output data.
83
+ `MOInput(x, out_dim)` has length `length(x) * out_dim`.
84
+
85
+ ```jldoctest
86
+ julia> x = [1, 2, 3];
87
+
88
+ julia> MOInput(x, 2)
89
+ 6-element KernelFunctions.MOInputIsotopicByOutputs{Int64, Vector{Int64}}:
90
+ (1, 1)
91
+ (2, 1)
92
+ (3, 1)
93
+ (1, 2)
94
+ (2, 2)
95
+ (3, 2)
96
+ ```
97
+ As shown above, an `MOInput` represents a vector of tuples.
98
+ The first `length(x)` elements represent the inputs for the first output, the second
99
+ `length(x)` elements represent the inputs for the second output, etc.
100
+ See [Inputs for Multiple Outputs](@ref) in the docs for more info.
101
+
102
+ `MOInput` will be deprecated in version 0.11 in favour of `MOInputIsotopicByOutputs`,
103
+ and removed in version 0.12.
104
+ """
105
+ const MOInput = MOInputIsotopicByOutputs
0 commit comments