FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
abacus-develop/source/source_base/container_operator.h at develop · pplab/abacus-develop · GitHub
pplab
/
abacus-develop
Public
forked from
deepmodeling/abacus-develop
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
abacus-develop
/
source
/
source_base
/
container_operator.h
Copy path
More file actions
More file actions
Latest commit
History
History
History
66 lines (58 loc) · 1.63 KB
Breadcrumbs
abacus-develop
/
source
/
source_base
/
container_operator.h
Copy path
File metadata and controls
66 lines (58 loc) · 1.63 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#
ifndef
CONTAINER_OPERATOR_H
#
define
CONTAINER_OPERATOR_H
#
include
<
cassert
>
#
include
<
vector
>
#
include
<
map
>
template
<
typename
T>
std::vector<T>
operator
+ (
const
std::vector<T> & x1,
const
std::vector<T> & x2 )
{
assert
(x1.
size
()==x2.
size
());
std::vector<T> x;
for
(std::
size_t
i=
0
; i!=x1.
size
(); ++i )
x.
push_back
(x1[i]+x2[i]);
return
x;
}
template
<
typename
T>
std::vector<T>
operator
- (
const
std::vector<T> & x1,
const
std::vector<T> & x2 )
{
assert
(x1.
size
()==x2.
size
());
std::vector<T> x;
for
(std::
size_t
i=
0
; i!=x1.
size
(); ++i )
x.
push_back
(x1[i]-x2[i]);
return
x;
}
template
<
typename
T1
,
typename
T2
>
std::map<
T1
,
T2
>
operator
+ (
const
std::map<
T1
,
T2
> & x1,
const
std::map<
T1
,
T2
> & x2 )
{
assert
(x1.
size
()==x2.
size
());
std::map<
T1
,
T2
> x;
for
(
const
auto
&x1i : x1 )
x.
insert
(
std::make_pair
( x1i.
first
, x1i.
second
+ x2.
at
(x1i.
first
) ));
return
x;
}
template
<
typename
T1
,
typename
T2
>
std::map<
T1
,
T2
>
operator
- (
const
std::map<
T1
,
T2
> & x1,
const
std::map<
T1
,
T2
> & x2 )
{
assert
(x1.
size
()==x2.
size
());
std::map<
T1
,
T2
> x;
for
(
const
auto
&x1i : x1 )
x.
insert
(
std::make_pair
( x1i.
first
, x1i.
second
- x2.
at
(x1i.
first
) ));
return
x;
}
template
<
typename
T1
,
typename
T2
>
std::vector<
T2
>
operator
* (
const
T1
& x1,
const
std::vector<
T2
> & x2 )
{
std::vector<
T2
> x;
for
(std::
size_t
i=
0
; i!=x2.
size
(); ++i )
x.
push_back
(x1*x2[i]);
return
x;
}
template
<
typename
T1
,
typename
T21
,
typename
T22
>
std::map<
T21
,
T22
>
operator
* (
const
T1
& x1,
const
std::map<
T21
,
T22
> & x2 )
{
std::map<
T21
,
T22
> x;
for
(
const
auto
& x2i : x2 )
x.
insert
(
std::make_pair
( x2i.
first
, x1*x2i.
second
));
return
x;
}
#
endif
//
CONTAINER_OPERATOR_H
Back
|
FazBrowse Home
|
New Git URL