This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[mtao@ruemo ~/hg/testcode/c++/eigen/head]% cat main.cpp | |
#include <Eigen/Dense> | |
#include <iostream> | |
int main(int,char**) | |
{ | |
Eigen::Matrix<double,Eigen::Dynamic,1> x(20); | |
std::iota(x.begin(),x.end(),0); | |
// 0 1 2 3 4.... | |
std::cout << x.transpose() << std::endl; | |
x = x.head(x.size()-1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Copyright (c) 2015 Michael Tao | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files (the "Software"), to deal | |
in the Software without restriction, including without limitation the rights | |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
copies of the Software, and to permit persons to whom the Software is | |
furnished to do so, subject to the following conditions: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <fstream> | |
#include <sstream> | |
#include <iostream> | |
#include <iterator> | |
#include <vector> | |
int main(int argc, char * argv[]) { | |
if(argc < 2) { | |
std::cout << "Nothing here!" << std::endl; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <vector> | |
#include <algorithm> | |
#include <iterator> | |
#include <iostream> | |
int main(int argc, char* argv[]) { | |
std::vector<int> indices(1e6); | |
/* | |
std::transform(indices.begin(),indices.end(), indices.begin(), [&indices](int& v) -> int { | |
return std::distance(indices.data(),&v); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <algorithm> | |
#include <iterator> | |
#include <vector> | |
#include <sstream> | |
template <typename T> | |
std::string to_csv(const std::vector<T>& vec) { | |
std::stringstream ss; | |
std::copy(vec.begin(),vec.end()-1,std::ostream_iterator<T>(ss,",")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef PIFDSL_HPP | |
#define PIFDSL_HPP | |
#include <map> | |
namespace pif { | |
using hash = std::map<string,string>; | |
} | |
//example: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ImGui GLUT binding with OpenGL | |
// In this binding, ImTextureID is used to store an OpenGL 'GLuint' texture identifier. Read the FAQ about ImTextureID in imgui.cpp. | |
// If your context is GL3/GL3 then prefer using the code in opengl3_example. | |
// You *might* use this code with a GL3/GL4 context but make sure you disable the programmable pipeline by calling "glUseProgram(0)" before ImGui::Render(). | |
// We cannot do that from GL2 code because the function doesn't exist. | |
// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. | |
// If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown(). | |
// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "active_set.h" | |
#include <set> | |
template <> | |
const ActiveSet::IndexPair& ActiveSet::getIndexPair<ActiveSet::VariableType::Free>() const { | |
return m_active_pair; | |
} | |
template <> | |
const ActiveSet::IndexPair& ActiveSet::getIndexPair<ActiveSet::VariableType::Dirichlet>() const { | |
return m_dirichlet_pair; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <Eigen/Core> | |
//Mimics http://stackoverflow.com/a/40958644 | |
template <typename Scalar, int D, int E, int... Is> | |
auto eigen_unpack_impl(const Eigen::Matrix<Scalar, D, E>& a, std::integer_sequence<int,Is...>) { | |
return std::tie( a(Is)... ); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <tuple> | |
//sample vector class | |
struct Vec3 { | |
public: | |
Vec3(const std::initializer_list<double>& a) { std::copy(a.begin(),a.end(),data); } | |
double& operator()(size_t i) { return data[i]; } | |
private: |
OlderNewer