Thread Subject: sparse matrix bug?

Subject: sparse matrix bug?

From: Ofek Shilon

Date: 18 May, 2005 04:26:57

Message: 1 of 14

take a very simple accumulating sparse-matrix generation:

   A=sparse([1,1],[1,1],[1,2])

No problem:

   A =

       (1,1) 3

However, while trying to declare the space to allocate:

   A=sparse([1,1],[1,1],[1,2],1,1,1)

I get the very annoying:

   ??? Error using ==> sparse
   Index exceeds matrix dimensions.

which seems like an obvious bug. Is it possible that while analyzing
the syntax 'sparse(i,j,s,n,m,nzmax)' matlab checks nzmax versus
numel(i) | numel(j) , instead of versus max(i)|max(j) ?

Subject: sparse matrix bug?

From: Titus Edelhofer

Date: 18 May, 2005 13:31:34

Message: 2 of 14

Hi,
this is not a bug, you may call it "not too descriptive error message".
Try
A=sparse([1,1],[1,1],[1,2],1,1,2)
instead... ;-)

Titus

"Ofek Shilon" <ofek@simbionix.com> schrieb im Newsbeitrag
news:1116415617.514627.64740@f14g2000cwb.googlegroups.com...
> take a very simple accumulating sparse-matrix generation:
>
> A=sparse([1,1],[1,1],[1,2])
>
> No problem:
>
> A =
>
> (1,1) 3
>
> However, while trying to declare the space to allocate:
>
> A=sparse([1,1],[1,1],[1,2],1,1,1)
>
> I get the very annoying:
>
> ??? Error using ==> sparse
> Index exceeds matrix dimensions.
>
> which seems like an obvious bug. Is it possible that while analyzing
> the syntax 'sparse(i,j,s,n,m,nzmax)' matlab checks nzmax versus
> numel(i) | numel(j) , instead of versus max(i)|max(j) ?
>

Subject: sparse matrix bug?

From: Ofek Shilon

Date: 18 May, 2005 07:45:12

Message: 3 of 14

seems like a bug to me. theres no reason that i can thing of to halt
the execution of A=3Dsparse([1,1],[1,1],[1,2],1,1=AD,1) . nzmax should be
compared to the product max(i)*max(j) (my original post had a typo
there). i had quite a bad time locating this particular 'feature' in
my program - the example i gave is a simplified one, of course.


Ofek


Titus Edelhofer May 18, 7:31 am show options

Newsgroups: comp.soft-sys.matlab
From: "Titus Edelhofer" <titus.edelho...@mathworks.de> - Find messages
by this author
Date: Wed, 18 May 2005 13:31:34 +0200
Local: Wed,May 18 2005 7:31 am
Subject: Re: sparse matrix bug?
Reply | Reply to Author | Forward | Print | Individual Message | Show
original | Report Abuse

Hi,
this is not a bug, you may call it "not too descriptive error message".

Try
A=3Dsparse([1,1],[1,1],[1,2],1,1=AD,2)
instead... ;-)


Titus


"Ofek Shilon" <o...@simbionix.com> schrieb im Newsbeitrag
news:1116415617.514627.64740@f14g2000cwb.googlegroups.com...

> take a very simple accumulating sparse-matrix generation:

> A=3Dsparse([1,1],[1,1],[1,2])


> No problem:


> A =3D


> (1,1) 3


> However, while trying to declare the space to allocate:


> A=3Dsparse([1,1],[1,1],[1,2],1,1=AD,1)


> I get the very annoying:


> ??? Error using =3D=3D> sparse
> Index exceeds matrix dimensions.


> which seems like an obvious bug. Is it possible that while analyzing
> the syntax 'sparse(i,j,s,n,m,nzmax)' matlab checks nzmax versus
> numel(i) | numel(j) , instead of versus max(i)|max(j) ?

Subject: sparse matrix bug?

From: Titus Edelhofer

Date: 18 May, 2005 16:54:02

Message: 4 of 14

Hi Ofek,

I disagree: nzmax is the number of non zero entries, i.e., it need to be
always at least the length of i, j and s (and usually is length(i)).
I admit, the routine could error out with a "better" error message,
when nzmax<numel(i).
The reason for the parameter nzmax is to give the user the possibility
to tell the sparse, that you are going to add some elements later (and
want to reserve the memory already at construction).

