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

Last change on this file since 2992 was 2992, checked in by Peter, 8 years ago

set svndigest:ignore proprty to reflect when files were initially copied from other file (and early history should be ignored). closes #750

  • 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.5 KB
Line 
1// $Id: VectorConstView.cc 2992 2013-03-03 05:03:44Z 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 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
31namespace theplu {
32namespace yat {
33namespace utility {
34
35
36  VectorConstView::VectorConstView(const VectorConstView& other)
37    : VectorBase(), const_view_(NULL)
38  {
39    copy(other);
40  }
41
42
43  VectorConstView::VectorConstView(const VectorBase& other)
44    : VectorBase(), const_view_(NULL)
45  {
46    copy(other);
47  }
48
49
50  VectorConstView::VectorConstView(const VectorBase& v, size_t offset,size_t n,
51                                   size_t stride)
52    : VectorBase()
53  {
54    const_view_ = new gsl_vector_const_view(
55                   gsl_vector_const_subvector_with_stride(v.gsl_vector_p(),
56                                                          offset, stride,n));
57    const_vec_ = &(const_view_->vector);
58  }
59
60
61  VectorConstView::VectorConstView(const Matrix& m, size_t i, bool row)
62    : VectorBase(), const_view_(NULL)
63  {
64    const_view_ =
65      new gsl_vector_const_view(row ?
66                                gsl_matrix_const_row(m.gsl_matrix_p(),i) :
67                                gsl_matrix_const_column(m.gsl_matrix_p(),i));
68    const_vec_ = &(const_view_->vector);
69  }
70
71
72  VectorConstView::~VectorConstView(void)
73  {
74    delete_allocated_memory();
75  }
76
77
78  void VectorConstView::copy(const VectorBase& other)
79  {
80    const_view_ =
81      new gsl_vector_const_view(gsl_vector_const_subvector(other.gsl_vector_p(),
82                                                           0, other.size()));
83    const_vec_ = &(const_view_->vector);
84  }
85
86
87  void VectorConstView::delete_allocated_memory(void)
88  {
89    delete const_view_;
90    const_view_=NULL;
91    const_vec_ = NULL;
92  }
93
94
95  bool VectorConstView::isview(void) const
96  {
97    return true;
98  }
99
100}}} // of namespace utility, yat, and thep
Note: See TracBrowser for help on using the repository browser.