A high-performance general-purpose compute library
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
21namespace af
22{
26{
27public:
28 dim_t dims[4];
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
69
71 dim_t elements() const;
72
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
110AFAPI dim4 operator+(const dim4& first, const dim4& second);
111
113AFAPI dim4 operator-(const dim4& first, const dim4& second);
114
116AFAPI dim4 operator*(const dim4& first, const dim4& second);
117
123static inline
124std::ostream&
125operator<<(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
139static inline
140std::istream&
141operator>>(std::istream& istr, dim4& dims)
142{
143 istr >> dims[0]
144 >> dims[1]
145 >> dims[2]
146 >> dims[3];
147 return istr;
148}
149
151AFAPI bool isSpan(const af_seq &seq);
152
155
157AFAPI dim_t calcDim(const af_seq &seq, const dim_t &parentDim);
158}
159
160#endif
Generic object that represents size and shape.
Definition: dim4.hpp:26
dim4(const unsigned ndims, const dim_t *const dims)
Constructs a dim4 object from a C array of dim_t objects.
dim4 & operator-=(const dim4 &other)
Element-wise subtraction of the dim4 objects.
const dim_t & operator[](const unsigned dim) const
Returns the reference to the element at a give index.
dim_t & operator[](const unsigned dim)
Returns the reference to the element at a give index.
const dim_t * get() const
Returns the underlying pointer to the dim4 object.
Definition: dim4.hpp:106
dim4(const dim4 &other)
Copy constructor.
dim4 & operator*=(const dim4 &other)
Element-wise multiplication of the dim4 objects.
dim_t elements()
Returns the number of elements represented by this dim4.
dim_t ndims()
Returns the number of axis whose values are greater than one.
bool operator!=(const dim4 &other) const
Returns true if two dim4s store different values.
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.
dim_t elements() const
Returns the number of elements represented by this dim4.
bool operator==(const dim4 &other) const
Returns true if the two dim4 represent the same shape.
dim4 & operator+=(const dim4 &other)
Element-wise addition of the dim4 objects.
dim_t ndims() const
Returns the number of axis whose values are greater than one.
dim_t * get()
Returns the underlying pointer to the dim4 object.
Definition: dim4.hpp:103
dim4()
Default constructor. Creates an invalid dim4 object.
seq is used to create sequences for indexing af::array
Definition: seq.h:46
long long dim_t
Definition: defines.h:56
#define AFAPI
Definition: defines.h:38
AFAPI array operator+(const array &lhs, const array &rhs)
Adds 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 left shift operation on 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.
AFAPI array operator-(const array &lhs, const array &rhs)
Subtracts two arrays or an array and a value.
Definition: algorithm.h:15
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.
AFAPI size_t seqElements(const af_seq &seq)
Returns the number of elements that the af_seq object represents.
AFAPI bool isSpan(const af_seq &seq)
Returns true if the af_seq object represents the entire range of an axis.
C-style struct to creating sequences for indexing.
Definition: seq.h:20