Titus

"Ofek Shilon" <ofek@simbionix.com> schrieb im Newsbeitrag
news:1116427512.377765.120370@o13g2000cwo.googlegroups.com...
seems like a bug to me. theres no reason that i can thing of to halt
the execution of A=sparse([1,1],[1,1],[1,2],1,1­,1) . nzmax should be
compared to the product max(i)*max(j) (my original post had a typo
there). i had quite a bad time locating this particular 'feature' in
my program - the example i gave is a simplified one, of course.


Ofek


Titus Edelhofer May 18, 7:31 am show options

Newsgroups: comp.soft-sys.matlab
From: "Titus Edelhofer" <titus.edelho...@mathworks.de> - Find messages
by this author
Date: Wed, 18 May 2005 13:31:34 +0200
Local: Wed,May 18 2005 7:31 am
Subject: Re: sparse matrix bug?
Reply | Reply to Author | Forward | Print | Individual Message | Show
original | Report Abuse

Hi,
this is not a bug, you may call it "not too descriptive error message".

Try
A=sparse([1,1],[1,1],[1,2],1,1­,2)
instead... ;-)


Titus


"Ofek Shilon" <o...@simbionix.com> schrieb im Newsbeitrag
news:1116415617.514627.64740@f14g2000cwb.googlegroups.com...

> take a very simple accumulating sparse-matrix generation:

> A=sparse([1,1],[1,1],[1,2])


> No problem:


> A =


> (1,1) 3


> However, while trying to declare the space to allocate:


> A=sparse([1,1],[1,1],[1,2],1,1­,1)


> I get the very annoying:


> ??? Error using ==> sparse
> Index exceeds matrix dimensions.


> which seems like an obvious bug. Is it possible that while analyzing
> the syntax 'sparse(i,j,s,n,m,nzmax)' matlab checks nzmax versus
> numel(i) | numel(j) , instead of versus max(i)|max(j) ?

Subject: sparse matrix bug?

From: Ofek Shilon

Date: 18 May, 2005 11:29:55

Message: 5 of 14

Hi Titus
I disagree also.
The syntax for the 'sparse' command is designed to enable accomulation.
When sparse encounters repeated couples of indices in i & j, according
to its documentation and indeed its behavior, the formed matrix
accumulates the values in the repeated locations adding them to the
previous ones it encountered. Check again that -
   A=3Dsparse([1,1],[1,1],[1,2])
gives the result -
     A =3D
       (1,1) 3
that is, a 1x1 matrix, although i and j are of length 2 (that is the
most minimalistic example of this useful feature).
Now in my real life situation i need to accumulate a very large amount
of data into a relatively small sparse matrix. To allocate memory by
the size of the accumulating vectors i,j & s would be both disasterous
to the performence and comletely unnecessary.
A possible explanation to the situation is that the implementation of
the built-in 'sparse' caches the entire accumulated data into the
designated storage prior to arranging (and squeezing) it, but that
seems extremely wasteful and very untypical to the mathworks guys. A
more probable explanation (IMHO) is just an irrelevant check of the
data, i.e., a bug.

is there anyone from the mathworks around, who can say what's happening
inside there?

Ofek




Hi Ofek,

I disagree: nzmax is the number of non zero entries, i.e., it need to
be
always at least the length of i, j and s (and usually is length(i)).
I admit, the routine could error out with a "better" error message,
when nzmax<numel(i).
The reason for the parameter nzmax is to give the user the possibility
to tell the sparse, that you are going to add some elements later (and
want to reserve the memory already at construction).


Titus


"Ofek Shilon" <o...@simbionix.com> schrieb im Newsbeitrag
news:1116427512.377765.120370@o13g2000cwo.googlegroups.com...


seems like a bug to me. theres no reason that i can thing of to halt
the execution of A=3Dsparse([1,1],[1,1],[1,2],1,1=AD=AD,1) . nzmax should
be
compared to the product max(i)*max(j) (my original post had a typo
there). i had quite a bad time locating this particular 'feature' in
my program - the example i gave is a simplified one, of course.
Ofek

