Skip to content

Commit

Permalink
remove constraint on leading stride for dynamic layout (#62)
Browse files Browse the repository at this point in the history
* remove constraint on leading stride for dynamic layout

* fix up PR

* make default storage order & leading stride behavior configurable
  • Loading branch information
wolfv authored and JohanMabille committed Mar 14, 2018
1 parent a6d6d7f commit 9e2037c
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions include/xtensor-blas/xblas_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@
#include "xflens/cxxblas/typedefs.h"
#include "xtensor/xutils.hpp"

#ifndef DEFAULT_LEADING_STRIDE_BEHAVIOR
#define DEFAULT_LEADING_STRIDE_BEHAVIOR throw std::runtime_error("No valid layout chosen.");
#endif

#ifndef DEFAULT_STORAGE_ORDER_BEHAVIOR
#define DEFAULT_STORAGE_ORDER_BEHAVIOR throw std::runtime_error("Cannot handle layout_type of e.");
#endif

namespace xt
{
template <layout_type L = layout_type::row_major, class T>
Expand Down Expand Up @@ -83,7 +91,7 @@ namespace xt
{
return cxxblas::StorageOrder::ColMajor;
}
throw std::runtime_error("Cannot handle layout_type of e.");
DEFAULT_STORAGE_ORDER_BEHAVIOR;
}

/**
Expand All @@ -93,30 +101,27 @@ namespace xt
template <class A, std::enable_if_t<A::static_layout == layout_type::row_major>* = nullptr>
inline BLAS_IDX get_leading_stride(const A& a)
{
return (BLAS_IDX) (a.strides().front() == 0 ? a.shape().back() : a.strides().front());
return static_cast<BLAS_IDX>(a.strides().front() == 0 ? a.shape().back() : a.strides().front());
}

template <class A, std::enable_if_t<A::static_layout == layout_type::column_major>* = nullptr>
inline BLAS_IDX get_leading_stride(const A& a)
{
return (BLAS_IDX) (a.strides().back() == 0 ? a.shape().front() : a.strides().back());
return static_cast<BLAS_IDX>(a.strides().back() == 0 ? a.shape().front() : a.strides().back());
}

template <class A, std::enable_if_t<A::static_layout != layout_type::row_major && A::static_layout != layout_type::column_major>* = nullptr>
inline BLAS_IDX get_leading_stride(const A& a)
{
if (a.layout() == layout_type::row_major)
{
return (BLAS_IDX) (a.strides().front() == 0 ? a.shape().back() : a.strides().front());
return static_cast<BLAS_IDX>(a.strides().front() == 0 ? a.shape().back() : a.strides().front());
}
else if (a.layout() == layout_type::column_major)
{
return (BLAS_IDX) (a.strides().back() == 0 ? a.shape().front() : a.strides().back());
}
else
{
throw std::runtime_error("No valid layout chosen.");
return static_cast<BLAS_IDX>(a.strides().back() == 0 ? a.shape().front() : a.strides().back());
}
DEFAULT_LEADING_STRIDE_BEHAVIOR;
}

/*******************************
Expand Down

0 comments on commit 9e2037c

Please sign in to comment.