-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* remove tensor.h * rm src/tensor.cpp * new api :: consistent_variable * update basic_flat_shape * check bound * fix windows build
- Loading branch information
Showing
16 changed files
with
161 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
FUNCTION(BUILD_STDML_TENSOR_LIB target) | ||
# libtensor will be shared by python/haskell bindings | ||
FILE(GLOB_RECURSE srcs ${CMAKE_SOURCE_DIR}/src/stdml/*) | ||
ADD_LIBRARY(${target} ${srcs}) | ||
SET_TARGET_PROPERTIES(${target} PROPERTIES POSITION_INDEPENDENT_CODE ON) | ||
TARGET_LINK_LIBRARIES(${target} dl) | ||
SET_PROPERTY(TARGET ${target} PROPERTY CXX_STANDARD 17) | ||
INSTALL(TARGETS ${target} ARCHIVE DESTINATION lib) | ||
ENDFUNCTION() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
SET(CPACK_DEBIAN_PACKAGE_MAINTAINER "lg4869@outlook.com") | ||
SET(CPACK_GENERATOR "TGZ") | ||
SET(CPACK_PACKAGE_DIRECTORY ${CMAKE_SOURCE_DIR}/release) | ||
SET(CPACK_PACKAGE_VERSION | ||
"latest" | ||
CACHE STRING "Release version.") | ||
IF(BUILD_DEB) | ||
SET(CPACK_GENERATOR "TGZ;DEB") | ||
# SET(CPACK_GENERATOR "TGZ;RPM") | ||
ENDIF() | ||
INCLUDE(CPack) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#pragma once | ||
#include <stdexcept> | ||
#include <string> | ||
|
||
namespace ttl | ||
{ | ||
namespace internal | ||
{ | ||
struct std_to_string { | ||
template <typename T> | ||
std::string operator()(const T &x) const | ||
{ | ||
return std::to_string(x); | ||
} | ||
}; | ||
|
||
template <typename T, typename Str = std_to_string> | ||
class consistent_variable | ||
{ | ||
T value_; | ||
bool assigned_; | ||
|
||
public: | ||
consistent_variable() : assigned_(false) {} | ||
|
||
consistent_variable(T value) : value_(std::move(value)), assigned_(true) {} | ||
|
||
void operator=(T v) | ||
{ | ||
if (assigned_) { | ||
if (value_ != v) { | ||
// TODO: customized exception | ||
throw std::invalid_argument( | ||
"consistent_variable was assigned: " + Str()(value_) + | ||
" now assigned: " + Str()(v)); | ||
} | ||
} else { | ||
value_ = std::move(v); | ||
assigned_ = true; | ||
} | ||
} | ||
|
||
operator T() const | ||
{ | ||
if (!assigned_) { | ||
// TODO: customized exception | ||
throw std::runtime_error("consistent_variable not assigned"); | ||
} | ||
return value_; | ||
} | ||
}; | ||
} // namespace internal | ||
} // namespace ttl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#pragma once | ||
#include <ttl/bits/consistent_variable.hpp> | ||
|
||
namespace ttl | ||
{ | ||
using ttl::internal::consistent_variable; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#include "testing.hpp" | ||
|
||
#include <ttl/consistent_variable> | ||
|
||
TEST(consistent_variable_test, test_1) | ||
{ | ||
ttl::consistent_variable<int> i; | ||
i = 1; | ||
try { | ||
i = 2; | ||
ASSERT_TRUE(false); | ||
} catch (...) { | ||
ASSERT_TRUE(true); | ||
} | ||
|
||
try { | ||
i = 1; | ||
ASSERT_TRUE(true); | ||
} catch (...) { | ||
ASSERT_TRUE(false); | ||
} | ||
} | ||
|
||
TEST(consistent_variable_test, test_2) | ||
{ | ||
ttl::consistent_variable<int> i; | ||
try { | ||
int j = i; | ||
ASSERT_TRUE(false); | ||
ASSERT_EQ(j, 0); | ||
} catch (...) { | ||
ASSERT_TRUE(true); | ||
} | ||
|
||
i = 1; | ||
try { | ||
int j = i; | ||
ASSERT_TRUE(true); | ||
ASSERT_EQ(j, 1); | ||
} catch (...) { | ||
ASSERT_TRUE(false); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.