Titus Edelhofer May 18, 7:31 am show options
Newsgroups: comp.soft-sys.matlab
From: "Titus Edelhofer" <titus.edelho...@mathworks.de> - Find messages
by this author
Date: Wed, 18 May 2005 13:31:34 +0200
Local: Wed,May 18 2005 7:31 am
Subject: Re: sparse matrix bug?
Hi,
this is not a bug, you may call it "not too
 descriptive error message".
Try
A=3Dsparse([1,1],[1,1],[1,2],1,1=AD=AD,2)
instead... ;-)
Titus

"Ofek Shilon" <o...@simbionix.com> schrieb im Newsbeitrag
news:1116415617.514627.64740@f14g2000cwb.googlegroups.com...
> take a very simple accumulating sparse-matrix generation:
> A=3Dsparse([1,1],[1,1],[1,2])
> No problem:
> A =3D
> (1,1) 3
> However, while trying to declare the space to allocate:
> A=3Dsparse([1,1],[1,1],[1,2],1,1=AD=AD,1)
> I get the very annoying:
> ??? Error using =3D=3D> sparse
> Index exceeds matrix dimensions.
> which seems like an obvious bug. Is it possible that while analyzing
> the syntax 'sparse(i,j,s,n,m,nzmax)' matlab checks nzmax versus
> numel(i) | numel(j) , instead of versus max(i)|max(j) ?

Subject: sparse matrix bug?

From: Penny Anderson

Date: 18 May, 2005 14:40:39

Message: 6 of 14

Ofek,

I agree with you and I actually added it to our enhancement database 6
months ago (see how prescient I am ;-). However, there is no promise that we
will implement this new behavior for sparse.

Penny Anderson
The MathWorks, Inc.

"Ofek Shilon" <ofek@simbionix.com> wrote in message
news:1116440995.308920.9610@g44g2000cwa.googlegroups.com...
Hi Titus
I disagree also.
The syntax for the 'sparse' command is designed to enable accomulation.
When sparse encounters repeated couples of indices in i & j, according
to its documentation and indeed its behavior, the formed matrix
accumulates the values in the repeated locations adding them to the
previous ones it encountered. Check again that -
   A=sparse([1,1],[1,1],[1,2])
gives the result -
     A =
       (1,1) 3
that is, a 1x1 matrix, although i and j are of length 2 (that is the
most minimalistic example of this useful feature).
Now in my real life situation i need to accumulate a very large amount
of data into a relatively small sparse matrix. To allocate memory by
the size of the accumulating vectors i,j & s would be both disasterous
to the performence and comletely unnecessary.
A possible explanation to the situation is that the implementation of
the built-in 'sparse' caches the entire accumulated data into the
designated storage prior to arranging (and squeezing) it, but that
seems extremely wasteful and very untypical to the mathworks guys. A
more probable explanation (IMHO) is just an irrelevant check of the
data, i.e., a bug.

is there anyone from the mathworks around, who can say what's happening
inside there?

Ofek




Hi Ofek,

I disagree: nzmax is the number of non zero entries, i.e., it need to
be
always at least the length of i, j and s (and usually is length(i)).
I admit, the routine could error out with a "better" error message,
when nzmax<numel(i).
The reason for the parameter nzmax is to give the user the possibility
to tell the sparse, that you are going to add some elements later (and
want to reserve the memory already at construction).


Titus


"Ofek Shilon" <o...@simbionix.com> schrieb im Newsbeitrag
news:1116427512.377765.120370@o13g2000cwo.googlegroups.com...


seems like a bug to me. theres no reason that i can thing of to halt
the execution of A=sparse([1,1],[1,1],[1,2],1,1­­,1) . nzmax should
be
compared to the product max(i)*max(j) (my original post had a typo
there). i had quite a bad time locating this particular 'feature' in
my program - the example i gave is a simplified one, of course.
Ofek

Titus Edelhofer May 18, 7:31 am show options
Newsgroups: comp.soft-sys.matlab
From: "Titus Edelhofer" <titus.edelho...@mathworks.de> - Find messages
by this author
Date: Wed, 18 May 2005 13:31:34 +0200
Local: Wed,May 18 2005 7:31 am
Subject: Re: sparse matrix bug?
Hi,
this is not a bug, you may call it "not too
 descriptive error message".
Try
A=sparse([1,1],[1,1],[1,2],1,1­­,2)
instead... ;-)
Titus

