Skip to content

Could we define "views" of Datasets? #74

@heliosdrm

Description

@heliosdrm

The only way of taking a fragment of a Dataset is creating another one. This is not optimal, and it might be good to have another subtype of AbstractDataset, whose contents are a view to the data of another Dataset.

The easiest would be to define:

Base.view(d::AbstractDataset, i) = view(d.data, i)

and then some type like DatasetView <: AbstractDataset whose data is a SubArray{<:SArray}, such that one could do:

d = Dataset(x)
dv = Dataset(@view d[xx])

(Notice that this code actually works right now, but it produces a copy of the contents before creating dv.)

Such dv::DatasetView should behave as if I had written dv = d[xx], but that way we would save the superfluous allocation.

I acknowledge that it would be nicer if the interface is directly dv = @view d, but I'm not sure if that would be right. Base.view (and thus the macro @view) is meant to produce a SubArray, which is defined as a container encoding a "view" of a parent AbstractArray. So, although technically it might be feasible to write a method of Base.view that takes and returns an AbstractDataset, for me that would only feel right if we define AbstractDataset <: AbstractArray -- which maybe makes sense too, but might need some deeper thought to ensure that the API of AbstractDataset is fully consistent with what is expected from AbstractArrays (or at least AbstractVectors).

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions