How to implement a realization backend
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 30/100
- Loại issue
- Tài liệu
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- r
- Lĩnh vực
- backend-api-design, documentation
Hướng nghiên cứu
Bắt đầu với vignette Implementing A DelayedArray Backend, sau đó đọc R/RealizationSink-class.R và R/read_block.R. So sánh workflow ADSRealizationSink được đề xuất với R/writeHDF5Array.R và R/writeTENxMatrix.R trong HDF5Array. Hoàn tất khi các realization backend và các coercion method của chúng được dokument trong vignette, nhất quán với API hiện tại.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
The Implementing A DelayedArray Backend vignette only covers how to implement a backend for read access only. Backends that support saving DelayedArray objects (a.k.a. realization backends) are not covered yet. Reasons for this are various: no demand so far, exact procedure still kind of a work-in-progress and subject to changes, lack of time, etc...
In the meantime, I'm putting some material here (and will move it to the Implementing A DelayedArray Backend vignette as time allows).
Say we want to implement a realization backend for the ADS format (the imaginary format made up for the Implementing A DelayedArray Backend vignette), the 2 core things we need to implement are:
-
A RealizationSink subclass for the ADS backend. RealizationSink is a virtual class defined in the DelayedArray package (in
R/RealizationSink-class.R). By analogy with the HDF5RealizationSink class defined in the HDF5Array package (inR/writeHDF5Array.R), let's assume that the RealizationSink subclass for the ADS backend will be called ADSRealizationSink. -
Coercion methods from ADSRealizationSink to ADSArraySeed, ADSArray, and DelayedArray.
RealizationSink subclass
The purpose of an ADSRealizationSink object is to point to a new ADS dataset and allow writing blocks of data to it. The class definition for ADSRealizationSink would typically look something like:
setClass("ADSRealizationSink",
contains="RealizationSink",
representation(
dim="integer", # Naming this slot "dim" makes dim() work out of the box.
dimnames="list",
type="character", # Single string.
## Additional slots would typically include the path or connection to a file....
...
)
)
Then we need a constructor function for these objects. The constructor should be named as the class and its first 3 arguments should be dim, dimnames, and type. It can have more arguments but those are optional and calling ADSRealizationSink() with the first 3 arguments only (i.e. ADSRealizationSink(dim, dimnames, type)) should work. Furthermore, every call to ADSRealizationSink() should create a new dataset that is ready to be written to.
ADSRealizationSink objects must support the following operations (via defining appropriate methods):
dim(),dimnames(), andtype(). These should return the values that were passed to the call toADSRealizationSink()that was used to create the object.write_block(). This is a generic defined in the DelayedArray package inR/read_block.R.close(). This base R S3 generic is promoted to S4 generic in the DelayedArray package inR/RealizationSink-class.R. A default method for RealizationSink objects is provided and does nothing (no-op). Implement a method for ADSRealizationSink objects only if some connection needs to be closed and/or other resources need to be released after writing the data is complete and before the ADSRealizationSink object can be turned into an ADSArraySeed object for reading.
Coercion methods from ADSRealizationSink to ADSArraySeed, ADSArray, and DelayedArray
From ADSRealizationSink to ADSArraySeed
Think of an ADSRealizationSink object as a "write" connection to an ADS data set. Think of an ADSArraySeed object as a "read only" connection to an ADS data set. The purpose of the coercion from ADSRealizationSink to ADSArraySeed is to change the nature of this connection from "write" to "read only" and to produce an object that can be wrapped into a DelayedArray object.
From ADSRealizationSink to ADSArray and DelayedArray
setAs("ADSRealizationSink", "ADSArray",
function(from) DelayedArray(as(from, "ADSArraySeed"))
)
setAs("ADSRealizationSink", "DelayedArray", function(from) as(from, "ADSArray"))
A basic example
Once we have the above (i.e. ADSRealizationSink objects, ADSRealizationSink() constructor, and the 3 coercion methods), we can realize an arbitrary DelayedArray object x as a new pristine ADSArray object x2 by using the simple code below:
realize_as_ADSArray <- function(x)
{
sink <- ADSRealizationSink(dim(x), dimnames(x), type(x))
DelayedArray:::BLOCK_write_to_sink(x, sink)
close(sink)
as(sink, "DelayedArray") # a pristine ADSArray object semantically equivalent to `x`
}
DelayedArray:::BLOCK_write_to_sink() reads blocks from x, realizes them in memory, and writes them to sink (with write_block()).
Note that realize_as_ADSArray() also works on an ordinary array or any array-like object that supports extract_array(), not just on a DelayedArray object.
Add some convenience
Now we can build some convenience on top of this.
One basic convenience is a coercion method from ANY to ADSArray that just does what realize_as_ADSArray() does:
setAs("ANY", "ADSArray", function(from) realize_as_ADSArray(from))
Unfortunately, trying to coerce a DelayedArray or DelayedMatrix object to ADSArray would produce a broken object if we didn't also have the following coercion methods:
setAs("DelayedArray", "ADSArray", function(from) realize_as_ADSArray(from))
setAs("DelayedMatrix", "ADSArray", function(from) realize_as_ADSArray(from))
So in the same way that an array-like object x (ordinary array or DelayedArray object) can be realized as an HDF5Array or RleArray object with as(x, "HDF5Array") or as(x, "RleArray"), now it can also be realized as an ADSArray object with as(x, "ADSArray").
Real examples of realization backends
Refer to R/writeHDF5Array.R and R/writeTENxMatrix.R in the HDF5Array package for the implementation of the HDF5Array and TENxMatrix realization backends.
Note that you can use supportedRealizationBackends() to see the list of realization backends currently supported.
- Ngôn ngữ chính
- R
- Star
- 29
- Fork
- 12
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của Bioconductor/DelayedArray
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 38/100
Bioconductor/DelayedArray#129 · 11 bình luận ·
-
Custom delayed operations Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
Bioconductor/DelayedArray#127 · 1 bình luận ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
Bioconductor/DelayedArray#125 · 1 bình luận ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
Bioconductor/DelayedArray#123 ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 20/100
Bioconductor/DelayedArray#122 ·
Tất cả issue của Bioconductor/DelayedArray
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
robjhyndman/forecast#1220 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
JamesHWade/deputy#192 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
bug triage_needed
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
pharmaverse/rtables#1123 · 1 bình luận · 1 reaction ·