text:
#include "main.h"

#include <boost/program_options.hpp>
#include <errno.h>
#include <signal.h>

#include <log4cplus/logger.h>
#include <log4cplus/loggingmacros.h>
#include <log4cplus/configurator.h>
#include <fuse/fuse_common.h>

#include "buildconf.hpp"

const int RECONNECT_ATTEMPTS = 30;
const int RECONNECT_INTERVAL_MS = 500;

using namespace std;
namespace asio = boost::asio;
namespace po = boost::program_options;

static asio::io_service ioSvc;

using namespace bithorde;

log4cplus::Logger sigLogger = log4cplus::Logger::getInstance("signal");
bool terminating = false;
void sigint(int sig) {
	LOG4CPLUS_INFO(sigLogger, "Intercepted signal#" << sig);
	if (sig == SIGINT) {
		if (terminating) {
			LOG4CPLUS_INFO(sigLogger, "Force Exiting...");
			exit(-1);
		} else {
			terminating = true;
			LOG4CPLUS_INFO(sigLogger, "Cleanly Exiting...");
			ioSvc.stop();
		}
	}
}

int main(int argc, char *argv[])
{
	signal(SIGINT, &sigint);
	log4cplus::BasicConfigurator config;
	config.configure();

	BHFuseOptions opts;

	po::options_description desc("Supported options");
	desc.add_options()
		("help,h",
			"Show help")
		("version,v",
			"Show version")
		("name,n", po::value< string >()->default_value("bhget"),
			"Bithorde-name of this client")
		("debug,d",
			"Show fuse-commands, for debugging purposes")
		("url,u", po::value< string >()->default_value("/tmp/bithorde"),
			"Where to connect to bithorde. Either host:port, or /path/socket")
		("mountpoint", po::value< string >(&opts.mountpoint),
			"Where to mount filesystem")
		("blocksize", po::value< int >(&opts.blockSize)->default_value(32),
			"Blocksize in KB.")
		("readahead", po::value< int >(&opts.readAheadKB)->default_value(-1),
			"Amount to let the kernel pre-load, in KB. -1 means use automatic value")
		("timeout", po::value< int >(&opts.assetTimeoutMs)->default_value(1000),
			"How many millisecond to wait for assets to be found.")
	;
	po::positional_options_description p;
	p.add("mountpoint", 1);

	po::command_line_parser parser(argc, argv);
	parser.options(desc).positional(p);

	po::variables_map vm;
	po::store(parser.run(), vm);
	po::notify(vm);

	if (vm.count("version"))
		return bithorde::exit_version();

	if (vm.count("help") || !vm.count("mountpoint")) {
		cerr << desc << endl;
		return 1;
	}

	opts.name = "bhfuse";
	if (vm.count("debug"))
		opts.debug = true;

	BHFuse fs(ioSvc, vm["url"].as<string>(), opts);

	return ioSvc.run();
}

FUSEAsset::Ptr INodeCache::lookup(const BitHordeIds& ids)
{
	for (auto iter=begin(); iter != end(); iter++) {
		if (auto asset=dynamic_pointer_cast<FUSEAsset>(iter->second)) {
			if (idsOverlap(ids, asset->asset->confirmedIds())) {
				return asset;
			}
		}
	}
	return FUSEAsset::Ptr();
}

BHFuse::BHFuse(asio::io_service& ioSvc, string bithorded, const BHFuseOptions& opts) :
	BoostAsioFilesystem(ioSvc, opts),
	ioSvc(ioSvc),
	bithorded(bithorded),
	opts(opts),
	_timerSvc(boost::make_shared<TimerService>(ioSvc)),
	_ino_allocator(2)
{
	client = Client::create(ioSvc, "bhfuse");
	client->authenticated.connect(boost::bind(&BHFuse::onConnected, this, _1, _2));
	client->disconnected.connect(boost::bind(&BHFuse::reconnect, this));

	client->connect(bithorded);
}

void BHFuse::reconnect()
{
	cerr << "Disconnected, trying reconnect..." << endl;
	for (int i=0; i < RECONNECT_ATTEMPTS; i++) {
		usleep(RECONNECT_INTERVAL_MS * 1000);
		try {
			client->connect(bithorded);
			return;
		} catch (boost::system::system_error e) {
			cerr << "Failed to reconnect, retrying..." << endl;
		}
	}
	cerr << "Giving up." << endl;
	ioSvc.stop();
}

void BHFuse::onConnected(bithorde::Client&, std::string remoteName) {
	if (remoteName.empty()) {
		(cerr << "Failed authentication" << endl).flush();
		ioSvc.stop();
	} else {
		(cerr << "Connected to " << remoteName << endl).flush();
	}
}

void BHFuse::fuse_init(fuse_conn_info* conn)
{
	if (opts.readAheadKB >= 0)
		conn->max_readahead = opts.readAheadKB<<10;
}

int BHFuse::fuse_lookup(fuse_req_t req, fuse_ino_t parent, const char *name) {
	if (parent != 1)
		return ENOENT;

	LookupParams lp(parent, name);

	MagnetURI uri;
	if (uri.parse(name)) {
		auto ids = uri.toIdList();
		if (ids.size()) {
			if (auto asset = _inode_cache.lookup(ids)) {
				asset->fuse_reply_lookup(req);
			} else {
				Lookup * lookup = new Lookup(this, req, ids);
				lookup->perform(client);
			}
			return 0;
		}
	}
	return ENOENT;
}

void BHFuse::fuse_forget(fuse_ino_t ino, u_long nlookup) {
	unrefInode(ino, nlookup);
}

int BHFuse::fuse_getattr(fuse_req_t req, fuse_ino_t ino, fuse_file_info *) {
	if (ino == 1) {
		struct stat attr;
		bzero(&attr, sizeof(attr));
		attr.st_mode = S_IFDIR | 0444;
		attr.st_blksize = 32*1024;
		attr.st_ino = ino;
		attr.st_nlink = 2;
		fuse_reply_attr(req, &attr, 5);
	} else if (_inode_cache.count(ino)) {
		_inode_cache[ino]->fuse_reply_stat(req);
	} else {
		return ENOENT;
	}
	return 0;
}

int BHFuse::fuse_open(fuse_req_t req, fuse_ino_t ino, fuse_file_info *fi) {
	FUSEAsset * a;
	if (_inode_cache.count(ino) && (a = dynamic_cast<FUSEAsset*>(_inode_cache[ino].get()))) {
		a->fuse_dispatch_open(req, fi);
		return 0;
	} else {
		return ENOENT;
	}
}

int BHFuse::fuse_release(fuse_req_t req, fuse_ino_t ino, fuse_file_info * fi) {
	if (FUSEAsset * a = dynamic_cast<FUSEAsset*>(_inode_cache[ino].get())) {
		a->fuse_dispatch_close(req, fi);
		return 0;
	} else {
		return EBADF;
	}
}

int BHFuse::fuse_read(fuse_req_t req, fuse_ino_t ino, size_t size, off_t off, fuse_file_info *)
{
	if (FUSEAsset* a = dynamic_cast<FUSEAsset*>(_inode_cache[ino].get())) {
		a->read(req, off, size);
		return 0;
	} else {
		return EBADF;
	}
}

FUSEAsset * BHFuse::registerAsset(boost::shared_ptr< ReadAsset > asset)
{
	fuse_ino_t ino = _ino_allocator.allocate();
	FUSEAsset::Ptr a = FUSEAsset::create(this, ino, asset);
	_inode_cache[ino] = a;
	return static_cast<FUSEAsset*>(a.get());
}

TimerService& BHFuse::timerSvc()
{
	return *_timerSvc;
}

bool BHFuse::unrefInode(fuse_ino_t ino, int count)
{
	INode::Ptr i = _inode_cache[ino];
	if (i) {
		if (!i->dropRefs(count)) {
			_inode_cache.erase(ino);
			_ino_allocator.free(ino);
		}
		return true;
	} else {
		return false;
	}
}

ext: cpp

max_stars_repo_name: zidz/bithorde

max_issues_repo_name: zidz/bithorde

max_forks_repo_name: zidz/bithorde


text:
#include <iostream>
#include <caffe/caffe.hpp>
#include <boost/lexical_cast.hpp>
// opencv
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <algorithm>
#include <iosfwd>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include <fstream>
#include <unistd.h>

// definitions
#define NO_OPERATION      0
#define MEAN_SUBTRACTION  1
#define SCALE_DATA        2

using namespace caffe;
using namespace std;
using std::string;

void WriteCVMatToFile(string fileName, cv::Mat data);
cv::Mat ReadCVMatFromFile(string filename);
int CheckForRequest(string filename);
void SetProcessDone(string filename, bool flag);
/*************************************************/
class CaffeForward {
 public:
  CaffeForward( const string& model_file,const string& weight_file,const string& prep_op,const string& prep_file);

  std::vector<std::vector<float> > ForwardProcess(std::vector <cv::Mat> &inputs);
  void SaveChannels(std::vector<std::vector<float> > outputs , const string& output_dir);
  private:
  void WrapInputLayer(std::vector<cv::Mat>* input_channels, int input_idx);
  void SetMean(const string& mean_file);
  void Preprocess(const cv::Mat& img, std::vector<cv::Mat>* input_channels, int input_idx);

 public:
 	int num_outputs_, num_inputs_;
 private:
  shared_ptr<Net<float> > net_;
  std::vector<cv::Size> input_geometry_;
  std::vector<int> num_channels_;
  cv::Mat mean_;
  double scale_;
  unsigned char prep_op_;
};
/*************************************************/
/* CAFFE FORWARD */
CaffeForward::CaffeForward( const string& model_file,const string& weight_file,const string& prep_op,const string& prep_file)
{
  #ifdef CPU_ONLY
    Caffe::set_mode(Caffe::CPU);
  #else
    Caffe::set_mode(Caffe::GPU);
  #endif
	/* Load the network. */
  net_.reset(new Net<float>(model_file, TEST));
  net_->CopyTrainedLayersFrom(weight_file);

  num_outputs_ = net_->num_outputs();
  num_inputs_ = net_->num_inputs();
	cout << "net inputs x outputs dimension: " << num_inputs_ << "x" << num_outputs_ << endl;

  for(int i = 0; i < num_inputs_; i++)
  {
    Blob<float>* input_layer = net_->input_blobs()[i];
    num_channels_.push_back(input_layer->channels());
    input_geometry_.push_back(cv::Size(input_layer->width(), input_layer->height()));
    cout << "input " << i << " (channels x width x height): " << num_channels_[i] <<"x"<<input_geometry_[i].width<<"x"<<input_geometry_[i].height << endl;
    CHECK(num_channels_[i] == 3 || num_channels_[i] == 1) << "Input layer should have 1 or 3 channels.";
  }
  for(int i = 0; i < num_outputs_; i++)
  {
    Blob<float>* output_layer = net_->output_blobs()[i];
    cout << "output " << i << " (channels x width x height): " << output_layer->channels()<< "x" << output_layer->width() << "x" << output_layer->height() << endl;
  }

  if ( prep_op == "MEAN_SUBTRACTION" )
  {
    SetMean(prep_file);
    prep_op_ = MEAN_SUBTRACTION;
  }
  else if( prep_op == "SCALE_DATA" )
  {
    scale_  = boost::lexical_cast<double>(prep_file);
    prep_op_ = SCALE_DATA;
  }
  else
    prep_op_ = NO_OPERATION;
}

/*************************************************/
/* SET MEAN */
void CaffeForward::SetMean(const string& mean_file) {
  /*cv::Mat mean_img = cv::imread(mean_file.c_str(), -1);
  cv::resize(mean_img, mean_, input_geometry_);
  mean_.convertTo(mean_, CV_32FC3);
  return;*/
  /*
  BlobProto blob_proto;
  ReadProtoFromBinaryFileOrDie(mean_file.c_str(), &blob_proto);
  // Convert from BlobProto to Blob<float>
  Blob<float> mean_blob;
  mean_blob.FromProto(blob_proto);
  CHECK_EQ(mean_blob.channels(), num_channels_)
    << "Number of channels of mean file doesn't match input layer.";
  // The format of the mean file is planar 32-bit float BGR or grayscale.
  std::vector<cv::Mat> channels;
  float* data = mean_blob.mutable_cpu_data();
  for (int i = 0; i < num_channels_; ++i) {
    // Extract an individual channel.
    cv::Mat channel(mean_blob.height(), mean_blob.width(), CV_32FC1, data);
    channels.push_back(channel);
    data += mean_blob.height() * mean_blob.width();
  }
  // Merge the separate channels into a single image.
  cv::Mat mean;
  cv::merge(channels, mean);
  cv::imwrite("/home/ali/Codes/Caffe/mean.PNG", mean);
  // Compute the global mean pixel value and create a mean image filled with this value.
  cv::Scalar channel_mean = cv::mean(mean);
  mean_ = cv::Mat(input_geometry_, mean.type(), channel_mean);
  mean_ = mean;
  cv::imwrite("/home/ali/Codes/Caffe/mean2.PNG", mean_);*/
}

