sparse matrices

5 views
Skip to first unread message

Sergey Solovyev

unread,
Jun 5, 2010, 3:36:09 AM6/5/10
to tumbi
I was really sad ones found that it's impossible to resize sparse
matrices in nsp. I.e. I tried to perform operation sp(:) on my sparse
matrix to represent it as vector and got an error. I can make my own
functions for that, but hope I've just missed something?

Jean-Philippe Chancelier

unread,
Jun 5, 2010, 7:26:54 AM6/5/10
to tu...@googlegroups.com, torren...@gmail.com

Sergey> I was really sad ones found that it's impossible to resize sparse
Sergey> matrices in nsp. I.e. I tried to perform operation sp(:) on my
Sergey> sparse matrix to represent it as vector and got an error. I can make
Sergey> my own functions for that, but hope I've just missed something?

Yes you are right resize2vect_sp is not implemented but you
can use the function matrix instead.

matrix(a,1,size(a,'*'))

we should implement a(:) and a.redim[1,-1] which are missing.

jpc

bruno

unread,
Jun 7, 2010, 3:52:03 AM6/7/10
to tumbi

Hi,

as Jpc said you can use matrix(A, size(A,'*'),1) in place of A(:)
but
we have implemented the missing operations :

A(:) // -> reshape to a sparse column vector
A.redim[-1,1] // -> same operation but work in place

and redim (alias matrix and reshape) should now work as explained
in the corresponding help page (also the reshape operation
for sparse should be faster).

hth
Bruno

Sergey Solovyev

unread,
Jun 7, 2010, 7:14:12 AM6/7/10
to tumbi
So I need to update and re-compile nsp for that, correct?
Also I wonder if it's possible to create a sparse matrix as a field
of my new object in *-types.def file ?

bruno

unread,
Jun 7, 2010, 7:55:28 AM6/7/10
to tumbi


On 7 juin, 13:14, Sergey Solovyev <torrentsh...@gmail.com> wrote:
>  So I need to update and re-compile nsp for that, correct?

yes, cvs update then make (but for some more involved changes
you need to do a make distclean and a re configure|autogen
operation before make).

>  Also I wonder if it's possible to create a sparse matrix as a field
> of my new object in *-types.def file ?

I guess yes as some nsp objects have nsp object as field (for
example
see nsp2/src/types-test/codegen/contours.defs) but I am still
not familiar with this part of nsp...

hth
Bruno

Jean-Philippe Chancelier

unread,
Jun 7, 2010, 8:09:03 AM6/7/10
to tu...@googlegroups.com, bruno....@iecn.u-nancy.fr

>> �Also I wonder if it's possible to create a sparse matrix as a field of

>> my new object in *-types.def file ?

bruno> I guess yes as some nsp objects have nsp object as field (for
bruno> example see nsp2/src/types-test/codegen/contours.defs) but I am still
bruno> not familiar with this part of nsp...

It should, but it won't since I have to add some informations in
the generator to make this point work (you can use basic C objects + Matrix
BMatrix, List up to now). You could also imagine to type the field
as a "NspObject*" to be able to store any nsp object but this is
also unfinished. I'll try to update this as soon as possible
jpc


Sergey Solovyev

unread,
Jun 7, 2010, 9:12:21 AM6/7/10
to tumbi
Ok. I can leave it as NspMatrix for now and change ones it will be
possible.
Anyway I will be continuing development of my tollbox for at least 2
months I suppose.

On Jun 7, 4:09 pm, Jean-Philippe Chancelier <j...@cermics.enpc.fr>
wrote:

Jean-Philippe Chancelier

unread,
Jun 12, 2010, 4:28:04 PM6/12/10
to tu...@googlegroups.com, torren...@gmail.com

Hi,
you can now use sparse matrices in the class code
generation. (See example in classa-types.defs).
jpc

Sergey Solovyev

unread,
Jul 9, 2010, 2:55:54 PM7/9/10
to tumbi
Will it take much time from nsp team to override or function for
working with sparse matrices?
I suppose it's obviously will appear in the future, so patching this
on toolbox layer is quite useless work...

On Jun 13, 12:28 am, Jean-Philippe Chancelier <j...@cermics.enpc.fr>
wrote:

bruno

unread,
Jul 11, 2010, 4:29:30 AM7/11/10
to tumbi
On 9 juil, 20:55, Sergey Solovyev <torrentsh...@gmail.com> wrote:
>   Will it take much time from nsp team to override or function for
> working with sparse matrices?
>   I suppose it's obviously will appear in the future, so patching this
> on toolbox layer is quite useless work...
>

Hi Sergey,

do you mean that the last modification from Jpc is not working ?
May be additionnal details could help us.

Bruno

Sergey Solovyev

unread,
Jul 11, 2010, 5:12:24 AM7/11/10
to tu...@googlegroups.com
Weel, I mean some necessary math. function are not overloaded for sparse and that's why sometimes
I need to convert matrix to full represetnaion in order to perform an operation. Also it's quite complecated that looks like I can't compare sparse matrices,
 i.e. a == b , a<>b e.t.c. is not working, I get messages that appropriate functions are not overloaded for sparse.

But I realize that all of these things can't be created in a moment...

2010/7/11 bruno <bruno....@iecn.u-nancy.fr>

--
You received this message because you are subscribed to the Google Groups "tumbi" group.
To post to this group, send email to tu...@googlegroups.com.
To unsubscribe from this group, send email to tumbi+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/tumbi?hl=en.


bruno

unread,
Jul 11, 2010, 10:33:43 AM7/11/10
to tumbi


On 11 juil, 11:12, Sergey Solovyev <torrentsh...@gmail.com> wrote:
> Weel, I mean some necessary math. function are not overloaded for sparse and
> that's why sometimes
> I need to convert matrix to full represetnaion in order to perform an
> operation. Also it's quite complecated that looks like I can't compare
> sparse matrices,
>  i.e. a == b , a<>b e.t.c. is not working, I get messages that appropriate
> functions are not overloaded for sparse.
>
> But I realize that all of these things can't be created in a moment...

I suppose you want to deal with boolean sparse matrices ? Otherwise
you can test "full equality" using A.equal[B]. Nevertheless you can
simulate boolean sparse matrices using sparse matrices made of
0 and 1. A few tricks :

If A is a sparse matrix then B=spones(A) gives
B(i,j) = 1 when A(i,j) != 0.

A <> B could be replaced by spones(A-B) (though this
fails for +- Inf components).

If A and B are sparse matrices of 0 and 1 then

* A & B could be replaced by A .*B

* A | B by max(A,B)

hth
Bruno

Reply all
Reply to author
Forward
0 new messages