"Ofek Shilon" <o...@simbionix.com> schrieb im Newsbeitrag
news:1116415617.514627.64740@f14g2000cwb.googlegroups.com...
> take a very simple accumulating sparse-matrix generation:
> A=sparse([1,1],[1,1],[1,2])
> No problem:
> A =
> (1,1) 3
> However, while trying to declare the space to allocate:
> A=sparse([1,1],[1,1],[1,2],1,1­­,1)
> I get the very annoying:
> ??? Error using ==> sparse
> Index exceeds matrix dimensions.
> which seems like an obvious bug. Is it possible that while analyzing
> the syntax 'sparse(i,j,s,n,m,nzmax)' matlab checks nzmax versus
> numel(i) | numel(j) , instead of versus max(i)|max(j) ?

Subject: sparse matrix bug?

From: spasmous

Date: 18 May, 2005 11:43:44

Message: 7 of 14


Ofek Shilon wrote:
> To allocate memory by...
> the size of the accumulating vectors i,j & s would be both
disasterous
> to the performence...

Really? Did you check?

I agree with you though - if you tell it nzmax=1 then it should
over-ride the estimated one.

Subject: sparse matrix bug?

From: Ofek Shilon

Date: 18 May, 2005 23:36:57

Message: 8 of 14

Penny,

Thanks for the reply. So it is indeed an allocation implementation
issue and not a simple bug in the syntax check?

  Ofek


Penny Anderson wrote:
> Ofek,
>
> I agree with you and I actually added it to our enhancement database
6
> months ago (see how prescient I am ;-). However, there is no promise
that we
> will implement this new behavior for sparse.
>
> Penny Anderson
> The MathWorks, Inc.
>
> "Ofek Shilon" <ofek@simbionix.com> wrote in message
> news:1116440995.308920.9610@g44g2000cwa.googlegroups.com...
> Hi Titus
> I disagree also.
> The syntax for the 'sparse' command is designed to enable
accomulation.
> When sparse encounters repeated couples of indices in i & j,
according
> to its documentation and indeed its behavior, the formed matrix
> accumulates the values in the repeated locations adding them to the
> previous ones it encountered. Check again that -
> A=3Dsparse([1,1],[1,1],[1,2])
> gives the result -
> A =3D
> (1,1) 3
> that is, a 1x1 matrix, although i and j are of length 2 (that is the
> most minimalistic example of this useful feature).
> Now in my real life situation i need to accumulate a very large
amount
> of data into a relatively small sparse matrix. To allocate memory by
> the size of the accumulating vectors i,j & s would be both
disasterous
> to the performence and comletely unnecessary.
> A possible explanation to the situation is that the implementation of
> the built-in 'sparse' caches the entire accumulated data into the
> designated storage prior to arranging (and squeezing) it, but that
> seems extremely wasteful and very untypical to the mathworks guys. A
> more probable explanation (IMHO) is just an irrelevant check of the
> data, i.e., a bug.
>
> is there anyone from the mathworks around, who can say what's
happening
> inside there?
>
> Ofek
>
>
>
>
> Hi Ofek,
>
> I disagree: nzmax is the number of non zero entries, i.e., it need to
> be
> always at least the length of i, j and s (and usually is length(i)).
> I admit, the routine could error out with a "better" error message,
> when nzmax<numel(i).
> The reason for the parameter nzmax is to give the user the
possibility
> to tell the sparse, that you are going to add some elements later
(and
> want to reserve the memory already at construction).
>
>
> Titus
>
>
> "Ofek Shilon" <o...@simbionix.com> schrieb im Newsbeitrag
> news:1116427512.377765.120370@o13g2000cwo.googlegroups.com...
>
>
> seems like a bug to me. theres no reason that i can thing of to halt
> the execution of A=3Dsparse([1,1],[1,1],[1,2],1,1=AD=AD,1) . nzmax
should
> be
> compared to the product max(i)*max(j) (my original post had a typo
> there). i had quite a bad time locating this particular 'feature'
in
> my program - the example i gave is a simplified one, of course.
> Ofek
>
> Titus Edelhofer May 18, 7:31 am show options
> Newsgroups: comp.soft-sys.matlab
> From: "Titus Edelhofer" <titus.edelho...@mathworks.de> - Find
messages
> by this author
> Date: Wed, 18 May 2005 13:31:34 +0200
> Local: Wed,May 18 2005 7:31 am
> Subject: Re: sparse matrix bug?
> Hi,
> this is not a bug, you may call it "not too
> descriptive error message".
> Try
> A=3Dsparse([1,1],[1,1],[1,2],1,1=AD=AD,2)
> instead... ;-)
> Titus
>
> "Ofek Shilon" <o...@simbionix.com> schrieb im Newsbeitrag
> news:1116415617.514627.64740@f14g2000cwb.googlegroups.com...
> > take a very simple accumulating sparse-matrix generation:
> > A=3Dsparse([1,1],[1,1],[1,2])
> > No problem:
> > A =3D
> > (1,1) 3
> > However, while trying to declare the space to allocate:
> > A=3Dsparse([1,1],[1,1],[1,2],1,1=AD=AD,1)
> > I get the very annoying:
> > ??? Error using =3D=3D> sparse
> > Index exceeds matrix dimensions.
> > which seems like an obvious bug. Is it possible that while
analyzing
> > the syntax 'sparse(i,j,s,n,m,nzmax)' matlab checks nzmax versus
> > numel(i) | numel(j) , instead of versus max(i)|max(j) ?

