source: trunk/yat/utility/VectorConstView.cc @ 1714

Last change on this file since 1714 was 1714, checked in by Peter, 12 years ago

left over

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.4 KB
Line 
1// $Id: VectorConstView.cc 1714 2009-01-13 19:58:08Z peter $
2
3/*
4  Copyright (C) 2003 Daniel Dalevi, Peter Johansson
5  Copyright (C) 2004 Jari Häkkinen, Peter Johansson
6  Copyright (C) 2005, 2006, 2007 Jari Häkkinen, Peter Johansson, Markus Ringnér
7  Copyright (C) 2008, 2009 Peter Johansson
8
9  This file is part of the yat library, http://dev.thep.lu.se/trac/yat
10
11  The yat library is free software; you can redistribute it and/or
12  modify it under the terms of the GNU General Public License as
13  published by the Free Software Foundation; either version 3 of the
14  License, or (at your option) any later version.
15
16  The yat library is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  General Public License for more details.
20
21  You should have received a copy of the GNU General Public License
22  along with yat. If not, see <http://www.gnu.org/licenses/>.
23*/
24
25#include "VectorConstView.h"
26#include "Matrix.h"
27
28namespace theplu {
29namespace yat {
30namespace utility {
31
32
33  VectorConstView::VectorConstView(const VectorConstView& other)
34    : VectorBase(), const_view_(NULL)
35  {
36    copy(other);
37  }
38
39
40  VectorConstView::VectorConstView(const VectorBase& other)
41    : VectorBase(), const_view_(NULL)
42  {
43    copy(other);
44  }
45
46
47  VectorConstView::VectorConstView(const VectorBase& v, size_t offset,size_t n,
48                                   size_t stride)
49    : VectorBase()
50  {
51    const_view_ = new gsl_vector_const_view(
52                   gsl_vector_const_subvector_with_stride(v.gsl_vector_p(), 
53                                                          offset, stride,n));
54    const_vec_ = &(const_view_->vector);
55  }
56
57
58  VectorConstView::VectorConstView(const Matrix& m, size_t i, bool row)
59    : VectorBase(), const_view_(NULL)
60  {
61    const_view_ = 
62      new gsl_vector_const_view(row ? 
63                                gsl_matrix_const_row(m.gsl_matrix_p(),i) :
64                                gsl_matrix_const_column(m.gsl_matrix_p(),i));
65    const_vec_ = &(const_view_->vector);
66  }
67
68
69  VectorConstView::~VectorConstView(void)
70  {
71    delete_allocated_memory();
72  }
73
74
75  void VectorConstView::copy(const VectorBase& other)
76  {
77    const_view_ = 
78      new gsl_vector_const_view(gsl_vector_const_subvector(other.gsl_vector_p(), 
79                                                           0, other.size()));
80    const_vec_ = &(const_view_->vector);
81  }
82
83
84  void VectorConstView::delete_allocated_memory(void)
85  {
86    delete const_view_;
87    const_view_=NULL;
88    const_vec_ = NULL;
89  }
90
91
92  bool VectorConstView::isview(void) const
93  {
94    return true;
95  }
96
97}}} // of namespace utility, yat, and thep
Note: See TracBrowser for help on using the repository browser.