/*************************************************/
/* FORWARD PROCESS */
std::vector <std::vector<float> > CaffeForward::ForwardProcess(std::vector <cv::Mat> & inputs)
{
  for (int i = 0; i < inputs.size(); i++)
  {
    Blob<float>* input_layer = net_->input_blobs()[i];
    input_layer->Reshape(1, input_layer->channels(), input_layer->height(), input_layer->width());
  }
  net_->Reshape();
  for (int i = 0; i < inputs.size(); i++)
  {
    std::vector<cv::Mat> input_channels;
    WrapInputLayer(&input_channels, i);
    Preprocess(inputs[i], &input_channels, i);
  }

  net_->Forward();

  std::vector<std::vector<float> > outputs;

  for (int i = 0; i < num_outputs_; i++)
  {
    Blob<float>* output_layer = net_->output_blobs()[i];
    // cout << output_layer->width() << "x"<< output_layer->height() << "x" <<output_layer->channels() << endl;
  	const float* begin = output_layer->cpu_data();
  	const float* end = begin + output_layer->channels()*output_layer->width()*output_layer->height();
		outputs.push_back(std::vector<float>(begin, end));
  }

  return outputs;
}

/*************************************************/
/* SAVE CHANNELS */
void CaffeForward::SaveChannels(std::vector<std::vector<float> > outputs, const string& output_dir )
{
  for (int i = 0; i < outputs.size(); i++)
  {
    Blob<float>* output_layer = net_->output_blobs()[i];
    char filename[100];
    for (int ch = 0; ch < output_layer->channels(); ch++)
    {
      std::vector<float> channel;
      int p_start = ch*output_layer->width()*output_layer->height();
      int length = output_layer->width()*output_layer->height();
      channel.assign(outputs[i].begin()+p_start, outputs[i].begin()+p_start+length);
      cv::Mat img = cv::Mat(channel).reshape(0,output_layer->height());
      sprintf(filename,"%s/o_%02d_ch_%02d.txt", output_dir.c_str(),i,ch);
      WriteCVMatToFile(filename, img);
      double min, max;
      cv::minMaxLoc(img, &min, &max);
      img = img - min;
      img = img / (max - min);
      img.convertTo(img, CV_8UC1, 255.0);
      sprintf(filename,"%s/o_%02d_ch_%02d.jpg", output_dir.c_str(),i,ch);
      cv::imwrite(filename, img);
    }
  }
}
 /*************************************************/
 /* WRAP INPUT LAYER */
void CaffeForward::WrapInputLayer(std::vector<cv::Mat>* input_channels, int input_idx)
{
  Blob<float>* input_layer = net_->input_blobs()[input_idx];
  int width = input_layer->width();
  int height = input_layer->height();
  float* input_data = input_layer->mutable_cpu_data();
  for (int i = 0; i < input_layer->channels(); ++i) {
    cv::Mat channel(height, width, CV_32FC1, input_data);
    input_channels->push_back(channel);
    input_data += width * height;
  }
}
/*************************************************/
/* PREPROCESS */
void CaffeForward::Preprocess(const cv::Mat& img, std::vector<cv::Mat>* input_channels, int input_idx)
{
  cv::Mat sample;
  if (img.channels() == 3 && num_channels_[input_idx] == 1)
    cv::cvtColor(img, sample, cv::COLOR_BGR2GRAY);
  else if (img.channels() == 4 && num_channels_[input_idx] == 1)
    cv::cvtColor(img, sample, cv::COLOR_BGRA2GRAY);
  else if (img.channels() == 4 && num_channels_[input_idx] == 3)
    cv::cvtColor(img, sample, cv::COLOR_BGRA2BGR);
  else if (img.channels() == 1 && num_channels_[input_idx] == 3)
    cv::cvtColor(img, sample, cv::COLOR_GRAY2BGR);
  else
    sample = img;
  cv::Mat sample_resized;
  if (sample.size() != input_geometry_[input_idx])
    cv::resize(sample, sample_resized, input_geometry_[input_idx]);
  else
    sample_resized = sample;

  cv::Mat sample_float;
  if (num_channels_[input_idx] == 3)
    sample_resized.convertTo(sample_float, CV_32FC3);
  else
    sample_resized.convertTo(sample_float, CV_32FC1);

  cv::Mat sample_preprocessed;

  if (prep_op_ == SCALE_DATA)
    sample_preprocessed = (1.0 / 256.0) * sample_float;
  else if(prep_op_ == MEAN_SUBTRACTION)
    cv::subtract(sample_float, mean_, sample_preprocessed);
  else
    sample_preprocessed = sample_float;

  cv::split(sample_preprocessed, *input_channels);
  CHECK(reinterpret_cast<float*>(input_channels->at(0).data)
        == net_->input_blobs()[input_idx]->cpu_data())
    << "Input channels are not wrapping the input layer of the network.";
}

/*************************************************/
/* MAIN */
int main(int argc, char** argv)
{
	std::cout << "\n\n\nProgram is started" << std::endl;

	::google::InitGoogleLogging(argv[0]);

  string model_file   = argv[1];    // deploy file
  string weight_file  = argv[2];    // weights
  string prep_op      = argv[3];    // preprocess operation
  string prep_file    = argv[4];    // preprocess file
  string root_data    = argv[5];    // input directory
  string output_dir   = argv[6];    // output directory to save the files

  CaffeForward CaffeForward(model_file, weight_file, prep_op, prep_file);

  string filename;
  int request = 0;
  while (request >= 0)
  {
    filename = root_data + "/initiate_process.txt";
    request = CheckForRequest(filename);

    if(request > 0)
    {
      filename = root_data + "/process_done.txt";
      SetProcessDone(filename, 0);
      cout << "request is registered" << endl;
      std::vector<cv::Mat> inputs;
      filename = root_data + "/img.jpg";
      cv::Mat img = cv::imread(filename, -1);
      CHECK(!img.empty()) << "Unable to decode image " << filename;
      inputs.push_back(img);

      filename = root_data + "/joint.txt";
      cv::Mat state = ReadCVMatFromFile(filename);
      CHECK(!state.empty()) << "Unable to decode joint values " << filename;
      inputs.push_back(state);

      std::vector< std::vector<float> > outputs = CaffeForward.ForwardProcess(inputs);
      CaffeForward.SaveChannels(outputs, output_dir);

      filename = root_data + "/process_done.txt";
      SetProcessDone(filename, 1);
      cout << "process done" << endl;
    }
    usleep(10000);
  }
  return 0;
}

int CheckForRequest(string filename)
{
  ifstream reader(filename.c_str());
  if (reader.is_open())
  {
    string line;
    getline(reader, line);
    reader.close();
    ofstream writer(filename.c_str());
    writer << 0 << endl;
    writer.close();
    return boost::lexical_cast<int> (line);
  }
  return 0;
}

void WriteCVMatToFile(string fileName, cv::Mat data)
{
    int nRow = data.size().height;
    int nCol = data.size().width;
    ofstream fileWriter;
    fileWriter.open(fileName.c_str());

    fileWriter << nRow << endl;
    fileWriter << nCol << endl;

    for(int i = 0; i < nRow; i++)
    {
      for(int j = 0; j < nCol; j++)
      {
        fileWriter << std::fixed << std::setprecision(20) << data.at<float>(i,j) << endl;
      }
    }
    fileWriter.close();
}
cv::Mat ReadCVMatFromFile(string filename)
{
  ifstream reader(filename.c_str());
  int rows, cols;
  string line;

  getline(reader, line);
  rows = boost::lexical_cast<int>(line);
  getline(reader, line);
  cols = boost::lexical_cast<int>(line);

  cv::Mat im( cv::Size(rows, cols), CV_32FC1, cv::Scalar(255) );

  for(int i = 0; i < rows; i++)
  {
    for(int j = 0; j < cols; j++)
    {
      getline(reader, line);
      im.at<float>(j, i) = boost::lexical_cast<float>(line);
    }
  }

  reader.close();
  return im;
}

void SetProcessDone(string filename, bool flag)
{
  ofstream writer(filename.c_str());
  if (flag)
    writer << 1 << endl;
  else
    writer << 0 << endl;
  writer.close();
}

max_stars_repo_name: AliGhadirzadeh/Caffe

max_issues_repo_name: AliGhadirzadeh/Caffe

max_forks_repo_name: AliGhadirzadeh/Caffe


text:
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE JPetManagerTest

#include <boost/test/unit_test.hpp>
#include "./JPetManager/JPetManager.h"
#include "./JPetOptionsGenerator/JPetOptionsGenerator.h"
#include "./JPetOptionsGenerator/JPetOptionsGeneratorTools.h"
#include <cstdio> //for std::remove

BOOST_AUTO_TEST_SUITE(FirstSuite)

BOOST_AUTO_TEST_CASE( create_unique_manager )
{
  JPetManager& manager = JPetManager::getManager();
  JPetManager* pManager = &manager;
  JPetManager& manager2 = JPetManager::getManager(); // it should be the same Manager
  JPetManager* pManager2 = &manager2;
  BOOST_REQUIRE_EQUAL(pManager, pManager2);
}

BOOST_AUTO_TEST_CASE( threadsEnabled )
{
  JPetManager& manager = JPetManager::getManager();
  BOOST_REQUIRE(!manager.areThreadsEnabled());
  manager.setThreadsEnabled(true);
  BOOST_REQUIRE(manager.areThreadsEnabled());
  manager.setThreadsEnabled(false);
  BOOST_REQUIRE(!manager.areThreadsEnabled());
}

BOOST_AUTO_TEST_CASE( manager_getOptions )
{
  JPetManager& manager = JPetManager::getManager();
  auto options = manager.getOptions();
  BOOST_REQUIRE_EQUAL(options.size(), 0u);
}

BOOST_AUTO_TEST_CASE( emptyRun )
{
  JPetManager& manager = JPetManager::getManager();
  BOOST_REQUIRE(!manager.run(0, nullptr));
  auto options = manager.getOptions();
  BOOST_REQUIRE_EQUAL(options.size(), 0u);
}

BOOST_AUTO_TEST_CASE( goodRootRun )
{
  JPetManager& manager = JPetManager::getManager();
  manager.clearRegisteredTasks();
  const char* args[7] = {"test/Path", "--file", "unitTestData/JPetManagerTest/goodRootFile.root", "--type", "root", "-p", "conf_trb3.xml"};
  BOOST_REQUIRE(manager.run(7, args));
}

BOOST_AUTO_TEST_CASE(goodZipRun)
{
  std::remove("unitTestData/JPetManagerTest/xx14099113231.hld");
  JPetManager& manager = JPetManager::getManager();
  manager.clearRegisteredTasks();
  const char* args[14] = {"test/Path", "--file", "unitTestData/JPetManagerTest/xx14099113231.hld.xz", "--type", "zip", "-p", "unitTestData/JPetManagerTest/conf_trb3.xml", "-r", "0", "10", "-l", "unitTestData/JPetManagerTest/large_barrel.json", "-i", "44"};
  BOOST_REQUIRE(manager.run(14, args));
}

BOOST_AUTO_TEST_SUITE_END()

max_stars_repo_name: Alvarness/j-pet-framework

max_issues_repo_name: Alvarness/j-pet-framework

max_forks_repo_name: Alvarness/j-pet-framework


text:
#include "oaz/games/game.hpp"

#include <boost/python.hpp>
#include <boost/python/def.hpp>
#include <boost/python/module.hpp>
#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
#include <vector>

#include "Python.h"

namespace p = boost::python;

BOOST_PYTHON_MODULE(game) {  // NOLINT
  PyEval_InitThreads();

  p::class_<std::vector<int> >("IntVec").def(
      p::vector_indexing_suite<std::vector<int> >());

  p::class_<oaz::games::Game, boost::noncopyable>("Game", p::no_init);
}

max_stars_repo_name: ameroueh/oaz

max_issues_repo_name: ameroueh/oaz

max_forks_repo_name: ameroueh/oaz


text:
#include <SDL2/SDL.h>
#include <boost/dynamic_bitset>
#include <iostream>
#include <fstream>
#include <string>

#include "PDBP/pdbp.h"

int main(int argc, char **argv) {
  PDBP pdbp;

  std::string fileName;
  std::string fileExt = ".ch8";
  bool correctExt = false;

  if (argc == 2) {
    fileName = argv[1];
    correctExt = fileName.substr(fileName.size() - fileExt.size(), fileExt.size()) == fileExt;
  }
  if (argc != 2 || !correctExt) {
    std::cerr << "bad args" << std::endl;
    return 1;
  }

  std::ifstream file(fileName, std::ios::binary);
  file >>

  pdbp.initDisplay();

  // pdbp.drawPixel(0, 0, 0x40, 0xB0, 0xC0);
  // pdbp.drawPixel(1, 1, 0xFF, 0xFF, 0xFF);
  pdbp.drawRect(2, 3, 4, 4, 0x40, 0xB0, 0xC0);
  // pdbp.drawPixel(2, 1, 0x40, 0xB0, 0xC0);
  pdbp.applyDrawToDisplay();

  // pdbp.setKeyMap(SDLK_UP, [] { std::cout << "Up" << std::endl; });
  // pdbp.setKeyMap(SDLK_DOWN, [] { std::cout << "Down" << std::endl; });
  // pdbp.setKeyMap(SDLK_LEFT, [] { std::cout << "Left" << std::endl; });
  // pdbp.setKeyMap(SDLK_RIGHT, [] { std::cout << "Right" << std::endl; });

  while(!pdbp.pollQuit()) {
    // std::cout << "hi" << std::endl;
  }

  pdbp.exitDisplay(); // tries to delete deallocated pointers
	return 0;
}


