|
Ublas : |
From: Kresimir Fresl (fresl_at_[hidden])
Date: 2004-12-29 11:34:24
Hi Dmitri,
> Umfpack "symbolic" driver function (in C) accept
> an " int " for matrix sizes and " int* " for indexes array.
> (Strictly speaking, it should have been 'unsigned' and 'unsigned*',
> if I don't miss some point.)
> As I understand, ublas matrix methods do some 'unsigned' comparisons
> to check sizes inside the code. This causes g++ to issue warning
> messages like this:
> "Warning : comparison of signed vs. unsigned.",
> even when compiling the basic examples from umfpack bindings documentation.
Yes, size_type in ublas vectors and matrices is unsigned (as in standard
library).
On the other hand, umfpack functions expect that index arrays are arrays
of int's. As Mr. Davis replied, unsigned int's are not often used in C.
(And, if I correctly remember, there were some discussions in C++
newgroups whether size_type in standard library, which is also index
type in std::vector, should be int or unsigned. ;o)
As the introductory example in umfpack bindings documentation shows,
matrix type should be
ublas::compressed_matrix<double, ublas::column_major, 0,
ublas::unbounded_array<int>, ublas::unbounded_array<double> >
Fourth template argument is index array type.
Probably we should state explicitly (not just in the example) that
index array must be array of int's, and not unsigned's which is
default type in ublas.
Some time ago there was a suggestion to add size_t -> int casts
to umfpack bindings. Here's part of my reply:
==================================================================
Pointer to size_t (ie. unsigned) cannot be cast to pointer to int.
I know that compilers do not complain when one says:
unsigned *i;
int *j;
j = (int*) i;
but if (s)he does it C++ way:
j = static_cast<int*> (i);
(s)he will get (g++, Comeau, Intel):
error: invalid type conversion: "unsigned int *" to "int *"
I also know that one can write:
j = reinterpret_cast<int*> (i);
and that compilers will not complain, but it is neither
safe nor truely portable: size_t need not be unsigned int.
Umfpack expects that index arrays are int arrays.
So, matrix must be declared as:
ublas::compressed_matrix<double, ublas::column_major, 0,
ublas::unbounded_array<int>, ublas::unbounded_array<double> >
It is more verbose than one would like, but I am afraid that
we can do nothing.
===================================================================
> I like to compile with 'g++ -ansi -pedantic -Wall' and don't like warnings.
> :)
> What can I do ?
I add `-Wno-sign-compare'. Maybe this should be recommended in bindings
docs, too ;o).
I think that one can expect similar problems with other bindings.
Namely, size() functions in vector and matrix traits classes return
int's because unsigned types do not exist in Fortran.
Regards,
fres