Subject: sparse matrix bug?

From: Titus Edelhofer

Date: 19 May, 2005 09:20:43

Message: 9 of 14

Hi Ofek,
O.K., now I found the word "accumulating" in your original post as well...
;-)
So in fact for i=[1 1], j=[1 1] something like
size(unique([i' j'], 'rows'), 1)
should be the correct value of nzmax.

Sorry for not reading your first post more precisely...

Titus

"Ofek Shilon" <ofek@simbionix.com> schrieb im Newsbeitrag
news:1116440995.308920.9610@g44g2000cwa.googlegroups.com...
Hi Titus
I disagree also.
The syntax for the 'sparse' command is designed to enable accomulation.
When sparse encounters repeated couples of indices in i & j, according
to its documentation and indeed its behavior, the formed matrix
accumulates the values in the repeated locations adding them to the
previous ones it encountered. Check again that -
   A=sparse([1,1],[1,1],[1,2])
gives the result -
     A =
       (1,1) 3
that is, a 1x1 matrix, although i and j are of length 2 (that is the
most minimalistic example of this useful feature).
Now in my real life situation i need to accumulate a very large amount
of data into a relatively small sparse matrix. To allocate memory by
the size of the accumulating vectors i,j & s would be both disasterous
to the performence and comletely unnecessary.
A possible explanation to the situation is that the implementation of
the built-in 'sparse' caches the entire accumulated data into the
designated storage prior to arranging (and squeezing) it, but that
seems extremely wasteful and very untypical to the mathworks guys. A
more probable explanation (IMHO) is just an irrelevant check of the
data, i.e., a bug.

is there anyone from the mathworks around, who can say what's happening
inside there?

Ofek




Hi Ofek,

I disagree: nzmax is the number of non zero entries, i.e., it need to
be
always at least the length of i, j and s (and usually is length(i)).
I admit, the routine could error out with a "better" error message,
when nzmax<numel(i).
The reason for the parameter nzmax is to give the user the possibility
to tell the sparse, that you are going to add some elements later (and
want to reserve the memory already at construction).


Titus


"Ofek Shilon" <o...@simbionix.com> schrieb im Newsbeitrag
news:1116427512.377765.120370@o13g2000cwo.googlegroups.com...


seems like a bug to me. theres no reason that i can thing of to halt
the execution of A=sparse([1,1],[1,1],[1,2],1,1­­,1) . nzmax should
be
compared to the product max(i)*max(j) (my original post had a typo
there). i had quite a bad time locating this particular 'feature' in
my program - the example i gave is a simplified one, of course.
Ofek

Titus Edelhofer May 18, 7:31 am show options
Newsgroups: comp.soft-sys.matlab
From: "Titus Edelhofer" <titus.edelho...@mathworks.de> - Find messages
by this author
Date: Wed, 18 May 2005 13:31:34 +0200
Local: Wed,May 18 2005 7:31 am
Subject: Re: sparse matrix bug?
Hi,
this is not a bug, you may call it "not too
 descriptive error message".
