It is possible to store explicit zero values in sparse matrices, but not via the sparse() function at the moment. You currently have to construct a sparse matrix with the desired structure of stored elements, then modify the field values of Mat.nzval to explicitly set some of them to zero. There's an open pull request that will change this, I think the only thing we were waiting for before merging was some performance benchmarking of packages that heavily utilize the sparse() function.
On Tuesday, February 23, 2016 at 2:58:44 PM UTC-8, Yankai Cao wrote: > > Hi, Stefan, > > Thanks for your reply. For my application, the structure of the matrix is > fixed, but the values of some elements might become zero from iteration to > iteration. Is it possible to keep the position of elements whose values is > zero? > For example: > I=[1;1;2] > J=[1;1;2] > V=[1.0;0.0;0.0] > Mat=sparse(I,J,V,2,2) > > what I get is > [1,1]=1 > > is it possible to get the following? > [ 1, 1] = 1.0 > [2, 2] = 0.0 > > > Thanks. > > > > Yankai > > > > On Tuesday, February 23, 2016 at 4:50:07 PM UTC-6, Stefan Karpinski wrote: >> >> You can't have two values at the same row and column, which is what the >> first two lines of this output would indicate: >> >> [1, 1] = 1.0 >> [1, 1] = 1.0 >> [2, 2] = 1.0 >> >> >> Since the indices (1,1) appear twice the associated values are added, >> giving 2.0. >> >> On Tue, Feb 23, 2016 at 5:03 PM, Yankai Cao <[email protected]> wrote: >> >>> I am new to Julia. I have 2 questions about constructting sparse matrix >>> from arrays. >>> >>> 1. >>> I=[1;1;2] >>> J=[1;1;2] >>> V=[1.0;1.0;1.0] >>> Mat=sparse(I,J,V,2,2) >>> >>> According to the Julia guide "If the combine function is not supplied, >>> duplicates are added by default." I expect Mat to be >>> [ 1, 1] =1.0 >>> [ 1, 1] = 1.0 >>> [2, 2] = 1.0 >>> >>> however, what I get is >>> [1,1]=2 >>> [2,2]=1 >>> >>> So what is the default behavior without combine function? How do I >>> specify the combine function? There is no instructions about it right now. >>> >>> 2. when i change V=[1.0;0.0;0.0]. I expected >>> [ 1, 1] = 1.0 >>> [2, 2] = 0 >>> >>> what I get is >>> [1,1]=1 >>> >>> How can I let julia to combine elements only according to the indexes I, >>> J ? How to keep those elements with value 0 ? >>> >>> >>> Thanks in advance. >>> >>> >>> Yankai >>> >>> >>> >>> >>> >>
