Ignore:
Timestamp:
Mar 5, 2007, 10:45:32 PM (16 years ago)
Author:
Jari Häkkinen
Message:

Fixes #155. Added asserts to check vectors in all non-const functions since no inline functions exists anymore.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/yat/utility/vector.cc

    r782 r783  
    3030#include "utility.h"
    3131
     32#include <cassert>
    3233#include <iostream>
    3334#include <sstream>
     35#include <utility>
    3436#include <vector>
    35 #include <utility>
    3637
    3738namespace theplu {
     
    211212  void vector::div(const vector& other)
    212213  {
     214    assert(v_); assert(other.v_);
    213215    int status=gsl_vector_div(v_,other.v_);
    214216    if (status)
     
    237239  void vector::mul(const vector& other)
    238240  {
     241    assert(v_); assert(other.v_);
    239242    int status=gsl_vector_mul(v_,other.v_);
    240243    if (status)
     
    245248  void vector::reverse(void)
    246249  {
     250    assert(v_);
    247251    gsl_vector_reverse(v_);
    248252  }
     
    251255  void vector::set(const vector& vec)
    252256  {
     257    assert(v_); assert(vec.v_);
    253258    if (gsl_vector_memcpy(v_,vec.v_))
    254259      throw utility::GSL_error("vector::set dimension mis-match");
     
    258263  void vector::set_all(const double& value)
    259264  {
     265    assert(v_);
    260266    gsl_vector_set_all(v_,value);
    261267  }
     
    272278  void vector::swap(size_t i, size_t j)
    273279  {
     280    assert(v_);
    274281    int status=gsl_vector_swap_elements(v_, i, j);
    275282    if (status)
     
    280287  double& vector::operator()(size_t i)
    281288  {
     289    assert(v_);
    282290    double* d=gsl_vector_ptr(v_, i);
    283291    if (!d)
     
    348356  const vector& vector::operator+=(const vector& other)
    349357  {
    350     int status=gsl_vector_add(v_,other. v_);
     358    assert(v_);
     359    int status=gsl_vector_add(v_, other.v_);
    351360    if (status)
    352361      throw utility::GSL_error(std::string("vector::add", status));
     
    357366  const vector& vector::operator+=(double d)
    358367  {
     368    assert(v_);
    359369    gsl_vector_add_constant(v_, d);
    360370    return *this;
     
    364374  const vector& vector::operator-=(const vector& other)
    365375  {
     376    assert(v_);
    366377    int status=gsl_vector_sub(v_, other.v_);
    367378    if (status)
     
    373384  const vector& vector::operator*=(const double d)
    374385  {
     386    assert(v_);
    375387    gsl_vector_scale(v_, d);
    376388    return *this;
     
    426438  void set_basis(vector& v, size_t i)
    427439  {
     440    assert(v.gsl_vector_p());
    428441    gsl_vector_set_basis(v.gsl_vector_p(),i);
    429442  }
     
    432445  void sort(vector& v)
    433446  {
     447    assert(v.gsl_vector_p());
    434448    gsl_sort_vector(v.gsl_vector_p());
    435449  }
     
    448462  void swap(vector& v, vector& w)
    449463  {
     464    assert(v.gsl_vector_p()); assert(w.gsl_vector_p());
    450465    int status=gsl_vector_swap(v.gsl_vector_p(),w.gsl_vector_p());
    451466    if (status)
Note: See TracChangeset for help on using the changeset viewer.