Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/api/c/mean.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static outType mean(const af_array &in)
template<typename inType, typename outType>
static outType mean(const af_array &in, const af_array &weights)
{
typedef baseOutType<outType> bType;
typedef typename baseOutType<outType>::type bType;

Array<outType> input = cast<outType>(getArray<inType>(in));
Array<outType> wts = cast<outType>(getArray<bType>(weights));
Expand All @@ -55,7 +55,7 @@ static af_array mean(const af_array &in, dim_type dim)
template<typename inType, typename outType>
static af_array mean(const af_array &in, const af_array &weights, dim_type dim)
{
typedef baseOutType<outType> bType;
typedef typename baseOutType<outType>::type bType;

Array<outType> input = cast<outType>(getArray<inType>(in));
Array<outType> wts = cast<outType>(getArray<bType>(weights));
Expand Down
34 changes: 30 additions & 4 deletions src/api/c/stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,37 @@

#pragma once

template<typename T, typename Other>
struct is_same{
static const bool value = false;
};

template<typename T>
using baseOutType = typename std::conditional< std::is_same<T, cdouble>::value ||
std::is_same<T, double>::value,
double,
float>::type;
struct is_same<T, T> {
static const bool value = true;
};

template<bool, typename T, typename O>
struct cond_type;

template<typename T, typename Other>
struct cond_type<true, T, Other> {
typedef T type;
};

template<typename T, typename Other>
struct cond_type<false, T, Other> {
typedef Other type;
};

template<typename T>
struct baseOutType {
typedef typename cond_type< is_same<T, cdouble>::value ||
is_same<T, double>::value,
double,
float>::type type;
};

template<typename T>
inline T mean(const Array<T>& in)
{
Expand Down
4 changes: 2 additions & 2 deletions src/api/c/var.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static outType varAll(const af_array& in, bool isbiased)
template<typename inType, typename outType>
static outType varAll(const af_array& in, const af_array weights)
{
typedef baseOutType<outType> bType;
typedef typename baseOutType<outType>::type bType;

Array<outType> input = cast<outType>(getArray<inType>(in));
Array<outType> wts = cast<outType>(getArray<bType>(weights));
Expand Down Expand Up @@ -91,7 +91,7 @@ static af_array var(const af_array& in, bool isbiased, int dim)
template<typename inType, typename outType>
static af_array var(const af_array& in, const af_array& weights, dim_type dim)
{
typedef baseOutType<outType> bType;
typedef typename baseOutType<outType>::type bType;

Array<outType> input = cast<outType>(getArray<inType>(in));
Array<outType> wts = cast<outType>(getArray<bType>(weights));
Expand Down