Example of calling JAMA which uses TNT templates

J

jim.brown

Please refer me to the right place if this is the wrong place to post
this question.

I'm looking for an example of calling the Eigenvalue routines of JAMA
from a C++ program. The documentation says that the is the public method:

Eigenvalue (const TNT::Array2D< Real > &A)

I write this program

Array2D<double> A(3,3);
A[0][0] = 10.; A[0][1] = 0.; A[0][2] = 0.;
A[1][0] = 0.; A[1][1] = 20.; A[1][2] = 0.;
A[2][0] = 0.; A[2][1] = 0.; A[2][2] = 50.;

(which all works fine)
But then I can't figure out how to call the Eigenvalue routine.
I'm sure this is a C++ Template question not a JAMA or TNT
question. Here's what I tried:

Eigenvalue<&Array2D<double>A> EV;

and dozens of other lines.

I think I'm missing something fundamental.

Thanks
Jim
 
K

Kevin Goodsell

jim.brown said:
Please refer me to the right place if this is the wrong place to post
this question.

I'm looking for an example of calling the Eigenvalue routines of JAMA
from a C++ program. The documentation says that the is the public method:

By "public method" do you mean this is a member function of some class?
If so, what class?
Eigenvalue (const TNT::Array2D< Real > &A)

I write this program

Array2D<double> A(3,3);
A[0][0] = 10.; A[0][1] = 0.; A[0][2] = 0.;
A[1][0] = 0.; A[1][1] = 20.; A[1][2] = 0.;
A[2][0] = 0.; A[2][1] = 0.; A[2][2] = 50.;

