Skip to content

Commit

Permalink
std::valarray works as Storage. Documentation is still upcoming. Rela…
Browse files Browse the repository at this point in the history
…ted to #50
  • Loading branch information
shiozaki authored and evaleev committed Jul 29, 2014
1 parent 22b5477 commit 3ac7dd4
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 7 deletions.
2 changes: 1 addition & 1 deletion btas/generic/gemm_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ void gemm (
scal(beta, C);
return;
}

typedef typename _TensorA::value_type value_type;
assert(not ((transA == CblasConjTrans || transB == CblasConjTrans) && std::is_fundamental<value_type>::value));

Expand Down
4 changes: 2 additions & 2 deletions btas/generic/permute.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ namespace btas {
is_boxtensor<_TensorY>::value
>::type
>
void
permute(const _TensorX& X, const _Permutation& p, _TensorY& Y)
void
permute(const _TensorX& X, const _Permutation& p, _TensorY& Y)
{
const auto pr = permute(X.range(),p);
Y.resize(pr);
Expand Down
14 changes: 14 additions & 0 deletions btas/storage_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#ifndef BTAS_STORAGE_TRAITS_H_
#define BTAS_STORAGE_TRAITS_H_

#include <valarray>

#include <btas/index_traits.h>

namespace btas {
Expand Down Expand Up @@ -43,6 +45,18 @@ namespace btas {
typedef const_pointer const_iterator;
};

template <typename _T>
struct storage_traits<std::valarray<_T>> {
typedef _T value_type;
typedef _T& reference;
typedef const _T& const_reference;
typedef size_t size_type;
typedef ptrdiff_t difference_type;

typedef _T* iterator;
typedef typename std::add_const<_T*>::type const_iterator;
};

template <typename _Storage>
struct storage_traits {
typedef typename _Storage::value_type value_type;
Expand Down
6 changes: 3 additions & 3 deletions btas/tensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ namespace btas {
typedef const value_type& const_reference;

/// element iterator
typedef typename storage_type::iterator iterator;
typedef typename storage_traits<storage_type>::iterator iterator;

/// constant element iterator
typedef typename storage_type::const_iterator const_iterator;
typedef typename storage_traits<storage_type>::const_iterator const_iterator;

/// size type
typedef typename storage_type::size_type size_type;
typedef typename storage_traits<storage_type>::size_type size_type;

///@}

Expand Down
30 changes: 29 additions & 1 deletion unittest/tensor_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,35 @@ TEST_CASE("Tensor Constructors")
}
}

TEST_CASE("Tensor")
TEST_CASE("Custom Tensor")
{

SECTION("Storage")
{
{
typedef Tensor<double, btas::DEFAULT::range, std::vector<double> > Tensor;
Tensor T0;
Tensor T1(2,3,4);
}
{
typedef Tensor<double, btas::DEFAULT::range, btas::varray<double> > Tensor;
Tensor T0;
Tensor T1(2,3,4);
}
{
typedef Tensor<double, btas::DEFAULT::range, std::array<double, 24> > Tensor;
Tensor T0;
Tensor T1(2,3,4);
}
{
typedef Tensor<double, btas::DEFAULT::range, std::valarray<double> > Tensor;
Tensor T0;
Tensor T1(2,3,4);
}
}
}

TEST_CASE("Tensor Operations")
{
DTensor T2(3,2);
fillEls(T2);
Expand Down

0 comments on commit 3ac7dd4

Please sign in to comment.