Skip to content

Commit a0e9722

Browse files
authored
dev-0.7.0 (#81)
* new API :: device_type * more constructors * chebyshev_distenace * stdc++fs * COC * deprecate <stdtensor> * fix test * support .at() for rank 0 tensor * raw to flat * flat_tensor::{rank,size,dims} * simplify opencv example * fix test for gcc
1 parent 50553a9 commit a0e9722

20 files changed

+229
-65
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,5 @@ compile_commands.json
4747
CTestTestfile.cmake
4848
install_manifest.txt
4949
Makefile
50+
51+
*.png

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ ELSE()
3333
ADD_DEFINITIONS(-DUSE_FAKE_CUDA_RUNTIME)
3434
ENDIF()
3535

36+
IF(APPLE)
37+
ADD_DEFINITIONS(-DHAVE_STD_CPP_FS)
38+
ELSE()
39+
LINK_LIBRARIES(stdc++fs)
40+
ENDIF()
41+
3642
IF(BUILD_TESTS)
3743
ENABLE_TESTING()
3844
INCLUDE(cmake/tests.cmake)

CODE_OF_CONDUCT

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
"All things were made of numbers."
2+
Pythagoras (c. 570 BC ~ c. 495 BC)
3+
4+
"Beauty is the first test: there is no permanent place in the world for ugly mathematics."
5+
G. H. Hardy (1877 - 1947)
6+
7+
"I, in any case, am convinced that He does not play dice."
8+
Albert Einstein (1879 - 1955)

cmake/tests.cmake

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
INCLUDE(${CMAKE_SOURCE_DIR}/cmake/gtest.cmake)
22

3-
FUNCTION(ADD_GTEST target)
3+
FUNCTION(ADD_UNIT_TEST target)
44
ADD_EXECUTABLE(${target} ${ARGN} tests/main.cpp)
55
TARGET_USE_GTEST(${target})
6+
TARGET_INCLUDE_DIRECTORIES(${target}
7+
PRIVATE ${CMAKE_SOURCE_DIR}/tests/include)
68
TARGET_LINK_LIBRARIES(${target} stdtensor)
79
IF(HAVE_CUDA)
810
TARGET_LINK_LIBRARIES(${target} cudart)
@@ -13,9 +15,6 @@ ENDFUNCTION()
1315
FILE(GLOB tests tests/test_*.cpp)
1416
FOREACH(t ${tests})
1517
GET_FILENAME_COMPONENT(name ${t} NAME_WE)
16-
STRING(REPLACE "_"
17-
"-"
18-
name
19-
${name})
20-
ADD_GTEST(${name} ${t})
18+
STRING(REPLACE "_" "-" name ${name})
19+
ADD_UNIT_TEST(${name} ${t})
2120
ENDFOREACH()

examples/example_opencv.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ using bmp_t = ttl::matrix<pixel_t>;
88

99
void save_bmp(const bmp_t &bmp)
1010
{
11-
const cv::Mat img(cv::Size(bmp.shape().dims()[1], bmp.shape().dims()[0]),
12-
CV_8UC(3), (void *)bmp.data());
11+
uint32_t h, w;
12+
std::tie(h, w) = bmp.dims();
13+
// const auto [h, w] = bmp.dims(); // c++17
14+
const cv::Mat img(cv::Size(w, h), CV_8UC(3), bmp.data());
1315
cv::imwrite("i.png", img);
1416
}
1517

include/stdtensor

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

include/ttl/algorithm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ namespace ttl
66
{
77
using ttl::internal::argmax;
88
using ttl::internal::cast;
9+
using ttl::internal::chebyshev_distenace;
910
using ttl::internal::fill;
1011
using ttl::internal::hamming_distance;
1112
using ttl::internal::max;

include/ttl/bits/flat_tensor_mixin.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ class flat_tensor_mixin
4646
using shape_type = S;
4747
using device_type = D;
4848

49+
rank_t rank() const { return shape_.rank(); }
50+
51+
Dim size() const { return shape_.size(); }
52+
53+
const auto &dims() const { return shape_.dims(); }
54+
4955
size_t data_size() const { return shape_.size() * sizeof(R); }
5056

5157
const S &shape() const { return shape_; }

include/ttl/bits/raw_tensor_mixin.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22
#include <stdexcept>
33
#include <ttl/bits/raw_shape.hpp>
4+
#include <ttl/bits/std_access_traits.hpp>
45
#include <ttl/bits/std_tensor_fwd.hpp>
56
#include <ttl/bits/std_tensor_traits.hpp>
67

@@ -86,6 +87,14 @@ class raw_tensor_mixin
8687
return reinterpret_cast<ptr_type>(data_.get());
8788
}
8889

90+
template <typename R>
91+
auto typed() const
92+
{
93+
using Access = typename basic_access_traits<A>::type;
94+
using T = basic_tensor<R, basic_raw_shape<Dim>, D, Access>;
95+
return T(data<R>(), shape_);
96+
}
97+
8998
template <typename R, rank_t r, typename A1 = A>
9099
basic_tensor<R, basic_shape<r, Dim>, D, A1> ranked_as() const
91100
{
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#pragma once
2+
3+
namespace ttl
4+
{
5+
namespace internal
6+
{
7+
struct owner;
8+
struct readwrite;
9+
struct readonly;
10+
11+
template <typename A>
12+
struct basic_access_traits;
13+
14+
template <>
15+
struct basic_access_traits<owner> {
16+
using type = readwrite;
17+
};
18+
19+
template <>
20+
struct basic_access_traits<readwrite> {
21+
using type = readwrite;
22+
};
23+
24+
template <>
25+
struct basic_access_traits<readonly> {
26+
using type = readonly;
27+
};
28+
} // namespace internal
29+
} // namespace ttl

0 commit comments

Comments
 (0)