All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
slice.hpp
Go to the documentation of this file.
#ifndef VIENNACL_SLICE_HPP_
#define VIENNACL_SLICE_HPP_
/* =========================================================================
Copyright (c) 2010-2016, Institute for Microelectronics,
Institute for Analysis and Scientific Computing,
TU Wien.
Portions of this software are copyright by UChicago Argonne, LLC.
-----------------
ViennaCL - The Vienna Computing Library
-----------------
Project Head: Karl Rupp rupp@iue.tuwien.ac.at
(A list of authors and contributors can be found in the manual)
License: MIT (X11), see file LICENSE in the base directory
============================================================================= */
#include <vector>
#include <stddef.h>
#include <assert.h>
#include "viennacl/forwards.h"
namespace viennacl
{
template<typename SizeT /* see forwards.h for default argument*/,
typename DistanceT /* see forwards.h for default argument*/>
class basic_slice
{
public:
typedef SizeT size_type;
typedef DistanceT difference_type;
typedef size_type value_type;
typedef value_type const_reference;
typedef const_reference reference;
basic_slice() : start_(0), stride_(1), size_(0) {}
basic_slice(size_type start_index,
size_type stride_arg,
size_type size_arg) : start_(start_index), stride_(stride_arg), size_(size_arg) {}
size_type start() const { return start_; }
size_type stride() const { return stride_; }
size_type size() const { return size_; }
const_reference operator()(size_type i) const
{
assert(i < size());
return start_ + i * stride_;
}
const_reference operator[](size_type i) const { return operator()(i); }
bool operator==(const basic_slice & s) const { return (start_ == s.start_) && (stride_ == s.stride_) && (size_ == s.size_); }
bool operator!=(const basic_slice & s) const { return !(*this == s); }
private:
size_type start_;
size_type stride_;
size_type size_;
};
}
#endif
viennacl::basic_slice::operator==
bool operator==(const basic_slice &s) const
Definition: slice.hpp:65
viennacl::basic_slice::operator[]
const_reference operator[](size_type i) const
Definition: slice.hpp:63
viennacl::basic_slice::basic_slice
basic_slice()
Definition: slice.hpp:48
viennacl::basic_slice::value_type
size_type value_type
Definition: slice.hpp:44
viennacl::basic_slice::size
size_type size() const
Definition: slice.hpp:56
viennacl::basic_slice::operator!=
bool operator!=(const basic_slice &s) const
Definition: slice.hpp:66
viennacl::basic_slice::start
size_type start() const
Definition: slice.hpp:54
forwards.h
This file provides the forward declarations for the main types used within ViennaCL.
viennacl::basic_slice::size_type
SizeT size_type
Definition: slice.hpp:42
viennacl::basic_slice::basic_slice
basic_slice(size_type start_index, size_type stride_arg, size_type size_arg)
Definition: slice.hpp:49
viennacl::basic_slice::operator()
const_reference operator()(size_type i) const
Definition: slice.hpp:58
viennacl::basic_slice::reference
const_reference reference
Definition: slice.hpp:46
viennacl::basic_slice::difference_type
DistanceT difference_type
Definition: slice.hpp:43
viennacl::basic_slice::const_reference
value_type const_reference
Definition: slice.hpp:45
viennacl::basic_slice
A slice class that refers to an interval [start, stop), where 'start' is included, and 'stop' is excluded.
Definition: forwards.h:429
viennacl::basic_slice::stride
size_type stride() const
Definition: slice.hpp:55