source: trunk/yat/utility/VectorConstView.cc

Last change on this file was 3661, checked in by Peter, 4 years ago

update copyright years

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