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 {
23 class AFAPI dim4
24 {
25  public:
26  dim_t dims[4]; //FIXME: Make this C compatible
27  dim4(); //deleted
28 public:
29  dim4( dim_t first,
30  dim_t second = 1,
31  dim_t third = 1,
32  dim_t fourth = 1);
33  dim4(const dim4& other);
34  dim4(const unsigned ndims, const dim_t * const dims);
35  dim_t elements();
36  dim_t elements() const;
37  dim_t ndims();
38  dim_t ndims() const;
39  bool operator==(const dim4& other) const;
40  bool operator!=(const dim4& other) const;
41  dim4& operator*=(const dim4& other);
42  dim4& operator+=(const dim4& other);
43  dim4& operator-=(const dim4& other);
44  dim_t& operator[](const unsigned dim);
45  const dim_t& operator[](const unsigned dim) const;
46  dim_t* get() { return dims; }
47  const dim_t* get() const { return dims; }
48 };
49 
50 AFAPI dim4 operator+(const dim4& first, const dim4& second);
51 AFAPI dim4 operator-(const dim4& first, const dim4& second);
52 AFAPI dim4 operator*(const dim4& first, const dim4& second);
53 
54 static inline
55 std::ostream&
56 operator<<(std::ostream& ostr, const dim4& dims)
57 {
58  ostr << dims[0] << " "
59  << dims[1] << " "
60  << dims[2] << " "
61  << dims[3];
62  return ostr;
63 }
64 
65 static inline
66 std::istream&
67 operator>>(std::istream& istr, dim4& dims)
68 {
69  istr >> dims[0]
70  >> dims[1]
71  >> dims[2]
72  >> dims[3];
73  return istr;
74 }
75 
76 AFAPI bool isSpan(const af_seq &seq);
77 
78 AFAPI size_t seqElements(const af_seq &seq);
79 
80 AFAPI dim_t calcDim(const af_seq &seq, const dim_t &parentDim);
81 }
82 
83 #endif
AFAPI bool isSpan(const af_seq &seq)
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 seq for indexing af::array
Definition: seq.h:45
AFAPI dim_t calcDim(const af_seq &seq, const dim_t &parentDim)
long long dim_t
Definition: defines.h:50
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:31
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)
AFAPI array operator-(const array &lhs, const array &rhs)
Subtracts two arrays or an array and a value.
Definition: dim4.hpp:23
AFAPI array operator+(const array &lhs, const array &rhs)
Adds two arrays or an array and a value.