OverSim
yang.cc File Reference
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include "yang.h"

Go to the source code of this file.

Functions

void error (const char *v)
Vtr operator+ (const Vtr &v)
Vtr operator- (const Vtr &v)
Vtr operator+ (const Vtr &v1, const Vtr &v2)
Vtr operator- (const Vtr &v1, const Vtr &v2)
std::ostream & operator<< (std::ostream &s, const Vtr &v)
Vtr operator* (const double scalar, const Vtr &v)
Vtr operator* (const Vtr &v1, const Vtr &v2)
Vtr operator/ (const Vtr &v, const double scalar)
double dot (const Vtr &v1, const Vtr &v2)
Mtx operator- (const Mtx &mat)
Vtr operator* (const Vtr &v, const Mtx &mat)
Mtx operator- (const Mtx &m1, const Mtx &m2)
std::ostream & operator<< (std::ostream &s, const Mtx &mat)

Function Documentation

double dot ( const Vtr v1,
const Vtr v2 
)

Definition at line 127 of file yang.cc.

Referenced by Mtx::QRdecomp(), Mtx::QRdecomp_slow(), and Simplex::size().

{
int sz = v1.lenth;
if (sz != v2.lenth ) error("bad vtor sizes");
double tm = v1[0]*v2[0];
for (int i = 1; i < sz; i++) tm += v1[i]*v2[i];
return tm;
}
void error ( const char *  v)

Definition at line 11 of file yang.cc.

Referenced by XmlRpc::XmlRpcServer::acceptConnection(), XmlRpc::XmlRpcServer::bindAndListen(), Nps::coordsReqRpcResponse(), SingleHostUnderlayConfigurator::createNode(), KBRTestApp::deliver(), XmlRpc::XmlRpcClient::doConnect(), dot(), oversim::Koorde::findDeBruijnHop(), oversim::Koorde::findNode(), BrooseBucket::get(), Mtx::getcol(), P2pnsCache::getDataAtPos(), BrooseBucket::getDist(), oversim::ChordSuccessorList::getSuccessor(), Broose::handleBucketRequestRpc(), Broose::handleBucketResponseRpc(), XmlRpcInterface::handleCommonAPIPacket(), XmlRpc::XmlRpcClient::handleEvent(), GlobalCoordinator::handleMessage(), BrooseBucket::handleMessage(), oversim::ChordFingerTable::handleMessage(), oversim::ChordSuccessorList::handleMessage(), DHTDataStorage::handleMessage(), P2pnsCache::handleMessage(), SimpleTCP::handleMessage(), GlobalStatistics::handleMessage(), ConnectReaSE::handleMessage(), AccessNet::handleMessage(), GiaKeyListModule::handleMessages(), GiaTokenFactory::handleMessages(), GiaNeighbors::handleMessages(), oversim::Koorde::handleRpcDeBruijnRequest(), oversim::Chord::handleTimerEvent(), SimpleGameClient::handleTimerEvent(), Broose::handleTimerEvent(), oversim::Chord::handleUDPMessage(), CBRDHT::handleUpperMessage(), GlobalNodeList::initialize(), Broose::isSiblingFor(), BasePastry::isSiblingFor(), Kademlia::isSiblingFor(), oversim::Chord::isSiblingFor(), SingleHostUnderlayConfigurator::migrateNode(), Mtx::operator*(), operator*(), operator+(), Vtr::operator+=(), Mtx::operator+=(), operator-(), Vtr::operator-=(), Mtx::operator-=(), operator/(), Vtr::operator=(), Mtx::operator=(), XmlRpc::XmlRpcClient::parseResponse(), SingleHostUnderlayConfigurator::preKillNode(), XmlRpc::XmlRpcServerConnection::readHeader(), XmlRpc::XmlRpcClient::readHeader(), XmlRpc::XmlRpcServerConnection::readRequest(), XmlRpc::XmlRpcClient::readResponse(), MessageObserver::receivedMessage(), RealtimeScheduler::receiveWithTimeout(), MessageObserver::sentMessage(), Mtx::setcol(), InetUnderlayConfigurator::setUpIPv4(), InetUnderlayConfigurator::setUpIPv6(), XmlRpc::XmlRpcDispatch::waitForAndProcessEvents(), XmlRpc::XmlRpcClient::writeRequest(), and XmlRpc::XmlRpcServerConnection::writeResponse().

