useDynLib(DelayedArray)

import(methods)
importFrom(utils, object.size)
importFrom(stats, setNames,
                  dnorm, pnorm, qnorm,
                  dbinom, pbinom, qbinom,
                  dpois, ppois, qpois,
                  dlogis, plogis, qlogis)
importFrom(stats4, summary)
importClassFrom(Matrix, dgCMatrix)
importFrom(Matrix, sparseMatrix, crossprod, tcrossprod)
import(matrixStats)
import(BiocGenerics)
import(S4Vectors)
import(IRanges)

### - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
### Export S4 classes
###

exportClasses(
    ## Array-class.R:
    Array,

    ## ArrayGrid-class.R:
    ArrayViewport, ArrayGrid, ArbitraryArrayGrid, RegularArrayGrid,

    ## SparseArraySeed-class.R:
    SparseArraySeed,

    ## DelayedOp-class.R:
    DelayedOp,
    DelayedUnaryOp,
    DelayedSubset,
    DelayedAperm,
    DelayedUnaryIsoOp,
    DelayedUnaryIsoOpStack,
    DelayedUnaryIsoOpWithArgs,
    DelayedSubassign,
    DelayedDimnames,
    DelayedNaryOp,
    DelayedNaryIsoOp,
    DelayedAbind,

    ## DelayedArray-class.R:
    DelayedArray, DelayedMatrix,
    DelayedArray1,

    ## chunkGrid.R:
    integer_OR_NULL,

    ## RealizationSink-class.R:
    RealizationSink, arrayRealizationSink,

    ## RleArray-class.R:
    RleArraySeed, SolidRleArraySeed, RleRealizationSink, ChunkedRleArraySeed,
    RleArray, RleMatrix
)


### - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
### Export S3 methods
###

S3method(aperm, ArbitraryArrayGrid)
S3method(aperm, RegularArrayGrid)
S3method(aperm, SparseArraySeed)
S3method(aperm, DelayedArray)

S3method(as.array, Array)
S3method(as.array, SparseArraySeed)

S3method(as.character, Array)
S3method(as.character, ArrayGrid)

S3method(as.complex, Array)

S3method(as.data.frame, Array)

S3method(as.integer, Array)

S3method(as.logical, Array)

S3method(as.matrix, Array)
S3method(as.matrix, SparseArraySeed)

S3method(as.numeric, Array)

S3method(as.raw, Array)

S3method(as.vector, Array)

S3method(mean, DelayedArray)

S3method(range, DelayedArray)

S3method(rowsum, dgCMatrix)
S3method(rowsum, DelayedMatrix)

S3method(split, DelayedArray)

S3method(summary, DelayedOp)
S3method(summary, DelayedSubset)
S3method(summary, DelayedAperm)
S3method(summary, DelayedUnaryIsoOpStack)
S3method(summary, DelayedUnaryIsoOpWithArgs)
S3method(summary, DelayedDimnames)
S3method(summary, DelayedNaryIsoOp)
S3method(summary, DelayedAbind)

S3method(t, Array)

S3method(unique, DelayedArray)

### We also export them thru the export() directive so that (a) they can be
### called directly, (b) tab-completion on the name of the generic shows them,
### and (c) methods() doesn't asterisk them.

export(
    aperm.ArbitraryArrayGrid,
    aperm.RegularArrayGrid,
    aperm.SparseArraySeed,
    aperm.DelayedArray,

    as.array.Array,
    as.array.SparseArraySeed,

    as.character.ArrayGrid,
    as.character.Array,

    as.complex.Array,

    as.data.frame.Array,

    as.integer.Array,

    as.logical.Array,

    as.matrix.Array,
    as.matrix.SparseArraySeed,

    as.numeric.Array,

    as.raw.Array,

    as.vector.Array,

    mean.DelayedArray,

    range.DelayedArray,

    rowsum.dgCMatrix,
    rowsum.DelayedMatrix,

    split.DelayedArray,

    summary.DelayedOp,
    summary.DelayedSubset,
    summary.DelayedAperm,
    summary.DelayedUnaryIsoOpStack,
    summary.DelayedUnaryIsoOpWithArgs,
    summary.DelayedDimnames,
    summary.DelayedNaryIsoOp,
    summary.DelayedAbind,

    t.Array,

    unique.DelayedArray
)


### - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
### Export S4 methods for generics not defined in DelayedArray
###

