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

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

allow construction of view into zero-sized Vector.

  • 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.6 KB
RevLine 
[22]1// $Id: VectorConstView.cc 3104 2013-11-02 02:42:56Z peter $
[12]2
[570]3/*
4  Copyright (C) 2003 Daniel Dalevi, Peter Johansson
[2119]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
[2787]8  Copyright (C) 2009, 2012 Peter Johansson
[570]9
[1437]10  This file is part of the yat library, http://dev.thep.lu.se/trac/yat
[570]11
[675]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
[1486]14  published by the Free Software Foundation; either version 3 of the
[675]15  License, or (at your option) any later version.
[570]16
[675]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
[570]20  General Public License for more details.
21
22  You should have received a copy of the GNU General Public License
[1487]23  along with yat. If not, see <http://www.gnu.org/licenses/>.
[570]24*/
25
[2881]26#include <config.h>
27
[1027]28#include "VectorConstView.h"
[1121]29#include "Matrix.h"
[125]30
[42]31namespace theplu {
[680]32namespace yat {
[616]33namespace utility {
[12]34
35
[1027]36  VectorConstView::VectorConstView(const VectorConstView& other)
[1130]37    : VectorBase(), const_view_(NULL)
[686]38  {
[1710]39    copy(other);
[686]40  }
[12]41
[686]42
[1027]43  VectorConstView::VectorConstView(const VectorBase& other)
[1130]44    : VectorBase(), const_view_(NULL)
[1008]45  {
[1710]46    copy(other);
[1008]47  }
48
49
[1027]50  VectorConstView::VectorConstView(const VectorBase& v, size_t offset,size_t n,
51                                   size_t stride)
52    : VectorBase()
[1008]53  {
54    const_view_ = new gsl_vector_const_view(
[2687]55                   gsl_vector_const_subvector_with_stride(v.gsl_vector_p(),
[1008]56                                                          offset, stride,n));
57    const_vec_ = &(const_view_->vector);
58  }
59
60
[1121]61  VectorConstView::VectorConstView(const Matrix& m, size_t i, bool row)
[1015]62    : VectorBase(), const_view_(NULL)
[42]63  {
[2687]64    const_view_ =
65      new gsl_vector_const_view(row ?
[1008]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
[1027]72  VectorConstView::~VectorConstView(void)
[42]73  {
[1008]74    delete_allocated_memory();
[42]75  }
[22]76
[42]77
[1710]78  void VectorConstView::copy(const VectorBase& other)
[42]79  {
[3104]80    if (!other.gsl_vector_p()) // nothing to do
81      return;
[2687]82    const_view_ =
83      new gsl_vector_const_view(gsl_vector_const_subvector(other.gsl_vector_p(),
[1710]84                                                           0, other.size()));
85    const_vec_ = &(const_view_->vector);
[1008]86  }
87
88
[1027]89  void VectorConstView::delete_allocated_memory(void)
[1008]90  {
[1710]91    delete const_view_;
92    const_view_=NULL;
[1027]93    const_vec_ = NULL;
[810]94  }
95
96
[1710]97  bool VectorConstView::isview(void) const
98  {
99    return true;
100  }
101
[686]102}}} // of namespace utility, yat, and thep
Note: See TracBrowser for help on using the repository browser.