dim4.hpp (2020-07-07 17:43:34 +0530, (build 218dd2c99))
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 
50  dim4(const unsigned ndims, const dim_t * const dims);
51 
53  dim_t elements();
54 
56  dim_t elements() const;
57 
59  dim_t ndims();
60 
62  dim_t ndims() const;
63 
65  bool operator==(const dim4& other) const;
66 
68  bool operator!=(const dim4& other) const;
69 
71  dim4& operator*=(const dim4& other);
72 
74  dim4& operator+=(const dim4& other);
75 
77  dim4& operator-=(const dim4& other);
78 
80  dim_t& operator[](const unsigned dim);
81 
84  const dim_t& operator[](const unsigned dim) const;
85 
87  dim_t *get() { return dims; }
88 
90  const dim_t* get() const { return dims; }
91 };
92 
94 AFAPI dim4 operator+(const dim4& first, const dim4& second);
95 
97 AFAPI dim4 operator-(const dim4& first, const dim4& second);
98 
100 AFAPI dim4 operator*(const dim4& first, const dim4& second);
101 
107 static inline
108 std::ostream&
109 operator<<(std::ostream& ostr, const dim4& dims)
110 {
111  ostr << dims[0] << " "
112  << dims[1] << " "
113  << dims[2] << " "
114  << dims[3];
115  return ostr;
116 }
117 
123 static inline
124 std::istream&
125 operator>>(std::istream& istr, dim4& dims)
126 {
127  istr >> dims[0]
128  >> dims[1]
129  >> dims[2]
130  >> dims[3];
131  return istr;
132 }
133 
135 AFAPI bool isSpan(const af_seq &seq);
136 
138 AFAPI size_t seqElements(const af_seq &seq);
139 
141 AFAPI dim_t calcDim(const af_seq &seq, const dim_t &parentDim);
142 }
143 
144 #endif
af::dim4
Generic object that represents size and shape.
Definition: dim4.hpp:33
af::operator!=
AFAPI array operator!=(const array &lhs, const array &rhs)
Performs an inequality operation on two arrays or an array and a value.
dim_t
long long dim_t
Definition: defines.h:56
af::operator==
AFAPI array operator==(const array &lhs, const array &rhs)
Performs an equality operation on two arrays or an array and a value.
AFAPI
#define AFAPI
Definition: defines.h:38
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::operator-
AFAPI array operator-(const array &lhs, const array &rhs)
Subtracts two arrays or an array and a value.
af::seqElements
AFAPI size_t seqElements(const af_seq &seq)
Returns the number of elements that the af_seq object represents.
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.
seq.h
af::operator*
AFAPI array operator*(const array &lhs, const array &rhs)
Multiplies two arrays or an array and a value.
af::isSpan
AFAPI bool isSpan(const af_seq &seq)
Returns true if the af_seq object represents the entire range of an axis.
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)
Performs an left shift operation on two arrays or an array and a value.
defines.h
af_seq
C-style struct to creating sequences for indexing.
Definition: seq.h:20