exportMethods(
    ## Methods for generics defined in the base package:
    length, names, "names<-",
    dim, "dim<-", dimnames, "dimnames<-",
    "[", "[[", "[<-",
    lengths,
    as.array, as.matrix, as.data.frame, as.vector,
    as.logical, as.integer, as.numeric, as.complex, as.character, as.raw,
    c, split,
    drop, t,
    is.na, is.finite, is.infinite, is.nan,
    "!",
    #"+", "-", "*", "/", "^", "%%", "%/%",  # "Arith" group generic
    "==", "!=", "<=", ">=", "<", ">",       # "Compare" group generic
    sweep,
    anyNA, which,
    unique,
    max, min, range, sum, prod, any, all,   # "Summary" group generic
    mean,
    round, signif,
    rowSums, colSums, rowMeans, colMeans,
    nchar, tolower, toupper,
    sub, gsub,

    ## Methods for generics defined in the methods package:
    coerce, show,

    ## Methods for generics defined in the stats package:
    dnorm, pnorm, qnorm,
    dbinom, pbinom, qbinom,
    dpois, ppois, qpois,
    dlogis, plogis, qlogis,

    ## Methods for generics defined in the stats4 package:
    summary,

    ## Methods for generics defined in the Matrix package:
    crossprod, tcrossprod,

    ## Methods for generics defined in the BiocGenerics package:
    cbind, rbind,
    dims,
    grepl,
    path, "path<-",
    table,
    type, "type<-",
    updateObject,

    ## Methods for generics defined in the S4Vectors package:
    showAsCell, isEmpty,
    splitAsList,

    ## Methods for generics defined in the IRanges package:
    ranges, start, end, width
)


### - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
### Export non-generic functions
###

export(
    ## array_selection.R:
    Lindex2Mindex, Mindex2Lindex, linearInd,

    ## ArrayGrid-class.R:
    ArrayViewport, makeNindexFromArrayViewport,
    ArbitraryArrayGrid, RegularArrayGrid,

    ## SparseArraySeed-class.R:
    SparseArraySeed, dense2sparse, sparse2dense,

    ## makeCappedVolumeBox.R:
    makeCappedVolumeBox, makeRegularArrayGridOfCappedLengthViewports,

    ## blockGrid.R:
    setAutoBlockSize, getAutoBlockSize,
    get_type_size, getAutoBlockLength,
    setAutoBlockShape, getAutoBlockShape,
    blockGrid, rowGrid, colGrid, multGrids,

    ## blockApply.R:
    setAutoGridMaker, getAutoGridMaker,
    setAutoBPPARAM, getAutoBPPARAM,
    blockApply, blockReduce,
    effectiveGrid, currentBlockId, currentViewport,

    ## showtree.R:
    showtree, seedApply, modify_seeds,

    ## simplify.R:
    isPristine, contentIsPristine,

    ## DelayedArray-class.R:
    new_DelayedArray,

    ## RealizationSink-class.R:
    supportedRealizationBackends,
    getRealizationBackend, setRealizationBackend,
    RealizationSink,

    ## realize.R:
    BLOCK_write_to_sink,

    ## RleArray-class.R:
    RleArray
)


### - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
### Export S4 generics defined in DelayedArray + export corresponding methods
###

export(
    ## dgCMatrix-utils.R:
    rowsum, colsum,

    ## bind-arrays.R:
    arbind, acbind,

    ## extract_array.R:
    extract_array,

    ## ArrayGrid-class.R:
    refdim, maxlength, aperm, downsample,

    ## SparseArraySeed-class.R:
    nzindex, nzdata, sparsity, is_sparse, extract_sparse_array,

    ## read_block.R:
    read_block, write_block,
    read_sparse_block, write_sparse_block,

    ## mapToGrid.R:
    mapToGrid, mapToRef,

    ## makeCappedVolumeBox.R:
    isLinear,

    ## DelayedOp-class.R:
    is_noop,

    ## showtree.R:
    nseed, seed, "seed<-",

    ## simplify.R:
    simplify, netSubsetAndAperm,

    ## DelayedArray-class.R:
    matrixClass, DelayedArray,

    ## chunkGrid.R:
    chunkdim, chunkGrid,

    ## RealizationSink-class.R:
    close,

    ## realize.R:
    realize,

    ## DelayedArray-utils.R:
    pmax2, pmin2, apply,

    ## DelayedMatrix-stats.R:
    rowMaxs, colMaxs, rowMins, colMins, rowRanges, colRanges
)

### Exactly the same list as above.
exportMethods(
    rowsum, colsum,
    arbind, acbind,
    extract_array,
    refdim, maxlength, aperm, downsample,
    nzindex, nzdata, sparsity, is_sparse, extract_sparse_array,
    read_block, write_block,
    mapToGrid, mapToRef,
    isLinear,
    is_noop,
    nseed, seed, "seed<-",
    simplify, netSubsetAndAperm,
    matrixClass, DelayedArray,
    chunkdim, chunkGrid,
    close,
    realize,
    pmax2, pmin2, apply,
    rowMaxs, colMaxs, rowMins, colMins, rowRanges, colRanges
)

