ViennaCL - The Vienna Computing Library: viennacl/slice.hpp Source File

ViennaCL - The Vienna Computing Library 1.7.1 Free open-source GPU-accelerated linear algebra and solver library. |

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
slice.hpp
Go to the documentation of this file.
1 #ifndef VIENNACL_SLICE_HPP_
2 #define VIENNACL_SLICE_HPP_
3
4 /* =========================================================================
5 Copyright (c) 2010-2016, Institute for Microelectronics,
6 Institute for Analysis and Scientific Computing,
7 TU Wien.
8 Portions of this software are copyright by UChicago Argonne, LLC.
9
10 -----------------
11 ViennaCL - The Vienna Computing Library
12 -----------------
13
14 Project Head: Karl Rupp rupp@iue.tuwien.ac.at
15
16 (A list of authors and contributors can be found in the manual)
17
18 License: MIT (X11), see file LICENSE in the base directory
19 ============================================================================= */
20
25 #include <vector>
26 #include <stddef.h>
27 #include <assert.h>
28 #include "viennacl/forwards.h"
29
30 namespace viennacl
31 {
32
37 template<typename SizeT /* see forwards.h for default argument*/,
38 typename DistanceT /* see forwards.h for default argument*/>
39 class basic_slice
40 {
41 public:
42 typedef SizeT size_type;
43 typedef DistanceT difference_type;
44 typedef size_type value_type;
45 typedef value_type const_reference;
46 typedef const_reference reference;
47
48 basic_slice() : start_(0), stride_(1), size_(0) {}
49 basic_slice(size_type start_index,
50 size_type stride_arg,
51 size_type size_arg) : start_(start_index), stride_(stride_arg), size_(size_arg) {}
52
53
54 size_type start() const { return start_; }
55 size_type stride() const { return stride_; }
56 size_type size() const { return size_; }
57
58 const_reference operator()(size_type i) const
59 {
60 assert(i < size());
61 return start_ + i * stride_;
62 }
63 const_reference operator[](size_type i) const { return operator()(i); }
64
65 bool operator==(const basic_slice & s) const { return (start_ == s.start_) && (stride_ == s.stride_) && (size_ == s.size_); }
66 bool operator!=(const basic_slice & s) const { return !(*this == s); }
67
68 private:
69 size_type start_;
70 size_type stride_;
71 size_type size_;
72 };
73
74
75 }
76
77 #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