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, dgRMatrix, lgCMatrix, lgRMatrix)
importFrom(Matrix, sparseMatrix, crossprod, tcrossprod)

import(BiocGenerics)
import(MatrixGenerics)
import(S4Vectors)
import(IRanges)


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

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

    ## ArrayGrid-class.R:
    ArrayViewport, DummyArrayViewport, SafeArrayViewport,
    ArrayGrid, DummyArrayGrid, ArbitraryArrayGrid, RegularArrayGrid,

    ## SparseArraySeed-class.R:
    SparseArraySeed,

    ## DelayedOp-class.R:
    DelayedOp,
    DelayedUnaryOp,
    DelayedUnaryIsoOp,
    DelayedNaryOp,

    ## DelayedSubset-class.R:
    DelayedSubset,

    ## DelayedAperm-class.R:
    DelayedAperm,

    ## DelayedUnaryIsoOpStack-class.R:
    DelayedUnaryIsoOpStack,

    ## DelayedUnaryIsoOpWithArgs-class.R:
    DelayedUnaryIsoOpWithArgs,

    ## DelayedSubassign-class.R:
    DelayedSubassign,

    ## DelayedSetDimnames-class.R:
    DelayedSetDimnames,

    ## DelayedNaryIsoOp-class.R:
    DelayedNaryIsoOp,

    ## DelayedAbind-class.R:
    DelayedAbind,

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

    ## chunkGrid.R:
    integer_OR_NULL,

    ## write_block.R:
    RealizationSink, arrayRealizationSink,

    ## ConstantArray-class.R:
    ConstantArraySeed,
    ConstantArray, ConstantMatrix,

    ## RleArraySeed-class.R:
    RleArraySeed, SolidRleArraySeed, RleRealizationSink, ChunkedRleArraySeed,

    ## RleArray-class.R:
    RleArray, RleMatrix
)


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

S3method(aperm, DummyArrayGrid)
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, SparseArraySeed)
S3method(mean, DelayedArray)

S3method(range, SparseArraySeed)
S3method(range, DelayedArray)

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

S3method(scale, DelayedMatrix)

S3method(split, DelayedArray)

S3method(summary, DelayedOp)
S3method(summary, DelayedSubset)
S3method(summary, DelayedAperm)
S3method(summary, DelayedUnaryIsoOpStack)
S3method(summary, DelayedUnaryIsoOpWithArgs)
S3method(summary, DelayedSetDimnames)
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.DummyArrayGrid,
    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.SparseArraySeed,
    mean.DelayedArray,

    range.SparseArraySeed,
    range.DelayedArray,

    rowsum.dgCMatrix,
    rowsum.DelayedMatrix,

    scale.DelayedMatrix,

    split.DelayedArray,

    summary.DelayedOp,
    summary.DelayedSubset,
    summary.DelayedAperm,
    summary.DelayedUnaryIsoOpStack,
    summary.DelayedUnaryIsoOpWithArgs,
    summary.DelayedSetDimnames,
    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
    anyNA, which,
    unique,
    max, min, range, sum, prod, any, all,   # "Summary" group generic
    mean,
    log, round, signif,
    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,
    rowSums, colSums, rowMeans, colMeans,

    ## Methods for generics defined in the MatrixGenerics package:
    rowMins, colMins,
    rowMaxs, colMaxs,
    rowRanges, colRanges,

    ## Methods for generics defined in the S4Vectors package:
    bindROWS,
    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:
    DummyArrayViewport, ArrayViewport, makeNindexFromArrayViewport,
    DummyArrayGrid, ArbitraryArrayGrid, RegularArrayGrid,

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

    ## makeCappedVolumeBox.R:
    makeCappedVolumeBox, makeRegularArrayGridOfCappedLengthViewports,

    ## AutoBlock-global-settings.R:
    setAutoBlockSize, getAutoBlockSize,
    get_type_size, getAutoBlockLength,
    setAutoBlockShape, getAutoBlockShape,

    ## AutoGrid.R:
    defaultAutoGrid, blockGrid,
    rowAutoGrid, rowGrid,
    colAutoGrid, colGrid,
    setAutoGridMaker, getAutoGridMaker,
    defaultSinkAutoGrid,
    defaultMultAutoGrids, multGrids,

    ## blockApply.R:
    setAutoBPPARAM, getAutoBPPARAM,
    set_grid_context, effectiveGrid, currentBlockId, currentViewport,
    gridApply, viewportApply, blockApply,
    gridReduce, viewportReduce, blockReduce,

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

    ## simplify.R:
    isPristine, contentIsPristine,

    ## DelayedArray-class.R:
    new_DelayedArray,

    ## write_block.R:
    supportedRealizationBackends,
    getAutoRealizationBackend, setAutoRealizationBackend,
    getRealizationBackend, setRealizationBackend,
    AutoRealizationSink, RealizationSink,
    sinkApply,

    ## realize.R:
    BLOCK_write_to_sink,

    ## RleArray-class.R:
    RleArray,

    ## ConstantArray-class.R:
    ConstantArray,
    ConstantArraySeed
)


### - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
### Export S4 generics defined in DelayedArray, and corresponding methods
###

export(
    ## sparseMatrix-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, "is_sparse<-", extract_sparse_array,

    ## read_block.R:
    read_block, read_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,

    ## write_block.R:
    close, write_block,

    ## realize.R:
    realize,

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

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

### 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, read_sparse_block,
    mapToGrid, mapToRef,
    isLinear,
    is_noop,
    nseed, seed, "seed<-",
    simplify, netSubsetAndAperm,
    matrixClass, DelayedArray,
    chunkdim, chunkGrid,
    close, write_block,
    realize,
    pmax2, pmin2, apply, sweep, scale,
    rowMaxs, colMaxs, rowMins, colMins, rowRanges, colRanges
)

