Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rbind and cbind methods for mmMatrix #5

Closed
agrueneberg opened this issue Mar 30, 2015 · 5 comments
Closed

Add rbind and cbind methods for mmMatrix #5

agrueneberg opened this issue Mar 30, 2015 · 5 comments

Comments

@agrueneberg
Copy link
Member

rbind will be easy for rmmMatrix, cbind for cmmMatrix. The other ones will be tricky and probably involve creating new chunks.

@agrueneberg
Copy link
Member Author

Another option, instead of manually adding chunks to an existing mmMatrix, would be to create a whole new one that combines all input parameters of rbind or cbind. This would allow for both functions to be easily implemented and for multiple mmMatrix arguments, and also result in leaner chunking (our main overhead).

@agrueneberg
Copy link
Member Author

We also have to decide whether to get the current storage location of an mmMatrix via an attribute of the mmMatrix (which impacts portability as we cannot always guarantee accuracy of that value since an mmMatrix can be loaded directly using load) or as a separate parameter (which would be unusual for an *bind method).

@agrueneberg
Copy link
Member Author

Looks like additional parameters can be added to the *bind methods. vmode, folderOut, nChunks, and dimorder would be nice.

@agrueneberg
Copy link
Member Author

Here's an initial draft for rbind for rmmMatrix:

rbind.rmmMatrix<-function(...,vmode='byte',folderOut=NULL,nChunks=NULL,dimorder=c(2,1),deparse.level=1){
    allargs<-list(...)
    alldims<-unique(sapply(allargs,function(arg){
        dims<-dim(arg)
        if(is.null(dims)){
            c(1, length(arg))
        }else{
            dims
        }
    }))
    numcols<-unique(alldims[2,])
    if(length(numcols)>1){
        stop('all params need the same number of columns')
    }
    numrows<-sum(alldims[1,])
    mmmatrix<-rmmMatrix(nrow=numrows,ncol=numcols,vmode=vmode,folderOut=folderOut,nChunks=nChunks,dimorder=dimorder)
    currow<-1
    for(arg in 1:ncol(alldims)){
        argrows<-alldims[1,arg]
        for(argrow in 1:argrows){
            if(argrows>1){
                mmmatrix[currow,]<-allargs[[arg]][argrow,]
            }else{
                mmmatrix[currow,]<-allargs[[arg]]
            }
            currow<-currow+1
        }
    }
    mmmatrix
}

Let me know what you think. In the meantime I will time it out for larger matrices. There is are some possible performance improvements when copying more than one row at the same time.

@agrueneberg
Copy link
Member Author

I'll reopen this in the LinkedMatrix repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant