Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
libdrt
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Klemm, Carl Philipp
libdrt
Commits
77d0fd61
Commit
77d0fd61
authored
2 years ago
by
Carl Philipp Klemm
Browse files
Options
Downloads
Patches
Plain Diff
Clean up tensoroptions usage,
add another conveniance calcDrt variant
parent
a13bbd25
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
CMakeLists.txt
+1
-1
1 addition, 1 deletion
CMakeLists.txt
drt.cpp
+10
-1
10 additions, 1 deletion
drt.cpp
eisdrt/drt.h
+2
-0
2 additions, 0 deletions
eisdrt/drt.h
eistotorch.cpp
+1
-7
1 addition, 7 deletions
eistotorch.cpp
tensoroptions.h
+17
-0
17 additions, 0 deletions
tensoroptions.h
with
31 additions
and
9 deletions
CMakeLists.txt
+
1
−
1
View file @
77d0fd61
...
@@ -35,7 +35,7 @@ target_include_directories(${PROJECT_NAME}_test PRIVATE . ${TORCH_INCLUDE_DIRS})
...
@@ -35,7 +35,7 @@ target_include_directories(${PROJECT_NAME}_test PRIVATE . ${TORCH_INCLUDE_DIRS})
set_target_properties
(
${
PROJECT_NAME
}
PROPERTIES COMPILE_FLAGS
"-Wall -O2 -march=native -g"
LINK_FLAGS
"-flto"
)
set_target_properties
(
${
PROJECT_NAME
}
PROPERTIES COMPILE_FLAGS
"-Wall -O2 -march=native -g"
LINK_FLAGS
"-flto"
)
install
(
TARGETS
${
PROJECT_NAME
}
RUNTIME DESTINATION bin
)
install
(
TARGETS
${
PROJECT_NAME
}
RUNTIME DESTINATION bin
)
set
(
API_HEADERS_DIR drt/
)
set
(
API_HEADERS_DIR
eis
drt/
)
set
(
API_HEADERS
set
(
API_HEADERS
${
API_HEADERS_DIR
}
/drt.h
${
API_HEADERS_DIR
}
/drt.h
)
)
...
...
This diff is collapsed.
Click to expand it.
drt.cpp
+
10
−
1
View file @
77d0fd61
...
@@ -22,7 +22,7 @@ static torch::Tensor guesStartingPoint(torch::Tensor& omega, torch::Tensor& impe
...
@@ -22,7 +22,7 @@ static torch::Tensor guesStartingPoint(torch::Tensor& omega, torch::Tensor& impe
static
torch
::
Tensor
aImag
(
torch
::
Tensor
&
omega
)
static
torch
::
Tensor
aImag
(
torch
::
Tensor
&
omega
)
{
{
torch
::
Tensor
tau
=
1.0
/
(
omega
/
(
2
*
M_PI
));
torch
::
Tensor
tau
=
1.0
/
(
omega
/
(
2
*
M_PI
));
torch
::
Tensor
out
=
torch
::
zeros
({
omega
.
numel
(),
omega
.
numel
()},
t
orch
::
T
ensorOpt
ions
().
dtype
(
torch
::
kFloat32
));
torch
::
Tensor
out
=
torch
::
zeros
({
omega
.
numel
(),
omega
.
numel
()},
tensorOpt
Cpu
<
fvalue
>
(
));
auto
outAccessor
=
out
.
accessor
<
float
,
2
>
();
auto
outAccessor
=
out
.
accessor
<
float
,
2
>
();
auto
omegaAccessor
=
omega
.
accessor
<
float
,
1
>
();
auto
omegaAccessor
=
omega
.
accessor
<
float
,
1
>
();
auto
tauAccessor
=
tau
.
accessor
<
float
,
1
>
();
auto
tauAccessor
=
tau
.
accessor
<
float
,
1
>
();
...
@@ -168,3 +168,12 @@ torch::Tensor calcDrt(const std::vector<eis::DataPoint>& data, const std::vector
...
@@ -168,3 +168,12 @@ torch::Tensor calcDrt(const std::vector<eis::DataPoint>& data, const std::vector
torch
::
Tensor
omegaTensor
=
fvalueVectorToTensor
(
const_cast
<
std
::
vector
<
fvalue
>&>
(
omegaVector
)).
clone
();
torch
::
Tensor
omegaTensor
=
fvalueVectorToTensor
(
const_cast
<
std
::
vector
<
fvalue
>&>
(
omegaVector
)).
clone
();
return
calcDrt
(
impedanceSpectra
,
omegaTensor
,
fm
,
fp
);
return
calcDrt
(
impedanceSpectra
,
omegaTensor
,
fm
,
fp
);
}
}
torch
::
Tensor
calcDrt
(
const
std
::
vector
<
eis
::
DataPoint
>&
data
,
FitMetics
&
fm
,
const
FitParameters
&
fp
)
{
torch
::
Tensor
omegaTensor
;
torch
::
Tensor
impedanceSpectra
=
eisToComplexTensor
(
data
,
&
omegaTensor
);
return
calcDrt
(
impedanceSpectra
,
omegaTensor
,
fm
,
fp
);
}
This diff is collapsed.
Click to expand it.
eisdrt/drt.h
+
2
−
0
View file @
77d0fd61
...
@@ -20,3 +20,5 @@ struct FitParameters
...
@@ -20,3 +20,5 @@ struct FitParameters
torch
::
Tensor
calcDrt
(
torch
::
Tensor
&
impedanceSpectra
,
torch
::
Tensor
&
omegaTensor
,
FitMetics
&
fm
,
const
FitParameters
&
fp
);
torch
::
Tensor
calcDrt
(
torch
::
Tensor
&
impedanceSpectra
,
torch
::
Tensor
&
omegaTensor
,
FitMetics
&
fm
,
const
FitParameters
&
fp
);
torch
::
Tensor
calcDrt
(
const
std
::
vector
<
eis
::
DataPoint
>&
data
,
const
std
::
vector
<
fvalue
>&
omegaVector
,
FitMetics
&
fm
,
const
FitParameters
&
fp
);
torch
::
Tensor
calcDrt
(
const
std
::
vector
<
eis
::
DataPoint
>&
data
,
const
std
::
vector
<
fvalue
>&
omegaVector
,
FitMetics
&
fm
,
const
FitParameters
&
fp
);
torch
::
Tensor
calcDrt
(
const
std
::
vector
<
eis
::
DataPoint
>&
data
,
FitMetics
&
fm
,
const
FitParameters
&
fp
);
This diff is collapsed.
Click to expand it.
eistotorch.cpp
+
1
−
7
View file @
77d0fd61
...
@@ -7,13 +7,7 @@
...
@@ -7,13 +7,7 @@
torch
::
Tensor
eisToComplexTensor
(
const
std
::
vector
<
eis
::
DataPoint
>&
data
,
torch
::
Tensor
*
freqs
)
torch
::
Tensor
eisToComplexTensor
(
const
std
::
vector
<
eis
::
DataPoint
>&
data
,
torch
::
Tensor
*
freqs
)
{
{
torch
::
TensorOptions
options
=
tensorOptCpu
<
fvalue
>
();
torch
::
Tensor
output
=
torch
::
empty
({
static_cast
<
long
int
>
(
data
.
size
())},
tensorOptCplxCpu
<
fvalue
>
());
if
constexpr
(
std
::
is_same
<
fvalue
,
float
>::
value
)
options
=
options
.
dtype
(
torch
::
kComplexFloat
);
else
options
=
options
.
dtype
(
torch
::
kComplexDouble
);
torch
::
Tensor
output
=
torch
::
empty
({
static_cast
<
long
int
>
(
data
.
size
())},
options
);
if
(
freqs
)
if
(
freqs
)
*
freqs
=
torch
::
empty
({
static_cast
<
long
int
>
(
data
.
size
())},
tensorOptCpu
<
fvalue
>
());
*
freqs
=
torch
::
empty
({
static_cast
<
long
int
>
(
data
.
size
())},
tensorOptCpu
<
fvalue
>
());
...
...
This diff is collapsed.
Click to expand it.
tensoroptions.h
+
17
−
0
View file @
77d0fd61
#pragma once
#pragma once
#include
<c10/core/ScalarType.h>
#include
<torch/torch.h>
#include
<torch/torch.h>
template
<
typename
V
>
template
<
typename
V
>
...
@@ -16,3 +17,19 @@ inline torch::TensorOptions tensorOptCpu(bool grad = true)
...
@@ -16,3 +17,19 @@ inline torch::TensorOptions tensorOptCpu(bool grad = true)
options
=
options
.
requires_grad
(
grad
);
options
=
options
.
requires_grad
(
grad
);
return
options
;
return
options
;
}
}
template
<
typename
V
>
inline
torch
::
TensorOptions
tensorOptCplxCpu
(
bool
grad
=
true
)
{
static_assert
(
std
::
is_same
<
V
,
float
>::
value
||
std
::
is_same
<
V
,
double
>::
value
,
"This function can only be passed double or float types"
);
torch
::
TensorOptions
options
;
if
constexpr
(
std
::
is_same
<
V
,
float
>::
value
)
options
=
options
.
dtype
(
torch
::
kComplexFloat
);
else
options
=
options
.
dtype
(
torch
::
kComplexDouble
);
options
=
options
.
layout
(
torch
::
kStrided
);
options
=
options
.
device
(
torch
::
kCPU
);
options
=
options
.
requires_grad
(
grad
);
return
options
;
}
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