But I don't know what else I could provide but the code below.
As far as I understand it, MatView Mat::viewAsSqua re() requires code
from "all.hpp", right?
Should I post the code from "all.hpp"?
Anna
#include "all.hpp"
static const bool USE_EQ_DOUBLES = true; // 1 to for match within
tolerance
static const char *MAT_PRINT_FORM AT = "%8.4f "; // default mat print format
namespace GslMat
//-----------------------------------------------------------------------------
MatView Mat::viewAsSqua re ()
{
// size_t ncols = size_t(sqrt(thi s->nelems()));
size_t ncols = static_cast< size_t >( sqrt( this->nelems() ) );
// check that can square properly (assertion is not essential but
protects the user)
ASSERT(ncols * ncols == this->nelems());
return MatView(*this, 0, 0, ncols, ncols, ncols);
}
When you provide a sample that depends on stuff not present in the sample, then
it is not possible to test your code as given, so the responder has to create a
compilable example which might (for some unknown reason) not exhibit the problem.
If you create the self-contained example yourself, and post that, then everybody
can be on the same page. But very often, the exercise of creating a
self-contained example will allow you to solve the problem for yourself.
Yes, it works for me.
>
But I don't know what else I could provide but the code below.
As far as I understand it, MatView Mat::viewAsSqua re() requires code
from "all.hpp", right?
Should I post the code from "all.hpp"?
Anna
>
#include "all.hpp"
>
static const bool USE_EQ_DOUBLES = true; // 1 to for match within
tolerance
static const char *MAT_PRINT_FORM AT = "%8.4f "; // default mat print
format
>
namespace GslMat
>
//-----------------------------------------------------------------------------
>
MatView Mat::viewAsSqua re ()
{
// size_t ncols = size_t(sqrt(thi s->nelems()));
size_t ncols = static_cast< size_t >( sqrt( this->nelems() ) );
// check that can square properly (assertion is not essential but
protects the user)
ASSERT(ncols * ncols == this->nelems());
return MatView(*this, 0, 0, ncols, ncols, ncols);
}
Anna:
If my simpler example works for you, the it is really up to *you* to figure out
what is between the simple example and your code. We cannot do that because we
do not have the code.
But since your code is at namespace and class scope, perhaps you have done
something to redefine size_t in this scope.
Thank god, the constructor error is gone!! Thanks very much!
By the way, why are you not getting the ambiguous call on the sqrt here?
I do get the ambiguous call error in the line you suggested:
Error 6 error C2668: 'sqrt' : ambiguous call to overloaded function
cmat.cpp 1101 ASMModel
Now this is one of the last bugs remaining.
What is the type of this->nelems?
I don't know, the code is so huge and I am so newbie to C++ that I have
not yet been able to figure out where nelems originates from.
"Anna Smidt" <a.smidt@nospam gmail.comha scritto nel messaggio
news:%23jSGA9qN JHA.1172@TK2MSF TNGP03.phx.gbl. ..
Thank god, the constructor error is gone!! Thanks very much!
>
>By the way, why are you not getting the ambiguous call on the sqrt here?
I do get the ambiguous call error in the line you suggested:
Error 6 error C2668: 'sqrt' : ambiguous call to overloaded function
cmat.cpp 1101 ASMModel
You may try using ::sqrt() or std::sqrt() instead.
Until I know better, I will use double() to resolve the problem. When I
know more C++, I will find out if that's correct or if I have to use a
different conversion.
Thank god, the constructor error is gone!! Thanks very much!
>
>By the way, why are you not getting the ambiguous call on the sqrt here?
I do get the ambiguous call error in the line you suggested:
Error 6 error C2668: 'sqrt' : ambiguous call to overloaded
function cmat.cpp 1101 ASMModel
>
Now this is one of the last bugs remaining.
>
>What is the type of this->nelems?
I don't know, the code is so huge and I am so newbie to C++ that I have
not yet been able to figure out where nelems originates from.
Anna:
1. Clearly nelems() is a method of the class Mat; can you not find it in the
class definition? Do a Visual Studio search for it if you do not see it.
2. However, it seems to me that nelems() must return the number of elements of
the matrix (i.e. nrows*ncols). Taking the square root can only make sense if the
matrix is square (nrows == ncols), in which case why not just use nrows or ncols?
By the way, next time you start a new thread you should use the group
microsoft.publi c.vc.language
The group you are using (microsoft.publ ic.dotnet.langu ages.vc) is intended for
the C++/CLI language which targets the .NET platform (and which you are not using).
"Bo Persson" <bop@gmb.dkha scritto nel messaggio
news:6mgct9Fgnk tjU1@mid.indivi dual.net...
Anna Smidt wrote:
>Oh, I have a question before I go to bed:
>>
>double hypotenuse = sqrt( square(p.y - q.y) + square(p.x - q.x) );
>>
>Why is there a space after "sqrt(" and before the last ")"?
>
Because some people believe that it makes to code easier to read.
>
They are wrong. :-)
It seems that Google C++ style guide agress with you, too :)
"Anna Smidt" <a.smidt@nospam gmail.comha scritto nel messaggio
news:uad5kGrNJH A.4928@TK2MSFTN GP05.phx.gbl...
>I am not sure if I have found out correctly:
>
MatView (double other[], size_t nelems, char *sIsRowVec=NULL ): Mat()
{
sIsRowVec? init(other, 0, 0, 1, nelems, 1): init(other, 0, 0, nelems, 1);
}
>
>
Does this tell me what type of nelems are?
No.
You posted this code:
MatView Mat::viewAsSqua re ()
{
size_t ncols = size_t(sqrt(thi s->nelems()));
so: nelems() should be a member function of Mat class or some class from
which Mat class is derived.
I am not sure if I have found out correctly:
>
MatView (double other[], size_t nelems, char *sIsRowVec=NULL ): Mat()
{
sIsRowVec? init(other, 0, 0, 1, nelems, 1): init(other, 0, 0,
nelems, 1);
}
>
>
Does this tell me what type of nelems are?
Anna:
No. This nelems is just a dummy variable name. The nelems in your expression is
a method, as you can tell from the parentheses on this->nelems().
Anna, you seem a little out of your depth:
Math-wise
C++-wise
Visual Studio-wise
What are you trying to do exactly? It seems that you are trying to use an
external library that does not appear to be written very well. This is not an
easy thing to do. Maybe you should be tackling something simpler?
Comment