dim4.hpp (2020-10-27 00:11:00 -0400, (build d99887ae))
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  * https://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
45  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
124 std::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
140 std::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
AFAPI bool isSpan(const af_seq &seq)
Returns true if the af_seq object represents the entire range of an axis.
Definition: algorithm.h:14
AFAPI array operator==(const array &lhs, const array &rhs)
Performs an equality operation on two arrays or an array and a value.
AFAPI array operator*(const array &lhs, const array &rhs)
Multiplies two arrays or an array and a value.
AFAPI array operator>>(const array &lhs, const array &rhs)
Performs an right shift operation on two arrays or an array and a value.
seq is used to create sequences for indexing af::array
Definition: seq.h:45
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.
long long dim_t
Definition: defines.h:56
AFAPI array operator!=(const array &lhs, const array &rhs)
Performs an inequality operation on two arrays or an array and a value.
#define AFAPI
Definition: defines.h:38
AFAPI array operator<<(const array &lhs, const array &rhs)
Performs an left shift operation on two arrays or an array and a value.
C-style struct to creating sequences for indexing.
Definition: seq.h:20
AFAPI size_t seqElements(const af_seq &seq)
Returns the number of elements that the af_seq object represents.
AFAPI array operator-(const array &lhs, const array &rhs)
Subtracts two arrays or an array and a value.
Generic object that represents size and shape.
Definition: dim4.hpp:25
AFAPI array operator+(const array &lhs, const array &rhs)
Adds two arrays or an array and a value.