Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions source/api_c/tests/test_deeppot_a_ptexpt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -169,16 +169,7 @@ TEST_F(TestInferDeepPotAPtExptC, numb_types_spin) {

TEST_F(TestInferDeepPotAPtExptC, type_map) {
const char* type_map = DP_DeepPotGetTypeMap(dp);
std::string type_map_str(type_map);
std::istringstream iss(type_map_str);
std::vector<std::string> types;
std::string token;
while (iss >> token) {
types.push_back(token);
}
EXPECT_EQ(types.size(), 2);
EXPECT_EQ(types[0], "O");
EXPECT_EQ(types[1], "H");
EXPECT_STREQ(type_map, "O H");
DP_DeleteChar(type_map);
}

Expand Down
1 change: 1 addition & 0 deletions source/api_cc/src/DeepPotPD.cc
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,7 @@ void DeepPotPD::get_type_map(std::string& type_map) {

std::vector<int> type_map_arr(type_map_size, 0);
type_map_tensor->CopyToCpu(type_map_arr.data());
type_map.clear();
for (auto char_c : type_map_arr) {
type_map += std::string(1, char_c);
}
Expand Down
7 changes: 5 additions & 2 deletions source/api_cc/src/DeepPotPT.cc
Original file line number Diff line number Diff line change
Expand Up @@ -452,9 +452,12 @@ template void DeepPotPT::compute<float, std::vector<ENERGYTYPE>>(
const bool atomic);
void DeepPotPT::get_type_map(std::string& type_map) {
auto ret = module.run_method("get_type_map").toList();
type_map.clear();
for (const torch::IValue& element : ret) {
type_map += torch::str(element); // Convert each element to a string
type_map += " "; // Add a space between elements
if (!type_map.empty()) {
type_map += " ";
}
type_map += torch::str(element);
}
}

Expand Down
5 changes: 4 additions & 1 deletion source/api_cc/src/DeepPotPTExpt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -947,9 +947,12 @@ template void DeepPotPTExpt::compute<float, std::vector<ENERGYTYPE>>(
const bool atomic);

void DeepPotPTExpt::get_type_map(std::string& type_map_str) {
type_map_str.clear();
for (const auto& t : type_map) {
if (!type_map_str.empty()) {
type_map_str += " ";
}
type_map_str += t;
type_map_str += " ";
}
}

Expand Down
7 changes: 5 additions & 2 deletions source/api_cc/src/DeepSpinPT.cc
Original file line number Diff line number Diff line change
Expand Up @@ -476,9 +476,12 @@ template void DeepSpinPT::compute<float, std::vector<ENERGYTYPE>>(
const bool atomic);
void DeepSpinPT::get_type_map(std::string& type_map) {
auto ret = module.run_method("get_type_map").toList();
type_map.clear();
for (const torch::IValue& element : ret) {
type_map += torch::str(element); // Convert each element to a string
type_map += " "; // Add a space between elements
if (!type_map.empty()) {
type_map += " ";
}
type_map += torch::str(element);
}
}

Expand Down
5 changes: 4 additions & 1 deletion source/api_cc/src/DeepSpinPTExpt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1028,9 +1028,12 @@ template void DeepSpinPTExpt::compute<float, std::vector<ENERGYTYPE>>(
const bool atomic);

void DeepSpinPTExpt::get_type_map(std::string& type_map_str) {
type_map_str.clear();
for (const auto& t : type_map) {
if (!type_map_str.empty()) {
type_map_str += " ";
}
type_map_str += t;
type_map_str += " ";
}
}

Expand Down
7 changes: 7 additions & 0 deletions source/api_cc/tests/test_deeppot_dpa_ptexpt_spin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <algorithm>
#include <cmath>
#include <fstream>
#include <string>
#include <vector>

#include "DeepSpin.h"
Expand Down Expand Up @@ -96,6 +97,12 @@ TYPED_TEST(TestInferDeepSpinDpaPtExpt, test_get_use_spin) {
EXPECT_FALSE(use_spin[2]); // H has no spin
}

TYPED_TEST(TestInferDeepSpinDpaPtExpt, type_map) {
std::string type_map;
this->dp.get_type_map(type_map);
EXPECT_EQ(type_map, "Ni O H");
}

TYPED_TEST(TestInferDeepSpinDpaPtExpt, cpu_build_nlist) {
using VALUETYPE = TypeParam;
const std::vector<VALUETYPE>& coord = this->coord;
Expand Down
7 changes: 7 additions & 0 deletions source/api_cc/tests/test_deeppot_pd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <algorithm>
#include <cmath>
#include <fstream>
#include <string>
#include <vector>

#include "DeepPot.h"
Expand Down Expand Up @@ -89,6 +90,12 @@ class TestInferDeepPotAPd : public ::testing::Test {

TYPED_TEST_SUITE(TestInferDeepPotAPd, PDValueTypes);

TYPED_TEST(TestInferDeepPotAPd, type_map) {
std::string type_map = "stale";
this->dp.get_type_map(type_map);
EXPECT_EQ(type_map, "O H");
}

TYPED_TEST(TestInferDeepPotAPd, cpu_build_nlist) {
using VALUETYPE = TypeParam;
std::vector<VALUETYPE>& coord = this->coord;
Expand Down
7 changes: 7 additions & 0 deletions source/api_cc/tests/test_deeppot_pt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <algorithm>
#include <cmath>
#include <fstream>
#include <string>
#include <vector>

#include "DeepPot.h"
Expand Down Expand Up @@ -82,6 +83,12 @@ class TestInferDeepPotAPt : public ::testing::Test {

TYPED_TEST_SUITE(TestInferDeepPotAPt, ValueTypes);

TYPED_TEST(TestInferDeepPotAPt, type_map) {
std::string type_map;
this->dp.get_type_map(type_map);
EXPECT_EQ(type_map, "O H");
}

TYPED_TEST(TestInferDeepPotAPt, cpu_build_nlist) {
using VALUETYPE = TypeParam;
std::vector<VALUETYPE>& coord = this->coord;
Expand Down
3 changes: 1 addition & 2 deletions source/api_cc/tests/test_deeppot_ptexpt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -944,8 +944,7 @@ TYPED_TEST_SUITE(TestDeepPotPTExptMetadata, ValueTypes);
TYPED_TEST(TestDeepPotPTExptMetadata, type_map) {
std::string type_map;
this->dp.get_type_map(type_map);
EXPECT_NE(type_map.find("O"), std::string::npos);
EXPECT_NE(type_map.find("H"), std::string::npos);
EXPECT_EQ(type_map, "O H");
}

TYPED_TEST(TestDeepPotPTExptMetadata, cutoff) {
Expand Down
Loading