Statistics
| Revision:

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

History | View | Annotate | Download (710 Bytes)

1
/*
2
 * $Id: dvect17.cpp 1609 2014-02-05 05:56:01Z stevenmartell $
3
 *
4
 * Author: David Fournier
5
 * Copyright (c) 2008-2012 Regents of the University of California
6
 */
7
/**
8
 * \file
9
 * Description not yet available.
10
 */
11
#include "fvar.hpp"
12

    
13
/**
14
 * 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
 */
18
dvector extract_diagonal(const dmatrix& m)
19
{
20
  if ( (m.rowmin()!=m.colmin()) || (m.rowmax()!=m.colmax()))
21
  {
22
    cerr << "Error in extract_diagonal function -- input matrix not square" <<endl;
23
    ad_exit(1);
24
  }
25

    
26
  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
  }
31

    
32
  return(tmp);
33
}