Skip to content

Generating large sparse matrices #3

@KASR

Description

@KASR

When generating large matrices it can happen that the number of elements is larger then the max value that can be stored in "int" format. If this happens I use the workaround below to generate the matrix in multiple steps. However this is not ideal. Can the "int" limitation be changed into "long" or would this result in other problems?

if length(MyRowIdx) > intmax('int32')
    
    Idx = false(length(MyRowIdx),1);
    Idx( 1 : intmax('int32') ) = true;
    H = fsparse(MyRowIdx(Idx), MyColIdx(Idx), Val(Idx), [numElem, numElem]);
    
    MyRowIdx(Idx) = [];
    MyColIdx(Idx) = [];
    Val(Idx) = [];
    
    while any(MyRowIdx)
        
        Idx = false(length(MyRowIdx),1);
        Idx( 1 : min( length(MyRowIdx) , intmax('int32') ) ) = true;
        
        H = H + fsparse(MyRowIdx(Idx), MyColIdx(Idx), Val(Idx), [numElem, numElem]);
        
        MyRowIdx(Idx) = [];
        MyColIdx(Idx) = [];
        Val(Idx) = [];
        
    end
    
else
    % we can generate the matrix in a single fsparse call
    H = fsparse(MyRowIdx, MyColIdx, Val, [numElem, numElem]);
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions