A high-performance general-purpose compute library

- Main Page
- Tutorials
- Release Notes
- Examples

dim4.hpp
Go to the documentation of this file.
1/*******************************************************
2 * Copyright (c) 2014, ArrayFire
3 * All rights reserved.
4 *
5 * This file is distributed under 3-clause BSD license.
6 * The complete license agreement can be obtained at:
7 * http://arrayfire.com/licenses/BSD-3-Clause
8 ********************************************************/
9
10#pragma once
11
12#ifdef __cplusplus
13
14#include <ostream>
15#include <istream>
16#include <vector>
17#include <af/defines.h>
18#include <af/seq.h>
19
20
21 namespace af
22{
25 class AFAPI dim4
26{
27 public:
28 dim_t dims[4];
30 dim4();
31
33 dim4( dim_t first,
34 dim_t second = 1,
35 dim_t third = 1,
36 dim_t fourth = 1);
37
41 dim4(const dim4& other);
42
43#if AF_API_VERSION >= 38
44#if AF_COMPILER_CXX_RVALUE_REFERENCES
48 dim4(dim4 &&other) AF_NOEXCEPT = default;
49
53 dim4 &operator=(dim4 other) AF_NOEXCEPT;
54#endif
55#endif
56
65 dim4(const unsigned ndims, const dim_t *const dims);
66
68 dim_t elements();
69
71 dim_t elements() const;
72
74 dim_t ndims();
75
77 dim_t ndims() const;
78
80 bool operator==(const dim4 &other) const;
81
83 bool operator!=(const dim4 &other) const;
84
86 dim4 &operator*=(const dim4 &other);
87
89 dim4 &operator+=(const dim4 &other);
90
92 dim4 &operator-=(const dim4 &other);
93
96 dim_t &operator[](const unsigned dim);
97
100 const dim_t &operator[](const unsigned dim) const;
101
103 dim_t *get() { return dims; }
104
106 const dim_t *get() const { return dims; }
107};
108
110 AFAPI dim4 operator+(const dim4& first, const dim4& second);
111
113 AFAPI dim4 operator-(const dim4& first, const dim4& second);
114
116 AFAPI dim4 operator*(const dim4& first, const dim4& second);
117
123 static inline
124std::ostream&
125 operator<<(std::ostream& ostr, const dim4& dims)
126{
127 ostr << dims[0] << " "
128 << dims[1] << " "
129 << dims[2] << " "
130 << dims[3];
131 return ostr;
132}
133
139 static inline
140std::istream&
141 operator>>(std::istream& istr, dim4& dims)
142{
143 istr >> dims[0]
144 >> dims[1]
145 >> dims[2]
146 >> dims[3];
147 return istr;
148}
149
151 AFAPI bool isSpan(const af_seq &seq);
152
154 AFAPI size_t seqElements(const af_seq &seq);
155
157 AFAPI dim_t calcDim(const af_seq &seq, const dim_t &parentDim);
158}
159
160#endif
af::dim4
Generic object that represents size and shape.
Definition dim4.hpp:26
af::dim4::dim4
dim4(const unsigned ndims, const dim_t *const dims)
Constructs a dim4 object from a C array of dim_t objects.
af::dim4::operator-=
dim4 & operator-=(const dim4 &other)
Element-wise subtraction of the dim4 objects.
af::dim4::operator[]
const dim_t & operator[](const unsigned dim) const
Returns the reference to the element at a give index.
af::dim4::operator[]
dim_t & operator[](const unsigned dim)
Returns the reference to the element at a give index.
af::dim4::get
const dim_t * get() const
Returns the underlying pointer to the dim4 object.
Definition dim4.hpp:106
af::dim4::dim4
dim4(const dim4 &other)
Copy constructor.
af::dim4::operator*=
dim4 & operator*=(const dim4 &other)
Element-wise multiplication of the dim4 objects.
af::dim4::elements
dim_t elements()
Returns the number of elements represented by this dim4.
af::dim4::ndims
dim_t ndims()
Returns the number of axis whose values are greater than one.
af::dim4::operator!=
bool operator!=(const dim4 &other) const
Returns true if two dim4s store different values.
af::dim4::dim4
dim4(dim_t first, dim_t second=1, dim_t third=1, dim_t fourth=1)
Creates an new dim4 given a set of dimension.
af::dim4::elements
dim_t elements() const
Returns the number of elements represented by this dim4.
af::dim4::operator==
bool operator==(const dim4 &other) const
Returns true if the two dim4 represent the same shape.
af::dim4::operator+=
dim4 & operator+=(const dim4 &other)
Element-wise addition of the dim4 objects.
af::dim4::ndims
dim_t ndims() const
Returns the number of axis whose values are greater than one.
af::dim4::get
dim_t * get()
Returns the underlying pointer to the dim4 object.
Definition dim4.hpp:103
af::dim4::dim4
dim4()
Default constructor. Creates an invalid dim4 object.
af::seq
seq is used to create sequences for indexing af::array
Definition seq.h:46
defines.h
dim_t
long long dim_t
Definition defines.h:56
AFAPI
#define AFAPI
Definition defines.h:38
af::operator+
AFAPI array operator+(const array &lhs, const array &rhs)
Adds two arrays or an array and a value.
af::operator*
AFAPI array operator*(const array &lhs, const array &rhs)
Multiplies two arrays or an array and a value.
af::operator<<
AFAPI array operator<<(const array &lhs, const array &rhs)
Performs an left shift operation on two arrays or an array and a value.
af::operator>>
AFAPI array operator>>(const array &lhs, const array &rhs)
Performs an right shift operation on two arrays or an array and a value.
af::operator-
AFAPI array operator-(const array &lhs, const array &rhs)
Subtracts two arrays or an array and a value.
af
Definition algorithm.h:15
af::calcDim
AFAPI dim_t calcDim(const af_seq &seq, const dim_t &parentDim)
Returns the number of elements that will be represented by seq if applied on an array.
af::seqElements
AFAPI size_t seqElements(const af_seq &seq)
Returns the number of elements that the af_seq object represents.
af::isSpan
AFAPI bool isSpan(const af_seq &seq)
Returns true if the af_seq object represents the entire range of an axis.
seq.h
af_seq
C-style struct to creating sequences for indexing.
Definition seq.h:20