Try
A=sparse([1,1],[1,1],[1,2],1,1­­,2)
instead... ;-)
Titus

"Ofek Shilon" <o...@simbionix.com> schrieb im Newsbeitrag
news:1116415617.514627.64740@f14g2000cwb.googlegroups.com...
> take a very simple accumulating sparse-matrix generation:
> A=sparse([1,1],[1,1],[1,2])
> No problem:
> A =
> (1,1) 3
> However, while trying to declare the space to allocate:
> A=sparse([1,1],[1,1],[1,2],1,1­­,1)
> I get the very annoying:
> ??? Error using ==> sparse
> Index exceeds matrix dimensions.
> which seems like an obvious bug. Is it possible that while analyzing
> the syntax 'sparse(i,j,s,n,m,nzmax)' matlab checks nzmax versus
> numel(i) | numel(j) , instead of versus max(i)|max(j) ?

Subject: sparse matrix bug?

From: Ofek Shilon

Date: 19 May, 2005 01:19:35

Message: 10 of 14

>So in fact for i=[1 1], j=[1 1] something like
>size(unique([i' j'], 'rows'), 1)
>should be the correct value of nzmax.

Hi Titus
There is no "correct value" for nzmax - you gave the tightest
allocation possible which is still sufficient (though might
not pass syntax check currently), but that would require
complete re-allocation if a need arises to add non-zeros.
My problem was that the syntax check kicked me out, seemingly
for allocating too small a memory, when that was clearly not
the case.

glad we worked this out :)

  Ofek

Subject: sparse matrix bug?

From: Penny Anderson

Date: 19 May, 2005 11:06:13

Message: 11 of 14

Ofek,

The algorithm is naively using a default nzmax=max([length(i) length(j)
length(s)]) and if you specify nzmax less than this, it simply errors. We
can work on this.

Penny Anderson
The MathWorks, Inc.

"Ofek Shilon" <ofek@simbionix.com> wrote in message
news:1116484617.460575.323190@g47g2000cwa.googlegroups.com...
Penny,

Thanks for the reply. So it is indeed an allocation implementation
issue and not a simple bug in the syntax check?

  Ofek


Penny Anderson wrote:
> Ofek,
>
> I agree with you and I actually added it to our enhancement database
6
> months ago (see how prescient I am ;-). However, there is no promise
that we
> will implement this new behavior for sparse.
>
> Penny Anderson
> The MathWorks, Inc.
>
> "Ofek Shilon" <ofek@simbionix.com> wrote in message
> news:1116440995.308920.9610@g44g2000cwa.googlegroups.com...
> Hi Titus
> I disagree also.
> The syntax for the 'sparse' command is designed to enable
accomulation.
> When sparse encounters repeated couples of indices in i & j,
according
> to its documentation and indeed its behavior, the formed matrix
> accumulates the values in the repeated locations adding them to the
> previous ones it encountered. Check again that -
> A=sparse([1,1],[1,1],[1,2])
> gives the result -
> A =
> (1,1) 3
> that is, a 1x1 matrix, although i and j are of length 2 (that is the
> most minimalistic example of this useful feature).
> Now in my real life situation i need to accumulate a very large
amount
> of data into a relatively small sparse matrix. To allocate memory by
> the size of the accumulating vectors i,j & s would be both
disasterous
> to the performence and comletely unnecessary.
> A possible explanation to the situation is that the implementation of
> the built-in 'sparse' caches the entire accumulated data into the
> designated storage prior to arranging (and squeezing) it, but that
> seems extremely wasteful and very untypical to the mathworks guys. A
> more probable explanation (IMHO) is just an irrelevant check of the
> data, i.e., a bug.
>
> is there anyone from the mathworks around, who can say what's
happening
> inside there?
>
> Ofek
>
>
>
>
> Hi Ofek,
>
> I disagree: nzmax is the number of non zero entries, i.e., it need to
> be
> always at least the length of i, j and s (and usually is length(i)).
> I admit, the routine could error out with a "better" error message,
> when nzmax<numel(i).
> The reason for the parameter nzmax is to give the user the
possibility
> to tell the sparse, that you are going to add some elements later
(and
> want to reserve the memory already at construction).
>
>
> Titus
>
>
> "Ofek Shilon" <o...@simbionix.com> schrieb im Newsbeitrag
> news:1116427512.377765.120370@o13g2000cwo.googlegroups.com...
>
>
> seems like a bug to me. theres no reason that i can thing of to halt
> the execution of A=sparse([1,1],[1,1],[1,2],1,1­­,1) . nzmax
should
> be
> compared to the product max(i)*max(j) (my original post had a typo
> there). i had quite a bad time locating this particular 'feature'
in
> my program - the example i gave is a simplified one, of course.
> Ofek
>
> Titus Edelhofer May 18, 7:31 am show options
> Newsgroups: comp.soft-sys.matlab
> From: "Titus Edelhofer" <titus.edelho...@mathworks.de> - Find
messages
> by this author
> Date: Wed, 18 May 2005 13:31:34 +0200
> Local: Wed,May 18 2005 7:31 am
> Subject: Re: sparse matrix bug?
> Hi,
> this is not a bug, you may call it "not too
> descriptive error message".
> Try
> A=sparse([1,1],[1,1],[1,2],1,1­­,2)
> instead... ;-)
> Titus
>
> "Ofek Shilon" <o...@simbionix.com> schrieb im Newsbeitrag
> news:1116415617.514627.64740@f14g2000cwb.googlegroups.com...
> > take a very simple accumulating sparse-matrix generation:
> > A=sparse([1,1],[1,1],[1,2])
> > No problem:
> > A =
> > (1,1) 3
> > However, while trying to declare the space to allocate:
> > A=sparse([1,1],[1,1],[1,2],1,1­­,1)
> > I get the very annoying:
> > ??? Error using ==> sparse
> > Index exceeds matrix dimensions.
> > which seems like an obvious bug. Is it possible that while
analyzing
> > the syntax 'sparse(i,j,s,n,m,nzmax)' matlab checks nzmax versus
> > numel(i) | numel(j) , instead of versus max(i)|max(j) ?