text:
#ifndef __PRINTS_HPP__
#define __PRINTS_HPP__

#include <Eigen/Core>
#include <Eigen/Dense>
#include <vector>
#include <iostream>

template <typename T, int m, int n>
void printMat(const Eigen::Matrix<T, m, n>& mat){
    for (int i = 0; i < m; i++){
        for (int j = 0; j < n; j++){
            std::cout << mat(i, j) << ", ";
        }
        std::cout << std::endl;
    }
}

void printMat(const Eigen::MatrixXd& mat){
    for (int i = 0; i < mat.rows(); i++){
        for (int j = 0; j < mat.cols(); j++){
            std::cout << mat(i, j) << ", ";
        }
        std::cout << std::endl;
    }
}

void printMat(const Eigen::RowVectorXd& mat){
    for (int j = 0; j < mat.cols(); j++){
        std::cout << mat(j) << ", ";
    }
    std::cout << std::endl;
}

template <typename Ty = int>
void printVector(const std::vector<Ty>& vec){
    for (size_t i = 0; i < vec.size(); i++){
        std::cout << vec[i] << ", ";
    }
    std::cout << std::endl;
}

#endif  //__PRINTS_HPP__

ext: hpp

max_stars_repo_name: Enigmatisms/Operation

max_issues_repo_name: Enigmatisms/Operation

max_forks_repo_name: Enigmatisms/Operation


text:
// Copyright (C) 2012-2013 Vicente Botet
//
//  Distributed under the Boost Software License, Version 1.0. (See accompanying
//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#include <boost/config.hpp>
#if ! defined  BOOST_NO_CXX11_DECLTYPE
#define BOOST_RESULT_OF_USE_DECLTYPE
#endif

#define BOOST_THREAD_VERSION 4
//#define BOOST_THREAD_USES_LOG
#define BOOST_THREAD_USES_LOG_THREAD_ID

#include <boost/thread/detail/log.hpp>
#include <boost/thread/future.hpp>
#include <boost/assert.hpp>
#include <string>
#include <iostream>

#if defined BOOST_THREAD_PROVIDES_FUTURE_UNWRAP

int p1()
{
  BOOST_THREAD_LOG << "P1" << BOOST_THREAD_END_LOG;
  return 123;
}

boost::future<int> p2()
{
  BOOST_THREAD_LOG << "<P2" << BOOST_THREAD_END_LOG;
  boost::future<int> f1 = boost::async(boost::launch::async, &p1);
  BOOST_THREAD_LOG << "P2>" << BOOST_THREAD_END_LOG;
  return boost::move(f1);
}

int main()
{
  const int number_of_tests = 100;
  BOOST_THREAD_LOG << "<MAIN" << BOOST_THREAD_END_LOG;
  for (int i=0; i< number_of_tests; i++)
  try
  {

#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
    {
      boost::future<int> inner_future = boost::async(boost::launch::async, &p2);
      inner_future.wait();
      int ii = inner_future.get();
      BOOST_THREAD_LOG << "ii= "<< ii << "" << BOOST_THREAD_END_LOG;
    }
#endif
    {
      boost::future<boost::future<int> > outer_future = boost::async(boost::launch::async, &p2);
      boost::future<int> inner_future = outer_future.unwrap();
      inner_future.wait();
      int ii = inner_future.get();
      BOOST_THREAD_LOG << "ii= "<< ii << "" << BOOST_THREAD_END_LOG;
    }
    {
      boost::future<boost::future<int> > outer_future = boost::async(boost::launch::async, &p2);
      boost::future<int> inner_future = outer_future.unwrap();
      int ii = inner_future.get();
      BOOST_THREAD_LOG << "ii= "<< ii << "" << BOOST_THREAD_END_LOG;
    }
  }
  catch (std::exception& ex)
  {
    std::cout << "ERRORRRRR "<<ex.what() << "" << std::endl;
    BOOST_THREAD_LOG << "ERRORRRRR "<<ex.what() << "" << BOOST_THREAD_END_LOG;
    return 1;
  }
  catch (...)
  {
    std::cout << " ERRORRRRR exception thrown" << std::endl;
    BOOST_THREAD_LOG << " ERRORRRRR exception thrown" << BOOST_THREAD_END_LOG;
    return 2;
  }
  BOOST_THREAD_LOG << "MAIN>" << BOOST_THREAD_END_LOG;
  return 0;
}
#else

int main()
{
  return 0;
}
#endif

max_stars_repo_name: zsims/boost


text:
/*  $Id$
 *
 *  Copyright 2010 Anders Wallin (anders.e.e.wallin "at" gmail.com)
 *
 *  This file is part of OpenCAMlib.
 *
 *  OpenCAMlib is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  OpenCAMlib is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with OpenCAMlib.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef BPC_PY_H
#define BPC_PY_H

#include <boost/python.hpp>

#include "batchpushcutter.hpp"

#include "fiber_py.hpp"

namespace ocl
{
/// \brief python wrapper for batchpushcutter
class BatchPushCutter_py : public BatchPushCutter {
    public:
        BatchPushCutter_py() : BatchPushCutter() {}
        /// return CL-points to Python
        boost::python::list getCLPoints() const {
            boost::python::list plist;
            BOOST_FOREACH(Fiber f, *fibers) {
                BOOST_FOREACH( Interval i, f.ints ) {
                    if ( !i.empty() ) {
                        Point tmp = f.point(i.lower);
                        CLPoint p1 = CLPoint( tmp.x, tmp.y, tmp.z );
                        p1.cc = new CCPoint(i.lower_cc);
                        tmp = f.point(i.upper);
                        CLPoint p2 = CLPoint( tmp.x, tmp.y, tmp.z );
                        p2.cc = new CCPoint(i.upper_cc);
                        plist.append(p1);
                        plist.append(p2);
                    }
                }

            }
            return plist;
        };
        /// return triangles under cutter to Python. Not for CAM-algorithms,
        /// more for visualization and demonstration.
        boost::python::list getOverlapTriangles(Fiber& f) {
            boost::python::list trilist;
            std::list<Triangle> *overlap_triangles = new std::list<Triangle>();
            //int plane = 3; // XY-plane
            //Bbox bb; //FIXME
            //KDNode2::search_kdtree( overlap_triangles, bb,  root, plane);
            CLPoint cl;
            if (x_direction) {
                cl.x = 0;
                cl.y = f.p1.y;
                cl.z = f.p1.z;
            } else if (y_direction) {
                cl.x = f.p1.x;
                cl.y = 0;
                cl.z = f.p1.z;
            } else {
                assert(0);
            }
            overlap_triangles = root->search_cutter_overlap(cutter, &cl);

            BOOST_FOREACH(Triangle t, *overlap_triangles) {
                trilist.append(t);
            }
            delete overlap_triangles;
            return trilist;
        };
        /// return list of Fibers to python
        boost::python::list getFibers_py() const {
            boost::python::list flist;
            BOOST_FOREACH(Fiber f, *fibers) {
                flist.append( Fiber_py(f) );
            }
            return flist;
        };

};

} // end namespace

#endif

max_stars_repo_name: JohnyEngine/CNC

max_issues_repo_name: JohnyEngine/CNC

max_forks_repo_name: JohnyEngine/CNC


text:
/**
 *  sim_onlineca_multi.cpp
 *
 *  Simulate the LTL motion planning with collision avoidance
 *  with multiple moving obstacles.
 *
 *  Created by Yinan Li on Feb. 27, 2021.
 *  Hybrid Systems Group, University of Waterloo.
 */

#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <sys/stat.h>
#include <boost/numeric/odeint.hpp>
#include <cstdlib>
#include <ctime>

#include "src/grid.h"
#include "src/definitions.h"
#include "src/abstraction.hpp"
#include "src/DBAparser.h"
#include "src/bsolver.hpp"
#include "src/patcher.h"
#include "src/hdf5io.h"

#include "car.hpp"
#include "odes.hpp"

