Boost logo

Glas :

Re: [glas] value_type

From: Dan Piponi (dpiponi_at_[hidden])
Date: 2005-10-03 15:55:10


>Currently all types that are a model of the NumericValue concept can be
>used as a value_type of a matrix. Do you think this is too restrictive?
>And if yes, what exactly is too restrictive for your case ?
>(the doc for the NumericValue concept is attached)

In order to use matrix multiplication one only needs the underlying type to be a semiring, ie. no assumption need be made about whether the underlying type has a subtraction or division. Examples of semirings without subtraction or division that are widely used in many algorithms are the set {true,flase} with the boolean operations and the set R\union\infty with the operations max() and + (see Cormen, Leiserson, Rivest).

--
Dan Piponi

Glas: NumericValue concept

NumericValue concept

Description

This is the concept for numerical data types used as values in vectors and matrices. Currently, the concept contains all operations on values. This could easily be split up into for example, AdditiveNumericValue, MultiplicativeNumericValue, FunctionNumericValue, PrintNumericValue, etc.

Refinement of

DefaultConstructible Assignable

Associated types

Notation

X A type that is a model of NumericValue
abs_value_traits<X>::type Type of modulus or absolute value of type X
x,y Objects of type X
z Object of type convertible to X

Definitions

Valid expressions

Name Expression Type requirements Return type
Constructor X(z) X
Zero member zero<X>() X
One member one<X>() X
Addition x + y X
Addition x += y X
Negation - x X
Subtraction x - y X
Subtraction x -= y X
Multiplication x * y X
Multiplication x *= y X
Division x / y X
Division x /= y X
Modulus abs(x) abs_value_traits<X>::type
Square of modulus abs_square(x) abs_value_traits<X>::type
Sum of the absolute value of real and imaginary parts scalar_abs_sum(x) abs_value_traits<X>::type
Maximum of the absolute value of real and imaginary parts scalar_abs_max(x) abs_value_traits<X>::type
Conjugate conj(x) X

Expression semantics

Name Expression Precondition Semantics Postcondition
Constructor X(z)
Zero member zero<X>() The zero member is such that a + zero<X>() == a.
One member one<X>() The one member is such that a * one<X>() == a.
Addition x + y
Addition x += y Is equivalent to x = x + y
Negation - x
Subtraction x - y
Subtraction x -= y Is equivalent to x = x - y
Multiplication x * y
Multiplication x *= y Is equivalent to x = x * y
Division x / y y != zero<X>()
Division x /= y y != zero<X>() Is equivalent to x = x / y
Modulus abs(x)
Square of modulus abs_square(x)
Sum of the absolute value of real and imaginary parts scalar_abs_sum(x)
Maximum of the absolute value of real and imaginary parts scalar_abs_max(x)
Conjugate conj(x)

Complexity guarantees

Invariants

Models

Notes