コード例 #1
0
ファイル: orth.hpp プロジェクト: masteroftime/viennamesh-dev
dense2D<typename mtl::Collection
<typename mtl::Collection<VVector>::value_type
>::value_type, parameters<> >
inline orthogonalize_factors(VVector& v, tag::vector)
{
    using ::mtl::two_norm;
    using math::zero;
    using mtl::size1D;
    typedef typename mtl::Collection<VVector>::size_type  Size;
    typedef typename mtl::Collection<VVector>::value_type Vector;
    typedef typename mtl::Collection<Vector>::value_type  Scalar;

    dense2D<Scalar, parameters<> > tau(size1D(v), size1D(v));
    tau= zero(Scalar());

    for (Size j= 0; j < size1D(v); ++j) {
        for (Size i= 0; i < j; ++i) {
            Scalar t= dot(entry1D(v, i), entry1D(v, j)) / tau[i][i];
            tau[i][j]= t;
            entry1D(v, j)-= t * entry1D(v, i);
        }
        tau[j][j]= dot(entry1D(v, j), entry1D(v, j));
    }
    return tau;
}
コード例 #2
0
ファイル: unit_vector.hpp プロジェクト: guolisen/DLStudy
    typename traits::unit_vector<Value>::type
    inline unit_vector(std::size_t k, std::size_t n)
    {
	using math::zero; using math::one;
	dense_vector<Value> v(n, zero(Value()));
	v[k]= one(Value());
	return v;
    }
コード例 #3
0
    // To prevent that cout << A * B prints the element-wise product, suggestion by Hui Li
    // It is rather inefficient, esp. for multiple products (complexity increases with the number of arguments :-!)
    //    or sparse matrices. 
    // Better compute your product first and print it then when compute time is an issue,
    // this is ONLY for convenience.
    result_value_type
    operator()(std::size_t r, std::size_t c) const
    {
	using math::zero;
	MTL_THROW_IF(num_cols(first) != num_rows(second), incompatible_size());

	result_value_type ref, sum(zero(ref));
	for (std::size_t i= 0; i < num_cols(first); i++)
	    sum+= first(r, i) * second(i, c);
	return sum;
    }
コード例 #4
0
typename Collection<Matrix>::value_type
inline trace(const Matrix& matrix)
{
    using math::zero;
    typedef typename Collection<Matrix>::value_type value_type;

    MTL_THROW_IF(num_rows(matrix) != num_cols(matrix), matrix_not_square());

    // If matrix is empty then the result is the identity from the default-constructed value
    if (num_rows(matrix) == 0) {
	value_type ref;
	return zero(ref);
    }

    value_type value= matrix[0][0];
    for (unsigned i= 1; i < num_rows(matrix); i++)
	value+= matrix[i][i];	
    return value;
}
コード例 #5
0
    static inline void init(Value& value)
    {
	using math::zero;
	value= zero(value);
    }
コード例 #6
0
ファイル: sparse_banded.hpp プロジェクト: FaceMixer/FaceMixer
    /// Value of matrix entry
    value_type operator()(size_type r, size_type c) const
    {
	using math::zero;
	utilities::maybe<size_type> o= offset(r, c);
	return o ? data[o.value()] : zero(value_type());
    }
コード例 #7
0
ファイル: imag.hpp プロジェクト: guolisen/DLStudy
	result_type operator()(const Value& v) const
	{
	    using math::zero;
	    return zero(v);
	}
コード例 #8
0
ファイル: imag.hpp プロジェクト: guolisen/DLStudy
	static inline result_type apply(const Value& v)
	{
	    using math::zero;
	    return zero(v);
	}
コード例 #9
0
ファイル: signum.hpp プロジェクト: FaceMixer/FaceMixer
	static inline Value apply(const Value& v)
	{
	    using math::zero; using math::one;
	    return v == zero(v) ? zero(v) : ( v < zero(v) ? -one(v) : one(v) );
	}