Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
usadelndsoc
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
JYU Condensed Matter Theory
usadelndsoc
Commits
57bd4a70
Commit
57bd4a70
authored
2 years ago
by
patavirt
Browse files
Options
Downloads
Patches
Plain Diff
Adjust to const + rename SimpleVector
parent
14b4732f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
src/action.hpp
+7
-7
7 additions, 7 deletions
src/action.hpp
src/common.hpp
+1
-1
1 addition, 1 deletion
src/common.hpp
src/core.cpp
+6
-7
6 additions, 7 deletions
src/core.cpp
src/main.cpp
+9
-7
9 additions, 7 deletions
src/main.cpp
src/vector.hpp
+12
-8
12 additions, 8 deletions
src/vector.hpp
with
35 additions
and
30 deletions
src/action.hpp
+
7
−
7
View file @
57bd4a70
...
...
@@ -15,15 +15,15 @@
#include
"array.hpp"
template
<
typename
Scalar
>
inline
Matrix
<
Scalar
,
4
,
4
>
template
<
typename
Scalar
,
typename
ScalarW
=
typename
std
::
remove_const
<
Scalar
>
::
type
>
inline
Matrix
<
Scalar
W
,
4
,
4
>
get_Q_matrix
(
array
::
ArrayView
<
Scalar
,
array
::
Shape
<
2
,
2
,
2
>
>
Q
)
{
auto
g
=
Q
.
part
(
0u
).
matrix
();
auto
gt
=
Q
.
part
(
1u
).
matrix
();
Matrix
<
double
,
2
,
2
>
I
;
Matrix
<
Scalar
,
2
,
2
>
N
,
Nt
;
Matrix
<
Scalar
,
4
,
4
>
Qm
;
Matrix
<
Scalar
W
,
2
,
2
>
N
,
Nt
;
Matrix
<
Scalar
W
,
4
,
4
>
Qm
;
I
<<
1
,
0
,
0
,
1
;
...
...
@@ -39,13 +39,13 @@ get_Q_matrix(array::ArrayView<Scalar, array::Shape<2,2,2> > Q)
return
Qm
;
}
template
<
typename
Scalar
,
typename
Shape
,
typename
Shape2
>
inline
Scalar
S_2
(
array
::
ArrayView
<
Scalar
,
Shape
>
Q
,
array
::
ArrayView
<
Complex
,
Shape2
>
U
,
double
h
)
template
<
typename
Scalar
,
typename
Shape
,
typename
Shape2
,
typename
ScalarW
=
typename
std
::
remove_const
<
Scalar
>
::
type
>
inline
Scalar
W
S_2
(
array
::
ArrayView
<
Scalar
,
Shape
>
Q
,
array
::
ArrayView
<
const
Complex
,
Shape2
>
U
,
double
h
)
{
const
int
N_i
[
4
]
=
{
0
,
1
,
-
1
,
0
};
const
int
N_j
[
4
]
=
{
1
,
0
,
0
,
-
1
};
const
size_t
invk
[
4
]
=
{
3
,
2
,
1
,
0
};
Scalar
S
=
Scalar
(
0
);
Scalar
W
S
=
Scalar
(
0
);
size_t
nx
=
Q
.
dim
(
0
);
size_t
ny
=
Q
.
dim
(
1
);
...
...
This diff is collapsed.
Click to expand it.
src/common.hpp
+
1
−
1
View file @
57bd4a70
...
...
@@ -16,7 +16,7 @@
#include
<cppad/example/cppad_eigen.hpp>
#include
"array.hpp"
#include
"
simple
vector.hpp"
#include
"vector.hpp"
typedef
std
::
complex
<
double
>
Complex
;
typedef
CppAD
::
AD
<
double
>
ADDouble
;
...
...
This diff is collapsed.
Click to expand it.
src/core.cpp
+
6
−
7
View file @
57bd4a70
...
...
@@ -14,8 +14,8 @@ using namespace array::python;
class
CLASS_Action
{
public:
typedef
PyArrayView
<
Complex
,
Shape
<
Dynamic
,
Dynamic
,
4
,
4
,
4
>
>
UType
;
typedef
PyArrayView
<
Complex
,
Shape
<
Dynamic
,
Dynamic
,
2
,
2
,
2
>
>
QType
;
typedef
PyArrayView
<
const
Complex
,
Shape
<
Dynamic
,
Dynamic
,
4
,
4
,
4
>
>
UType
;
typedef
PyArrayView
<
const
Complex
,
Shape
<
Dynamic
,
Dynamic
,
2
,
2
,
2
>
>
QType
;
private:
UType
U_
;
...
...
@@ -39,9 +39,9 @@ public:
if
(
Qval
.
dim
(
0
)
!=
nx_
||
Qval
.
dim
(
1
)
!=
ny_
)
throw
std
::
out_of_range
(
"Q array wrong size"
);
StoredComplex
Array
<
ADComplex
,
Shape
<
Dynamic
,
Dynamic
,
2
,
2
,
2
>
>
Array
<
ADComplex
,
Shape
<
Dynamic
,
Dynamic
,
2
,
2
,
2
>
,
std
::
vector
<
ADDouble
>
>
Q
({
nx_
,
ny_
,
2
,
2
,
2
});
StoredComplex
Array
<
ADComplex
,
Shape
<
1
>
>
res
;
Array
<
ADComplex
,
Shape
<
1
>
,
std
::
vector
<
ADDouble
>
>
res
;
auto
a
=
Qval
.
reshape
<
Dynamic
>
({
Qval
.
size
()});
auto
b
=
Q
.
reshape
<
Dynamic
>
({
Q
.
size
()});
...
...
@@ -57,14 +57,13 @@ public:
auto
grad
(
QType
Q
)
{
SimpleVector
<
double
>
x
(
reinterpret_cast
<
double
*>
(
Q
.
data
()),
2
*
Q
.
size
());
Vector
<
double
>
x
(
reinterpret_cast
<
double
*>
(
const_cast
<
Complex
*>
(
Q
.
data
())),
2
*
Q
.
size
());
CppAD
::
ADFun
<
double
>
f
=
eval_ad
(
Q
);
auto
jac
=
f
.
Jacobian
(
x
);
std
::
array
<
size_t
,
1
>
shape
=
{
jac
.
size
()
/
2
};
return
Stored
Array
<
Complex
,
Shape
<
Dynamic
>
,
0
,
true
,
Simple
Vector
<
double
>
>
(
std
::
move
(
jac
),
shape
);
return
Array
<
Complex
,
Shape
<
Dynamic
>
,
Vector
<
double
>
>
(
std
::
move
(
jac
),
shape
);
}
};
...
...
This diff is collapsed.
Click to expand it.
src/main.cpp
+
9
−
7
View file @
57bd4a70
...
...
@@ -25,10 +25,10 @@ void dump(ArrayView<Scalar,Shape> Q)
int
main0
()
{
StoredComplex
Array
<
Complex
,
Shape
<
2
,
2
,
2
,
2
,
2
>
>
Qval
;
Array
<
Complex
,
Shape
<
2
,
2
,
2
,
2
,
2
>
,
std
::
vector
<
double
>
>
Qval
;
StoredComplex
Array
<
ADComplex
,
Shape
<
2
,
2
,
2
,
2
,
2
>
>
Q
;
Stored
Array
<
Complex
,
Shape
<
2
,
2
,
4
,
4
,
4
>
>
U
;
Array
<
ADComplex
,
Shape
<
2
,
2
,
2
,
2
,
2
>
,
std
::
vector
<
ADDouble
>
>
Q
;
Array
<
Complex
,
Shape
<
2
,
2
,
4
,
4
,
4
>
>
U
;
for
(
size_t
i
=
0
;
i
<
Qval
.
dim
(
0
);
++
i
)
{
for
(
size_t
j
=
0
;
i
<
Qval
.
dim
(
1
);
++
i
)
{
...
...
@@ -51,8 +51,10 @@ int main0()
CppAD
::
Independent
(
Q
.
storage
());
StoredComplexArray
<
ADComplex
,
Shape
<
1
>
>
res
;
res
(
0u
)
=
S_2
(
Q
,
U
,
0.1
);
Array
<
ADComplex
,
Shape
<
1
>
,
std
::
vector
<
ADDouble
>
>
res
;
ArrayView
<
const
Complex
,
Shape
<
2
,
2
,
4
,
4
,
4
>
>
U_const
=
U
;
res
(
0u
)
=
S_2
(
Q
,
U_const
,
0.1
);
CppAD
::
ADFun
<
double
>
f
(
Q
.
storage
(),
res
.
storage
());
...
...
@@ -70,7 +72,7 @@ int main0()
int
main
()
{
Stored
Array
<
ADDouble
,
Shape
<
8
,
8
>
>
Q
;
Array
<
ADDouble
,
Shape
<
8
,
8
>
>
Q
;
for
(
size_t
i
=
0
;
i
<
Q
.
dim
(
0
);
++
i
)
{
for
(
size_t
j
=
0
;
i
<
Q
.
dim
(
1
);
++
i
)
{
...
...
@@ -80,7 +82,7 @@ int main()
CppAD
::
Independent
(
Q
.
storage
());
Stored
Array
<
ADDouble
,
Shape
<
1
>
>
res
;
Array
<
ADDouble
,
Shape
<
1
>
>
res
;
res
(
0u
)
=
laplacian
(
Q
);
CppAD
::
ADFun
<
double
>
f
(
Q
.
storage
(),
res
.
storage
());
...
...
This diff is collapsed.
Click to expand it.
src/
simple
vector.hpp
→
src/vector.hpp
+
12
−
8
View file @
57bd4a70
...
...
@@ -10,8 +10,10 @@
#include
<vector>
namespace
array
{
template
<
class
Scalar
>
class
Simple
Vector
class
Vector
{
public:
typedef
Scalar
value_type
;
...
...
@@ -40,15 +42,15 @@ private:
}
public
:
Simple
Vector
()
Vector
()
:
storage_
(),
data_
(
storage_
.
data
()),
size_
(
storage_
.
size
())
{}
Simple
Vector
(
size_t
n
)
Vector
(
size_t
n
)
:
storage_
(
n
),
data_
(
storage_
.
data
()),
size_
(
storage_
.
size
())
{}
Simple
Vector
(
const
Simple
Vector
&
other
)
Vector
(
const
Vector
&
other
)
:
storage_
(
other
.
storage_
),
data_
(
other
.
data_
),
size_
(
other
.
size_
)
{
if
(
other
.
own_data
())
{
...
...
@@ -59,18 +61,18 @@ public:
}
}
Simple
Vector
(
Simple
Vector
&&
other
)
Vector
(
Vector
&&
other
)
:
storage_
(
std
::
move
(
other
.
storage_
)),
data_
(
other
.
data_
),
size_
(
other
.
size_
)
{
other
.
data_
=
other
.
storage_
.
data
();
other
.
size_
=
other
.
storage_
.
size
();
}
Simple
Vector
(
Scalar
*
data
,
size_t
size
)
Vector
(
Scalar
*
data
,
size_t
size
)
:
storage_
(),
data_
(
data
),
size_
(
size
)
{}
Simple
Vector
&
operator
=
(
const
Simple
Vector
&
other
)
Vector
&
operator
=
(
const
Vector
&
other
)
{
if
(
other
.
own_data
())
{
storage_
=
other
.
storage_
;
...
...
@@ -84,7 +86,7 @@ public:
return
*
this
;
}
Simple
Vector
&
operator
=
(
Simple
Vector
&&
other
)
Vector
&
operator
=
(
Vector
&&
other
)
{
if
(
other
.
own_data
())
{
storage_
=
std
::
move
(
other
.
storage_
);
...
...
@@ -131,4 +133,6 @@ public:
}
};
}
#endif // SIMPLEVECTOR_HPP_
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment