Skip to content

Instantly share code, notes, and snippets.

View mtao's full-sized avatar

Michael Tao mtao

View GitHub Profile
#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);
@mtao
mtao / filereader.cpp
Created July 31, 2014 18:33
file_token_reader
#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;
@mtao
mtao / eigen_boost_serialization.hpp
Last active March 15, 2024 02:49
Boost serialization for Eigen Matrix and SparseMatrix structures (plus triplets as a helper in SparseMatrix)
/*
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:
@mtao
mtao / eigen_slice_eats_two.cpp
Last active September 23, 2022 04:52
Eigen always eats the first two values
[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);