octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ASCII file format for sparse matrices?


From: Jordi Gutiérrez Hermoso
Subject: Re: ASCII file format for sparse matrices?
Date: Fri, 13 May 2011 16:35:17 -0500

Moving this discussion to the maintainers' mailing list...

On 13 May 2011 14:08, Rui Maciel <address@hidden> wrote:
> On 05/13/2011 02:06 PM, Jordi Gutiérrez Hermoso wrote:
>>
>> Probably not, unless they are your plans. This is the source file that
>> you can begin inspecting to provide a patch:
>>
>>
>>  http://hg.savannah.gnu.org/hgweb/octave/file/tip/src/ov-base-sparse.cc#l396
>>
>> Note that most of the work is done in op>>  here:
>>
>>
>>  http://hg.savannah.gnu.org/hgweb/octave/file/tip/liboctave/dSparse.cc#l7599
>>
>> Which as you can see, is just a thin wrapper of the actual
>> read_sparse_matrix function:
>>
>>
>>  http://hg.savannah.gnu.org/hgweb/octave/file/tip/liboctave/Sparse.h#l586
>>
>> The actual sparse representation right now only is CCS. It would
>> probably take a significant amount of rewriting much of the sparse
>> matrix code if you have another representation in mind. However, if
>> all you want is to extend the flexibility of the load command, that
>> can probably be arranged.
>
> I've just took a peek at the source code and, at least at first glance, it
> doesn't look like it takes that much work to implement a proper "dictionary
> of keys" format.  Well, it won't take that much work provided that it's
> possible to declare a temporary std::list for the DoK coefficients, import
> all [i,j,value] triplets into that list, sort the list in order of j and i
> and then fill the Sparse<T>& a object as before.

If you want a sorted dictionary, std::map exactly fits the bill,
doesn't it? Besides that detail, I think you're right that this is the
way to go. We use the C++ stdlib without any scruple in Octave, so
you're free to use std::map (or std::list if you think that's better).

I see one problem regarding efficiency, since if you can't assume the
keys are already sorted in the file, you will inevitably lose
something while you do the sorting. Perhaps add another keyword to be
read with extract_keyword that specifies if the matrix is already in
CCS so that you don't sort unnecessarily?

- Jordi G. H.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]