int main(int argc, char *argv[])
{
    std::string specfile, ctlrfile, cafile, graphfile;
    specfile = "dba1.txt";
    ctlrfile = "controller_dba1_0.2-0.2-0.2.h5";
    graphfile = "gwin.h5";
    const double eta[] = {0.2, 0.2, 0.2};

    cafile = "controller_safety_abst-0.8-0.9-0.1-0.1.h5";
    const double eta_r[] = {0.1, 0.1, 0.1};

    /* Input arguments:
     * ./simMulti dbafile ctlrfile cafile graphfile eta[0] eta_r[0]
     */
    if(argc!=1) {
	if(argc==7) {
	    specfile = std::string(argv[1]);
	    ctlrfile = std::string(argv[2]);
	    cafile = std::string(argv[3]);
	    graphfile = std::string(argv[4]);
	    eta[0] = std::atof(argv[5]);
	    eta[1] = std::atof(argv[5]);
	    eta[2] = std::atof(argv[5]);
	    eta_r[0] = std::atof(argv[6]);
	    eta_r[1] = std::atof(argv[6]);
	    eta_r[2] = std::atof(argv[6]);
	} else {
	    std::cout << "Improper number of arguments.\n";
	    std::exit(1);
	}
    }
    std::cout << "Simulate " << specfile << " with controller " << ctlrfile << '\n';

    /**
     * Setup the motion planning workspace
     **/
    const int x_dim = 3;
    const double theta = 3.5;
    const double xlb[] = {0, 0, -theta};
    const double xub[] = {10, 10, theta};
    /* set the control values */
    const int u_dim = 2;
    const double ulb[] = {-1.0, -1.0};
    double uub[] = {1.0, 1.0};
    /* discretization precision */
    double mu[] = {0.3, 0.3};
    /* generate grid */
    rocs::grid x_grid(x_dim,eta,xlb,xub);
    x_grid.gridding();
    rocs::grid u_grid(u_dim,mu,ulb,uub);
    std::cout << "Number of discrete states: " << x_grid._nv << "\n";
    std::cout << "Number of discrete inputs: " << u_grid._nv << "\n";

    clock_t tb, te;

    /**
     * Load specification
     **/
    std::cout << "\nReading the specification...\n";
    rocs::UintSmall nAP = 0, nNodes = 0, q0 = 0;
    std::vector<rocs::UintSmall> acc;
    std::vector<std::vector<rocs::UintSmall>> arrayM;
    if (!rocs::read_spec(specfile, nNodes, nAP, q0, arrayM, acc))
	std::exit(1);
    boost::dynamic_bitset<> isacc(nNodes, false);
    for (rocs::UintSmall i = 0; i < acc.size(); ++i)
	isacc[acc[i]] = true;

    /**
     * Load global controller
     **/
    std::cout << "\nLoading global controller...\n";
    std::vector<long long> w_x0, encode3;
    std::vector<NODE_POST> nts_ctrlr;
    std::vector<CTRL> ctrl;
    std::vector<int> q_prime;
    rocs::h5FileHandler planRdr(ctlrfile, H5F_ACC_RDONLY);
    planRdr.read_discrete_controller(w_x0, encode3, nts_ctrlr, ctrl, q_prime);

    /**
     * Load local safety controller
     **/
    std::cout << "\nLoading local safety controller...\n";
    rocs::h5FileHandler reader(cafile, H5F_ACC_RDONLY);
    std::vector<size_t> optCtlr;
    std::vector<double> value;
    boost::dynamic_bitset<> safeCtlr;
    boost::dynamic_bitset<> win;
    size_t cdims[2];
    reader.read_discrete_controller(win, safeCtlr, cdims, optCtlr, value);
    double xrlb[] = {-3, -3, -theta};
    double xrub[] = {3, 3, theta};
    rocs::grid rel_grid(3, eta_r, xrlb, xrub);
    rel_grid.gridding();

    /**
     * Launch patcher
     **/
    rocs::Patcher local;
    struct stat buffer;
    if(stat(graphfile.c_str(), &buffer) == 0) {
    	/* Read from a file */
    	std::cout << "\nReading winning graph...\n";
    	rocs::h5FileHandler graphRdr(graphfile, H5F_ACC_RDONLY);
    	tb = clock();
    	graphRdr.read_winning_graph(local);
    	te = clock();
    	std::cout << "Time of reading graph: " << (float)(te - tb)/CLOCKS_PER_SEC << '\n';
    } else {
    	std::cout << "Graph file doesn't exist.\n";
    	return 1;
    }
    int horizon = 3;  //set forward propagation horizon

    /**
     * Simulation
     **/
    const double drange[] = {3.0, 3.0};
    /* set ode solver */
    const double tsim = 0.1; //simulation time
    const double dt = 0.001; //integration step size for odeint
    boost::numeric::odeint::runge_kutta_cash_karp54<rocs::Rn> rk45;
    boost::dynamic_bitset<> u_safe(cdims[1]);

    /* Initial condition of the ego robot */
    rocs::Rn x{1, 1, M_PI/3.0};
    rocs::Rn u{0, 0};
    long long x_index = x_grid.val_to_id(x);
    std::vector<long long>::iterator p1;
    p1 = std::lower_bound(w_x0.begin(), w_x0.end(), x_index);
    if(*p1 != x_index) {
	std::cout << x[0] <<  " "  << x[1] << " " << x[2];
	std::cout << " is not in the winning set, change a new initial state." << std::endl;
	return 1;
    }
    /* Initial condition of 3 obstacles */
    rocs::Rn uomax{0.8, 0.8};
    rocs::Rn uomin{-0.8, -0.8};
    double v;

    /* State in local relative coordinate */
    rocs::Rn xr1{0,0,0};
    rocs::Rn xr2{0,0,0};
    rocs::Rn xr3{0,0,0};
    long long xr_id1, xr_id2, xr_id3;

    /* obstacle 1 */
    rocs::Rn xo1{3.0, 10.0, -1.5};
    rocs::Rn uo1{0.1, 0.0};
    auto obstacle_behavior1 = [&uo1, tsim](int j) {
				  double t = tsim*j;
				  if(t >= 0) {
				      uo1[0] = 0.2;
				      uo1[1] = 0.0;
				  }
			      };

    /* obstacle 2 */
    rocs::Rn xo2{5.3, 0.0, 2.0};
    rocs::Rn uo2{0.5, 0.0};
    auto obstacle_behavior2 = [&uo2, tsim](int j) {
				  double t = tsim*j;
				  if(t >= 0) {
				      if(t < 14) {
					  uo2[0] = 0.5;
					  uo2[1] = 0.0;
				      } else {
					  uo2[0] = 0.5;
					  uo2[1] = 0.6;
				      }
				  }
			      };

    /* obstacle 3 */
    rocs::Rn xo3{10.0, 6.4, M_PI};
    rocs::Rn uo3{0.15, 0.0};
    auto obstacle_behavior3 = [&uo3, tsim](int j) {
				  double t = tsim*j;
				  if(t >= 0) {
				      if(t < 31) {
					  uo3[0] = 0.2;
					  uo3[1] = 0.0;
				      } else if(t < 35) {
					  uo3[0] = 0.2;
					  uo3[1] = 0.3;
				      } else {
					  uo3[0] = 0.2;
					  uo3[1] = 0.0;
				      }
				  }
			      };

    /* Open files for writing results and logs */
    std::string simfile = "traj_closedloop_ca_4.txt";
    std::ofstream ctlrWtr(simfile);
    if(!ctlrWtr.is_open())
	ctlrWtr.open(simfile, std::ios::out);
    std::string simother1 = "traj_other_robot_4_1.txt";
    std::string simother2 = "traj_other_robot_4_2.txt";
    std::string simother3 = "traj_other_robot_4_3.txt";
    std::ofstream otherWtr1(simother1);
    std::ofstream otherWtr2(simother2);
    std::ofstream otherWtr3(simother3);
    if(!otherWtr1.is_open())
    	otherWtr1.open(simother1, std::ios::out);
    if(!otherWtr2.is_open())
    	otherWtr2.open(simother2, std::ios::out);
    if(!otherWtr3.is_open())
    	otherWtr3.open(simother3, std::ios::out);
    /********** Logging **********/
    std::ofstream logger;
    logger.open("logs_4.txt", std::ios::out);
    /********** Logging **********/

    /* Simulation loop */
    srand(time(NULL));
    float tpat = 0;
    int max_num_achieve_acc=5, max_num_iteration=1500; //3000000;
    rocs::UintSmall q;
    int i, j;
    double t0, tc; //record the time when an obstacle detected
    bool o1, o2, o3;
    o1 = false;
    o2 = false;
    o3 = false;
    std::vector<CTRL>::iterator p7;
    NODE_POST p5;
    std::cout << "\nLaunching simulation...\n";
    for(q = q0, i = j = 0; i<max_num_achieve_acc && j<max_num_iteration; ++j) {
	/* choose obstacle trajectory */
	obstacle_behavior1(j);
	obstacle_behavior2(j);
	obstacle_behavior3(j);

	/* Determine the control u by the product state (x_index, q) */
	p5 = nts_ctrlr[encode3[x_index]];
	p7 = std::lower_bound(ctrl.begin()+p5.pos, ctrl.begin()+p5.pos+p5.num_a,
			      q, [](const CTRL &item, const int val) {
				     return item.q < val;});
	if(p7->q != q) {
	    // std::cout << j << "th iteration: " << "Reach accepting state " << i << " times.\n";
	    // std::cout << "Automaton state: " << q << '\n';
	    // std::cout << "Position in ctrl list: " << p5.pos << ", number of actions: " << p5.num_a << '\n';
	    std::cout << "Error in ctrl" << std::endl;
	    break;
	}
	u_grid.id_to_val(u, p7->u);

	/* Print to screen */
	std::cout << "# " << j << ":\n";
	std::cout << "x: [" << x[0] <<  ','  << x[1] << ',' << x[2] << "]\n";
	std::cout << "Nominal control: " << p7->u << '('
		  << '[' << u[0] << ',' << u[1] << "])\n";
	std::cout << "current dba state: " << q << "\n";

	tc = j*tsim; //record the current time

	/* Get the relative state xr */
	xr1[0] = xo1[0]-x[0];
	xr1[1] = xo1[1]-x[1];
	xr1[2] = xo1[2]-x[2];
	xr2[0] = xo2[0]-x[0];
	xr2[1] = xo2[1]-x[1];
	xr2[2] = xo2[2]-x[2];
	xr3[0] = xo3[0]-x[0];
	xr3[1] = xo3[1]-x[1];
	xr3[2] = xo3[2]-x[2];
	if(xr1[2] > M_PI) //convert angle into [-pi, pi]
	    xr1[2] -= 2*M_PI;
	if(xr1[2] < -M_PI)
	    xr1[2] += 2*M_PI;
	if(xr2[2] > M_PI) //convert angle into [-pi, pi]
	    xr2[2] -= 2*M_PI;
	if(xr2[2] < -M_PI)
	    xr2[2] += 2*M_PI;
	if(xr3[2] > M_PI) //convert angle into [-pi, pi]
	    xr3[2] -= 2*M_PI;
	if(xr3[2] < -M_PI)
	    xr3[2] += 2*M_PI;
	inertia_to_body(xr1, x); //convert from the inertial to body frame
	inertia_to_body(xr2, x);
	inertia_to_body(xr3, x);

	/* Deal with obstacles */
	if(std::fabs(xr1[0])*std::fabs(xr1[0]) +
	   std::fabs(xr1[1])*std::fabs(xr1[1]) < drange[0]*drange[1]) {
	    o1 = true;
	    std::cout << "Obstacle 1 detected.\n";
	    std::cout << "Relative coordinate: ";
	    if(rel_grid._bds.isout(xr1)) { // xr is the out-of-domain node
		std::cout << rel_grid._nv;
	    } else {
		xr_id1 = rel_grid.val_to_id(xr1); //uniform grid rel_grid
		std::cout << xr_id1;
	    }
	    std::cout << "([" << xr1[0] << ',' << xr1[1] << ',' << xr1[2] << "])\n";
	} else {
	    o1 = false;
	}//end if obstacle is within range

	if(std::fabs(xr2[0])*std::fabs(xr2[0]) +
	   std::fabs(xr2[1])*std::fabs(xr2[1]) < drange[0]*drange[1]) {
	    o2 = true;
	    std::cout << "Obstacle 2 detected.\n";
	    std::cout << "Relative coordinate: ";
	    if(rel_grid._bds.isout(xr2)) { // xr is the out-of-domain node
		std::cout << rel_grid._nv;
	    } else {
		xr_id2 = rel_grid.val_to_id(xr2); //uniform grid rel_grid
		std::cout << xr_id2;
	    }
	    std::cout << "([" << xr2[0] << ',' << xr2[1] << ',' << xr2[2] << "])\n";
	} else {
	    o2 = false;
	}//end if obstacle is within range

	if(std::fabs(xr3[0])*std::fabs(xr3[0]) +
	   std::fabs(xr3[1])*std::fabs(xr3[1]) < drange[0]*drange[1]) {
	    o3 = true;
	    std::cout << "Obstacle 3 detected.\n";
	    std::cout << "Relative coordinate: ";
	    if(rel_grid._bds.isout(xr3)) { // xr is the out-of-domain node
		std::cout << rel_grid._nv;
	    } else {
		xr_id3 = rel_grid.val_to_id(xr3); //uniform grid rel_grid
		std::cout << xr_id3;
	    }
	    std::cout << "([" << xr3[0] << ',' << xr3[1] << ',' << xr3[2] << "])\n";
	} else {
	    o3 = false;
	}//end if obstacle is within range

	/* Perform RH (receding horizon) */
	if(o1||o2||o3) {
	    /********** Logging **********/
	    logger << tc << '(' << j << "): "
	       << x_index << '(' << x[0] << ',' << x[1] << ',' << x[2] << "), ";
	    if(o1) {
		logger << "o1," << xr_id1 << '(' << xr1[0] << ',' << xr1[1] << ',' << xr1[2] << "), ";
		for(size_t k = 0; k < cdims[1]; ++k)
		    logger << safeCtlr[xr_id1*cdims[1]+k];
		logger << '\n';
	    }
	    if(o2) {
		logger << "o2," << xr_id2 << '(' << xr2[0] << ',' << xr2[1] << ',' << xr2[2]<< "), ";
		for(size_t k = 0; k < cdims[1]; ++k)
		    logger << safeCtlr[xr_id2*cdims[1]+k];
		logger << '\n';
	    }
	    if(o3) {
		logger << "o3," << xr_id3 << '(' << xr3[0] << ',' << xr3[1] << ',' << xr3[2] << ")";
		for(size_t k = 0; k < cdims[1]; ++k)
		    logger << safeCtlr[xr_id3*cdims[1]+k];
		logger << '\n';
	    }
	    std::cout << "o1:"<< o1 <<", o2:"<< o2 <<", o3:" << o3 <<'\n';
	    // std::cout << "Current state id of the robot:" << xp << ", key:" << key << '\n';
	    /********** Logging **********/

	    size_t xp = x_index*nNodes+q; // (idx,idq)=idx*nNodes+idq (buchi.c)
	    size_t uid;

	    /********** Logging **********/
	    size_t row, key = local._encode[xp];
	    row = local._idmap[key];
	    // std::cout << "id_n0n1: " << xp << ',' << " id_np: " << key << '\n';
	    for(size_t k = 0; k < u_grid._nv; ++k) {
		if(local._winfts._npost[row*local._na+k]) {//outdeg>0
		    logger << k << ' ';
		}
	    }
	    logger << ", ";
	    /********** Logging **********/

	    /* Determine safe inputs for RH module */
	    std::cout << "Use RH to find safe control inputs.\n ";
	    u_safe.set();
	    int nSafeAct = 0;
	    rocs::Rn uu(u_dim);
	    double dtemp, u_dist=(uub[0]-ulb[0])*(uub[0]-ulb[0])+(uub[1]-ulb[1])*(uub[1]-ulb[1]);
	    for(size_t k = 0; k < cdims[1]; ++k) {
		if(o1)
		    u_safe[k] = u_safe[k] & safeCtlr[xr_id1*cdims[1]+k];
		if(o2)
		    u_safe[k] = u_safe[k] & safeCtlr[xr_id2*cdims[1]+k];
		if(o3)
		    u_safe[k] = u_safe[k] & safeCtlr[xr_id3*cdims[1]+k];

		if(u_safe[k]) {
		    /************* Logging **************/
		    // std::cout << k << ',';
		    // std::cout << "Outdeg: "
		    // 	      << local._winfts._npost[row*local._na+k]
		    // 	      << '\n';
		    /************* Logging **************/
		    if(local._winfts._npost[row*local._na+k]) {//outdeg>0
			++nSafeAct; //count the # of safe valid controls
			/* take the closest to the original one */
			u_grid.id_to_val(uu, k);
			dtemp = (uu[0]-u[0])*(uu[0]-u[0])+(uu[1]-u[1])*(uu[1]-u[1]);
			if(dtemp < u_dist) {
			    uid = k;
			    u_dist= dtemp;
			}
			/************* Logging **************/
			// std::cout << "Post nodes: ";
			// size_t pidstart=local._winfts._ptrpost[row*local._na+k];
			// for(size_t pid=pidstart; pid<pidstart+local._winfts._npost[row*local._na+k]; ++pid)
			//     std::cout << local._winfts._idpost[pid] << ' ';
			// std::cout << '\n';
			/************* Logging **************/
		    }
		    // /************* Logging **************/
		    // logger << k << ' ';
		    // /************* Logging **************/
		}
		/********** Logging **********/
		logger << u_safe[k];
		/********** Logging **********/
	    }
	    /********** Logging **********/
	    u_grid.id_to_val(uu, uid);
	    logger << '\n'
		   << p7->u << ' ' << u[0] << ',' << u[1] << ';'
		   << uid << ' ' << uu[0] << ',' << uu[1] << ' ' << u_dist << ';';
	    /********** Logging **********/

	    /* Get a safe control from patcher */
	    if(u_safe[p7->u]) {
		std::cout << "The static strategy is safe.\n";
		// u_grid.id_to_val(u, uid);
		logger << p7->u << ' ';
	    } else if(nSafeAct > 1) {
		tb = clock();
		int suc = local.solve_local_reachability(xp, horizon, u_safe);
		te = clock();
		tpat += (float)(te - tb)/CLOCKS_PER_SEC;
		std::cout << "Average time for RH: "
			  << tpat/(j+1) << ".\n";
		if(!suc) {//if fails in re-planning, use the closest u
		    std::cout << "Apply the safe control input closest to the original one.\n";
		    u_grid.id_to_val(u, uid);
		    logger << uid << ' ';
		} else {
		    std::cout << "Apply controls returned by local reachability.\n";
		    u_grid.id_to_val(u, local._ctlr);
		    logger << local._ctlr << ' ';
		}
	    } else if(nSafeAct > 0) {
		std::cout << "Apply the only one safe control.\n";
		u_grid.id_to_val(u, uid);
		logger << uid << ' ';
	    } else {
		std::cout << "No safe controls. Freeze.\n";
		u[0] = 0;
		u[1] = 0;
		logger << p7->u << ' ';
	    }
	    /********** Logging **********/
	    logger << u[0] << ',' << u[1] << "\n\n";
	    /********** Logging **********/
	}//end RH

	/* Write to txt file */
	// ctlrWtr << j << ':';
	for(int d = 0; d < x_dim; ++d) {
	    /* the controlled state */
	    ctlrWtr << x[d];
	    /* the state of the other robot */
	    otherWtr1 << xo1[d];
	    otherWtr2 << xo2[d];
	    otherWtr3 << xo3[d];
	    if(d<x_dim-1) {
		ctlrWtr << ',';
		otherWtr1 << ',';
		otherWtr2 << ',';
		otherWtr3 << ',';
	    }
	}
	ctlrWtr << ';';
	otherWtr1 << ';';
	otherWtr2 << ';';
	otherWtr3 << ';';
	for(int d = 0; d < u_dim; ++d) {
	    ctlrWtr << u[d];
	    otherWtr1 << uo1[d];
	    otherWtr2 << uo2[d];
	    otherWtr3 << uo3[d];
	    if(d<u_dim-1) {
		ctlrWtr << ',';
		otherWtr1 << ',';
		otherWtr2 << ',';
		otherWtr3 << ',';
	    }
	}
	ctlrWtr << '\n';
	otherWtr1 << '\n';
	otherWtr2 << '\n';
	otherWtr3 << '\n';

	/* Integrate ego robot trajectory */
	boost::numeric::odeint::integrate_const(rk45, car_dynamics(u), x, 0.0, tsim, dt);
	if(x[2] > M_PI) //convert angle into [-pi, pi]
	    x[2] -= 2*M_PI;
	if(x[2] < -M_PI)
	    x[2] += 2*M_PI;

	/* integrate obstacle trajectory after it appears */
	boost::numeric::odeint::integrate_const(rk45, car_dynamics(uo1), xo1, 0.0, tsim, dt);
	if(xo1[2] > M_PI) //convert angle into [-pi, pi]
	    xo1[2] -= 2*M_PI;
	if(xo1[2] < -M_PI)
	    xo1[2] += 2*M_PI;
	boost::numeric::odeint::integrate_const(rk45, car_dynamics(uo2), xo2, 0.0, tsim, dt);
	if(xo2[2] > M_PI) //convert angle into [-pi, pi]
	    xo2[2] -= 2*M_PI;
	if(xo2[2] < -M_PI)
	    xo2[2] += 2*M_PI;
	boost::numeric::odeint::integrate_const(rk45, car_dynamics(uo3), xo3, 0.0, tsim, dt);
	if(xo3[2] > M_PI) //convert angle into [-pi, pi]
	    xo3[2] -= 2*M_PI;
	if(xo3[2] < -M_PI)
	    xo3[2] += 2*M_PI;

	/* Update automaton state q */
	x_index = x_grid.val_to_id(x);
	q = q_prime[p5.label*nNodes + q];
	if(isacc[q])
	    std::cout << "******** achieve acc \'" << q << "\' " << ++i << " time ********" << std::endl;
    }

    ctlrWtr.close();
    otherWtr1.close();
    otherWtr2.close();
    otherWtr3.close();
    logger.close();

    return 0;
}