{
std::cout << v << "\n";
exit(1);
}
Vtr operator* ( const double  scalar,
const Vtr v 
)

Definition at line 107 of file yang.cc.

{
Vtr tm(v.lenth);
for (int i = 0; i < v.lenth; i++) tm[i] = scalar*v[i];
return tm;
}
Vtr operator* ( const Vtr v1,
const Vtr v2 
)

Definition at line 113 of file yang.cc.

{
int sz = v1.lenth;
if (sz != v2.lenth ) error("bad vtor sizes");
Vtr tm(sz);
for (int i = 0; i < sz; i++)
tm[i] = v1[i]*v2[i];
return tm;
}
Vtr operator* ( const Vtr v,
const Mtx mat 
)

Definition at line 214 of file yang.cc.

{
if (v.lenth != mat.nrows)
error("op*(Vtr, Mtx): Error: Mat. and vec. size do no match.");
Vtr res(mat.ncols, 0.0);
for (int i=0; i<mat.ncols; i++)
for (int j=0; j<v.lenth; j++)
res[i] = v.ets[j] * mat.ets[j][i];
return res;
}
Vtr operator+ ( const Vtr v)

Definition at line 57 of file yang.cc.

{ // usage: v1 = + v2;
return v;
}
Vtr operator+ ( const Vtr v1,
const Vtr v2 
)

Definition at line 65 of file yang.cc.

{ // v=v1+v2
if (v1.lenth != v2.lenth ) error("Vtr::op+: Error Bad vtor sizes");
Vtr sum = v1; // It would cause problem without copy constructor
sum += v2;
return sum;
}
Vtr operator- ( const Vtr v)

Definition at line 61 of file yang.cc.

{ // usage: v1 = - v2;
return Vtr(v.lenth) - v;
}
Vtr operator- ( const Vtr v1,
const Vtr v2 
)

Definition at line 72 of file yang.cc.

{ // v=v1-v2
// if (v1.lenth != v2.lenth ) error("bad vtor sizes");
Vtr sum = v1; // It would cause problem without copy constructor
sum -= v2;
return sum;
}
Mtx operator- ( const Mtx mat)

Definition at line 195 of file yang.cc.

{ // usage: mat1 = - mat2;
return Mtx(mat.nrows,mat.ncols) - mat;
}
Mtx operator- ( const Mtx m1,
const Mtx m2 
)

Definition at line 226 of file yang.cc.

{ // matrix subtract
if(m1.nrows !=m2.nrows || m1.ncols !=m2.ncols)
error("bad matrix sizes");
Mtx sum = m1;
sum -= m2;
return sum;
}
Vtr operator/ ( const Vtr v,
const double  scalar 
)

Definition at line 122 of file yang.cc.

{
if (scalar == 0) error("division by zero in vector-scalar division");
return (1.0/scalar)*v;
}
std::ostream& operator<< ( std::ostream &  s,
const Vtr v 
)

Definition at line 79 of file yang.cc.

{
for (int i =0; i < v.lenth; i++ ) {
s << v[i] << " ";
if (i%10 == 9) s << "\n";
}
return s;
}
std::ostream& operator<< ( std::ostream &  s,
const Mtx mat 
)

Definition at line 272 of file yang.cc.

{
for (int i = 0; i < mat.rows(); i++) {
s << "| ";
for(int j = 0; j < mat.cols(); j++) {
s.setf(std::ios_base::fixed, std::ios_base::floatfield);
s.precision(4);
s.width(8);
s << mat.ets[i][j];
}
s << " |" << std::endl;
}
return s;
}