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
38 changes: 38 additions & 0 deletions excuter/cpp-common/src/deepx/dtype.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -475,5 +475,43 @@ namespace deepx
}
}

template <Precision P>
struct PrecisionWrapper {};

template <typename PrecisionWrapper>
struct to_tensor_type;

template <>
struct to_tensor_type<PrecisionWrapper<Precision::Float64>> {
using type = double;
};

template <>
struct to_tensor_type<PrecisionWrapper<Precision::Float32>> {
using type = float;
};

template <>
struct to_tensor_type<PrecisionWrapper<Precision::Int64>> {
using type = int64_t;
};

template <>
struct to_tensor_type<PrecisionWrapper<Precision::Int32>> {
using type = int32_t;
};

template <>
struct to_tensor_type<PrecisionWrapper<Precision::Int16>> {
using type = int16_t;
};

template <>
struct to_tensor_type<PrecisionWrapper<Precision::Int8>> {
using type = int8_t;
};

template <Precision p>
using tensor_t = typename to_tensor_type<PrecisionWrapper<p>>::type;
} // namespace deepx
#endif
24 changes: 21 additions & 3 deletions excuter/cpp-common/test/0_dtypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ using namespace std;
using namespace deepx::tf;
using namespace deepx;

int main(int argc, char **argv)
{

void test_1() {
unordered_map<string, TypeDef> dtype_map = {
{"tensor<any>", make_dtype(DataCategory::Tensor, Precision::Any)},
{"tensor<int>", make_dtype(DataCategory::Tensor, Precision::Int)},
Expand Down Expand Up @@ -54,6 +52,26 @@ int main(int argc, char **argv)
}

cout << string(80, '=') << endl;
}

// test to tensor type
void test_2() {
if (typeid(tensor_t<Precision::Float64>)== typeid(double)) {
std::cout<<"it's ok"<<std::endl;
} else {
std::cout<<"it's wrong"<<std::endl;
}

if (typeid(tensor_t<Precision::Float32>)== typeid(float)) {
std::cout<<"it's ok"<<std::endl;
} else {
std::cout<<"it's wrong"<<std::endl;
}
}

int main(int argc, char **argv)
{
// test_1();
test_2();
return 0;
}
Loading