Subject: sparse matrix bug?

From: Paul Koppen

Date: 23 Jan, 2012 16:00:10

Message: 12 of 14

It is now almost 7 years later, I totally agree with Ofek (why require more memory when the user *knows* the actual memory upperbound), but still no fix in Matlab :-(

Time for a *BUMP*. Please?

Thanks,
Paul


"Penny Anderson" <no.spam.for.me@nospam.org> wrote in message <d6ia15$683$1@fred.mathworks.com>...
> Ofek,
>
> The algorithm is naively using a default nzmax=max([length(i) length(j)
> length(s)]) and if you specify nzmax less than this, it simply errors. We
> can work on this.
>
> Penny Anderson
> The MathWorks, Inc.
>
> "Ofek Shilon" <ofek@simbionix.com> wrote in message
> news:1116484617.460575.323190@g47g2000cwa.googlegroups.com...
> Penny,
>
> Thanks for the reply. So it is indeed an allocation implementation
> issue and not a simple bug in the syntax check?
>
> Ofek
>
>
> Penny Anderson wrote:
> > Ofek,
> >
> > I agree with you and I actually added it to our enhancement database
> 6
> > months ago (see how prescient I am ;-). However, there is no promise
> that we
> > will implement this new behavior for sparse.
> >
> > Penny Anderson
> > The MathWorks, Inc.
> >
> > "Ofek Shilon" <ofek@simbionix.com> wrote in message
> > news:1116440995.308920.9610@g44g2000cwa.googlegroups.com...
> > Hi Titus
> > I disagree also.
> > The syntax for the 'sparse' command is designed to enable
> accomulation.
> > When sparse encounters repeated couples of indices in i & j,
> according
> > to its documentation and indeed its behavior, the formed matrix
> > accumulates the values in the repeated locations adding them to the
> > previous ones it encountered. Check again that -
> > A=sparse([1,1],[1,1],[1,2])
> > gives the result -
> > A =
> > (1,1) 3
> > that is, a 1x1 matrix, although i and j are of length 2 (that is the
> > most minimalistic example of this useful feature).
> > Now in my real life situation i need to accumulate a very large
> amount
> > of data into a relatively small sparse matrix. To allocate memory by
> > the size of the accumulating vectors i,j & s would be both
> disasterous
> > to the performence and comletely unnecessary.
> > A possible explanation to the situation is that the implementation of
> > the built-in 'sparse' caches the entire accumulated data into the
> > designated storage prior to arranging (and squeezing) it, but that
> > seems extremely wasteful and very untypical to the mathworks guys. A
> > more probable explanation (IMHO) is just an irrelevant check of the
> > data, i.e., a bug.
> >
> > is there anyone from the mathworks around, who can say what's
> happening
> > inside there?
> >
> > Ofek
> >
> >
> >
> >
> > Hi Ofek,
> >
> > I disagree: nzmax is the number of non zero entries, i.e., it need to
> > be
> > always at least the length of i, j and s (and usually is length(i)).
> > I admit, the routine could error out with a "better" error message,
> > when nzmax<numel(i).
> > The reason for the parameter nzmax is to give the user the
> possibility
> > to tell the sparse, that you are going to add some elements later
> (and
> > want to reserve the memory already at construction).
> >
> >
> > Titus
> >
> >
> > "Ofek Shilon" <o...@simbionix.com> schrieb im Newsbeitrag
> > news:1116427512.377765.120370@o13g2000cwo.googlegroups.com...
> >
> >
> > seems like a bug to me. theres no reason that i can thing of to halt
> > the execution of A=sparse([1,1],[1,1],[1,2],1,1­­,1) . nzmax
> should
> > be
> > compared to the product max(i)*max(j) (my original post had a typo
> > there). i had quite a bad time locating this particular 'feature'
> in
> > my program - the example i gave is a simplified one, of course.
> > Ofek
> >
> > Titus Edelhofer May 18, 7:31 am show options
> > Newsgroups: comp.soft-sys.matlab
> > From: "Titus Edelhofer" <titus.edelho...@mathworks.de> - Find
> messages
> > by this author
> > Date: Wed, 18 May 2005 13:31:34 +0200
> > Local: Wed,May 18 2005 7:31 am
> > Subject: Re: sparse matrix bug?
> > Hi,
> > this is not a bug, you may call it "not too
> > descriptive error message".
> > Try
> > A=sparse([1,1],[1,1],[1,2],1,1­­,2)
> > instead... ;-)
> > Titus
> >
> > "Ofek Shilon" <o...@simbionix.com> schrieb im Newsbeitrag
> > news:1116415617.514627.64740@f14g2000cwb.googlegroups.com...
> > > take a very simple accumulating sparse-matrix generation:
> > > A=sparse([1,1],[1,1],[1,2])
> > > No problem:
> > > A =
> > > (1,1) 3
> > > However, while trying to declare the space to allocate:
> > > A=sparse([1,1],[1,1],[1,2],1,1­­,1)
> > > I get the very annoying:
> > > ??? Error using ==> sparse
> > > Index exceeds matrix dimensions.
> > > which seems like an obvious bug. Is it possible that while
> analyzing
> > > the syntax 'sparse(i,j,s,n,m,nzmax)' matlab checks nzmax versus
> > > numel(i) | numel(j) , instead of versus max(i)|max(j) ?
>
>

Subject: sparse matrix bug?

From: Matt J

Date: 23 Jan, 2012 21:37:51

Message: 13 of 14

"Paul Koppen" wrote in message <jfk06a$pb4$1@newscl01ah.mathworks.com>...
>
> It is now almost 7 years later, I totally agree with Ofek (why require more memory when the user *knows* the actual memory upperbound), but still no fix in Matlab :-(
===========

I agree that it is strange that this bug in SPARSE still hasn't been fixed. Bear in mind, however, that you can use ACCUMARRAY to do accumulating sparse matrix generation without this problem:

M=accumarray([1 1;1 1],[1,2],[1,1],[],[],true)

Subject: sparse matrix bug?

From: Bruno Luong

Date: 23 Jan, 2012 21:37:51

Message: 14 of 14

"Paul Koppen" wrote in message <jfk06a$pb4$1@newscl01ah.mathworks.com>...
> It is now almost 7 years later, I totally agree with Ofek (why require more memory when the user *knows* the actual memory upperbound), but still no fix in Matlab :-(
>
> Time for a *BUMP*. Please?
>
> Thanks,
> Paul
>

+1. The restriction can be wasteful when working on FEM, domain where sparse matrix is supposed to be designed for.

Bruno

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com