-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature improve tensor interface #41
Conversation
…ault one every time before building them
…plit up the declaration and initialisation
… tensors less clunky
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cpp-linter Review
Click here for the full clang-format patch
diff --git a/nuTens/tensors/tensor.hpp b/nuTens/tensors/tensor.hpp
index e3a587a..2b0eaac 100644
--- a/nuTens/tensors/tensor.hpp
+++ b/nuTens/tensors/tensor.hpp
@@ -56 +56 @@ class Tensor
- Tensor(const std::vector<float>& values, NTdtypes::scalarType type = NTdtypes::kFloat,
+ Tensor(std::vector<float> values, NTdtypes::scalarType type = NTdtypes::kFloat,
Only 3 out of 9 clang-tidy concerns fit within this pull request's diff.
Click here for the full clang-tidy patch
diff --git a/benchmarks/benchmarks.cpp b/benchmarks/benchmarks.cpp
index ebd71ca..cb6f4c3 100644
--- a/benchmarks/benchmarks.cpp
+++ b/benchmarks/benchmarks.cpp
@@ -99 +99 @@ static void BM_constMatterOscillations(benchmark::State &state)
- std::unique_ptr<BaseMatterSolver> matterSolver = std::make_unique<ConstDensityMatterSolver>(3, 2.6);
+ std::unique_ptr<BaseMatterSolver> matterSolver = 0 = std::make_unique<ConstDensityMatterSolver>(3, 2.6);
diff --git a/nuTens/propagator/const-density-solver.hpp b/nuTens/propagator/const-density-solver.hpp
index 5aa5b34..19470ea 100644
--- a/nuTens/propagator/const-density-solver.hpp
+++ b/nuTens/propagator/const-density-solver.hpp
@@ -82 +82 @@ class ConstDensityMatterSolver : public BaseMatterSolver
- void calculateEigenvalues(const Tensor &energies, Tensor &eigenvectors, Tensor &eigenvalues);
+ void calculateEigenvalues(const Tensor &energies, Tensor &eigenvectors, Tensor &eigenvalues) override;
diff --git a/nuTens/tensors/tensor.hpp b/nuTens/tensors/tensor.hpp
index e3a587a..f825ea5 100644
--- a/nuTens/tensors/tensor.hpp
+++ b/nuTens/tensors/tensor.hpp
@@ -52 +52 @@ class Tensor
- Tensor(){};
+ Tensor()= default;;
@@ -56 +56 @@ class Tensor
- Tensor(const std::vector<float>& values, NTdtypes::scalarType type = NTdtypes::kFloat,
+ Tensor(std::vector<float> values, NTdtypes::scalarType type = NTdtypes::kFloat,
diff --git a/nuTens/tensors/torch-tensor.cpp b/nuTens/tensors/torch-tensor.cpp
index 3324317..cf91698 100644
--- a/nuTens/tensors/torch-tensor.cpp
+++ b/nuTens/tensors/torch-tensor.cpp
@@ -20 +20 @@ std::string Tensor::getTensorLibrary()
-Tensor::Tensor(std::vector<float> values, NTdtypes::scalarType type, NTdtypes::deviceType device, bool requiresGrad)
+Tensor::Tensor(const std::vector<float>& values, NTdtypes::scalarType type, NTdtypes::deviceType device, bool requiresGrad)
Have any feedback or feature suggestions? Share it here.
|
||
/// @brief Construct a 1-d array with specified values | ||
/// @arg values The values to include in the tensor | ||
Tensor(std::vector<float> values, NTdtypes::scalarType type = NTdtypes::kFloat, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-format suggestions
Tensor(std::vector<float> values, NTdtypes::scalarType type = NTdtypes::kFloat, | |
Tensor(std::vector<float> values, NTdtypes::scalarType type = NTdtypes::kFloat, |
bool requiresGrad = true); | ||
/// @brief Initialise this tensor with ones | ||
/// @brief Default constructor with no initialisation | ||
Tensor(){}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-tidy diagnostics
- use '= default' to define a trivial default constructor [modernize-use-equals-default]
Tensor(){}; | |
Tensor()= default;; |
|
||
/// @brief Construct a 1-d array with specified values | ||
/// @arg values The values to include in the tensor | ||
Tensor(std::vector<float> values, NTdtypes::scalarType type = NTdtypes::kFloat, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-tidy suggestions
Tensor(std::vector<float> values, NTdtypes::scalarType type = NTdtypes::kFloat, | |
Tensor(std::vector<float> values, NTdtypes::scalarType type = NTdtypes::kFloat, |
@@ -17,45 +17,72 @@ std::string Tensor::getTensorLibrary() | |||
return "PyTorch"; | |||
} | |||
|
|||
Tensor &Tensor::ones(int length, NTdtypes::scalarType type, NTdtypes::deviceType device, bool requiresGrad) | |||
Tensor::Tensor(std::vector<float> values, NTdtypes::scalarType type, NTdtypes::deviceType device, bool requiresGrad) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-tidy diagnostics
- the parameter 'values' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param]
Tensor::Tensor(std::vector<float> values, NTdtypes::scalarType type, NTdtypes::deviceType device, bool requiresGrad) | |
Tensor::Tensor(const std::vector<float>& values, NTdtypes::scalarType type, NTdtypes::deviceType device, bool requiresGrad) |
Codecov ReportAttention: Patch coverage is
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
|
…sity matter solver
Cpp-Linter Report
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cpp-linter Review
Click here for the full clang-format patch
diff --git a/nuTens/tensors/tensor.hpp b/nuTens/tensors/tensor.hpp
index e3a587a..2b0eaac 100644
--- a/nuTens/tensors/tensor.hpp
+++ b/nuTens/tensors/tensor.hpp
@@ -56 +56 @@ class Tensor
- Tensor(const std::vector<float>& values, NTdtypes::scalarType type = NTdtypes::kFloat,
+ Tensor(std::vector<float> values, NTdtypes::scalarType type = NTdtypes::kFloat,
Only 3 out of 9 clang-tidy concerns fit within this pull request's diff.
Click here for the full clang-tidy patch
diff --git a/benchmarks/benchmarks.cpp b/benchmarks/benchmarks.cpp
index 2f729d2..87fcbe1 100644
--- a/benchmarks/benchmarks.cpp
+++ b/benchmarks/benchmarks.cpp
@@ -100 +100 @@ static void BM_constMatterOscillations(benchmark::State &state)
- std::unique_ptr<BaseMatterSolver> matterSolver = std::make_unique<ConstDensityMatterSolver>(3, 2.6);
+ std::unique_ptr<BaseMatterSolver> matterSolver = 0 = std::make_unique<ConstDensityMatterSolver>(3, 2.6);
diff --git a/nuTens/propagator/const-density-solver.hpp b/nuTens/propagator/const-density-solver.hpp
index 5aa5b34..19470ea 100644
--- a/nuTens/propagator/const-density-solver.hpp
+++ b/nuTens/propagator/const-density-solver.hpp
@@ -82 +82 @@ class ConstDensityMatterSolver : public BaseMatterSolver
- void calculateEigenvalues(const Tensor &energies, Tensor &eigenvectors, Tensor &eigenvalues);
+ void calculateEigenvalues(const Tensor &energies, Tensor &eigenvectors, Tensor &eigenvalues) override;
diff --git a/nuTens/tensors/tensor.hpp b/nuTens/tensors/tensor.hpp
index e3a587a..f825ea5 100644
--- a/nuTens/tensors/tensor.hpp
+++ b/nuTens/tensors/tensor.hpp
@@ -52 +52 @@ class Tensor
- Tensor(){};
+ Tensor()= default;;
@@ -56 +56 @@ class Tensor
- Tensor(const std::vector<float>& values, NTdtypes::scalarType type = NTdtypes::kFloat,
+ Tensor(std::vector<float> values, NTdtypes::scalarType type = NTdtypes::kFloat,
diff --git a/nuTens/tensors/torch-tensor.cpp b/nuTens/tensors/torch-tensor.cpp
index 3324317..cf91698 100644
--- a/nuTens/tensors/torch-tensor.cpp
+++ b/nuTens/tensors/torch-tensor.cpp
@@ -20 +20 @@ std::string Tensor::getTensorLibrary()
-Tensor::Tensor(std::vector<float> values, NTdtypes::scalarType type, NTdtypes::deviceType device, bool requiresGrad)
+Tensor::Tensor(const std::vector<float>& values, NTdtypes::scalarType type, NTdtypes::deviceType device, bool requiresGrad)
Have any feedback or feature suggestions? Share it here.
|
||
/// @brief Construct a 1-d array with specified values | ||
/// @arg values The values to include in the tensor | ||
Tensor(std::vector<float> values, NTdtypes::scalarType type = NTdtypes::kFloat, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-format suggestions
Tensor(std::vector<float> values, NTdtypes::scalarType type = NTdtypes::kFloat, | |
Tensor(std::vector<float> values, NTdtypes::scalarType type = NTdtypes::kFloat, |
bool requiresGrad = true); | ||
/// @brief Initialise this tensor with ones | ||
/// @brief Default constructor with no initialisation | ||
Tensor(){}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-tidy diagnostics
- use '= default' to define a trivial default constructor [modernize-use-equals-default]
Tensor(){}; | |
Tensor()= default;; |
|
||
/// @brief Construct a 1-d array with specified values | ||
/// @arg values The values to include in the tensor | ||
Tensor(std::vector<float> values, NTdtypes::scalarType type = NTdtypes::kFloat, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-tidy suggestions
Tensor(std::vector<float> values, NTdtypes::scalarType type = NTdtypes::kFloat, | |
Tensor(std::vector<float> values, NTdtypes::scalarType type = NTdtypes::kFloat, |
@@ -17,45 +17,72 @@ std::string Tensor::getTensorLibrary() | |||
return "PyTorch"; | |||
} | |||
|
|||
Tensor &Tensor::ones(int length, NTdtypes::scalarType type, NTdtypes::deviceType device, bool requiresGrad) | |||
Tensor::Tensor(std::vector<float> values, NTdtypes::scalarType type, NTdtypes::deviceType device, bool requiresGrad) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-tidy diagnostics
- the parameter 'values' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param]
Tensor::Tensor(std::vector<float> values, NTdtypes::scalarType type, NTdtypes::deviceType device, bool requiresGrad) | |
Tensor::Tensor(const std::vector<float>& values, NTdtypes::scalarType type, NTdtypes::deviceType device, bool requiresGrad) |
Bencher
Click to view all benchmark results
Bencher - Continuous Benchmarking View Public Perf Page Docs | Repo | Chat | Help |
Slightly tidier way if building tensor objects and some new constructors to simplify things a bit