max_stars_repo_name: yinanl/rocs

max_issues_repo_name: yinanl/rocs

max_forks_repo_name: yinanl/rocs


text:
//  Unit test for boost::lexical_cast.
//
//  See http://www.boost.org for most recent version, including documentation.
//
//  Copyright Antony Polukhin, 2011-2020.
//
//  Distributed under the Boost
//  Software License, Version 1.0. (See accompanying file
//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt).

#include <boost/config.hpp>

#if defined(__INTEL_COMPILER)
#pragma warning(disable: 193 383 488 981 1418 1419)
#elif defined(BOOST_MSVC)
#pragma warning(disable: 4097 4100 4121 4127 4146 4244 4245 4511 4512 4701 4800)
#endif

#include <boost/lexical_cast.hpp>
#include <boost/test/unit_test.hpp>

using namespace boost;

#if defined(BOOST_NO_STRINGSTREAM) || defined(BOOST_NO_STD_WSTRING)
#define BOOST_LCAST_NO_WCHAR_T
#endif

template <class CharT>
void test_impl(const CharT* wc_arr)
{
    typedef CharT                       wide_char;
    typedef std::basic_string<CharT>    wide_string;
    const char c_arr[]            = "Test array of chars";
    const unsigned char uc_arr[]  = "Test array of chars";
    const signed char sc_arr[]    = "Test array of chars";

    // Following tests depend on realization of std::locale
    // and pass for popular compilers and STL realizations
    BOOST_CHECK(boost::lexical_cast<wide_char>(c_arr[0]) == wc_arr[0]);
    BOOST_CHECK(boost::lexical_cast<wide_string>(c_arr) == wide_string(wc_arr));

    BOOST_CHECK(boost::lexical_cast<wide_string>(sc_arr) == wide_string(wc_arr) );
    BOOST_CHECK(boost::lexical_cast<wide_string>(uc_arr) == wide_string(wc_arr) );

    BOOST_CHECK_EQUAL(boost::lexical_cast<wide_char>(uc_arr[0]), wc_arr[0]);
    BOOST_CHECK_EQUAL(boost::lexical_cast<wide_char>(sc_arr[0]), wc_arr[0]);
}

void test_char_types_conversions_wchar_t()
{
#ifndef BOOST_LCAST_NO_WCHAR_T
    test_impl(L"Test array of chars");
    wchar_t c = boost::detail::lcast_char_constants<wchar_t>::zero;
    BOOST_CHECK_EQUAL(L'0', c);

    c = boost::detail::lcast_char_constants<wchar_t>::minus;
    BOOST_CHECK_EQUAL(L'-', c);

    c = boost::detail::lcast_char_constants<wchar_t>::plus;
    BOOST_CHECK_EQUAL(L'+', c);

    c = boost::detail::lcast_char_constants<wchar_t>::lowercase_e;
    BOOST_CHECK_EQUAL(L'e', c);

    c = boost::detail::lcast_char_constants<wchar_t>::capital_e;
    BOOST_CHECK_EQUAL(L'E', c);

    c = boost::detail::lcast_char_constants<wchar_t>::c_decimal_separator;
    BOOST_CHECK_EQUAL(L'.', c);
#endif

    BOOST_CHECK(true);
}

void test_char_types_conversions_char16_t()
{
#if !defined(BOOST_NO_CXX11_CHAR16_T) && !defined(BOOST_NO_CXX11_UNICODE_LITERALS) && defined(BOOST_STL_SUPPORTS_NEW_UNICODE_LOCALES)
    test_impl(u"Test array of chars");
    char16_t c = boost::detail::lcast_char_constants<char16_t>::zero;
    BOOST_CHECK_EQUAL(u'0', c);

    c = boost::detail::lcast_char_constants<char16_t>::minus;
    BOOST_CHECK_EQUAL(u'-', c);

    c = boost::detail::lcast_char_constants<char16_t>::plus;
    BOOST_CHECK_EQUAL(u'+', c);

    c = boost::detail::lcast_char_constants<char16_t>::lowercase_e;
    BOOST_CHECK_EQUAL(u'e', c);

    c = boost::detail::lcast_char_constants<char16_t>::capital_e;
    BOOST_CHECK_EQUAL(u'E', c);

    c = boost::detail::lcast_char_constants<char16_t>::c_decimal_separator;
    BOOST_CHECK_EQUAL(u'.', c);
#endif

    BOOST_CHECK(true);
}

void test_char_types_conversions_char32_t()
{
#if !defined(BOOST_NO_CXX11_CHAR32_T) && !defined(BOOST_NO_CXX11_UNICODE_LITERALS) && defined(BOOST_STL_SUPPORTS_NEW_UNICODE_LOCALES)
    test_impl(U"Test array of chars");
    char32_t c = boost::detail::lcast_char_constants<char32_t>::zero;
    BOOST_CHECK_EQUAL(U'0', c);

    c = boost::detail::lcast_char_constants<char32_t>::minus;
    BOOST_CHECK_EQUAL(U'-', c);

    c = boost::detail::lcast_char_constants<char32_t>::plus;
    BOOST_CHECK_EQUAL(U'+', c);

    c = boost::detail::lcast_char_constants<char32_t>::lowercase_e;
    BOOST_CHECK_EQUAL(U'e', c);

    c = boost::detail::lcast_char_constants<char32_t>::capital_e;
    BOOST_CHECK_EQUAL(U'E', c);

    c = boost::detail::lcast_char_constants<char32_t>::c_decimal_separator;
    BOOST_CHECK_EQUAL(U'.', c);
#endif

    BOOST_CHECK(true);
}

unit_test::test_suite *init_unit_test_suite(int, char *[])
{
    unit_test::test_suite *suite =
        BOOST_TEST_SUITE("lexical_cast char => wide characters unit test (widening test)");
    suite->add(BOOST_TEST_CASE(&test_char_types_conversions_wchar_t));
    suite->add(BOOST_TEST_CASE(&test_char_types_conversions_char16_t));
    suite->add(BOOST_TEST_CASE(&test_char_types_conversions_char32_t));

    return suite;
}

max_issues_repo_name: qingkouwei/mediaones

max_forks_repo_name: qingkouwei/mediaones


text:
#include <gtest/gtest.h>
#include <boost/filesystem.hpp>
#include <string>

TEST(boost, filesystem)
{
  const auto path = boost::filesystem::current_path();
  ASSERT_FALSE(path.empty());
}

max_stars_repo_name: qis/toolchains-test

max_issues_repo_name: qis/toolchains-test

max_forks_repo_name: qis/toolchains-test


text:
/*
 *
 * Copyright (c) Kresimir Fresl 2002, 2003
 *
 * Permission to copy, modify, use and distribute this software
 * for any non-commercial or commercial purpose is granted provided
 * that this license appear on all copies of the software source code.
 *
 * Author assumes no responsibility whatsoever for its use and makes
 * no guarantees about its quality, correctness or reliability.
 *
 * Author acknowledges the support of the Faculty of Civil Engineering,
 * University of Zagreb, Croatia.
 *
 */

#ifndef BOOST_NUMERIC_BINDINGS_CBLAS_LEVEL_2_HPP
#define BOOST_NUMERIC_BINDINGS_CBLAS_LEVEL_2_HPP

#include <cassert>

#include <boost/numeric/bindings/traits/traits.hpp>
#include <boost/numeric/bindings/traits/type_traits.hpp>
#include <boost/numeric/bindings/atlas/cblas2_overloads.hpp>
#include <boost/numeric/bindings/atlas/cblas_enum.hpp>

#ifndef BOOST_NUMERIC_BINDINGS_NO_STRUCTURE_CHECK
#  include <boost/static_assert.hpp>
#  include <boost/type_traits/same_traits.hpp>
#endif

namespace boost { namespace numeric { namespace bindings {

  namespace atlas {

