Skip to contents

An h5mread wrapper that reads data from a virtually reshaped HDF5 dataset.

Usage

h5mread_from_reshaped(filepath, name, dim, starts, noreduce=FALSE,
                      as.integer=FALSE, method=0L)

Arguments

filepath

The path (as a single string) to the HDF5 file where the dataset to read from is located, or an H5File object.

Note that you must create and use an H5File object if the HDF5 file to access is stored in an Amazon S3 bucket. See ?H5File for how to do this.

Also please note that H5File objects must NOT be used in the context of parallel evaluation at the moment.

name

The name of the dataset in the HDF5 file.

dim

A vector of dimensions that describes the virtual reshaping i.e. the reshaping that is virtually applied upfront to the HDF5 dataset to read from.

Note that the HDF5 dataset is treated as read-only so never gets effectively reshaped, that is, the dataset dimensions encoded in the HDF5 file are not mmodified.

Also please note that arbitrary reshapings are not supported. Only reshapings that reduce the number of dimensions by collapsing a group of consecutive dimensions into a single dimension are supported. For example, reshaping a 10 x 3 x 5 x 1000 array as a 10 x 15 x 1000 array or as a 150 x 1000 matrix is supported.

starts

A multidimensional subsetting index with respect to the reshaped dataset, that is, a list with one list element per dimension in the reshaped dataset.

Each list element in starts must be a vector of valid positive indices along the corresponding dimension in the reshaped dataset. An empty vector (integer(0)) is accepted and indicates an empty selection along that dimension. A NULL is accepted and indicates a full selection along the dimension so has the same meaning as a missing subscript when subsetting an array-like object with [. (Note that for [ a NULL subscript indicates an empty selection.)

noreduce, as.integer, method

See ?h5mread for a description of these arguments.

Value

An array.

See also

Examples

temp_h5 <- tempfile(fileext=".h5")

## ---------------------------------------------------------------------
## BASIC USAGE
## ---------------------------------------------------------------------
a1 <- array(1:350, c(10, 5, 7))
h5write(a1, temp_h5, "A1")

## Collapse the first 2 dimensions:
h5mread_from_reshaped(temp_h5, "A1", dim=c(50, 7),
                      starts=list(8:11, NULL))
#>      [,1] [,2] [,3] [,4] [,5] [,6] [,7]
#> [1,]    8   58  108  158  208  258  308
#> [2,]    9   59  109  159  209  259  309
#> [3,]   10   60  110  160  210  260  310
#> [4,]   11   61  111  161  211  261  311
h5mread_from_reshaped(temp_h5, "A1", dim=c(50, 7),
                      starts=list(8:11, NULL))
#>      [,1] [,2] [,3] [,4] [,5] [,6] [,7]
#> [1,]    8   58  108  158  208  258  308
#> [2,]    9   59  109  159  209  259  309
#> [3,]   10   60  110  160  210  260  310
#> [4,]   11   61  111  161  211  261  311

## Collapse the last 2 dimensions:
h5mread_from_reshaped(temp_h5, "A1", dim=c(10, 35),
                      starts=list(NULL, 3:11))
#>       [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9]
#>  [1,]   21   31   41   51   61   71   81   91  101
#>  [2,]   22   32   42   52   62   72   82   92  102
#>  [3,]   23   33   43   53   63   73   83   93  103
#>  [4,]   24   34   44   54   64   74   84   94  104
#>  [5,]   25   35   45   55   65   75   85   95  105
#>  [6,]   26   36   46   56   66   76   86   96  106
#>  [7,]   27   37   47   57   67   77   87   97  107
#>  [8,]   28   38   48   58   68   78   88   98  108
#>  [9,]   29   39   49   59   69   79   89   99  109
#> [10,]   30   40   50   60   70   80   90  100  110

a2 <- array(1:150000 + 0.1*runif(150000), c(10, 3, 5, 1000))
h5write(a2, temp_h5, name="A2")

## Collapse the 2nd and 3rd dimensions:
h5mread_from_reshaped(temp_h5, "A2", dim=c(10, 15, 1000),
                      starts=list(NULL, 8:11, 999:1000))
#> , , 1
#> 
#>           [,1]     [,2]     [,3]     [,4]
#>  [1,] 149771.1 149781.1 149791.1 149801.0
#>  [2,] 149772.0 149782.1 149792.0 149802.1
#>  [3,] 149773.1 149783.1 149793.0 149803.1
#>  [4,] 149774.0 149784.1 149794.0 149804.1
#>  [5,] 149775.0 149785.1 149795.0 149805.0
#>  [6,] 149776.1 149786.1 149796.1 149806.1
#>  [7,] 149777.1 149787.0 149797.0 149807.0
#>  [8,] 149778.0 149788.0 149798.1 149808.0
#>  [9,] 149779.0 149789.1 149799.0 149809.1
#> [10,] 149780.1 149790.1 149800.1 149810.0
#> 
#> , , 2
#> 
#>           [,1]     [,2]     [,3]     [,4]
#>  [1,] 149921.1 149931.1 149941.1 149951.1
#>  [2,] 149922.0 149932.0 149942.1 149952.1
#>  [3,] 149923.1 149933.0 149943.0 149953.0
#>  [4,] 149924.1 149934.1 149944.0 149954.0
#>  [5,] 149925.0 149935.0 149945.1 149955.0
#>  [6,] 149926.0 149936.0 149946.0 149956.1
#>  [7,] 149927.0 149937.1 149947.1 149957.0
#>  [8,] 149928.0 149938.0 149948.0 149958.1
#>  [9,] 149929.0 149939.0 149949.0 149959.0
#> [10,] 149930.1 149940.1 149950.0 149960.1
#> 

## Collapse the first 3 dimensions:
h5mread_from_reshaped(temp_h5, "A2", dim=c(150, 1000),
                      starts=list(71:110, 999:1000))
#>           [,1]     [,2]
#>  [1,] 149771.1 149921.1
#>  [2,] 149772.0 149922.0
#>  [3,] 149773.1 149923.1
#>  [4,] 149774.0 149924.1
#>  [5,] 149775.0 149925.0
#>  [6,] 149776.1 149926.0
#>  [7,] 149777.1 149927.0
#>  [8,] 149778.0 149928.0
#>  [9,] 149779.0 149929.0
#> [10,] 149780.1 149930.1
#> [11,] 149781.1 149931.1
#> [12,] 149782.1 149932.0
#> [13,] 149783.1 149933.0
#> [14,] 149784.1 149934.1
#> [15,] 149785.1 149935.0
#> [16,] 149786.1 149936.0
#> [17,] 149787.0 149937.1
#> [18,] 149788.0 149938.0
#> [19,] 149789.1 149939.0
#> [20,] 149790.1 149940.1
#> [21,] 149791.1 149941.1
#> [22,] 149792.0 149942.1
#> [23,] 149793.0 149943.0
#> [24,] 149794.0 149944.0
#> [25,] 149795.0 149945.1
#> [26,] 149796.1 149946.0
#> [27,] 149797.0 149947.1
#> [28,] 149798.1 149948.0
#> [29,] 149799.0 149949.0
#> [30,] 149800.1 149950.0
#> [31,] 149801.0 149951.1
#> [32,] 149802.1 149952.1
#> [33,] 149803.1 149953.0
#> [34,] 149804.1 149954.0
#> [35,] 149805.0 149955.0
#> [36,] 149806.1 149956.1
#> [37,] 149807.0 149957.0
#> [38,] 149808.0 149958.1
#> [39,] 149809.1 149959.0
#> [40,] 149810.0 149960.1