-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtensorarray.hh
More file actions
executable file
·110 lines (92 loc) · 2.7 KB
/
tensorarray.hh
File metadata and controls
executable file
·110 lines (92 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
Copyright 2024 TensorArray-Creators
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include <typeinfo>
#include "dtype/uint1_t_x8.h"
namespace binary_tensor
{
namespace value
{
/**
* \brief Static tensor.
* \brief Not use for calulate
*/
template <unsigned int ...>
struct TensorArray;
template <unsigned int sz0, unsigned int ... sz>
struct TensorArray<sz0, sz...>
{
static_assert(sz0 != 0U, "A dimension must have a value.");
static_assert(sizeof...(sz) <= 255UL, "Max dimension is 255");
using value_type = TensorArray<sz...>;
using pointer = TensorArray<sz...>*;
using reference = TensorArray<sz...>&;
value_type data[sz0];
reference operator[](unsigned int index)
{
return data[index];
}
constexpr value_type operator[](unsigned int index) const
{
return data[index];
}
pointer begin()
{
return &data[0];
}
pointer end()
{
return &data[sz0];
}
const pointer cbegin() const
{
return &data[0];
}
const pointer cend() const
{
return &data[sz0];
}
pointer rbegin()
{
return &data[sz0 - 1];
}
pointer rend()
{
return &data[-1];
}
const pointer crbegin() const
{
return &data[sz0 - 1];
}
const pointer crend() const
{
return &data[-1];
}
};
template <>
struct TensorArray<>
{
using value_type = dtype::uint1_t_x8;
using pointer = dtype::uint1_t_x8*;
using reference = dtype::uint1_t_x8&;
value_type data;
operator reference()
{
return data;
}
constexpr operator value_type() const
{
return data;
}
};
}
}