    // y <- alpha * op (A) * x + beta * y
    // op (A) == A || A^T || A^H
    template <typename T, typename Matr, typename VctX, typename VctY>
    inline
    void gemv (CBLAS_TRANSPOSE const TransA,
               T const& alpha, Matr const& a, VctX const& x,
               T const& beta, VctY& y
               )
    {
#ifndef BOOST_NUMERIC_BINDINGS_NO_STRUCTURE_CHECK
      BOOST_STATIC_ASSERT((boost::is_same<
        typename traits::matrix_traits<Matr>::matrix_structure,
        traits::general_t
      >::value));
#endif

      int const m = traits::matrix_size1 (a);
      int const n = traits::matrix_size2 (a);
      assert (traits::vector_size (x) >= (TransA == CblasNoTrans ? n : m));
      assert (traits::vector_size (y) >= (TransA == CblasNoTrans ? m : n));
      // .. what about AtlasConj?

      CBLAS_ORDER const stor_ord
        = enum_cast<CBLAS_ORDER const>
        (storage_order<
#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
           typename traits::matrix_traits<Matr>::ordering_type
#else
           typename Matr::orientation_category
#endif
         >::value);

      detail::gemv (stor_ord, TransA, m, n, alpha,
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
                    traits::matrix_storage (a),
#else
                    traits::matrix_storage_const (a),
#endif
                    traits::leading_dimension (a),
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
                    traits::vector_storage (x),
#else
                    traits::vector_storage_const (x),
#endif
                    traits::vector_stride (x),
                    beta,
                    traits::vector_storage (y),
                    traits::vector_stride (y));
    }

    // y <- alpha * A * x + beta * y
    template <typename T, typename Matr, typename VctX, typename VctY>
    inline
    void gemv (T const& alpha, Matr const& a, VctX const& x,
               T const& beta, VctY& y) {
      gemv (CblasNoTrans, alpha, a, x, beta, y);
    }

    // y <- A * x
    template <typename Matr, typename VctX, typename VctY>
    inline
    void gemv (Matr const& a, VctX const& x, VctY& y) {
#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
      typedef typename traits::matrix_traits<Matr>::value_type val_t;
#else
      typedef typename Matr::value_type val_t;
#endif
      gemv (CblasNoTrans, (val_t) 1, a, x, (val_t) 0, y);
    }

    // y <- alpha * A * x + beta * y
    // A real symmetric matrix (T == float | double)
    // [from 'dsymv.f':]
    /* [...] with UPLO = 'U' or 'u', the  leading n by n upper
     * triangular part of the array A must contain the upper triangular
     * part of the symmetric matrix and the strictly lower triangular
     * part of A is not referenced.
     * [...] with UPLO = 'L' or 'l', the leading n by n lower
     * triangular part of the array A must contain the lower triangular
     * part of the symmetric matrix and the strictly  upper
     * triangular part of A is not referenced.
     */
    template <typename T, typename SymmMatr, typename VctX, typename VctY>
    inline
    void symv (CBLAS_UPLO const uplo, T const& alpha, SymmMatr const& a,
               VctX const& x, T const& beta, VctY& y)
    {
#ifndef BOOST_NUMERIC_BINDINGS_NO_STRUCTURE_CHECK
      BOOST_STATIC_ASSERT((boost::is_same<
        typename traits::matrix_traits<SymmMatr>::matrix_structure,
        traits::general_t
      >::value));
#endif

      int const n = traits::matrix_size1 (a);
      assert (n == traits::matrix_size2 (a));
      assert (traits::vector_size (x) >= n);
      assert (traits::vector_size (y) >= n);

      CBLAS_ORDER const stor_ord
        = enum_cast<CBLAS_ORDER const>
        (storage_order<
#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
           typename traits::matrix_traits<SymmMatr>::ordering_type
#else
           typename SymmMatr::orientation_category
#endif
         >::value);

      detail::symv (stor_ord, uplo, n, alpha,
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
                    traits::matrix_storage (a),
#else
                    traits::matrix_storage_const (a),
#endif
                    traits::leading_dimension (a),
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
                    traits::vector_storage (x),
#else
                    traits::vector_storage_const (x),
#endif
                    traits::vector_stride (x),
                    beta,
                    traits::vector_storage (y),
                    traits::vector_stride (y));
    }

    template <typename T, typename SymmMatr, typename VctX, typename VctY>
    inline
    void symv (T const& alpha, SymmMatr const& a, VctX const& x,
               T const& beta, VctY& y)
    {
#ifndef BOOST_NUMERIC_BINDINGS_NO_STRUCTURE_CHECK
      BOOST_STATIC_ASSERT((boost::is_same<
        typename traits::matrix_traits<SymmMatr>::matrix_structure,
        traits::symmetric_t
      >::value));
#endif

      int const n = traits::matrix_size1 (a);
      assert (n == traits::matrix_size2 (a));
      assert (traits::vector_size (x) >= n);
      assert (traits::vector_size (y) >= n);

      CBLAS_ORDER const stor_ord
        = enum_cast<CBLAS_ORDER const>
        (storage_order<
#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
           typename traits::matrix_traits<SymmMatr>::ordering_type
#else
           typename SymmMatr::orientation_category
#endif
         >::value);

      CBLAS_UPLO const uplo
        = enum_cast<CBLAS_UPLO const>
        (uplo_triang<
#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
           typename traits::matrix_traits<SymmMatr>::uplo_type
#else
           typename SymmMatr::packed_category
#endif
         >::value);

      detail::symv (stor_ord, uplo, n, alpha,
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
                    traits::matrix_storage (a),
#else
                    traits::matrix_storage_const (a),
#endif
                    traits::leading_dimension (a),
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
                    traits::vector_storage (x),
#else
                    traits::vector_storage_const (x),
#endif
                    traits::vector_stride (x),
                    beta,
                    traits::vector_storage (y),
                    traits::vector_stride (y));
    }

    // y <- A * x
    template <typename SymmMatr, typename VctX, typename VctY>
    inline
    void symv (SymmMatr const& a, VctX const& x, VctY& y) {
#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
      typedef typename traits::matrix_traits<SymmMatr>::value_type val_t;
#else
      typedef typename SymmMatr::value_type val_t;
#endif
      symv ((val_t) 1, a, x, (val_t) 0, y);
    }

    // y <- alpha * A * x + beta * y
    // A real symmetric matrix (T == float | double) in packed form
    // [from 'dspmv.f' (description assumes column major order):]
    /* A is an array of DIMENSION ( ( n*( n + 1 ) )/2 ).
     * Before entry with UPLO = 'U' or 'u', the array A must contain
     * the upper triangular  part of the symmetric matrix packed
     * sequentially, column by column, so that A( 1 ) contains a(1,1),
     * A( 2 ) and A( 3 ) contain a(1,2) and a(2,2) respectively, and
     * so on.
     * Before entry with UPLO = 'L' or 'l', the array A must contain
     * the lower triangular  part of the symmetric matrix packed
     * sequentially, column by column, so that A( 1 ) contains a(1,1),
     * A( 2 ) and A( 3 ) contain a(2,1) and a(3,1) respectively, and
     * so on.
     */
    template <typename T, typename SymmMatr, typename VctX, typename VctY>
    inline
    void spmv (T const& alpha, SymmMatr const& a, VctX const& x,
               T const& beta, VctY& y)
    {
#ifndef BOOST_NUMERIC_BINDINGS_NO_STRUCTURE_CHECK
      BOOST_STATIC_ASSERT((boost::is_same<
        typename traits::matrix_traits<SymmMatr>::matrix_structure,
        traits::symmetric_packed_t
      >::value));
#endif

      int const n = traits::matrix_size1 (a);
      assert (n == traits::matrix_size2 (a));
      assert (traits::vector_size (x) >= n);
      assert (traits::vector_size (y) >= n);

      CBLAS_ORDER const stor_ord
        = enum_cast<CBLAS_ORDER const>
        (storage_order<
#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
           typename traits::matrix_traits<SymmMatr>::ordering_type
#else
           typename SymmMatr::orientation_category
#endif
         >::value);

      CBLAS_UPLO const uplo
        = enum_cast<CBLAS_UPLO const>
        (uplo_triang<
#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
           typename traits::matrix_traits<SymmMatr>::uplo_type
#else
           typename SymmMatr::packed_category
#endif
         >::value);

      detail::spmv (stor_ord, uplo, n, alpha,
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
                    traits::matrix_storage (a),
                    traits::vector_storage (x),
#else
                    traits::matrix_storage_const (a),
                    traits::vector_storage_const (x),
#endif
                    traits::vector_stride (x),
                    beta,
                    traits::vector_storage (y),
                    traits::vector_stride (y));
    }

    // y <- A * x
    template <typename SymmMatr, typename VctX, typename VctY>
    inline
    void spmv (SymmMatr const& a, VctX const& x, VctY& y) {
#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
      typedef typename traits::matrix_traits<SymmMatr>::value_type val_t;
#else
      typedef typename SymmMatr::value_type val_t;
#endif
      spmv ((val_t) 1, a, x, (val_t) 0, y);
    }

    // y <- alpha * A * x + beta * y
    // A complex hermitian matrix
    // (T == std::complex<float> | std::complex<double>)
    template <typename T, typename HermMatr, typename VctX, typename VctY>
    inline
    void hemv (CBLAS_UPLO const uplo, T const& alpha, HermMatr const& a,
               VctX const& x, T const& beta, VctY& y)
    {
#ifndef BOOST_NUMERIC_BINDINGS_NO_STRUCTURE_CHECK
      BOOST_STATIC_ASSERT((boost::is_same<
        typename traits::matrix_traits<HermMatr>::matrix_structure,
        traits::general_t
      >::value));
#endif

      int const n = traits::matrix_size1 (a);
      assert (n == traits::matrix_size2 (a));
      assert (traits::vector_size (x) >= n);
      assert (traits::vector_size (y) >= n);

      CBLAS_ORDER const stor_ord
        = enum_cast<CBLAS_ORDER const>
        (storage_order<
#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
           typename traits::matrix_traits<HermMatr>::ordering_type
#else
           typename HermMatr::orientation_category
#endif
         >::value);

      detail::hemv (stor_ord, uplo, n, alpha,
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
                    traits::matrix_storage (a),
#else
                    traits::matrix_storage_const (a),
#endif
                    traits::leading_dimension (a),
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
                    traits::vector_storage (x),
#else
                    traits::vector_storage_const (x),
#endif
                    traits::vector_stride (x),
                    beta,
                    traits::vector_storage (y),
                    traits::vector_stride (y));
    }

    template <typename T, typename HermMatr, typename VctX, typename VctY>
    inline
    void hemv (T const& alpha, HermMatr const& a, VctX const& x,
               T const& beta, VctY& y)
    {
#ifndef BOOST_NUMERIC_BINDINGS_NO_STRUCTURE_CHECK
      BOOST_STATIC_ASSERT((boost::is_same<
        typename traits::matrix_traits<HermMatr>::matrix_structure,
        traits::hermitian_t
      >::value));
#endif

      int const n = traits::matrix_size1 (a);
      assert (n == traits::matrix_size2 (a));
      assert (traits::vector_size (x) >= n);
      assert (traits::vector_size (y) >= n);

      CBLAS_ORDER const stor_ord
        = enum_cast<CBLAS_ORDER const>
        (storage_order<
#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
           typename traits::matrix_traits<HermMatr>::ordering_type
#else
           typename HermMatr::orientation_category
#endif
         >::value);

      CBLAS_UPLO const uplo
        = enum_cast<CBLAS_UPLO const>
        (uplo_triang<
#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
           typename traits::matrix_traits<HermMatr>::uplo_type
#else
           typename HermMatr::packed_category
#endif
         >::value);

      detail::hemv (stor_ord, uplo, n, alpha,
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
                    traits::matrix_storage (a),
#else
                    traits::matrix_storage_const (a),
#endif
                    traits::leading_dimension (a),
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
                    traits::vector_storage (x),
#else
                    traits::vector_storage_const (x),
#endif
                    traits::vector_stride (x),
                    beta,
                    traits::vector_storage (y),
                    traits::vector_stride (y));
    }

    // y <- A * x
    template <typename HermMatr, typename VctX, typename VctY>
    inline
    void hemv (HermMatr const& a, VctX const& x, VctY& y) {
#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
      typedef typename traits::matrix_traits<HermMatr>::value_type val_t;
#else
      typedef typename HermMatr::value_type val_t;
#endif
      hemv ((val_t) 1, a, x, (val_t) 0, y);
    }

    // y <- alpha * A * x + beta * y
    // A complex hermitian matrix in packed form
    // (T == std::complex<float> | std::complex<double>)
    template <typename T, typename HermMatr, typename VctX, typename VctY>
    inline
    void hpmv (T const& alpha, HermMatr const& a, VctX const& x,
               T const& beta, VctY& y)
    {
#ifndef BOOST_NUMERIC_BINDINGS_NO_STRUCTURE_CHECK
      BOOST_STATIC_ASSERT((boost::is_same<
        typename traits::matrix_traits<HermMatr>::matrix_structure,
        traits::hermitian_packed_t
      >::value));
#endif

      int const n = traits::matrix_size1 (a);
      assert (n == traits::matrix_size2 (a));
      assert (traits::vector_size (x) >= n);
      assert (traits::vector_size (y) >= n);

      CBLAS_ORDER const stor_ord
        = enum_cast<CBLAS_ORDER const>
        (storage_order<
#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
           typename traits::matrix_traits<HermMatr>::ordering_type
#else
           typename HermMatr::orientation_category
#endif
         >::value);

      CBLAS_UPLO const uplo
        = enum_cast<CBLAS_UPLO const>
        (uplo_triang<
#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
           typename traits::matrix_traits<HermMatr>::uplo_type
#else
           typename HermMatr::packed_category
#endif
         >::value);

      detail::hpmv (stor_ord, uplo, n, alpha,
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
                    traits::matrix_storage (a),
                    traits::vector_storage (x),
#else
                    traits::matrix_storage_const (a),
                    traits::vector_storage_const (x),
#endif
                    traits::vector_stride (x),
                    beta,
                    traits::vector_storage (y),
                    traits::vector_stride (y));
    }

