mxnet
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
static_array.h
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  */
19 
23 #ifndef MXNET_COMMON_STATIC_ARRAY_H_
24 #define MXNET_COMMON_STATIC_ARRAY_H_
25 
26 #include <mshadow/base.h>
27 
28 namespace mxnet {
29 namespace common {
30 
39 template<typename T, int num>
40 struct StaticArray {
41  static const int kNum = num;
42 
44 
46  MSHADOW_XINLINE StaticArray(void) {}
47 
49  MSHADOW_XINLINE StaticArray(const T& val) {
50  #pragma unroll
51  for (int i = 0; i < num; ++i) {
52  this->array_[i] = val;
53  }
54  }
55 
57  MSHADOW_XINLINE StaticArray(const StaticArray<T, num>& sa) {
58  #pragma unroll
59  for (int i = 0; i < num; ++i) {
60  this->array_[i] = sa[i];
61  }
62  }
63 
64  MSHADOW_XINLINE T& operator[](const index_t idx) {
65  return array_[idx];
66  }
67 
68  MSHADOW_XINLINE const T& operator[](const index_t idx) const {
69  return array_[idx];
70  }
71 }; // StaticArray
72 
73 } // namespace common
74 } // namespace mxnet
75 #endif // MXNET_COMMON_STATIC_ARRAY_H_
T array_[kNum]
Definition: static_array.h:43
MSHADOW_XINLINE StaticArray(const StaticArray< T, num > &sa)
constuctor
Definition: static_array.h:57
MSHADOW_XINLINE StaticArray(const T &val)
constructor, fill in the array with the input value
Definition: static_array.h:49
static const int kNum
Definition: static_array.h:41
MSHADOW_XINLINE const T & operator[](const index_t idx) const
Definition: static_array.h:68
Static array. This code is borrowed from struct Shape<ndim>, except that users can specify the type o...
Definition: static_array.h:40
mshadow::index_t index_t
index type usually use unsigned
Definition: base.h:133
MSHADOW_XINLINE T & operator[](const index_t idx)
Definition: static_array.h:64
MSHADOW_XINLINE StaticArray(void)
default constructor, do nothing
Definition: static_array.h:46