Statistics
| Revision:

root / trunk / src / linad99 / dvect17.cpp @ 1609

History | View | Annotate | Download (710 Bytes)

1 417 arnima
/*
2
 * $Id$
3
 *
4
 * Author: David Fournier
5 1112 johnoel
 * Copyright (c) 2008-2012 Regents of the University of California
6 417 arnima
 */
7
/**
8
 * \file
9
 * Description not yet available.
10
 */
11
#include "fvar.hpp"
12
13
/**
14 1609 stevenmartell
 * Extract the diagonal elements from a matrix and return the corresponding vector
15
 * \param m a dmatrix
16
 * \return a dvector correpsonding to the diagonal elements.
17 417 arnima
 */
18 441 johnoel
dvector extract_diagonal(const dmatrix& m)
19 1112 johnoel
{
20
  if ( (m.rowmin()!=m.colmin()) || (m.rowmax()!=m.colmax()))
21 417 arnima
  {
22 1112 johnoel
    cerr << "Error in extract_diagonal function -- input matrix not square" <<endl;
23
    ad_exit(1);
24
  }
25 417 arnima
26 1112 johnoel
  dvector tmp(m.rowmin(),m.rowmax());
27
  for (int i=m.rowmin(); i<=m.rowmax(); i++)
28
  {
29
    tmp.elem(i)=m.elem(i,i);
30 417 arnima
  }
31 1112 johnoel
32
  return(tmp);
33
}