    // y <- A * x
    template <typename HermMatr, typename VctX, typename VctY>
    inline
    void hpmv (HermMatr const& a, VctX const& x, VctY& y) {
#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
      typedef typename traits::matrix_traits<HermMatr>::value_type val_t;
#else
      typedef typename HermMatr::value_type val_t;
#endif
      hpmv ((val_t) 1, a, x, (val_t) 0, y);
    }

    // A <- alpha * x * y^T + A
    // .. real & complex types
    template <typename T, typename Matr, typename VctX, typename VctY>
    inline
    void ger (T const& alpha, VctX const& x, VctY const& y, Matr& a) {
#ifndef BOOST_NUMERIC_BINDINGS_NO_STRUCTURE_CHECK
      BOOST_STATIC_ASSERT((boost::is_same<
        typename traits::matrix_traits<Matr>::matrix_structure,
        traits::general_t
      >::value));
#endif

      int const m = traits::matrix_size1 (a);
      int const n = traits::matrix_size2 (a);
      assert (traits::vector_size (x) >= m);
      assert (traits::vector_size (y) >= n);

      CBLAS_ORDER const stor_ord
        = enum_cast<CBLAS_ORDER const>
        (storage_order<
#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
           typename traits::matrix_traits<Matr>::ordering_type
#else
           typename Matr::orientation_category
#endif
         >::value);

      detail::ger (stor_ord, m, n, alpha,
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
                   traits::vector_storage (x),
#else
                   traits::vector_storage_const (x),
#endif
                   traits::vector_stride (x),
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
                   traits::vector_storage (y),
#else
                   traits::vector_storage_const (y),
#endif
                   traits::vector_stride (y),
                   traits::matrix_storage (a),
                   traits::leading_dimension (a));
    }

    // A <- x * y^T + A
    template <typename Matr, typename VctX, typename VctY>
    inline
    void ger (VctX const& x, VctY const& y, Matr& a) {
#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
      typedef typename traits::matrix_traits<Matr>::value_type val_t;
#else
      typedef typename Matr::value_type val_t;
#endif
      ger ((val_t) 1, x, y, a);
    }

    // A <- alpha * x * y^T + A
    // .. complex types only
    template <typename T, typename Matr, typename VctX, typename VctY>
    inline
    void geru (T const& alpha, VctX const& x, VctY const& y, Matr& a) {
#ifndef BOOST_NUMERIC_BINDINGS_NO_STRUCTURE_CHECK
      BOOST_STATIC_ASSERT((boost::is_same<
        typename traits::matrix_traits<Matr>::matrix_structure,
        traits::general_t
      >::value));
#endif

      int const m = traits::matrix_size1 (a);
      int const n = traits::matrix_size2 (a);
      assert (traits::vector_size (x) >= m);
      assert (traits::vector_size (y) >= n);

      CBLAS_ORDER const stor_ord
        = enum_cast<CBLAS_ORDER const>
        (storage_order<
#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
           typename traits::matrix_traits<Matr>::ordering_type
#else
           typename Matr::orientation_category
#endif
         >::value);

      detail::geru (stor_ord, m, n, alpha,
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
                    traits::vector_storage (x),
#else
                    traits::vector_storage_const (x),
#endif
                    traits::vector_stride (x),
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
                    traits::vector_storage (y),
#else
                    traits::vector_storage_const (y),
#endif
                    traits::vector_stride (y),
                    traits::matrix_storage (a),
                    traits::leading_dimension (a));
    }

    // A <- x * y^T + A
    template <typename Matr, typename VctX, typename VctY>
    inline
    void geru (VctX const& x, VctY const& y, Matr& a) {
#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
      typedef typename traits::matrix_traits<Matr>::value_type val_t;
#else
      typedef typename Matr::value_type val_t;
#endif
      geru ((val_t) 1, x, y, a);
    }

    // A <- alpha * x * y^H + A
    // .. complex types only
    template <typename T, typename Matr, typename VctX, typename VctY>
    inline
    void gerc (T const& alpha, VctX const& x, VctY const& y, Matr& a) {
#ifndef BOOST_NUMERIC_BINDINGS_NO_STRUCTURE_CHECK
      BOOST_STATIC_ASSERT((boost::is_same<
        typename traits::matrix_traits<Matr>::matrix_structure,
        traits::general_t
      >::value));
#endif

      int const m = traits::matrix_size1 (a);
      int const n = traits::matrix_size2 (a);
      assert (traits::vector_size (x) >= m);
      assert (traits::vector_size (y) >= n);

      CBLAS_ORDER const stor_ord
        = enum_cast<CBLAS_ORDER const>
        (storage_order<
#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
           typename traits::matrix_traits<Matr>::ordering_type
#else
           typename Matr::orientation_category
#endif
         >::value);

      detail::gerc (stor_ord, m, n, alpha,
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
                    traits::vector_storage (x),
#else
                    traits::vector_storage_const (x),
#endif
                    traits::vector_stride (x),
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
                    traits::vector_storage (y),
#else
                    traits::vector_storage_const (y),
#endif
                    traits::vector_stride (y),
                    traits::matrix_storage (a),
                    traits::leading_dimension (a));
    }

    // A <- x * y^H + A
    template <typename Matr, typename VctX, typename VctY>
    inline
    void gerc (VctX const& x, VctY const& y, Matr& a) {
#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
      typedef typename traits::matrix_traits<Matr>::value_type val_t;
#else
      typedef typename Matr::value_type val_t;
#endif
      gerc ((val_t) 1, x, y, a);
    }

    // A <- alpha * x * x^T + A
    // A real symmetric (see leading comments for 'symv()')
    template <typename T, typename SymmM, typename VctX>
    inline
    void syr (CBLAS_UPLO const uplo, T const& alpha, VctX const& x, SymmM& a) {
#ifndef BOOST_NUMERIC_BINDINGS_NO_STRUCTURE_CHECK
      BOOST_STATIC_ASSERT((boost::is_same<
        typename traits::matrix_traits<SymmM>::matrix_structure,
        traits::general_t
      >::value));
#endif

      int const n = traits::matrix_size1 (a);
      assert (n == traits::matrix_size2 (a));
      assert (traits::vector_size (x) >= n);

      CBLAS_ORDER const stor_ord
        = enum_cast<CBLAS_ORDER const>
        (storage_order<
#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
           typename traits::matrix_traits<SymmM>::ordering_type
#else
           typename SymmM::orientation_category
#endif
         >::value);

      detail::syr (stor_ord, uplo, n, alpha,
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
                   traits::vector_storage (x),
#else
                   traits::vector_storage_const (x),
#endif
                   traits::vector_stride (x),
                   traits::matrix_storage (a),
                   traits::leading_dimension (a));
    }

    template <typename T, typename SymmM, typename VctX>
    inline
    void syr (T const& alpha, VctX const& x, SymmM& a) {
#ifndef BOOST_NUMERIC_BINDINGS_NO_STRUCTURE_CHECK
      BOOST_STATIC_ASSERT((boost::is_same<
        typename traits::matrix_traits<SymmM>::matrix_structure,
        traits::symmetric_t
      >::value));
#endif

      int const n = traits::matrix_size1 (a);
      assert (n == traits::matrix_size2 (a));
      assert (traits::vector_size (x) >= n);

      CBLAS_ORDER const stor_ord
        = enum_cast<CBLAS_ORDER const>
        (storage_order<
#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
           typename traits::matrix_traits<SymmM>::ordering_type
#else
           typename SymmM::orientation_category
#endif
         >::value);

      CBLAS_UPLO const uplo
        = enum_cast<CBLAS_UPLO const>
        (uplo_triang<
#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
           typename traits::matrix_traits<SymmM>::uplo_type
#else
           typename SymmM::packed_category
#endif
         >::value);

      detail::syr (stor_ord, uplo, n, alpha,
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
                   traits::vector_storage (x),
#else
                   traits::vector_storage_const (x),
#endif
                   traits::vector_stride (x),
                   traits::matrix_storage (a),
                   traits::leading_dimension (a));
    }

    // A <- x * x^T + A
    template <typename SymmM, typename VctX>
    inline
    void syr (VctX const& x, SymmM& a) {
#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
      typedef typename traits::matrix_traits<SymmM>::value_type val_t;
#else
      typedef typename SymmM::value_type val_t;
#endif
      syr ((val_t) 1, x, a);
    }

    // A <- alpha * x * x^T + A
    // A real symmetric in packed form (see leading comments for 'spmv()')
    template <typename T, typename SymmM, typename VctX>
    inline
    void spr (T const& alpha, VctX const& x, SymmM& a) {
#ifndef BOOST_NUMERIC_BINDINGS_NO_STRUCTURE_CHECK
      BOOST_STATIC_ASSERT((boost::is_same<
        typename traits::matrix_traits<SymmM>::matrix_structure,
        traits::symmetric_packed_t
      >::value));
#endif

      int const n = traits::matrix_size1 (a);
      assert (n == traits::matrix_size2 (a));
      assert (traits::vector_size (x) >= n);

      CBLAS_ORDER const stor_ord
        = enum_cast<CBLAS_ORDER const>
        (storage_order<
#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
           typename traits::matrix_traits<SymmM>::ordering_type
#else
           typename SymmM::orientation_category
#endif
         >::value);

      CBLAS_UPLO const uplo
        = enum_cast<CBLAS_UPLO const>
        (uplo_triang<
#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
           typename traits::matrix_traits<SymmM>::uplo_type
#else
           typename SymmM::packed_category
#endif
         >::value);

      detail::spr (stor_ord, uplo, n, alpha,
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
                   traits::vector_storage (x),
#else
                   traits::vector_storage_const (x),
#endif
                   traits::vector_stride (x),
                   traits::matrix_storage (a));
    }

    // A <- x * x^T + A
    template <typename SymmM, typename VctX>
    inline
    void spr (VctX const& x, SymmM& a) {
#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
      typedef typename traits::matrix_traits<SymmM>::value_type val_t;
#else
      typedef typename SymmM::value_type val_t;
#endif
      spr ((val_t) 1, x, a);
    }

    // A <- alpha * x * y^T + alpha * y * x^T + A
    // A real symmetric (see leading comments for 'symv()')
    template <typename T, typename SymmM, typename VctX, typename VctY>
    inline
    void syr2 (CBLAS_UPLO const uplo, T const& alpha,
               VctX const& x, VctY const& y, SymmM& a)
    {
#ifndef BOOST_NUMERIC_BINDINGS_NO_STRUCTURE_CHECK
      BOOST_STATIC_ASSERT((boost::is_same<
        typename traits::matrix_traits<SymmM>::matrix_structure,
        traits::general_t
      >::value));
#endif

      int const n = traits::matrix_size1 (a);
      assert (n == traits::matrix_size2 (a));
      assert (traits::vector_size (x) >= n);
      assert (traits::vector_size (y) >= n);

      CBLAS_ORDER const stor_ord
        = enum_cast<CBLAS_ORDER const>
        (storage_order<
#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
           typename traits::matrix_traits<SymmM>::ordering_type
#else
           typename SymmM::orientation_category
#endif
         >::value);

      detail::syr2 (stor_ord, uplo, n, alpha,
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
                    traits::vector_storage (x),
#else
                    traits::vector_storage_const (x),
#endif
                    traits::vector_stride (x),
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
                    traits::vector_storage (y),
#else
                    traits::vector_storage_const (y),
#endif
                    traits::vector_stride (y),
                    traits::matrix_storage (a),
                    traits::leading_dimension (a));
    }

    template <typename T, typename SymmM, typename VctX, typename VctY>
    inline
    void syr2 (T const& alpha, VctX const& x, VctY const& y, SymmM& a) {
#ifndef BOOST_NUMERIC_BINDINGS_NO_STRUCTURE_CHECK
      BOOST_STATIC_ASSERT((boost::is_same<
        typename traits::matrix_traits<SymmM>::matrix_structure,
        traits::symmetric_t
      >::value));
#endif

      int const n = traits::matrix_size1 (a);
      assert (n == traits::matrix_size2 (a));
      assert (traits::vector_size (x) >= n);
      assert (traits::vector_size (y) >= n);

      CBLAS_ORDER const stor_ord
        = enum_cast<CBLAS_ORDER const>
        (storage_order<
#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
           typename traits::matrix_traits<SymmM>::ordering_type
#else
           typename SymmM::orientation_category
#endif
         >::value);

      CBLAS_UPLO const uplo
        = enum_cast<CBLAS_UPLO const>
        (uplo_triang<
#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
           typename traits::matrix_traits<SymmM>::uplo_type
#else
           typename SymmM::packed_category
#endif
         >::value);

      detail::syr2 (stor_ord, uplo, n, alpha,
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
                    traits::vector_storage (x),
#else
                    traits::vector_storage_const (x),
#endif
                    traits::vector_stride (x),
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
                    traits::vector_storage (y),
#else
                    traits::vector_storage_const (y),
#endif
                    traits::vector_stride (y),
                    traits::matrix_storage (a),
                    traits::leading_dimension (a));
    }

