forked from deepmodeling/abacus-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintarray.cpp
More file actions
162 lines (147 loc) · 3.8 KB
/
intarray.cpp
File metadata and controls
162 lines (147 loc) · 3.8 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*******************************************
* ESCP:Electro-Structure Calculate Package.
********************************************/
#include <cstdlib>
#include "intarray.h"
namespace ModuleBase
{
void IntArrayAlloc()
{
std::cout << "\n Allocation error for IntArray " << std::endl;
exit(0);
}
IntArray::IntArray(const int d1,const int d2)
{
dim = 2;
bound1 = (d1 <= 0) ? 1 : d1;
bound2 = (d2 <= 0) ? 1 : d2;
bound3 = bound4 = bound5 = bound6 = 0;
size = bound1 * bound2;
ptr = new int[size];zero_out();
assert( ptr != nullptr);
}
IntArray::IntArray(const int d1,const int d2,const int d3)
{
dim = 3;
bound1 = (d1 <= 0) ? 1 : d1;
bound2 = (d2 <= 0) ? 1 : d2;
bound3 = (d3 <= 0) ? 1 : d3;
bound4 = bound5 = bound6 = 0;
//set_new_handler(IntArrayAlloc);
size = bound1 * bound2 * bound3 ; //* sizeof(float);
ptr = new int[size];zero_out();
assert(ptr != nullptr);
}
IntArray::IntArray(const int d1,const int d2,const int d3,const int d4)
{
dim = 4;
bound1 = (d1 <= 0) ? 1 : d1;
bound2 = (d2 <= 0) ? 1 : d2;
bound3 = (d3 <= 0) ? 1 : d3;
bound4 = (d4 <= 0) ? 1 : d4;
bound5 = bound6 = 0;
//set_new_handler(IntArrayAlloc);
size = bound1 * bound2 * bound3 * bound4 ; //* sizeof(float);
ptr = new int[size];zero_out();
assert(ptr != nullptr);
}
IntArray::IntArray(const int d1,const int d2,const int d3,
const int d4,const int d5)
{
dim = 5;
bound1 = (d1 <= 0) ? 1 : d1;
bound2 = (d2 <= 0) ? 1 : d2;
bound3 = (d3 <= 0) ? 1 : d3;
bound4 = (d4 <= 0) ? 1 : d4;
bound5 = (d5 <= 0) ? 1 : d5;
//set_new_handler(IntArrayAlloc);
size = bound1 * bound2 * bound3 * bound4 * bound5;
ptr = new int[size];zero_out();
assert(ptr != nullptr);
}
IntArray::IntArray(const int d1,const int d2,const int d3,
const int d4,const int d5,const int d6)
{
dim = 6;
bound1 = (d1 <= 0) ? 1 : d1;
bound2 = (d2 <= 0) ? 1 : d2;
bound3 = (d3 <= 0) ? 1 : d3;
bound4 = (d4 <= 0) ? 1 : d4;
bound5 = (d5 <= 0) ? 1 : d5;
bound6 = (d6 <= 0) ? 1 : d6;
//set_new_handler(IntArrayAlloc);
size = bound1 * bound2 * bound3 * bound4 * bound5 * bound6;
ptr = new int[size];zero_out();
assert(ptr != nullptr);
}
//********************************
// Destructor for class IntArray
//********************************
IntArray ::~IntArray()
{
freemem();
}
void IntArray::freemem()
{
if(ptr!= nullptr)
{
delete [] ptr;
ptr = nullptr;
}
}
void IntArray::create(const int d1,const int d2,const int d3,const int d4,const int d5,const int d6)
{
size = d1 * d2 * d3 * d4 * d5 * d6;assert(size>0);
dim = 6;
bound1 = d1;bound2 = d2;bound3 = d3;bound4 = d4;bound5 = d5;bound6 = d6;
delete[] ptr; ptr = new int[size];
assert(ptr != nullptr);zero_out();
}
void IntArray::create(const int d1,const int d2,const int d3,const int d4,const int d5)
{
size = d1 * d2 * d3 * d4 * d5;assert(size>0);
dim = 5;
bound1 = d1;bound2 = d2;bound3 = d3;bound4 = d4;bound5 = d5;
delete[] ptr; ptr = new int[size];
assert(ptr != nullptr);zero_out();
}
void IntArray::create(const int d1,const int d2,const int d3,const int d4)
{
size = d1 * d2 * d3 * d4;assert(size>0);
dim = 4;
bound1 = d1;bound2 = d2;bound3 = d3;bound4 = d4;
delete[] ptr; ptr = new int[size];
assert(ptr != nullptr);zero_out();
}
void IntArray::create(const int d1,const int d2,const int d3)
{
size = d1 * d2 * d3;assert(size>0);
dim = 3;
bound1 = d1;bound2 = d2;bound3 = d3;bound4 = 1;
delete [] ptr;ptr = new int[size];
assert(ptr != nullptr);zero_out();
}
void IntArray::create(const int d1, const int d2)
{
size = d1 * d2;assert(size>0);
dim = 2;
bound1 = d1;bound2 = d2;bound3 = bound4 = 1;
delete[] ptr;ptr = new int[size];
assert(ptr != nullptr );zero_out();
}
//****************************
// zeroes out the whole array
//****************************
void IntArray::zero_out()
{
if (size <= 0)
{
return;
}
for (int i = 0;i < size; i++)
{
ptr[i] = 0;
}
return;
}
}