@@ -64,12 +64,15 @@ data[1] == data[1, :] # this is the first datapoint (D-dimensional)
6464data[5, 3] # value of the third variable, at the 5th timepoint
6565```
6666
67- Use `Matrix(dataset)` to create a `Matrix`, and `Dataset(matrix)`
68- to create a `Dataset` from a matrix. Notice: `Dataset(matrix)` assumes
69- that each column of the matrix represents one dynamic variable. If instead each
70- column of the matrix represents a datapoint, use `reinterpret(Dataset, matrix)`.
71-
72- If you have various timeseries vectors `x, y, z, ...` pass them like
67+ Use `Matrix(dataset)` or `reinterpret(Matrix, dataset) to create a `Matrix`
68+ from a `dataset`, the first method returning a matrix where each column is a
69+ a timeseries while the second returning a matrix where each column is
70+ a datapoint. Similarly, use
71+ `Dataset(matrix)` or `reinterpret(Dataset, matrix)` to create a `Dataset` from
72+ a `matrix` that has structure as noted by the `Matrix` methods. Notice that the 2
73+ matrix versions are just the transpose of each other.
74+
75+ If you have various timeseries `Vector`s `x, y, z, ...` pass them like
7376`Dataset(x, y, z, ...)`.
7477
7578See also [`read_dataset`](@ref), [`write_dataset`](@ref) and [`minmaxima`](@ref).
@@ -113,22 +116,20 @@ end
113116
114117
115118# Conversions:
116- @inbounds function Base. convert (:: Type{Matrix} , d:: AbstractDataset{D,T} ) where {D, T}
117- mat = Matrix {T} (length (d), D)
118- for i in 1 : length (d)
119- mat[i,:] .= d. data[i]
120- end
121- mat
119+ function Base. convert (:: Type{Matrix} , d:: AbstractDataset{D,T} ) where {D, T}
120+ L = length (d)
121+ m = reinterpret (T, d. data, (D,L))
122+ transpose (m)
123+ end
124+
125+ function Base. reinterpret (:: Type{M} , d:: AbstractDataset{D,T} ) where {M<: Matrix , D, T}
126+ L = length (d)
127+ reinterpret (T, d. data, (D,L))
122128end
123129
124130function Base. convert (:: Type{Dataset} , mat:: AbstractMatrix )
125- D = size (mat, 2 ); T = eltype (mat)
126- L = size (mat, 1 )
127- d = Vector {SVector{D, T}} (L)
128- for i in 1 : L
129- d[i] = SVector {D, T} (view (mat, i, :))
130- end
131- return Dataset (d)
131+ m = transpose (mat)
132+ reinterpret (Dataset, m)
132133end
133134
134135function Base. reinterpret (:: Type{Dataset} , mat:: Array{T,2} ) where {T<: Real }
@@ -142,8 +143,6 @@ function Base.convert(::Type{Dataset}, y::Vector{T}) where {T}
142143 return Dataset (data)
143144end
144145
145-
146-
147146# ## Pretty printing
148147function matname (d:: Dataset{D, T} ) where {D, T}
149148 N = length (d)
236235# Dataset IO #
237236# ####################################################################################
238237"""
239- read_dataset(file, V ::Type{Dataset{D, T} }, delim::Char = '\t '; skipstart = 0)
238+ read_dataset(file, ::Type{<: Dataset}, delim::Char = '\t '; skipstart = 0)
240239Read a `delim`-delimited text file directly into a dataset of dimension `D`
241240with numbers of type `T`.
242241
0 commit comments