    // A <- x * y^T + y * x^T + A
    template <typename SymmM, typename VctX, typename VctY>
    inline
    void syr2 (VctX const& x, VctY const& y, SymmM& a) {
#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
      typedef typename traits::matrix_traits<SymmM>::value_type val_t;
#else
      typedef typename SymmM::value_type val_t;
#endif
      syr2 ((val_t) 1, x, y, a);
    }

    // A <- alpha * x * y^T + alpha * y * x^T + A
    // A real symmetric in packed form (see leading comments for 'spmv()')
    template <typename T, typename SymmM, typename VctX, typename VctY>
    inline
    void spr2 (T const& alpha, VctX const& x, VctY const& y, SymmM& a) {
#ifndef BOOST_NUMERIC_BINDINGS_NO_STRUCTURE_CHECK
      BOOST_STATIC_ASSERT((boost::is_same<
        typename traits::matrix_traits<SymmM>::matrix_structure,
        traits::symmetric_packed_t
      >::value));
#endif

      int const n = traits::matrix_size1 (a);
      assert (n == traits::matrix_size2 (a));
      assert (traits::vector_size (x) >= n);
      assert (traits::vector_size (y) >= n);

      CBLAS_ORDER const stor_ord
        = enum_cast<CBLAS_ORDER const>
        (storage_order<
#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
           typename traits::matrix_traits<SymmM>::ordering_type
#else
           typename SymmM::orientation_category
#endif
         >::value);

      CBLAS_UPLO const uplo
        = enum_cast<CBLAS_UPLO const>
        (uplo_triang<
#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
           typename traits::matrix_traits<SymmM>::uplo_type
#else
           typename SymmM::packed_category
#endif
         >::value);

      detail::spr2 (stor_ord, uplo, n, alpha,
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
                    traits::vector_storage (x),
#else
                    traits::vector_storage_const (x),
#endif
                    traits::vector_stride (x),
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
                    traits::vector_storage (y),
#else
                    traits::vector_storage_const (y),
#endif
                    traits::vector_stride (y),
                    traits::matrix_storage (a));
    }

    // A <- x * y^T + y * x^T + A
    template <typename SymmM, typename VctX, typename VctY>
    inline
    void spr2 (VctX const& x, VctY const& y, SymmM& a) {
#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
      typedef typename traits::matrix_traits<SymmM>::value_type val_t;
#else
      typedef typename SymmM::value_type val_t;
#endif
      spr2 ((val_t) 1, x, y, a);
    }

    // A <- alpha * x * x^H + A
    // A hermitian
    template <typename T, typename HermM, typename VctX>
    inline
    void her (CBLAS_UPLO const uplo, T const& alpha, VctX const& x, HermM& a) {
#ifndef BOOST_NUMERIC_BINDINGS_NO_STRUCTURE_CHECK
      BOOST_STATIC_ASSERT((boost::is_same<
        typename traits::matrix_traits<HermM>::matrix_structure,
        traits::general_t
      >::value));
#endif

      int const n = traits::matrix_size1 (a);
      assert (n == traits::matrix_size2 (a));
      assert (traits::vector_size (x) >= n);

      CBLAS_ORDER const stor_ord
        = enum_cast<CBLAS_ORDER const>
        (storage_order<
#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
           typename traits::matrix_traits<HermM>::ordering_type
#else
           typename HermM::orientation_category
#endif
         >::value);

      detail::her (stor_ord, uplo, n, alpha,
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
                   traits::vector_storage (x),
#else
                   traits::vector_storage_const (x),
#endif
                   traits::vector_stride (x),
                   traits::matrix_storage (a),
                   traits::leading_dimension (a));
    }

    template <typename T, typename HermM, typename VctX>
    inline
    void her (T const& alpha, VctX const& x, HermM& a) {
#ifndef BOOST_NUMERIC_BINDINGS_NO_STRUCTURE_CHECK
      BOOST_STATIC_ASSERT((boost::is_same<
        typename traits::matrix_traits<HermM>::matrix_structure,
        traits::hermitian_t
      >::value));
#endif

      int const n = traits::matrix_size1 (a);
      assert (n == traits::matrix_size2 (a));
      assert (traits::vector_size (x) >= n);

      CBLAS_ORDER const stor_ord
        = enum_cast<CBLAS_ORDER const>
        (storage_order<
#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
           typename traits::matrix_traits<HermM>::ordering_type
#else
           typename HermM::orientation_category
#endif
         >::value);

      CBLAS_UPLO const uplo
        = enum_cast<CBLAS_UPLO const>
        (uplo_triang<
#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
           typename traits::matrix_traits<HermM>::uplo_type
#else
           typename HermM::packed_category
#endif
         >::value);

      detail::her (stor_ord, uplo, n, alpha,
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
                   traits::vector_storage (x),
#else
                   traits::vector_storage_const (x),
#endif
                   traits::vector_stride (x),
                   traits::matrix_storage (a),
                   traits::leading_dimension (a));
    }

    // A <- x * x^H + A
    template <typename HermM, typename VctX>
    inline
    void her (VctX const& x, HermM& a) {
#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
      typedef typename traits::matrix_traits<HermM>::value_type val_t;
#else
      typedef typename HermM::value_type val_t;
#endif
      typedef typename traits::type_traits<val_t>::real_type real_t;
      her ((real_t) 1, x, a);
    }

    // A <- alpha * x * x^H + A
    // A hermitian in packed form
    template <typename T, typename HermM, typename VctX>
    inline
    void hpr (T const& alpha, VctX const& x, HermM& a) {
#ifndef BOOST_NUMERIC_BINDINGS_NO_STRUCTURE_CHECK
      BOOST_STATIC_ASSERT((boost::is_same<
        typename traits::matrix_traits<HermM>::matrix_structure,
        traits::hermitian_packed_t
      >::value));
#endif

      int const n = traits::matrix_size1 (a);
      assert (n == traits::matrix_size2 (a));
      assert (traits::vector_size (x) >= n);

      CBLAS_ORDER const stor_ord
        = enum_cast<CBLAS_ORDER const>
        (storage_order<
#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
           typename traits::matrix_traits<HermM>::ordering_type
#else
           typename HermM::orientation_category
#endif
         >::value);

      CBLAS_UPLO const uplo
        = enum_cast<CBLAS_UPLO const>
        (uplo_triang<
#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
           typename traits::matrix_traits<HermM>::uplo_type
#else
           typename HermM::packed_category
#endif
         >::value);

      detail::hpr (stor_ord, uplo, n, alpha,
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
                   traits::vector_storage (x),
#else
                   traits::vector_storage_const (x),
#endif
                   traits::vector_stride (x),
                   traits::matrix_storage (a));
    }

    // A <- x * x^H + A
    template <typename HermM, typename VctX>
    inline
    void hpr (VctX const& x, HermM& a) {
#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
      typedef typename traits::matrix_traits<HermM>::value_type val_t;
#else
      typedef typename HermM::value_type val_t;
#endif
      typedef typename traits::type_traits<val_t>::real_type real_t;
      hpr ((real_t) 1, x, a);
    }

    // A <- alpha * x * y^H + y * (alpha * x)^H + A
    // A hermitian
    template <typename T, typename HermM, typename VctX, typename VctY>
    inline
    void her2 (CBLAS_UPLO const uplo, T const& alpha,
               VctX const& x, VctY const& y, HermM& a)
    {
#ifndef BOOST_NUMERIC_BINDINGS_NO_STRUCTURE_CHECK
      BOOST_STATIC_ASSERT((boost::is_same<
        typename traits::matrix_traits<HermM>::matrix_structure,
        traits::general_t
      >::value));
#endif

      int const n = traits::matrix_size1 (a);
      assert (n == traits::matrix_size2 (a));
      assert (traits::vector_size (x) >= n);
      assert (traits::vector_size (y) >= n);

      CBLAS_ORDER const stor_ord
        = enum_cast<CBLAS_ORDER const>
        (storage_order<
#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
           typename traits::matrix_traits<HermM>::ordering_type
#else
           typename HermM::orientation_category
#endif
         >::value);

      detail::her2 (stor_ord, uplo, n, alpha,
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
                    traits::vector_storage (x),
#else
                    traits::vector_storage_const (x),
#endif
                    traits::vector_stride (x),
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
                    traits::vector_storage (y),
#else
                    traits::vector_storage_const (y),
#endif
                    traits::vector_stride (y),
                    traits::matrix_storage (a),
                    traits::leading_dimension (a));
    }

    template <typename T, typename HermM, typename VctX, typename VctY>
    inline
    void her2 (T const& alpha, VctX const& x, VctY const& y, HermM& a) {
#ifndef BOOST_NUMERIC_BINDINGS_NO_STRUCTURE_CHECK
      BOOST_STATIC_ASSERT((boost::is_same<
        typename traits::matrix_traits<HermM>::matrix_structure,
        traits::hermitian_t
      >::value));
#endif

      int const n = traits::matrix_size1 (a);
      assert (n == traits::matrix_size2 (a));
      assert (traits::vector_size (x) >= n);
      assert (traits::vector_size (y) >= n);

      CBLAS_ORDER const stor_ord
        = enum_cast<CBLAS_ORDER const>
        (storage_order<
#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
           typename traits::matrix_traits<HermM>::ordering_type
#else
           typename HermM::orientation_category
#endif
         >::value);

      CBLAS_UPLO const uplo
        = enum_cast<CBLAS_UPLO const>
        (uplo_triang<
#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
           typename traits::matrix_traits<HermM>::uplo_type
#else
           typename HermM::packed_category
#endif
         >::value);

      detail::her2 (stor_ord, uplo, n, alpha,
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
                    traits::vector_storage (x),
#else
                    traits::vector_storage_const (x),
#endif
                    traits::vector_stride (x),
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
                    traits::vector_storage (y),
#else
                    traits::vector_storage_const (y),
#endif
                    traits::vector_stride (y),
                    traits::matrix_storage (a),
                    traits::leading_dimension (a));
    }

    // A <- x * y^H + y * x^H + A
    template <typename HermM, typename VctX, typename VctY>
    inline
    void her2 (VctX const& x, VctY const& y, HermM& a) {
#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
      typedef typename traits::matrix_traits<HermM>::value_type val_t;
#else
      typedef typename HermM::value_type val_t;
#endif
      her2 ((val_t) 1, x, y, a);
    }

    // A <- alpha * x * y^H + y * (alpha * x)^H + A
    // A hermitian in packed form
    template <typename T, typename HermM, typename VctX, typename VctY>
    inline
    void hpr2 (T const& alpha, VctX const& x, VctY const& y, HermM& a) {
#ifndef BOOST_NUMERIC_BINDINGS_NO_STRUCTURE_CHECK
      BOOST_STATIC_ASSERT((boost::is_same<
        typename traits::matrix_traits<HermM>::matrix_structure,
        traits::hermitian_packed_t
      >::value));
#endif

      int const n = traits::matrix_size1 (a);
      assert (n == traits::matrix_size2 (a));
      assert (traits::vector_size (x) >= n);
      assert (traits::vector_size (y) >= n);

      CBLAS_ORDER const stor_ord
        = enum_cast<CBLAS_ORDER const>
        (storage_order<
#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
           typename traits::matrix_traits<HermM>::ordering_type
#else
           typename HermM::orientation_category
#endif
         >::value);

      CBLAS_UPLO const uplo
        = enum_cast<CBLAS_UPLO const>
        (uplo_triang<
#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
           typename traits::matrix_traits<HermM>::uplo_type
#else
           typename HermM::packed_category
#endif
         >::value);

      detail::hpr2 (stor_ord, uplo, n, alpha,
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
                    traits::vector_storage (x),
#else
                    traits::vector_storage_const (x),
#endif
                    traits::vector_stride (x),
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
                    traits::vector_storage (y),
#else
                    traits::vector_storage_const (y),
#endif
                    traits::vector_stride (y),
                    traits::matrix_storage (a));
    }

    // A <- x * y^H + y * x^H + A
    template <typename HermM, typename VctX, typename VctY>
    inline
    void hpr2 (VctX const& x, VctY const& y, HermM& a) {
#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
      typedef typename traits::matrix_traits<HermM>::value_type val_t;
#else
      typedef typename HermM::value_type val_t;
#endif
      hpr2 ((val_t) 1, x, y, a);
    }

  } // namespace atlas

}}}

#endif // BOOST_NUMERIC_BINDINGS_CBLAS_LEVEL_2_HPP


text: #include <boost/preprocessor/slot.hpp>

max_stars_repo_name: miathedev/BoostForArduino

max_issues_repo_name: miathedev/BoostForArduino

max_forks_repo_name: miathedev/BoostForArduino