Skip to content

Instantly share code, notes, and snippets.

@daniel-perry
daniel-perry / inverse.cc
Created December 11, 2012 23:53
inverse of a symmetric matrix... taking into account singularity due to numerical error...
template < class MatrixType >
MatrixType inverse(const MatrixType & m)
{
typedef itk::Vector<typename MatrixType::ValueType, MatrixType::RowDimensions> VectorType;
typedef itk::SymmetricEigenAnalysis<MatrixType,VectorType> EigenAnalysisType;
EigenAnalysisType eigenAnalysis;
eigenAnalysis.SetOrderEigenMagnitudes(true); // order by abs val of eigenvals..
eigenAnalysis.SetDimension(MatrixType::RowDimensions);
VectorType eigenVals;
MatrixType eigenVecs;
@daniel-perry
daniel-perry / ssh-agent-singleton-bashrc.sh
Created August 3, 2012 21:58
how to setup ssh-agent so there is only one process running.
# ssh-agent singleton setup
# If no SSH agent is already running, start one now. Re-use sockets so we never
# have to start more than one session.
export SSH_AUTH_SOCK=$HOME/.ssh-socket
NKEYS_SSHAGENT=`ssh-add -l 2> /dev/null | wc -l`
if [ $NKEYS_SSHAGENT = 0 ]; then
# No ssh-agent running
rm -f $SSH_AUTH_SOCK
ssh-agent -a $SSH_AUTH_SOCK >/tmp/.ssh-script
source /tmp/.ssh-script