source: trunk/yat/utility/VectorConstView.cc

Last change on this file was 4207, checked in by Peter, 6 weeks ago

update copyright statements

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
  • Property svndigest:ignore set to 1026
File size: 3.2 KB
Line 
1// $Id: VectorConstView.cc 4207 2022-08-26 04:36:28Z 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, 2021, 2022 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 "MatrixBase.h"
30#include "VectorView.h"
31
32#include <cassert>
33
34namespace theplu {
35namespace yat {
36namespace utility {
37
38
39  VectorConstView::VectorConstView(const VectorConstView& other)
40    : VectorBase(), const_view_(NULL)
41  {
42    copy(other);
43  }
44
45
46  VectorConstView::VectorConstView(const VectorView& other)
47    : VectorBase(), const_view_(NULL)
48  {
49    copy(other);
50  }
51
52
53  VectorConstView::VectorConstView(const VectorBase& other)
54    : VectorBase(), const_view_(NULL)
55  {
56    copy(other);
57  }
58
59
60  VectorConstView::VectorConstView(const VectorBase& v, size_t offset,size_t n,
61                                   size_t stride)
62    : VectorBase()
63  {
64    const_view_ = new gsl_vector_const_view(
65                   gsl_vector_const_subvector_with_stride(v.gsl_vector_p(),
66                                                          offset, stride,n));
67    const_vec_ = &(const_view_->vector);
68  }
69
70
71  VectorConstView::VectorConstView(const MatrixBase& m, size_t i, bool row)
72    : VectorBase(), const_view_(NULL)
73  {
74    const_view_ =
75      new gsl_vector_const_view(row ?
76                                gsl_matrix_const_row(m.gsl_matrix_p(),i) :
77                                gsl_matrix_const_column(m.gsl_matrix_p(),i));
78    const_vec_ = &(const_view_->vector);
79  }
80
81
82  VectorConstView::VectorConstView(const gsl_vector* v)
83  {
84    const_view_ =
85      new gsl_vector_const_view(gsl_vector_const_subvector(v, 0, v->size));
86    const_vec_ = &(const_view_->vector);
87  }
88
89
90  VectorConstView::VectorConstView(const double* v, size_t size, size_t stride)
91  {
92    const_view_ =
93      new gsl_vector_const_view(gsl_vector_const_view_array_with_stride(v,
94                                                                        stride,
95                                                                        size));
96    const_vec_ = &(const_view_->vector);
97  }
98
99
100  VectorConstView::~VectorConstView(void)
101  {
102    delete_allocated_memory();
103  }
104
105
106  void VectorConstView::copy(const VectorBase& other)
107  {
108    if (!other.gsl_vector_p()) // nothing to do
109      return;
110    const_view_ =
111      new gsl_vector_const_view(gsl_vector_const_subvector(other.gsl_vector_p(),
112                                                           0, other.size()));
113    const_vec_ = &(const_view_->vector);
114  }
115
116
117  void VectorConstView::delete_allocated_memory(void)
118  {
119    delete const_view_;
120    const_view_=NULL;
121    const_vec_ = NULL;
122  }
123
124
125  bool VectorConstView::isview(void) const
126  {
127    return true;
128  }
129
130}}} // of namespace utility, yat, and thep
Note: See TracBrowser for help on using the repository browser.