Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangzhimin committed Apr 7, 2018
2 parents 58c1749 + dddcf58 commit 2634bfc
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 19 deletions.
10 changes: 5 additions & 5 deletions matazure/common.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma once
#pragma once

#include <matazure/tensor.hpp>
#include <matazure/algorithm.hpp>
Expand Down Expand Up @@ -502,11 +502,11 @@ inline auto slice(_Tensor ts, int_t positon_index)->decltype(make_lambda(interna
}

/// special for slice<rank-1>(tensor<_T, rank>, position_index), it produces a tensor<_T, rank-1>
template <int_t _DimIdx, typename _T, int_t _Rank, typename _Layout>
inline auto slice(tensor<_T, _Rank, _Layout> ts, int_t positon_index, enable_if_t<_DimIdx == _Rank-1>* = nullptr)->tensor<_T, _Rank-1, _Layout>{
const auto slice_ext = internal::slice_point<_DimIdx>(ts.shape());
template <typename _T, int_t _Rank>
inline auto dense_slice(tensor<_T, _Rank, first_major_layout<_Rank>> ts, int_t positon_index)->tensor<_T, _Rank-1, first_major_layout<_Rank-1>>{
const auto slice_ext = internal::slice_point<_Rank-1>(ts.shape());
auto slice_size = cumulative_prod(slice_ext)[_Rank-1];
tensor<_T, _Rank-1, _Layout> ts_re(slice_ext, shared_ptr<_T>(ts.shared_data().get() + positon_index * slice_size, [ts](_T *){ }));
tensor<_T, _Rank-1, first_major_layout<_Rank-1>> ts_re(slice_ext, shared_ptr<_T>(ts.shared_data().get() + positon_index * slice_size, [ts](_T *){ }));
return ts_re;
}

Expand Down
4 changes: 2 additions & 2 deletions matazure/point.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#pragma once

#include <matazure/config.hpp>
#include <matazure/type_traits.hpp>

namespace matazure {

Expand Down
37 changes: 26 additions & 11 deletions matazure/tensor.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/**
* Defines tensor classes of host end
*/

Expand Down Expand Up @@ -38,6 +38,21 @@ class first_major_layout{
});
}

first_major_layout(const first_major_layout &rhs) :
first_major_layout(rhs.shape())
{ }

first_major_layout & operator=(const first_major_layout &rhs) {
shape_ = rhs.shape();
stride_ = get_stride(shape_);

matazure::for_each(shape_, [](int_t b) {
if (b < 0) throw invalid_shape{};
});

return *this;
}

MATAZURE_GENERAL int_t index2offset(const pointi<rank> &id) const {
int_t offset = id[0];
for (int_t i = 1; i < rank; ++i) {
Expand Down Expand Up @@ -78,8 +93,8 @@ class first_major_layout{
}

private:
const pointi<rank> shape_;
const pointi<rank> stride_;
pointi<rank> shape_;
pointi<rank> stride_;
};

template <int_t _Rank>
Expand Down Expand Up @@ -453,7 +468,7 @@ struct is_tensor<static_tensor<_ValueType, _Ext>> : bool_constant<true> {};
template <typename _ValueType, int_t _Rank, typename _Layout = first_major_layout<_Rank>>
class tensor : public tensor_expression<tensor<_ValueType, _Rank, _Layout>> {
public:
static_assert(std::is_pod<_ValueType>::value, "only supports pod type now");
//static_assert(std::is_pod<_ValueType>::value, "only supports pod type now");
/// the rank of tensor
static const int_t rank = _Rank;
/**
Expand Down Expand Up @@ -662,10 +677,10 @@ class tensor : public tensor_expression<tensor<_ValueType, _Rank, _Layout>> {
#endif

public:
const pointi<rank> extent_;
const layout_type layout_;
const shared_ptr<value_type> sp_data_;
value_type * const data_;
pointi<rank> extent_;
layout_type layout_;
shared_ptr<value_type> sp_data_;
value_type * data_;
};

using column_major_layout = first_major_layout<2>;
Expand All @@ -675,9 +690,9 @@ using row_major_layout = last_major_layout<2>;
template <typename _ValueType, typename _Layout = column_major_layout>
using matrix = tensor<_ValueType, 2, _Layout>;

/// alias of tensor <_ValueType, 1>
template <typename _ValueType, typename _Layout = first_major_layout<1>>
using vector = tensor<_ValueType, 1, _Layout>;
///// alias of tensor <_ValueType, 1>
//template <typename _ValueType, typename _Layout = first_major_layout<1>>
//using vector = tensor<_ValueType, 1, _Layout>;

/// alias of tensor<static_tensor<_ValueType, _BlockDim>, _BlockDim::size(), _Layout>
template <typename _ValueType, typename _BlockDim, typename _Layout = first_major_layout<_BlockDim::size()>>
Expand Down
1 change: 0 additions & 1 deletion test/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
int main(int argc, char * argv[]){
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();

}

0 comments on commit 2634bfc

Please sign in to comment.