Commit 715ca0da authored by Davis King's avatar Davis King

Added more BLAS bindings.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%402777
parent de22808a
......@@ -237,7 +237,7 @@ namespace dlib
// At some point I need to improve the default (i.e. non BLAS) matrix
// multiplication algorithm...
if (alpha == 1)
if (alpha == static_cast<typename src_exp::type>(1))
{
if (add_to)
{
......@@ -283,8 +283,7 @@ namespace dlib
typename src_exp::type alpha, \
bool add_to \
) { \
typedef typename dest_exp::type T; \
const bool is_row_major_order = is_same_type<typename dest_exp::layout_type,row_major_layout>::value;
typedef typename dest_exp::type T;
#define DLIB_END_BLAS_BINDING }};
......@@ -455,7 +454,7 @@ namespace dlib
bool add_to
)
{
if (src_exp::cost > 9 || src_exp2::cost > 9)
if (has_matrix_multiply<src_exp>::value || has_matrix_multiply<src_exp2>::value)
{
matrix_assign_blas_proxy(dest, src.lhs, alpha, add_to);
matrix_assign_blas_proxy(dest, src.rhs, alpha, true);
......@@ -495,7 +494,8 @@ namespace dlib
bool add_to
)
{
if (src_exp::cost > 9 || src_exp2::cost > 9)
if (has_matrix_multiply<src_exp>::value || has_matrix_multiply<src_exp2>::value)
{
matrix_assign_blas_proxy(dest, src.lhs, alpha, add_to);
matrix_assign_blas_proxy(dest, src.rhs, -alpha, true);
......@@ -614,27 +614,20 @@ namespace dlib
const matrix_add_exp<matrix<T,NR,NC,MM,L> ,src_exp>& src
)
{
if (src_exp::cost > 5)
if (src.rhs.aliases(dest) == false)
{
if (src.rhs.aliases(dest) == false)
if (&src.lhs != &dest)
{
if (&src.lhs != &dest)
{
dest = src.lhs;
}
matrix_assign_blas_proxy(dest, src.rhs, 1, true);
}
else
{
matrix<T,NR,NC,MM,L> temp(src.lhs);
matrix_assign_blas_proxy(temp, src.rhs, 1, true);
temp.swap(dest);
dest = src.lhs;
}
matrix_assign_blas_proxy(dest, src.rhs, 1, true);
}
else
{
matrix_assign_default(dest,src);
matrix<T,NR,NC,MM,L> temp(src.lhs);
matrix_assign_blas_proxy(temp, src.rhs, 1, true);
temp.swap(dest);
}
}
......@@ -667,27 +660,20 @@ namespace dlib
const matrix_subtract_exp<matrix<T,NR,NC,MM,L> ,src_exp>& src
)
{
if (src_exp::cost > 5)
if (src.rhs.aliases(dest) == false)
{
if (src.rhs.aliases(dest) == false)
if (&src.lhs != &dest)
{
if (&src.lhs != &dest)
{
dest = src.lhs;
}
matrix_assign_blas_proxy(dest, src.rhs, -1, true);
}
else
{
matrix<T,NR,NC,MM,L> temp(src.lhs);
matrix_assign_blas_proxy(temp, src.rhs, -1, true);
temp.swap(dest);
dest = src.lhs;
}
matrix_assign_blas_proxy(dest, src.rhs, -1, true);
}
else
{
matrix_assign_default(dest,src);
matrix<T,NR,NC,MM,L> temp(src.lhs);
matrix_assign_blas_proxy(temp, src.rhs, -1, true);
temp.swap(dest);
}
}
......
......@@ -28,7 +28,7 @@ namespace dlib
struct is_small_matrix { static const bool value = false; };
template < typename EXP >
struct is_small_matrix<EXP, typename enable_if_c<EXP::NR>=1 && EXP::NC>=1 &&
EXP::NR<=100 && EXP::NC<=100>::type > { static const bool value = true; };
EXP::NR<=100 && EXP::NC<=100 && (EXP::cost < 70)>::type> { static const bool value = true; };
}
// ----------------------------------------------------------------------------------------
......@@ -114,7 +114,7 @@ namespace dlib
{
if (add_to)
{
if (alpha == 1)
if (alpha == static_cast<typename EXP2::type>(1))
{
for (long r = 0; r < src.nr(); ++r)
{
......@@ -124,7 +124,7 @@ namespace dlib
}
}
}
else if (alpha == -1)
else if (alpha == static_cast<typename EXP2::type>(-1))
{
for (long r = 0; r < src.nr(); ++r)
{
......@@ -147,7 +147,7 @@ namespace dlib
}
else
{
if (alpha == 1)
if (alpha == static_cast<typename EXP2::type>(1))
{
for (long r = 0; r < src.nr(); ++r)
{
......
This diff is collapsed.
// Copyright (C) 2009 Davis E. King (davisking@users.sourceforge.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_MATRIx_CONJ_TRANS_FUNCTIONS
#define DLIB_MATRIx_CONJ_TRANS_FUNCTIONS
#include "matrix_utilities.h"
#include "matrix_math_functions.h"
#include "matrix.h"
#include "../algs.h"
#include <cmath>
#include <complex>
#include <limits>
namespace dlib
{
/*!
The point of the two functions defined in this file is to make statements
of the form conj(trans(m)) and trans(conj(m)) look the same so that it is
easier to map them to BLAS functions later on.
!*/
// ----------------------------------------------------------------------------------------
struct op_conj_trans
{
template <typename EXP>
struct op : has_destructive_aliasing
{
const static long cost = EXP::cost;
const static long NR = EXP::NC;
const static long NC = EXP::NR;
typedef typename EXP::type type;
typedef typename EXP::mem_manager_type mem_manager_type;
template <typename M>
static type apply ( const M& m, long r, long c)
{ return std::conj(m(c,r)); }
template <typename M>
static long nr (const M& m) { return m.nc(); }
template <typename M>
static long nc (const M& m) { return m.nr(); }
};
};
template <typename EXP>
const matrix_unary_exp<EXP,op_conj_trans> trans (
const matrix_unary_exp<EXP,op_conj>& m
)
{
typedef matrix_unary_exp<EXP,op_conj_trans> exp;
return exp(m.m);
}
template <typename EXP>
const matrix_unary_exp<EXP,op_conj_trans> conj (
const matrix_unary_exp<EXP,op_trans>& m
)
{
typedef matrix_unary_exp<EXP,op_conj_trans> exp;
return exp(m.m);
}
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_MATRIx_CONJ_TRANS_FUNCTIONS
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment