[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[oMetah-devel] ometah/common geometry.hpp random.cpp random.hp...
From: |
Johann |
Subject: |
[oMetah-devel] ometah/common geometry.hpp random.cpp random.hp... |
Date: |
Fri, 11 Mar 2005 07:06:08 -0500 |
CVSROOT: /cvsroot/ometah
Module name: ometah
Branch:
Changes by: Johann <address@hidden> 05/03/11 12:06:08
Modified files:
common : geometry.hpp random.cpp random.hpp string.cpp
string.hpp
Log message:
* last corrections of the templates functions
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/ometah/ometah/common/geometry.hpp.diff?tr1=1.3&tr2=1.4&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/ometah/ometah/common/random.cpp.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/ometah/ometah/common/random.hpp.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/ometah/ometah/common/string.cpp.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/ometah/ometah/common/string.hpp.diff?tr1=1.2&tr2=1.3&r1=text&r2=text
Patches:
Index: ometah/common/geometry.hpp
diff -u ometah/common/geometry.hpp:1.3 ometah/common/geometry.hpp:1.4
--- ometah/common/geometry.hpp:1.3 Fri Mar 11 10:23:36 2005
+++ ometah/common/geometry.hpp Fri Mar 11 12:06:07 2005
@@ -2,7 +2,7 @@
/***************************************************************************
* geometry.hpp
*
- * $Id: geometry.hpp,v 1.3 2005/03/11 10:23:36 nojhan Exp $
+ * $Id: geometry.hpp,v 1.4 2005/03/11 12:06:07 nojhan Exp $
* Author : Johann Dréo <address@hidden>
****************************************************************************/
@@ -25,7 +25,7 @@
#ifndef GEOMETRY
#define GEOMETRY
-#define PI 3.1415926535
+#define PI 3.141592653589793238462
//! Translate 2D rectangular coordinates to polar ones
template<class T>
Index: ometah/common/random.cpp
diff -u ometah/common/random.cpp:1.1 ometah/common/random.cpp:1.2
--- ometah/common/random.cpp:1.1 Mon Feb 21 09:37:59 2005
+++ ometah/common/random.cpp Fri Mar 11 12:06:07 2005
@@ -1,7 +1,7 @@
/***************************************************************************
* random.cpp
*
- * $Id: random.cpp,v 1.1 2005/02/21 09:37:59 nojhan Exp $
+ * $Id: random.cpp,v 1.2 2005/03/11 12:06:07 nojhan Exp $
* Author : Johann Dréo <address@hidden>
****************************************************************************/
@@ -36,7 +36,7 @@
//! Draw a random number in a normal probability density function
template<class T>
-T randomNormal(T mean, T std)
+T randomNormal( T mean, T std )
{
T x1, x2, w, y1;
static T y2;
@@ -66,10 +66,10 @@
//! Draw a vector with each scalar drawn in a normal distribution
-template<class T, class U>
-U<T> randomNormal(U<T> & means, U<T> & stds)
+template<class T>
+T randomNormal( T & means, T & stds )
{
- U<T> v;
+ T v;
unsigned int i;
for(i=0; i<means.size(); i++) {
@@ -84,7 +84,7 @@
//! Draw a vector in a true multi-normal distribution
template<class T, class U>
-U<T> randomNormalMulti(U<T> means, U< U<T> > varcovar)
+T randomNormalMulti( T means, U varcovar )
{
/*
- Let $u$ a vector of $n$ number, following a centered/reducted
@@ -94,28 +94,28 @@
- the vector $y=m+Lu$ follow the multi-normal distribution,
with a mean $m$ and a variance-covariance matrix $V$.
*/
- U<T> finalPoint;
+ T finalPoint;
// Cholesky decomposition of the variance-covariance matrix
- U< U<T> > popVarCholesky; // low triangular matrix
+ U popVarCholesky; // low triangular matrix
popVarCholesky = cholesky( varcovar );
// Vector with terms in a centered/reducted normal distribution
- U<T> u;
- U<T> mean(means.size(),0.0);
- U<T> variance(means.size(),1.0);
+ T u;
+ T mean(means.size(),0.0);
+ T variance(means.size(),1.0);
u = randomNormal( mean,variance );
// temporary vector for multiplication
- U< U<T> > tempU;
+ U tempU;
tempU.push_back(u);
// post multiplication by the u vector
- U< U<T> > tempCompVar;
+ U tempCompVar;
tempCompVar = multiply( popVarCholesky, transpose(tempU) );
// transposition
- U<T> compVar = transpose(tempCompVar)[0];
+ T compVar = transpose(tempCompVar)[0];
// addition to the mean
finalPoint = VectorAddition( means, compVar );
@@ -125,29 +125,26 @@
//! Draw a random vector in a hyper cube
-template<class T, class U>
-U<T> randomHyperCube(U<T> mins, U<T> maxs)
+template<class T>
+T randomUniform( T mins, T maxs )
{
- U<T> res;
+ T res;
- unsigned int i;
- for(i=0; i<mins.size(); i++)
- {
- T r;
- r=(maxs[i]-mins[i])* // sur l'intervalle
- (T)rand()/RAND_MAX // entre 0 et 1
- +mins[i]; // dans les bornes
- res.push_back(r);
+ for(unsigned int i=0; i<mins.size(); i++) {
+ typename T::value_type r;
+ r = (maxs[i]-mins[i])*
+ (typename T::value_type)rand()/RAND_MAX
+ + mins[i];
+ res.push_back(r);
}
return res;
-
}
//! Draw a random vector in a hyper sphere
template<class T, class U>
-U<T> randomHyperSphere(U<T> & center, T radius)
+U randomSphere(U & center, T radius)
{
//FIXME
}
@@ -158,14 +155,13 @@
The biased method lead to a pseudo-normal distribution, bounded by a sphere
*/
template<class T, class U>
-U<T> randomHyperSphereBiased(U<T> & center, T radius)
+U randomHyperSphereBiased(U & center, T radius)
{
- T Pi=3.141592653589793238462;
T r;
- U<T> res;
+ U res;
- r=(radius)* // sur l'intervalle
- (T)rand()/RAND_MAX; // entre 0 et 1
+ r = (radius)*
+ (T)rand()/RAND_MAX;
res.push_back(r);
@@ -173,7 +169,7 @@
for(i=0; i<center.size(); i++)
{
- r=(2*Pi)*(T)rand()/RAND_MAX; // un angle au hasard sur 2Pi
+ r=(2*PI)*(T)rand()/RAND_MAX; // a random angle on 2Pi
res.push_back(r);
}
@@ -181,5 +177,3 @@
return res;
}
-
-
Index: ometah/common/random.hpp
diff -u ometah/common/random.hpp:1.1 ometah/common/random.hpp:1.2
--- ometah/common/random.hpp:1.1 Mon Feb 21 09:37:59 2005
+++ ometah/common/random.hpp Fri Mar 11 12:06:07 2005
@@ -1,7 +1,7 @@
/***************************************************************************
* random.hpp
*
- * $Id: random.hpp,v 1.1 2005/02/21 09:37:59 nojhan Exp $
+ * $Id: random.hpp,v 1.2 2005/03/11 12:06:07 nojhan Exp $
* Author : Johann Dréo <address@hidden>
****************************************************************************/
@@ -25,41 +25,37 @@
#ifndef RANDOM
#define RANDOM
+#define PI 3.141592653589793238462
+
//! Draw a random number between 0 and 1
template<class T>
T randomO1();
//! Draw a random number in a normal probability density function
template<class T>
-T randomNormal(T mean, T std);
-
+T randomNormal( T mean, T std );
//! Draw a vector with each scalar drawn in a normal distribution
template<class T, class U>
-U<T> randomNormal(U<T> & means, U<T> & stds);
-
+T randomNormal( T & means, U & stds );
//! Draw a vector in a true multi-normal distribution
template<class T, class U>
-U<T> randomNormalMulti(U<T> means, U< U<T> > varcovar);
-
+T randomNormalMulti( T means, U varcovar );
//! Draw a random vector in a hyper cube
-template<class T, class U>
-U<T> randomUniform(U<T> mins, U<T> maxs);
-
+template<class T>
+T randomUniform( T mins, T maxs );
//! Draw a random vector in a hyper sphere
template<class T, class U>
-U<T> randomSphere(U<T> & center, T radius);
-
+U randomSphere( U & center, T radius );
//! Draw a random vector in a hyper sphere, using a biased method
/*!
The biased method lead to a pseudo normal distribution, bounded by a sphere
*/
template<class T, class U>
-U<T> randomSphereBiased(U<T> & center, T radius);
-
+U randomSphereBiased( U & center, T radius );
#endif
Index: ometah/common/string.cpp
diff -u ometah/common/string.cpp:1.1 ometah/common/string.cpp:1.2
--- ometah/common/string.cpp:1.1 Thu Mar 10 18:03:41 2005
+++ ometah/common/string.cpp Fri Mar 11 12:06:07 2005
@@ -1,6 +1,6 @@
/***************************************************************************
- * $Id: string.cpp,v 1.1 2005/03/10 18:03:41 nojhan Exp $
+ * $Id: string.cpp,v 1.2 2005/03/11 12:06:07 nojhan Exp $
* Author : Johann Dréo <address@hidden>
****************************************************************************/
@@ -20,20 +20,12 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-//! Print a vector
-template<class T,class U, class V>
-void print( U<T> aVector, V aSeparator, ostream * outer )
-{
- *outer << aVector[0];
-
- for( unsigned int i=1; i<aVector.size(); i++ ) {
- *outer << aSeparator << aVector[i];
- }
-}
+
+#include "string.hpp"
//! Print a vector
template<class T,class U>
-void print( U<T> aVector, T aSeparator, ostream * outer )
+void print( T aVector, U aSeparator, ostream * outer )
{
*outer << aVector[0];
@@ -43,11 +35,12 @@
}
//! Make a double vector from a string vector
-template<class T>
-T<double> stringToDouble(T<string> VString)
+template<template <class T> class V>
+V<double> stringToDouble(V<string> VString)
{
+
double aDouble;
- T<double> VDouble;
+ V<double> VDouble;
VDouble.reserve( VString.size() );
@@ -74,14 +67,15 @@
"1.2,1" => <1.2,1>
"3:1.0" => <1.0,1.0,1.0>
*/
-template<class T>
-T<double> stringToDouble(string aString, string itemSeparator=",", string
multiSeparator=":")
+
+template<template <class T> class V>
+V<double> stringToDouble(string aString, string itemSeparator=",", string
multiSeparator=":")
{
- T<double> res;
+ V<double> res;
// if find a separator
if ( aString.find(multiSeparator) < aString.size() ) {
- T<double> tempvec = stringToDouble( stringSplit( aString, multiSeparator )
);
+ V<double> tempvec = stringToDouble( stringSplit( aString, multiSeparator )
);
res.reserve( (int)tempvec[0]);
for(unsigned int i=0; i<tempvec[0]; i++) {
@@ -97,8 +91,8 @@
/*!
This version modify directly the vector by reference
*/
-template<class T>
-void stringSplit (string text, string separators, T<string> & words)
+template<template<class T> class V>
+void stringSplit (string text, string separators, V<string> & words)
{
int n = text.length();
int start, stop;
@@ -115,13 +109,13 @@
}
//! Make a string vector from a string
-template<class T>
-T<string> stringSplit (string text, string separators)
+template<template<class T> class V>
+V<string> stringSplit (string text, string separators)
{
int n = text.length();
int start, stop;
- T<string> words;
+ V<string> words;
start = text.find_first_not_of(separators);
while ((start >= 0) && (start < n)) {
Index: ometah/common/string.hpp
diff -u ometah/common/string.hpp:1.2 ometah/common/string.hpp:1.3
--- ometah/common/string.hpp:1.2 Mon Feb 28 14:30:04 2005
+++ ometah/common/string.hpp Fri Mar 11 12:06:07 2005
@@ -1,6 +1,6 @@
/***************************************************************************
- * $Id: string.hpp,v 1.2 2005/02/28 14:30:04 nojhan Exp $
+ * $Id: string.hpp,v 1.3 2005/03/11 12:06:07 nojhan Exp $
* Author : Johann Dréo <address@hidden>
****************************************************************************/
@@ -23,21 +23,18 @@
#ifndef STRING
#define STRING
-#include <fstream>
+#include <ostream>
#include <string>
-//! Print a vector
-template<class T,class U, class V>
-void print( U<T> aVector, V aSeparator, ostream * outer );
-
+using namespace std;
//! Print a vector
template<class T,class U>
-void print( U<T> aVector, T aSeparator, ostream * outer );
+void print( T aVector, U aSeparator, ostream * outer );
//! Make a double vector from a string vector
-template<class T>
-T<double> stringToDouble(T<string> VString);
+template<template <class T> class V>
+V<double> stringToDouble(V<string> VString);
//! Make a double from a string
double stringToDouble(string aString);
@@ -48,18 +45,18 @@
"1.2,1" => <1.2,1>
"3:1.0" => <1.0,1.0,1.0>
*/
-template<class T>
-T<double> stringToDouble(string aString, string itemSeparator=",", string
multiSeparator=":");
+template<template <class T> class V>
+V<double> stringToDouble(string aString, string itemSeparator=",", string
multiSeparator=":");
//! Make a string vector from a string
/*!
This version modify directly the vector by reference
*/
-template<class T>
-void stringSplit (string text, string separators, T<string> & words);
+template<template<class T> class V>
+void stringSplit (string text, string separators, V<string> & words);
//! Make a string vector from a string
-template<class T>
-T<string> stringSplit (string text, string separators);
+template<template<class T> class V>
+V<string> stringSplit (string text, string separators);
#endif
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [oMetah-devel] ometah/common geometry.hpp random.cpp random.hp...,
Johann <=