-
Notifications
You must be signed in to change notification settings - Fork 2
/
Tensor.hpp
63 lines (45 loc) · 1.08 KB
/
Tensor.hpp
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
//
// Tensor.h
// audio_test
//
// Created by Alex on 19.04.2020.
// Copyright © 2020 Alex. All rights reserved.
//
#include <algorithm>
#ifndef TENSOR_H
#define TENSOR_H
template <typename T, unsigned int ...side>
class Tensor {
public:
T *value;
static constexpr unsigned int size = []{
int result = 1;
for (auto && a: {side...}){
result *= a;
}
return result;
}();
Tensor(): value(new T[size]) {}
explicit Tensor(T init): value(new T[size]){
std::fill(value, value + size, init);
}
Tensor(Tensor && other): value(other.value){
other.value = nullptr;
}
Tensor(const Tensor& other): value(new T[size]){
memcpy(value, other.value, sizeof(T) * size);
}
Tensor& operator = (Tensor& other) {
memcpy(value, other.value, sizeof(T) * size);
return *this;
}
Tensor& operator = (Tensor && other) {
value = other.value;
other.value = nullptr;
return *this;
}
~Tensor(){
delete[] value;
}
};
#endif //TENSOR_H