First obvious problem is that 'Real' may not be the same type as
'double' (since we don't know anything about 'Real'). Maybe you should
declare 'A' as Array2D said:
(which all works fine)
But then I can't figure out how to call the Eigenvalue routine.
I'm sure this is a C++ Template question not a JAMA or TNT
question. Here's what I tried:

Eigenvalue<&Array2D<double>A> EV;

This appears to be complete nonsense. Eigenvalue is a function, right?
So you call it just like any other function, with the name then the
arguments in parenthesis:

Eigenvalue(A);

If it is a member function, you'll need to specify an instance of the
class to use, like so:

some_class_instance.Eigenvalue(A);

Unless it is a static member function, in which case you can do it
without an instance, this way:

SomeClass::Eigenvalue(A);

-Kevin
 
J

jim.brown

Many thanks for the reply. I've supplied more information.

Here is the template definition of Eigenvalue in namespace JAMA.

template <class Real>
class Eigenvalue
{

The method I'm tring to call is a public method in class Eigenvalue
with this header.

Eigenvalue(const TNT::Array2D<Real> &A) {

You are right that the example I posted is nonsense but I had tried
other obvious calls as you suggest. If I understand templates
(and I don't much), Real is the type paramater to the template.
I should be able to instantiate a "double" version of this template.

If I try
Eigenvalue (A);
I get "A unknown size"

If I say
new Eigenvalue( A );
I get "JAMA::Eigenvalue: class has no constructors"

If I say
Eigenvalue(
The MS VC7 Compiler prompts me with
"Eigenvalue(const TNT::Array2D<Real>&A)"

I'm completely lost. JAMA and TNT are publicly available codes
and I have to believe they are well defined. I just don't know
how to call them.

Thanks again for the help

Jim


Kevin said:
jim.brown said:
Please refer me to the right place if this is the wrong place to post
this question.

I'm looking for an example of calling the Eigenvalue routines of JAMA
from a C++ program. The documentation says that the is the public method:


By "public method" do you mean this is a member function of some class?
If so, what class?
Eigenvalue (const TNT::Array2D< Real > &A)

I write this program

Array2D<double> A(3,3);
A[0][0] = 10.; A[0][1] = 0.; A[0][2] = 0.;
A[1][0] = 0.; A[1][1] = 20.; A[1][2] = 0.;
A[2][0] = 0.; A[2][1] = 0.; A[2][2] = 50.;


First obvious problem is that 'Real' may not be the same type as
'double' (since we don't know anything about 'Real'). Maybe you should
declare 'A' as Array2D said:
(which all works fine)
But then I can't figure out how to call the Eigenvalue routine.
I'm sure this is a C++ Template question not a JAMA or TNT
question. Here's what I tried:

Eigenvalue<&Array2D<double>A> EV;


This appears to be complete nonsense. Eigenvalue is a function, right?
So you call it just like any other function, with the name then the
arguments in parenthesis:

Eigenvalue(A);

If it is a member function, you'll need to specify an instance of the
class to use, like so:

some_class_instance.Eigenvalue(A);

Unless it is a static member function, in which case you can do it
without an instance, this way:

SomeClass::Eigenvalue(A);

-Kevin
 
J

John Harrison

jim.brown said:
Many thanks for the reply. I've supplied more information.

Here is the template definition of Eigenvalue in namespace JAMA.

template <class Real>
class Eigenvalue
{

The method I'm tring to call is a public method in class Eigenvalue
with this header.

Eigenvalue(const TNT::Array2D<Real> &A) {

That's not a method, its the constructor, it has the same name as the class.

Start like this

Array2D<double> A(3,3);
A[0][0] = 10.; A[0][1] = 0.; A[0][2] = 0.;
A[1][0] = 0.; A[1][1] = 20.; A[1][2] = 0.;
A[2][0] = 0.; A[2][1] = 0.; A[2][2] = 50.;
Eigenvalue<double> some_object(A);

Which creates an Eigenvalue object (called some_object) using the
constructor you mentioned.

How that relates to calculating the Eigen value is something you'll have to
go back to your documentation for.

john
 
J

jim.brown

This filled in the missing piece. Many thanks. I have it running now.
I appreciate your taking the time to post your reply.
Jim

John said:
Many thanks for the reply. I've supplied more information.

Here is the template definition of Eigenvalue in namespace JAMA.

template <class Real>
class Eigenvalue
{

The method I'm tring to call is a public method in class Eigenvalue
with this header.

Eigenvalue(const TNT::Array2D<Real> &A) {


That's not a method, its the constructor, it has the same name as the class.

Start like this

Array2D<double> A(3,3);
A[0][0] = 10.; A[0][1] = 0.; A[0][2] = 0.;
A[1][0] = 0.; A[1][1] = 20.; A[1][2] = 0.;
A[2][0] = 0.; A[2][1] = 0.; A[2][2] = 50.;
Eigenvalue<double> some_object(A);

Which creates an Eigenvalue object (called some_object) using the
constructor you mentioned.

How that relates to calculating the Eigen value is something you'll have to
go back to your documentation for.

john
 
K

Kevin Goodsell

jim.brown said:
Many thanks for the reply. I've supplied more information.

Please don't top-post. Read section 5 of the FAQ for posting guidelines.

http://www.parashift.com/c++-faq-lite/
Here is the template definition of Eigenvalue in namespace JAMA.

template <class Real>
class Eigenvalue
{

The method I'm tring to call is a public method in class Eigenvalue
with this header.

Eigenvalue(const TNT::Array2D<Real> &A) {

OK, that's quite a bit different from what I was expecting, so my reply
is not accurate. In the future you might want to give more context when
asking a question.

As John said, this is a constructor for the class. How you use the class
to extract the actual eigenvalues is unknown to us -- check the docs.
You are right that the example I posted is nonsense but I had tried
other obvious calls as you suggest. If I understand templates
(and I don't much), Real is the type paramater to the template.
I should be able to instantiate a "double" version of this template.

That's right, but the code snippets in your first post suggested that
Eigenvalue was a function taking a specialization of Array2d for an
unknown type 'Real'. There's a big difference between this:

void Func(vector<Type> vec);

and this:

template <class Type> void Func(vector<Type> vec);

You gave the former, while in reality Eigenvalue() is closer to the latter.
If I try
Eigenvalue (A);
I get "A unknown size"

If I say
new Eigenvalue( A );
I get "JAMA::Eigenvalue: class has no constructors"

If I say
Eigenvalue(
The MS VC7 Compiler prompts me with
"Eigenvalue(const TNT::Array2D<Real>&A)"

Eigenvalue is a class [template], so you actually want to create an
instance (probably -- it's also possible that you might want to use
static members of Eigenvalue, in which case an instance is not
required), and you probably want to initialize it (via the constructor
above) with an Array2d object:

Eigenvalue said:
I'm completely lost. JAMA and TNT are publicly available codes
and I have to believe they are well defined. I just don't know
how to call them.

That's about as far as we can help. The rest has to do with details of
the library. If the docs aren't helpful, you might see if there's a
forum or mailing list for those libraries and seek help there. Or search
the web, or examine the source code and see if you can figure it out
yourself.

-Kevin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top