Skip to content

Commit 6490bc5

Browse files
authored
merge from dev branch (#101)
* remove tensor.h * rm src/tensor.cpp * new api :: consistent_variable * update basic_flat_shape * check bound * fix windows build
1 parent 5c092a7 commit 6490bc5

File tree

16 files changed

+161
-120
lines changed

16 files changed

+161
-120
lines changed

.github/workflows/windows.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ jobs:
1111
steps:
1212
- uses: actions/checkout@v1
1313

14-
- run: cmake . -DBUILD_TESTS=1 -DBUILD_GTEST=1 -DUSE_STRICT=0 -DBUILD_LIB=1
14+
- run: cmake . -DBUILD_TESTS=1 -DBUILD_GTEST=1 -DUSE_STRICT=0 -DBUILD_LIB=0
1515
- run: cmake --build . --config Release
1616
- run: ctest -C Release

CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
2525

2626
OPTION(BUILD_LIB "Build c lib." OFF)
2727
IF(BUILD_LIB)
28-
ADD_LIBRARY(stdtensor src/tensor.cpp)
29-
INSTALL(TARGETS stdtensor ARCHIVE DESTINATION lib)
28+
INCLUDE(cmake/lib.cmake)
29+
BUILD_STDML_TENSOR_LIB(tensor)
3030
ENDIF()
3131

3232
INSTALL(DIRECTORY include DESTINATION .)
@@ -55,3 +55,7 @@ ENDIF()
5555
IF(BUILD_EXAMPLES)
5656
INCLUDE(cmake/examples.cmake)
5757
ENDIF()
58+
59+
IF(BUILD_RELEASE)
60+
INCLUDE(cmake/pack.cmake)
61+
ENDIF()

cmake/examples.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ FUNCTION(ADD_C_EXAMPLE target)
88
ENDFUNCTION()
99

1010
ADD_CPP_EXAMPLE(example-1 examples/example_1.cpp)
11-
ADD_C_EXAMPLE(example-c-api examples/example_c_api.c)
1211

1312
OPTION(USE_OPENCV "Build examples with libopencv-dev" OFF)
1413

cmake/lib.cmake

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FUNCTION(BUILD_STDML_TENSOR_LIB target)
2+
# libtensor will be shared by python/haskell bindings
3+
FILE(GLOB_RECURSE srcs ${CMAKE_SOURCE_DIR}/src/stdml/*)
4+
ADD_LIBRARY(${target} ${srcs})
5+
SET_TARGET_PROPERTIES(${target} PROPERTIES POSITION_INDEPENDENT_CODE ON)
6+
TARGET_LINK_LIBRARIES(${target} dl)
7+
SET_PROPERTY(TARGET ${target} PROPERTY CXX_STANDARD 17)
8+
INSTALL(TARGETS ${target} ARCHIVE DESTINATION lib)
9+
ENDFUNCTION()

cmake/pack.cmake

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
SET(CPACK_DEBIAN_PACKAGE_MAINTAINER "lg4869@outlook.com")
2+
SET(CPACK_GENERATOR "TGZ")
3+
SET(CPACK_PACKAGE_DIRECTORY ${CMAKE_SOURCE_DIR}/release)
4+
SET(CPACK_PACKAGE_VERSION
5+
"latest"
6+
CACHE STRING "Release version.")
7+
IF(BUILD_DEB)
8+
SET(CPACK_GENERATOR "TGZ;DEB")
9+
# SET(CPACK_GENERATOR "TGZ;RPM")
10+
ENDIF()
11+
INCLUDE(CPack)

cmake/tests.cmake

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ FUNCTION(ADD_UNIT_TEST target)
55
TARGET_USE_GTEST(${target})
66
TARGET_INCLUDE_DIRECTORIES(${target}
77
PRIVATE ${CMAKE_SOURCE_DIR}/tests/include)
8-
IF(BUILD_LIB)
9-
TARGET_LINK_LIBRARIES(${target} stdtensor)
10-
ENDIF()
118
IF(HAVE_CUDA)
129
TARGET_LINK_LIBRARIES(${target} cudart)
1310
ENDIF()

configure

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ BUILD_BENCHMARKS=0
88
BUILD_EXAMPLES=0
99
BUILD_GBENCH=0
1010
BUILD_GTEST=0
11-
BUILD_LIB=1 # FIXME: make it false
11+
BUILD_LIB=0
1212
BUILD_TESTS=0
1313

1414
HAVE_CUDA=0
@@ -55,6 +55,9 @@ parse_args() {
5555
CUDA_HOME="${i#*=}"
5656
echo "configure --with-cuda=$CUDA_HOME"
5757
;;
58+
--release=*)
59+
RELEASE="${i#*=}"
60+
;;
5861
--verbose)
5962
VERBOSE=1
6063
;;
@@ -119,6 +122,11 @@ add_cmake_flags() {
119122

120123
# add_cmake_flag BUILD_DOCS 1
121124
# add_cmake_flag CMAKE_FIND_DEBUG_MODE 1
125+
126+
if [ ! -z "$RELEASE" ]; then
127+
add_cmake_flag CPACK_PACKAGE_VERSION $RELEASE
128+
add_cmake_flag BUILD_RELEASE 1
129+
fi
122130
}
123131

124132
main() {

examples/example_c_api.c

Lines changed: 0 additions & 9 deletions
This file was deleted.

include/tensor.h

Lines changed: 0 additions & 30 deletions
This file was deleted.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#pragma once
2+
#include <stdexcept>
3+
#include <string>
4+
5+
namespace ttl
6+
{
7+
namespace internal
8+
{
9+
struct std_to_string {
10+
template <typename T>
11+
std::string operator()(const T &x) const
12+
{
13+
return std::to_string(x);
14+
}
15+
};
16+
17+
template <typename T, typename Str = std_to_string>
18+
class consistent_variable
19+
{
20+
T value_;
21+
bool assigned_;
22+
23+
public:
24+
consistent_variable() : assigned_(false) {}
25+
26+
consistent_variable(T value) : value_(std::move(value)), assigned_(true) {}
27+
28+
void operator=(T v)
29+
{
30+
if (assigned_) {
31+
if (value_ != v) {
32+
// TODO: customized exception
33+
throw std::invalid_argument(
34+
"consistent_variable was assigned: " + Str()(value_) +
35+
" now assigned: " + Str()(v));
36+
}
37+
} else {
38+
value_ = std::move(v);
39+
assigned_ = true;
40+
}
41+
}
42+
43+
operator T() const
44+
{
45+
if (!assigned_) {
46+
// TODO: customized exception
47+
throw std::runtime_error("consistent_variable not assigned");
48+
}
49+
return value_;
50+
}
51+
};
52+
} // namespace internal
53+
} // namespace ttl

0 commit comments

Comments
 (0)