Into

Modules

Documentation

namespace referencePii

This namespace contains general-purpose functions, type definitions, and data structures that are independent of other modules and plug-ins.

Utility functions for dealing with matrices.

Classes

struct

An adaptable unary function for taking the absolute value.

struct

An adaptable unary function for taking the absolute value of the square of a real number.

struct

An adaptable unary function for taking the absolute value of the square of a complex number.

struct

An adaptable unary function for taking the absolute value of a complex number.

struct

An adaptable binary function that calculates the absolute difference of its arguments, .

struct

An adaptable binary function that raises the absolute value of its first argument to the power of the second argument.

struct

An adaptable binary function that calculates the sum of absolute values, .

struct

A unary function that returns acos(x).

struct

A specialization for floats.

struct

A template that performs a logical AND operation on its boolean template parameters.

struct
struct

A unary function that returns asin(x).

struct

A specialization for floats.

struct

A unary function that returns tan(x).

struct

An adaptable binary function that calculates the arc tangent of two variables.

struct

Specialization for float arguments.

struct

A specialization for floats.

struct

An adaptable binary functor that performs the binary AND operation.

class

A unary/binary function adaptor that makes the results of two unary functions the arguments of a binary function.

struct

An stl-compatible model for an adaptable binary function.

struct

An adaptable binary unary functor that performs the binary NOT operation.

struct

An adaptable binary functor that performs the binary OR operation.

struct

An adaptable binary binary functor that shifts the left operand left as many times as indicated by the right operand.

struct

An adaptable binary binary functor that shifts the left operand right as many times as indicated by the right operand.

struct

An adaptable binary functor that performs the binary XOR operation.

struct

A unary function that bounds its argument to a predefined range.

struct

An adaptable unary function that casts its argument from type From to type To.

struct

A unary function that returns ceil(x).

struct

An adaptable unary function that returns the complex conjugate of a real number (which is the argument itself) or a complex number.

struct

A unary function that returns cos(x).

struct

A specialization for floats.

class

A unary function that increments/decrements its internal counter by a predefined value each time the function is called.

class

Implements eigenvalue calculations and stores the results of the calculations (eigenvalues and eigenvectors).

struct

An empty structure.

struct

An adaptable unary function for calculating the base-e exponential.

struct

A structure whose constant boolValue member evaluates to false.

struct

An adaptable binary function that uses a fast approximation (0.01 rad accuracy) to calculate the arc tangent of two variables.

struct

An adaptable binar function that uses a very fast but crude approximation (0.07 rad accuracy) to calculate the arc tangent of two variables.

struct

A unary function that returns floor(x).

struct

Helper function for algorithms that involve scrolling elements.

struct

An stl-compatible model for a generator function that takes no arguments.

struct

An adaptable binary function that calculates the hypotenuse given two orthogonal sides of a triangle, .

struct

Specialization for integer arguments.

struct

A structure whose nested type, Type, is T.

struct

A unary function that returns its argument: f(x) = x.

class

A class that wraps a floating-point number and allows one to twiddle its bits.

struct

A traits structure that specifies the bit counts and corresponding integer types for the double type.

struct

A traits structure that specifies the bit counts and corresponding integer types for the float type.

struct

A conditional template.

struct
struct

A conditional template that accepts a type name as the condition parameter.

struct

A unary function that returns the imaginary part of its argument.

struct

A unary function that returns the imaginary part of its argument.

struct
struct

An adaptable unary function that returns the inverse of its argument (1/x).

struct

A tester struct whose boolValue member evaluates statically to true if the template parameter T is an array.

struct
struct

A structure whose boolValue member evaluates statically to true if (and only if) Base is a base class of Derived.

struct

A type trait for checking the colorness of a type.

struct
struct
struct
struct
struct
struct
struct

A tester struct whose boolValue member evaluates statically to true if the template parameter T is a complex number (std::complex).

struct
struct

A tester struct whose boolValue member evaluates statically to true if the template parameter T is a const type.

struct
struct

A tester struct whose boolValue member evaluates statically to true if the template parameter T is a floating point number type.

struct
struct
struct
struct

A tester struct whose boolValue member evaluates statically to true if the template parameter T is an integer type (either signed or unsigned).

struct

A tester struct whose boolValue member evaluates statically to true if the template parameter T is a numeric primitive (non-bool) type.

struct

A tester struct whose boolValue member evaluates statically to true if the template parameter T is a numeric primitive (non-bool) type or a complex number (std::complex).

struct

A tester struct whose boolValue member evaluates statically to true if the template parameter T is a pointer.

struct
struct

A tester struct whose boolValue member evaluates statically to true if the template parameter T is a primitive type.

struct
struct

A tester struct whose boolValue member evaluates statically to true if the template parameter T is a reference.

struct
struct

A tester struct whose boolValue member evaluates statically to true if the template parameters T and U are the same type.

struct
struct

A tester struct whose boolValue member evaluates statically to true if the template parameter T is a signed integer type.

struct
struct
struct
struct
struct
struct

A tester struct whose boolValue member evaluates statically to true if the template parameter T is an unsigned integer type.

struct
struct
struct
struct
struct
struct

An adaptable unary function for calculating the natural logarithm.

struct

A unary function that adds rows to a matrix.

struct

An adaptable binary function that returns the maximum of its two arguments.

struct
class

An adaptable unary function that calculates the sum of its arguments in successive calls and records the number of times the function has been called.

struct

An adaptable binary function that returns the minimum of its two arguments.

struct
struct

A unary function (predicate) that always returns false.

struct

Logical not operation.

struct

Logical not operation.

struct

Utility for miscellaneous numerical property definitions.

struct

A structure that has a nested type Type if and only if T is a numeric primitive type.

struct

A structure that has a nested type Type if and only if T is a floating-point type.

struct

A structure that has a nested type Type if and only if T is a numeric primitive type.

struct

A structure that has a nested type Type if and only if T is a numeric primitive type or a complex number.

struct

A structure that has a nested type Type if and only if T is a primitive type.

struct

A template that performs a logical OR operation on its boolean template parameters.

struct
struct

An adaptable binary function that raises its first argument to the power of the second argument.

struct

A static functor that converts pointers to values and keeps other types as such.

struct
struct

A unary function that returns the real part of its argument.

struct

A unary function that returns the real part of its argument.

struct

A trait structure that converts any input type to a real output type.

struct

A specialization of the RealReturnValue template for float.

struct

A static functor that converts references to values and keeps other types as such.

struct
struct

An adaptable unary function that rounds its argument to the closest integer.

struct

A binary function that returns its first argument: f(x,y) = x.

struct

A binary function that returns its second argument: f(x,y) = y.

struct

A unary function that returns the sign (1, 0, or -1) of its argument.

struct

A unary function that returns sin(x).

struct

A specialization for floats.

struct

A unary function that returns the square root of its argument.

struct

A specialization for floats.

struct

An adaptable unary function that returns the square of its argument.

struct

An adaptable binary function that calculates the squared difference of its arguments, .

struct

A unary function that returns tan(x).

struct

A specialization for floats.

struct

A model for an adaptable ternary function.

struct

Converts a type to a corresponding floating-point type.

struct

Specialization for double.

struct

Specialization for long double.

struct

Constructs a real-valued counterpart of an integer-channel color.

struct

Constructs a real-valued counterpart of an integer-channel color.

struct
struct

A structure whose member type Type is a non-const version of the template parameter T.

struct
struct

A static functor that converts references to pointers and keeps pointers as such.

struct
struct

A static functor that converts pointers to references and keeps references as such.

struct
struct

A structure whose constant boolValue member evaluates to true.

class

A unary function adaptor that makes the result of one unary function the argument of another.

struct

An stl-compatible model for an adaptable unary function.

struct

Type for values passed through the va_arg mechanism ("..." in function parameters).

struct
struct
struct
struct
struct
struct
struct

The Type member typedef of this structure maps to the value_type member type of the type given as the template argument.

struct
struct

A unary function (predicate) that always returns true.

Enumerations

enum
{ OrdinaryCumulativeSum = 0, ZeroBorderCumulativeSum = 1 }

Different ways of calculating 2-d cumulative sum.

enum
{ OnlyValidPart, AssumeZeros, ShrinkWindow, ShrinkWindowSymmetrically }

The way row/column start/ends are handled with movingAverage().

enum
{ ExtendZeros, ExtendReplicate, ExtendSymmetric, ExtendPeriodic, ExtendNot }

Different ways of extending matrices.

enum
{ NearestNeighborInterpolation, LinearInterpolation }

Interpolation is needed in many occasions where discrete signals are sampled at arbitrary positions.

enum
{ MatrixTop = 1, MatrixBottom = 2, MatrixLeft = 4, MatrixRight = 8 }

Constant values for matrix borders.

enum
{ Horizontally = 1, Vertically = 2 }

An enumeration that specifies the direction of operation for certain matrix operations.

enum
{ IterableMatrix = 0, RandomAccessMatrix = 1 }

Matrix implementation levels.

enum
{ NoDecodingFlag = 0, TrimPropertyName = 1, TrimPropertyValue = 2, RemoveQuotes = 4, DowncasePropertyName = 8 }

Flags for controlling property decoding.

enum
{ ReadableProperties = 1, WritableProperties = 2, StoredProperties = 4, ScriptableProperties = 8, DesignableProperties = 16, DynamicProperties = 32 }

Property types for properties().

enum
{ ReleaseOwnership, RetainOwnership }

Pointer ownership modes.

enum
{ UnpackEconomyQR = 0, UnpackFullQR = 1 }

Unpacking styles for QR decomposition.

enum
{ SvdThinU = 0, SvdThinV = 0, SvdFullU = 1, SvdFullV = 2 }

Functions

template<class T>
T
( )

A generic template for absolute value.

template<class T>
T
(
  • const std::complex< T > & value
)

Calculates the absolute value of a complex number.

char
(
  • char value
)
short
(
  • short value
)
int
(
  • int value
)
long
(
  • long value
)
long long
(
  • long long value
)
unsigned char
(
  • unsigned char value
)
unsigned short
(
  • unsigned short value
)
unsigned int
(
  • unsigned int value
)
unsigned long
(
  • unsigned long value
)
unsigned long long
(
  • unsigned long long value
)
float
(
  • float value
)
double
(
  • double value
)
long double
(
  • long double value
)
bool
(
  • bool value
)
template<class T>
T
( )

Returns the absolute value ov value squared.

template<class T>
T
(
  • const std::complex< T > & value
)
template<class InputIterator, class BinaryFunction, class T>
T
(
  • InputIterator begin
  • InputIterator end
  • BinaryFunction func
  • T initialValue
)

Loops through all values in the range [begin, end) and applies func to each element and the current value of initialValue.

template<class InputIterator, class BinaryFunction, class UnaryPredicate, class T>
T
(
  • InputIterator begin
  • InputIterator end
  • UnaryPredicate predicate
  • BinaryFunction func
  • T initialValue
)

Loops through all values in the range [begin, end) and applies func to each element and the current value of initialValue, if predicate returns a non-zero value for the element.

template<class InputIterator, class BinaryFunction, class T>
T
( )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. This fuction works in the range [begin, begin + n).

template<class T>
double
(
  • T value
)
float
(
  • float value
)
template<class T>
T
(
  • T address
  • size_t bitMask
)

Align a memory address.

template<class InputIterator1, class InputIterator2>
bool
(
  • InputIterator1 begin1
  • InputIterator1 end1
  • InputIterator2 begin2
  • typename std::iterator_traits< InputIterator1 >::value_type tolerance
)

Compares each element in the range [begin, end) to the corresponding element in the range starting at begin2.

template<class Matrix1, class Matrix2>
bool
( )

Check if the absolute value of the difference between corresponding elements in two matrices are within the given tolerance.

template<class T>
T
( )

Returns the difference between two angles (in radians).

PII_CORE_EXPORT QVariantList
(
  • const QList< int > & types
  • void ** args
)

Converts args to to a QVariantList, assuming that each argument is a valid pointer of the type specified by types.

PII_CORE_EXPORT QStringList
(
  • int argc
  • char * argv
)

Converts C-style argument list to a QStringList.

template<class T, class size_type>
void
(
  • T * to
  • const T * from
  • const size_type itemCount
)

Performs array copy of non-overlapping arrays.

float
(
  • float value
)
template<class T>
double
(
  • T value
)
float
(
  • float value
)
template<class T>
double
(
  • T value
)
float
(
  • float y
  • float x
)

A fast (but slower than fastAtan2()) approximation to four-quadrant arctan.

template<class Real>
void
( )

Reduces a rectangular matrix to a bidiagonal form.

template<class Real>
void
( )

Unpacks the result of bidiagonal decomposition.

template<class Real>
void
( )

Unpacks the result of bidiagonal decomposition.

template<class Real>
void
( )

Unpacks the result of bidiagonal decomposition.

template<class Real>
( )

Unpacks the result of bidiagonal decomposition.

template<class Real>
void
( )

Unpacks the result of bidiagonal decomposition.

template<class Real>
( )

Unpacks the result of bidiagonal decomposition.

double PII_CORE_EXPORT
(
  • double a
  • double b
  • double c
)

Calculates the area of a triangle, given the lenghts of its sides.

double PII_CORE_EXPORT
(
  • double a
  • double b
  • double angle
)

Calculates the angle between sides a and b, given the known lengths of the sides and the angle opposite to side a.

double PII_CORE_EXPORT
(
  • double a
  • double b
  • double c
)

Calculates the angle opposite to side a, given the known lengths of all sides of a triangle.

double PII_CORE_EXPORT
(
  • double a
  • double b
  • double angle
)

Calculates the length of the third side of a triangle, given the lengths of two adjacent sides and the angle between them.

template<class T>
double
( )

Returns ceil(value).

float
(
  • float value
)
template<class T, class U>
( )

Calculates two-point central difference.

template<class T, class Collection>
QVariantList
(
  • const Collection & lst
)

Convert any collection to a QVariantList that contains the same values as QVariant objects.

template<class Collection, class T>
Collection
( )

Get a column from a matrix as a collection (QList, QVector)

template<class UnaryFunction, class Storage>
void
( )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

template<class UnaryFunction>
void
( )

Calculates all k-element subsets out of n elements and apply func to each.

template<class Matrix1, class Matrix2>
PiiMatrix< typename Matrix1::value_type >
( )

Concatenate two matrices.

template<class T>
T
( )

Calculates the complex conjugate of a real number.

template<class T>
std::complex< T >
(
  • const std::complex< T > & value
)

Calculates the conjugate of a complex scalar.

PII_CORE_EXPORT void
( )

Converts any color image (rgb/indexed) to gray scale.

PII_CORE_EXPORT void
( )

Converts any image to 32-bit rgb.

template<class InputIterator, class OutputIterator>
OutputIterator
(
  • InputIterator begin
  • InputIterator end
  • OutputIterator output
)

Copies all elements in the range [begin, end) to output.

PII_CORE_EXPORT void
(
  • QVariant::Type type
  • const void * source
  • void * target
)

Copies the object pointed to by source to the memory location at target.

template<class InputIterator, class OutputIterator>
OutputIterator
(
  • InputIterator begin
  • int n
  • OutputIterator output
)

Copies n elements starting at begin to output.

template<class T>
T
(
  • T value
  • T sign
)
template<class Iterator>
void
(
  • Iterator begin
  • Iterator end
  • typename Pii::VaArg< typename std::iterator_traits< Iterator >::value_type >::Type first
  • ...
)

Copies a variable number of arguments to a range of elements bounded by the iterators begin and end.

template<class Iterator>
void
(
  • Iterator begin
  • Iterator end
  • typename Pii::VaArg< typename std::iterator_traits< Iterator >::value_type >::Type first
  • va_list rest
)

Copies a variable argument list to a range of elements.

template<class T>
double
( )

Returns cos(value).

float
(
  • float value
)
PII_CORE_EXPORT int
(
  • unsigned int c
  • const unsigned char bits = INTBITS
)

Get the number of ones in a binary number.

template<unsigned char>
int
(
  • unsigned int c
)
PII_CORE_EXPORT int
(
  • unsigned int c
  • const unsigned char bits = INTBITS
)

Get the number of 0-to-1 or 1-to-0 transitions in a binary number.

template<unsigned char>
int
(
  • unsigned int c
)
template<class T>
PiiMatrix< double >
( )

Calculates the covariance matrix for a set of measurements.

template<class T>
( )
template<class T>
( )
template<class T>
( )
template<class T>
( )

Calculates the cross product of two vectors m1 and m2.

template<class UnaryFunction, class Matrix>
( )

Calculates two-dimensional cumulative sum of a matrix.

template<class U, class Matrix>
( )

Calculates two-dimensional cumulative sum of a matrix.

template<class U, class Matrix>
( )

Calculates the cumulative sum of matrix elements in the specified direction.

PII_CORE_EXPORT QVariantMap
(
  • const QString & encodedProperties
  • QChar propertySeparator = '\n'
  • QChar valueSeparator = '='
  • QChar escape = '\\'
  • PropertyDecodingFlags flags = TrimPropertyName|TrimPropertyValue|RemoveQuotes
)

Decode string-encoded properties into a variant map.

double
(
  • double deg
)

Convert an angle from degrees to radians.

template<class Collection>
void
(
  • Collection & c
)

Delete all members of a collection.

template<class T>
T
( )

calculate the determinant of a matrix.

template<class T>
T
( )

Calculates determinant of 2x2 matrix with direct calculation.

template<class T>
T
( )

Calculates determinant of 3x3 matrix with direct calculation.

template<class T>
( )

Difference and approximate derivative.

template<class Matrix1, class Matrix2>
void
( )

Divide the elements in m1 by the corresponding elements in m2.

template<class Matrix1, class Matrix2>
PiiBinaryMatrixTransform< Matrix1, Matrix2, std::divides< PII_COMBINE_TYPES(typename Matrix1::value_type, typename Matrix2::value_type)> >
( )

Divide the elements in m1 by the corresponding elements in m2.

template<class Real>
( )

Calculates the distance from abs(value) to the next real number larger in magnitude.

template<class Matrix1, class Matrix2>
bool
( )

Compare two matrices.

double
(
  • double p
)

Returns the value of the inverse normal cumulative distribution function (a.k.a the error function, erf) at p.

template<class T>
double
( )

Returns exp(value).

float
(
  • float value
)

Returns exp(value).

template<class T>
( )

Extend a matrix by adding new rows/columns to its sides.

template<class T>
(
  • const PiiMatrix< T > & mat
  • int topRows
  • int bottomRows
  • int leftCols
  • int rightCols
  • ExtendMode mode
)

Extend a matrix by adding new rows/columns to its sides.

template<class T>
T
(
  • T n
)

Returns the factorial of n (n!).

float
(
  • float y
  • float x
)

A very fast approximation to four-quadrant arctan.

template<class Iterator>
std::iterator_traits< Iterator >::value_type
(
  • Iterator data
  • int len
)

Returns the median of all elements in data.

template<class U, class T>
(
  • const PiiMatrix< T > & cumulativeSum
  • int windowRows
  • int windowColumns = 0
)

Fast 2-D moving average.

template<class InputIterator, class OutputIterator>
void
(
  • InputIterator input
  • int n
  • OutputIterator output
  • int windowSize
)

Fast moving average.

PII_CORE_EXPORT QStringList
(
  • const QString & pattern
  • QDir::Filters filters = QDir::Files|QDir::Readable|QDir::CaseSensitive
  • QDir::SortFlags sort = QDir::Name
)

Fetch a list of files matching a wildcard.

template<class Iterator>
Iterator
(
  • Iterator begin
  • Iterator end
  • typename std::iterator_traits< Iterator >::value_type value
)

Sets all values in the range [begin, end) to value.

template<class Iterator, class UnaryPredicate>
Iterator
(
  • Iterator begin
  • Iterator end
  • UnaryPredicate predicate
  • typename std::iterator_traits< Iterator >::value_type value
)

Sets all values in the range [begin, end) for which predicate returns a non-zero value to value.

template<class Iterator>
Iterator
(
  • Iterator begin
  • int n
  • typename std::iterator_traits< Iterator >::value_type value
)

Sets all values in the range [begin, begin + b) to value.

template<class T, class UnaryPredicate>
PiiMatrix< int >
(
  • const PiiMatrix< T > & mat
  • UnaryPredicate predicate
  • int cnt = 0
)

Find the row and column coordinates of all elements in mat that match predicate.

template<class T>
PiiMatrix< int >
( )

Find the row and column coordinates of all non-zero elements in mat.

template<class T>
QList< T >
(
  • const QObject * obj
  • unsigned int maxParents = < unsigned int >::maxValue()
)

Find all parent objects of obj up to maxParents parent objects.

PII_CORE_EXPORT QObject *
( )

Find the object that is the closest common ancestor of obj1 and obj2 in the object hierarchy.

template<class Rule, class T>
void
(
  • const PiiMatrix< T > & matrix
  • T value
  • int & r
  • int & c
)

Find the first occurrence of an element that matches Rule.

template<class T>
void
(
  • const PiiMatrix< T > & matrix
  • T value
  • int & r
  • int & c
)

Find the first occurrence (top to bottom, left to right) of value in matrix.

template<class T>
T
( )

Find the first parent of obj whose type matches T.

template<class T>
void
(
  • const PiiMatrix< T > & matrix
  • T value
  • int & r
  • int & c
)

Find the last occurrence (bottom to top, right to left) of value in matrix.

template<class Rule, class T>
void
(
  • const PiiMatrix< T > & matrix
  • T value
  • int & r
  • int & c
)

Find the last occurrence of an element that matches Rule.

template<class T>
PiiHeap< PiiMatrixValue< T >, 16 >
( )

Find cnt largest values in mat.

template<class T>
PiiHeap< PiiMatrixValue< T >, 16 >
( )

Find cnt smallest values in mat.

PII_CORE_EXPORT QList< QList< int > >
(
  • QLinkedList< QPair< int, int > > & pairs
)

Recursively connects neighbors given as a list of pairs.

PII_CORE_EXPORT int
( )

Returns the index of the first occurrence of separator in str, starting at startIndex.

template<class InputIterator, class UnaryFunction, class BinaryPredicate>
InputIterator
(
  • InputIterator begin
  • InputIterator end
  • BinaryPredicate op
  • UnaryFunction f
)

Find a special value such as maximum or minimum in the range specified by begin and end.

template<class T>
int
(
  • T c
)

Find the index of the first bit set to one.

PII_CORE_EXPORT PiiMatrix< double >
(
  • unsigned int order
  • const PiiMatrix< double > & x
  • const PiiMatrix< double > & y = < double >()
)

Fit a polynomial curve to data.

template<class T>
void
(
  • PiiMatrix< T > & matrix
  • Pii::MatrixDirections directions
)

Flip matrix in place either horizontally, vertically or both.

template<class T>
(
  • const PiiMatrix< T > & mat
  • Pii::MatrixDirections directions
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. This function doesn't modify the source matrix, but returns a copy.

unsigned int
(
  • double value1
  • float value2
)

Returns the sign bit of value1 - value2.

template<class T>
unsigned int
(
  • T value1
  • float value2
)

Returns the sign bit of value1 - value2.

template<class T>
double
( )

Returns floor(value).

float
(
  • float value
)
template<class InputIterator, class UnaryFunction>
( )

Applies func to each element in the range [begin, end).

template<class InputIterator, class UnaryPredicate, class UnaryFunction>
(
  • InputIterator begin
  • InputIterator end
  • UnaryPredicate predicate
  • UnaryFunction func
)

Applies func to each element in the range [begin, end) for which predicate returns a non-zero value.

template<class T>
T
(
  • T x
  • double mu
  • double sigma
)

A Gaussian function.

template<class T>
T
(
  • T number1
  • T number2
)

Find the greatest common divisor (gcd) for the given two numbers using Euclid's algorithm.

template<class Iterator, class Generator>
Iterator
(
  • Iterator begin
  • Iterator end
  • Generator generator
)

Sets all values in the range [begin, end) to the value returned by generator.

template<class Iterator, class Generator>
Iterator
( )

Sets all values in the range [begin, begin + n) to the value returned by generatore.

PII_CORE_EXPORT const QVector< QRgb > &

Returns a color table with shades of gray from zero to 255.

PII_CORE_EXPORT int
(
  • unsigned int a
  • unsigned int b
  • const unsigned char bits = INTBITS
)

Calculate the Hamming distance between two binary numbers.

template<unsigned char>
int
(
  • unsigned int a
  • unsigned int b
)
template<class Iterator>
void
(
  • Iterator x
  • int n
  • typename std::iterator_traits< Iterator >::value_type * tau
  • typename std::iterator_traits< Iterator >::value_type * beta = 0
)

Generates an elementary reflector (a.k.a the Householder transformation).

template<class T>
T
(
  • T a
  • T b
)

Calculates the hypotenuse given two orthogonal sides of a triangle.

template<class T>
T
( )

Returns the imaginary part of a real number, i.e.

template<class T>
T
(
  • const std::complex< T > & value
)

Returns the imaginary part of a complex number.

template<class T, int>
T
( )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

template<class T>
T
( )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

template<class T>
T
( )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

template<class T>
T
( )

Calculates the inner product of two vectors m1 and m2.

template<class InputIterator1, class InputIterator2, class T>
T
(
  • InputIterator1 begin1
  • InputIterator1 end1
  • InputIterator2 begin2
  • T initialValue
)

Returns the inner product of two vectors v1 and v2.

template<class InputIterator1, class InputIterator2, class T>
T
(
  • InputIterator1 begin1
  • int n
  • InputIterator2 begin2
  • T initialValue
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Returns the inner product of two n-dimensional vectors.

template<class T>
void
(
  • T * data
  • int size
)

Classical insertion sort.

template<class Collection>
Collection
(
  • const Collection & list1
  • const Collection & list2
)

Find the intersection of two lists.

template<class T>
( )

Invert a matrix.

template<class T>
bool
( )

Tests if a matrix is antisymmetric.

template<class T>
bool
( )

Test if a matrix is diagonal.

template<class T>
bool
(
  • T f
)

Returns true if f equals Inf.

template<class T>
bool
(
  • T f
)

Returns true if f is NaN.

template<class T>
bool
(
  • const PiiMatrix< T > & mat
  • const T & tolerance
)

Tests whether the given real matrix is "orthogonal-like".

template<class T>
bool
( )

Overloaded function which calls isOrthogonalLike() with default numerical difference tolerance for type T.

PII_CORE_EXPORT bool
( )

Returns true if parent is a parent of child.

template<class T>
bool
( )

Test if a matrix is singular.

template<class T>
bool
( )

Tests whether the given matrix is square matrix.

template<class T>
bool
( )

Test if a matrix is symmetric about the diagonal.

template<class Collection>
Collection
(
  • const Collection & list1
  • const Collection & list2
)

Find the union of two lists.

template<class T>
T
(
  • T * data
  • int size
  • int k
)

Returns the k:th smallest element from array.

template<class T>
int
(
  • T c
)

Find the index of the last bit set to one.

template<class T, class Collection>
( )

Converts a collection to a row matrix.

template<class T>
QVariantList
( )

Convert a QList to a QVariantList that contains the same values as QVariant objects.

template<class T>
double
( )

Returns log(value).

float
(
  • float value
)

Returns log(value).

template<class Iterator, class UnaryFunction>
Iterator
( )

Applies a unary function func to all elements in the range [begin, end), and stores the result in place.

template<class Iterator1, class Iterator2, class BinaryFunction>
void
(
  • Iterator1 begin1
  • Iterator1 end1
  • Iterator2 begin2
  • BinaryFunction func
)

Applies a binary function func to all elements in the range [begin1, end1), and stores the result in place.

template<class Iterator, class UnaryPredicate, class UnaryFunction>
Iterator
(
  • Iterator begin
  • Iterator end
  • UnaryPredicate predicate
  • UnaryFunction func
)

Applies a unary function func to all elements in the range [begin, end) for which predicate returns a non-zero value.

template<class Matrix, class UnaryFunction>
Matrix &
( )

Applies the unary function func to all elements of matrix.

template<class Matrix, class UnaryPredicate, class UnaryFunction>
Matrix &
( )

Applies the unary function func to all elements of matrix that match the given predicate.

template<class Iterator1, class Iterator2, class BinaryFunction>
void
( )

Applies a binary function func to all elements in the range [begin1, begin1 + n), and stores the result in place.

template<class Iterator, class UnaryFunction>
Iterator
( )

Applies a unary function func to all elements in the range [begin, begin + n), and stores the result in place.

template<class Matrix, class UnaryFunction>
Matrix &
( )

Applies the unary function func to all elements of matrix.

template<class Matrix, class UnaryPredicate, class UnaryFunction>
( )

Applies the unary function func to all elements of matrix that match the given predicate.

PII_CORE_EXPORT bool
( )

Match a list of crontab-like strings against the given time stamp.

PII_CORE_EXPORT PiiMatrix< double >
( )

Parse a string that describes a matrix in Matlab syntax.

template<class Stream, class Matrix>
void
( )

Print out a matrix in a matlab-friendly format.

template<class T>
( )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. This specialization just returns mat.

template<class T>
( )

Calculates the maximum among all elements in the specified direction.

template<class T>
T
( )

Returns the maximum of two arguments.

template<class T>
T
(
  • T a
  • T b
  • T c
)

Returns the maximum of three arguments.

template<class T>
T
(
  • T a
  • T b
  • T c
  • T d
)

Returns the maximum of four arguments.

template<class T, class R>
R
(
  • const PiiMatrix< T > & mat
  • int * r = 0
  • int * c = 0
)

Like maxAll(), but finds the maximum absolute value.

template<class Collection>
Collection::value_type
(
  • const Collection & collection
)

Shorthand for maxAll(collection.begin(), collection.end()).

template<class InputIterator>
std::iterator_traits< InputIterator >::value_type
(
  • InputIterator begin
  • InputIterator end
)

Returns the maximum value in [begin, end).

template<class T>
T
(
  • const PiiMatrix< T > & mat
  • int * r = 0
  • int * c = 0
)

Calculates the maximum of all elements in a matrix.

template<class U, class Matrix>
( )

Calculates the mean of matrix elements in the specified direction.

template<class U, class Matrix>
U
( )

Calculates the mean of all entries in a matrix.

template<class Iterator>
std::iterator_traits< Iterator >::value_type
(
  • Iterator data
  • int len
)

Returns the median of all elements in data.

template<class Iterator>
std::iterator_traits< Iterator >::value_type
(
  • Iterator data
)

Median of 25 values optimized to the theoretical maximum efficiency.

template<class Iterator>
std::iterator_traits< Iterator >::value_type
(
  • Iterator data
)

Median of three values optimized to the theoretical maximum efficiency.

template<class Iterator>
std::iterator_traits< Iterator >::value_type
(
  • Iterator data
)

Median of five values optimized to the theoretical maximum efficiency.

template<class Iterator>
std::iterator_traits< Iterator >::value_type
(
  • Iterator data
)

Median of seven values optimized to the theoretical maximum efficiency.

template<class Iterator>
std::iterator_traits< Iterator >::value_type
(
  • Iterator data
)

Median of nine values optimized to the theoretical maximum efficiency.

template<class T>
T
( )

Returns the median of all elements in mat.

template<class T>
( )

Calculates the minimum among all elements in the specified direction.

template<class T>
T
( )

Returns the minimum of two arguments.

template<class T>
T
(
  • T a
  • T b
  • T c
)

Returns the minimum of three arguments.

template<class T>
T
(
  • T a
  • T b
  • T c
  • T d
)

Returns the minimum of four arguments.

template<class T>
T
(
  • const PiiMatrix< T > & mat
  • int * r = 0
  • int * c = 0
)

Calculates the minimum of all elements in a matrix.

template<class InputIterator>
std::iterator_traits< InputIterator >::value_type
(
  • InputIterator begin
  • InputIterator end
)

Returns the minimum value in [begin, end).

template<class Collection>
Collection::value_type
(
  • const Collection & collection
)

Shorthand for minAll(collection.begin(), collection.end()).

template<class T>
void
(
  • const PiiMatrix< T > & mat
  • T * minimum
  • T * maximum
  • int * minR = 0
  • int * minC = 0
  • int * maxR = 0
  • int * maxC = 0
)

Find the maximum and maximum of all elements in a matrix.

template<class T>
T
( )

Returns the "modulus" of a floating point number.

template<class CalculationType, class Iterator>
void
(
  • Iterator begin
  • Iterator end
  • int width
)

Calculates the moving average of a sequence bounded by begin and end.

template<class T, class U>
( )

Calculates moving average over the rows/columns of a matrix.

template<class Matrix1, class Matrix2>
PiiBinaryMatrixTransform< Matrix1, Matrix2, std::multiplies< PII_COMBINE_TYPES(typename Matrix1::value_type, typename Matrix2::value_type)> >
( )

Multiplies the elements in m1 and m2.

template<class Matrix1, class Matrix2>
void
( )

Multiply the elements in m1 by the corresponding elements in m2.

template<class T, class InputIterator, class OutputIterator>
void
(
  • const PiiMatrix< T > & matrix
  • InputIterator input
  • OutputIterator output
)

A generic algorithm to multiply a column vector by a matrix from left.

template<class InputIterator, class T, class OutputIterator>
void
(
  • InputIterator input
  • const PiiMatrix< T > & matrix
  • OutputIterator output
)

A generic algorithm to multiply a row vector by a matrix from right.

template<class Matrix>
void
( )

Normalizes vectors in a matrix.

template<class Matrix>
PiiMatrix< double >
(
  • const PiiRandomAccessMatrix & mat
  • MatrixDirection direction = Horizontally
)

Normalizes vectors in a matrix.

PII_CORE_EXPORT double

Returns a random number from a distribution that follows N(0,1) (zero mean, unit variance Gaussian distribution).

PII_CORE_EXPORT PiiMatrix< double >
(
  • int rows
  • int columns
)

Returns a rows x columns matrix filled with normally distributed random numbers.

std::ostream &
(
  • std::ostream & out
  • const QString & str
)

Write a QString to an std output stream.

PII_CORE_EXPORT QList< int >
( )

Converts comma-separated type names to a list of type IDs.

template<class T>
int
(
  • T * data
  • int size
  • int pivot
)

Returns array which is arranged so that; there exist index k which value is restricted to 0 <= k < size.

template<class Matrix>
PiiMatrix< typename Matrix::value_type >
(
  • const PiiRandomAccessMatrix & X
)

Decorrelates a possibly correlated set of data.

template<class UnaryFunction, class Storage>
void
( )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

template<class UnaryFunction>
void
( )

Find all possible permutations of n elements.

( )
(
  • void
  • setProperties< QVariantMap >
  • (QObject &obj, const QStringList &properties, const QVariantMap &valueMap, Qt::CaseSensitivity sensitivity, const QString &commentMark)
  • PII_BUILDING_CORE
)

Returns a matrix whose elements are absolute values of mat squared.

Returns a matrix whose elements are absolute values of mat.

template<class T>
T
( )

Raise value to an integer power (n).

double
(
  • double value
  • double n
)

Raise value to a floating-point power (n).

float
(
  • float value
  • float n
)

Raise value to a floating-point power (n).

template<class Matrix>
PiiMatrix< typename Matrix::value_type >
(
  • const PiiRandomAccessMatrix & X
  • PiiMatrix< typename Matrix::value_type > * S = 0
)

Returns the PCA base vectors for a data set in X.

template<class Stream, class Matrix, class ColSeparator, class RowSeparator>
void
(
  • Stream & out
  • const PiiConceptualMatrix< Matrix, RandomAccessMatrix > & mat
  • const ColSeparator & columnSeparator
  • const RowSeparator & rowSeparator
)

Print matrix in a user-defined format.

PII_CORE_EXPORT QVariantMap
(
  • const QObject & obj
  • int propertyOffset = 0
  • PropertyFlags flags = DynamicProperties
)

Fetch the properties of a QObject as a map of name-value pairs.

PII_CORE_EXPORT QList< QPair< QString, QVariant > >
(
  • const QObject & obj
  • int propertyOffset = 0
  • PropertyFlags flags = DynamicProperties
)

Returns the properties of obj as a list.

PII_CORE_EXPORT const char *
( )

Finds the name of a property in obj that matches name in a case-insensitive manner.

template<class Matrix>
PiiMatrix< typename Matrix::value_type >
(
  • const PiiRandomAccessMatrix & A
)

Returns the Moore-Penrose pseudoinverse of an m-by-n matrix.

( )
(
  • SvdOptions
  • SvdOption
)
( )
( )
PII_CORE_EXPORT uint
(
  • const char * key
)

Hash function for null-terminated C strings.

template<class Matrix>
void
(
  • PiiRandomAccessMatrix & A
  • PiiMatrix< typename Matrix::value_type > & tau
)

QR decomposition.

template<class Matrix>
void
(
  • PiiRandomAccessMatrix & A
  • typename Matrix::value_type * tau
  • typename Matrix::value_type * bfr
)

QR decomposition.

template<class Matrix>
PiiMatrix< typename Matrix::value_type >
(
  • const PiiRandomAccessMatrix & A
  • PiiMatrix< typename Matrix::value_type > * R = 0
  • QrUnpackStyle style = UnpackEconomyQR
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. This version does not modify the input A, and returns the Q matrix unpacked.

template<class Real>
void
( )

Unpacks the result of QR decomposition.

template<class Real>
( )

Unpacks the result of QR decomposition.

double
(
  • double rad
)

Convert an angle from radians to degrees.

template<class T>
void
(
  • PiiMatrix< T > & mat
  • const T & lowerBound
  • const T & upperBound
)

Set random elements from range specified by parameters lowerBound and upperBound to matrix.

template<class Matrix>
int
(
  • const PiiRandomAccessMatrix & mat
  • typename Matrix::value_type tolerance = NAN
)

Estimates the number of linearly independent rows or columns of a matrix.

template<class T>
T
(
  • const std::complex< T > & value
)

Returns the real part of a complex number.

template<class T>
T
( )

Returns the real part of a real number, i.e.

template<class Matrix, class InputIterator>
void
(
  • PiiConceptualMatrix< Matrix, Pii::RandomAccessMatrix > & A
  • InputIterator v
  • typename Matrix::value_type tau
  • typename Matrix::value_type * bfr
)

Applies a reflection transform to a rectangular matrix from the left.

template<class Matrix, class InputIterator>
void
(
  • PiiConceptualMatrix< Matrix, Pii::RandomAccessMatrix > & A
  • InputIterator v
  • typename Matrix::value_type tau
)
template<class Matrix, class InputIterator>
void
(
  • PiiConceptualMatrix< Matrix, Pii::RandomAccessMatrix > & A
  • InputIterator v
  • typename Matrix::value_type tau
)

Applies a reflection transform to a rectangular matrix from the right.

template<class VariableMap>
(
  • const QString & string
  • const VariableMap & variables
)

Replaces variables in string and returns a new string.

template<class T>
(
  • const PiiMatrix< T > & matrix
  • int vertical
  • int horizontal
)

Replicate a matrix vertical times vertically and horizontal times horizontally.

unsigned short
(
  • unsigned short c
  • const unsigned char n
)
unsigned char
(
  • unsigned char c
  • const unsigned char n
)
template<unsigned char>
unsigned int
(
  • unsigned int c
  • const unsigned char n
)
unsigned int
(
  • unsigned int c
  • const unsigned char n
  • const unsigned char bits
)

Rotate a binary code left by n positions.

unsigned int
(
  • unsigned int c
  • const unsigned char n
)
unsigned int
(
  • unsigned int c
  • const unsigned char n
  • const unsigned char bits
)

Rotate a binary code right by n positions.

template<unsigned char>
unsigned int
(
  • unsigned int c
  • const unsigned char n
)
unsigned char
(
  • unsigned char c
  • const unsigned char n
)
unsigned short
(
  • unsigned short c
  • const unsigned char n
)
unsigned int
(
  • unsigned int c
  • const unsigned char n
)
rotation
(
  • mat
  • 0
  • 1
)
PII_CORE_EXPORT unsigned int
(
  • unsigned int n
  • const unsigned char bits = INTBITS
)

Rotate a binary number to its minimum value.

template<unsigned char>
unsigned int
(
  • unsigned int n
)
double
(
  • double value
)

Rounds a double argument to the closest integer.

template<class U, class T>
U
( )

Rounds value (of type T) to the closest integer and returns the result as another type (U).

template<class Collection, class T>
Collection
( )

Get a row from a matrix as a collection (QList, QVector)

PII_CORE_EXPORT int
(
  • const QVariantList & params
  • const QList< int > & types
)

Returns a numerical score for the goodness of a parameter set given a list of expected types.

void
(
  • long value
)

Seeds the random number generator with your favourite value.

PII_CORE_EXPORT void

Initializes the random number generator from system clock.

void PII_CORE_EXPORT
(
  • QVector< int > & indices
  • int n
  • int max
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Randomly selects n distinct integers in [0, max-1] and stores them to indices.

template<class Collection>
void
(
  • Collection & target
  • const Collection & source
  • int n
)

Select randomly n elements from source and insert them to target.

QVector< int > PII_CORE_EXPORT
(
  • int n
  • int max
)

Select randomly n distinct integers that are smaller than max.

template<class Iterator>
Iterator
(
  • Iterator begin
  • Iterator end
  • typename std::iterator_traits< Iterator >::value_type initialValue
)

Assigns sequentially increasing values to the range [begin, end).

template<class Iterator>
Iterator
(
  • Iterator begin
  • Iterator end
  • typename std::iterator_traits< Iterator >::value_type initialValue
  • typename std::iterator_traits< Iterator >::value_type step
)

Assigns sequentially increasing or decreasing values to the range [begin, end).

template<class Iterator>
Iterator
(
  • Iterator begin
  • int n
  • typename std::iterator_traits< Iterator >::value_type initialValue
)

Assigns sequentially increasing values to the range [begin, end + n).

template<class Iterator>
Iterator
(
  • Iterator begin
  • int n
  • typename std::iterator_traits< Iterator >::value_type initialValue
  • typename std::iterator_traits< Iterator >::value_type step
)

Assigns sequentially increasing or decreasing values to the range [begin, begin + n).

template<class Matrix, class Iterator>
void
(
  • PiiRandomAccessMatrix & matrix
  • Iterator vector
)

Sets diagonal entries in matrix to the values read from vector.

template<class Matrix>
void
(
  • PiiRandomAccessMatrix & matrix
)

Sets diagonal entries in matrix to ones and other entries to zero.

PII_CORE_EXPORT void
(
  • QObject & obj
  • const QVariantMap & lstProperties
)

Sets many properties in a bunch.

template<class Map>
void
(
  • QObject & obj
  • const QStringList & properties
  • const Map & valueMap
  • Qt::CaseSensitivity sensitivity = Qt::CaseSensitive
  • const QString & commentMark = "#"
)

Sets properties to an object.

PII_CORE_EXPORT void
( )
template<class T>
void
(
  • T value
  • PiiMatrix< T > & img
  • double dr
  • double dc
)
template<class Collection>
void
(
  • Collection & lst
)

Randomize the order of elements in a collection.

template<class Iterator>
void
(
  • Iterator begin
  • Iterator end
)

Randomize the order of elements in [begin, end).

template<class Iterator>
void
(
  • Iterator begin
  • PII_DIFF_TYPE n
)

Randomize the order of elements in a sequence.

template<class T>
T
( )

Returns the sign of value.

template<class T>
unsigned int
(
  • T value1
  • T value2
)

Returns the sign bit of value1 - value2.

unsigned int
(
  • float value1
  • float value2
)

Returns the sign bit of value1 - value2.

unsigned int
(
  • double value1
  • double value2
)

Returns the sign bit of value1 - value2.

template<class T>
T
( )

Get a binary mask for the sign bit of any integer type.

short
( )

Get a binary mask for the sign bit of any integer type.

float
(
  • float value
)
template<class T>
double
( )

Returns sin(value).

template<class T>
(
  • const PiiMatrix< T > & matrix
  • int column = 0
)

Sort matrix rows.

template<class T, class LessThan>
(
  • const PiiMatrix< T > & matrix
  • LessThan lessThan
  • int column = 0
)

Sort matrix rows.

template<class T, class LessThan>
void
(
  • PiiMatrix< T > & matrix
  • LessThan lessThan
  • int column = 0
)

Sort matrix rows into ascending order based on the value on the specified column.

PII_CORE_EXPORT QStringList
(
  • const QString & str
  • QChar separator = ','
  • QChar quote = '"'
  • QString::SplitBehavior behavior = QString::KeepEmptyParts
)

Splits a string in which each part may be quoted.

template<class T>
double
( )

Returns the square root of value.

float
(
  • float value
)
template<class T>
T
( )

Returns the value * value.

template<class U, class T>
U
( )

Calculates the standard deviation over all elements in a matrix.

template<class T>
T
(
  • const QString & number
  • bool * ok = 0
)

Convert a string to any type.

double
( )
float
( )
int
( )
long
( )
long long
( )
short
( )
unsigned int
( )
unsigned long
( )
unsigned long long
( )
unsigned short
( )
template<class Collection>
Collection
(
  • const Collection & list1
  • const Collection & list2
)

Create a list that consists of the elements of list1 that are not present in list2.

template<class Matrix>
PiiMatrix< typename Matrix::value_type >
( )

Subtracts sample mean from a data set.

template<class U, class Matrix>
( )

Calculates the sum of matrix elements in the specified direction.

template<class T, class Matrix>
T
( )

Calculates the sum of all entries in a matrix.

template<class Iterator1, class Iterator2>
void
(
  • Iterator1 begin1
  • Iterator1 end1
  • Iterator2 begin2
)
template<class Iterator1, class Iterator2>
void
(
  • Iterator1 begin1
  • int n
  • Iterator2 begin2
)
template<class T>
double
( )

Returns tan(value).

float
(
  • float value
)
PII_CORE_EXPORT double
(
  • const QString & number
  • bool * ok = 0
)

Converts a string into a number.

template<class InputIterator1, class InputIterator2, class OutputIterator, class BinaryFunction>
OutputIterator
(
  • InputIterator1 begin1
  • InputIterator1 end1
  • InputIterator2 begin2
  • OutputIterator output
  • BinaryFunction func
)

Applies a binary function func to all elements in the range [begin1, end1), using the corresponding element in the range starting at begin2 as the second argument to the function.

template<class InputIterator, class OutputIterator, class UnaryFunction>
OutputIterator
(
  • InputIterator begin
  • InputIterator end
  • OutputIterator output
  • UnaryFunction func
)

Applies a unary function func to all elements in the range [begin, end), and stores the returned value to output.

template<class Matrix, class InputIterator, class BinaryFunction>
Matrix &
( )

Performs func on each column of the given matrix.

template<class Matrix, class InputIterator, class BinaryFunction>
PiiMatrix< typename Matrix::value_type >
(
  • const PiiRandomAccessMatrix & matrix
  • InputIterator input
  • BinaryFunction func
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Returns a new matrix.

template<class Matrix, class InputIterator, class BinaryFunction>
PiiMatrix< typename Matrix::value_type >
( )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Returns a new matrix.

template<class InputIterator, class OutputIterator, class UnaryFunction>
OutputIterator
(
  • InputIterator begin
  • int n
  • OutputIterator output
  • UnaryFunction func
)

Applies a unary function func to all elements in the range [begin, begin + n), and stores the returned value to output.

template<class InputIterator1, class InputIterator2, class OutputIterator, class BinaryFunction>
OutputIterator
(
  • InputIterator1 begin1
  • int n
  • InputIterator2 begin2
  • OutputIterator output
  • BinaryFunction func
)

Applies a binary function func to all elements in the range [begin1, begin1 + n), using the corresponding element in the range starting at begin2 as the second argument to the function.

template<class Matrix, class InputIterator, class BinaryFunction>
Matrix &
( )

Performs func on each row of the given matrix.

double

Returns a uniformly distributed random number in [0,1].

double
(
  • double min
  • double max
)

Returns a uniformly distributed random number in [min, max].

PII_CORE_EXPORT PiiMatrix< double >
(
  • int rows
  • int columns
)

Returns a rows x columns matrix filled with uniformly distributed random numbers in [0,1].

PII_CORE_EXPORT PiiMatrix< double >
(
  • int rows
  • int columns
  • double min
  • double max
)

Returns a rows x columns matrix filled with uniformly distributed random numbers in [min, max].

template<class Matrix>
void
( )

Unpacks a matrix in which a series of elementary reflections are represented as row or column vectors.

template<class T>
(
  • const PiiMatrix< T > & img
  • double dr
  • double dc
)

Sample a matrix (typically an image) at continuous positions.

template<class T>
T
( )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Returns img(r,c).

template<class U, class T>
( )

Calculates the variance of matrix elements in the specified direction.

template<class U, class T>
U
( )

Calculates the variance over all elements in a matrix.

template<class T>
QList< T >
(
  • const QVariantList & variants
)

Converts a list of QVariant objects into a QList of type T.

template<class T>
QVector< T >
(
  • const QVariantList & variants
)

Convert a list of QVariant objects into a QVector of type T.

template<class T>
QVariantList
( )

Convert a QVector to a QVariantList that contains the same values as QVariant objects.

template<class Iterator, class UnaryFunction>
void
( )

Calculates the sum of neighbors in a sequence bounded by begin and end.

Variables

PII_CORE_EXPORT const QMetaObject

Enumeration details

  • enum CumulativeSumMode

    Different ways of calculating 2-d cumulative sum.

    • OrdinaryCumulativeSum - the size of the result matrix will be the same as that of the input.

    • ZeroBorderCumulativeSum - the size of the result matrix will be one larger than that of the input in both directions. The first row and column will be set to zero. This allows certain optimizations in border checking if the sum matrix is used for calculating moving averages.

  • enum EndPointHandling

    The way row/column start/ends are handled with movingAverage().

    • OnlyValidPart - nothing is assumed. Only the part of the matrix that can be unambiguously averaged will be returned. The size of the output matrix will be that of the input minus (window width - 1).

    • AssumeZeros - assume that everything outside the input matrix is zero. The size of the input will be retained.

    • ShrinkWindow - the size of the averaging window will decrease towards the end points. At the end point, only half of the window will be used. The size of the input matrix will be retained.

    • ShrinkWindowSymmetrically - the size of the averaging window will decrease towards the end points. The functioning is similar to ShrinkWindow except that the window shrinks on both sides. Both ends of the input signal will be retained as such. The value next to the end point will be the average of the two border values etc. The size of the input matrix will be retained. In this mode, the width parameter needs to be odd. If it isn't, it'll be made so. This mode is useful if you need to ensure that elements on both sides of the current window center always have equal effect.

  • enum ExtendMode

    Different ways of extending matrices.

    Matrices are often enlarged before applying a filtering operation to them to retain the original size.

    • ExtendZeros - pad with zeros

    • ExtendReplicate - replicate the value on the border

    • ExtendSymmetric - symmetrically mirror boundary values

    • ExtendPeriodic - take values from the opposite border

    • ExtendNot - do not extend

  • enum Interpolation

    Interpolation is needed in many occasions where discrete signals are sampled at arbitrary positions.

    Many operations work with multiple interpolation modes.

    • NearestNeighborInterpolation means that the interpolated value is that of the nearest discretized neighbor.

    • LinearInterpolation means that the interpolated value is built by a weighted sum of the nearest neighbors. With two-dimensional signals, linear interpolation is in fact bi-linear.

  • enum MatrixBorder

    Constant values for matrix borders.

    A composition of these values is used, for example, with the extend() function. For example, to extend a matrix on right-hand side and on the bottom, use MatrixBottom + MatrixRight.

  • enum MatrixDirection

    An enumeration that specifies the direction of operation for certain matrix operations.

  • enum MatrixImplementationLevel

    Matrix implementation levels.

  • enum PropertyDecodingFlag

    Flags for controlling property decoding.

    • NoDecodingFlag - no options apply

    • TrimPropertyName - remove white space in the beginning and end of property name.

    • TrimPropertyValue - remove white space in the beginning and end of property value.

    • RemoveQuotes - remove double quotes around property names/values. Implies TrimPropertyName and TrimPropertyValue.

    • DowncasePropertyName - convert all property names to lower case.

  • enum PropertyFlag

    Property types for properties().

  • enum PtrOwnership

    Pointer ownership modes.

    If the ownership of a pointer is released to the receiver in a function or constructor call, ReleaseOwnership is used. If the ownership is retained by the caller, this is indicated by RetainOwnership.

  • enum QrUnpackStyle

    Unpacking styles for QR decomposition.

    Assume the input matrix A is m-by-n.

    • UnpackEconomyQR - Either Q or R is m-by-n, and the other one is a o-by-o matrix, where o = min(m,n). If m >= n: Q will be m-by-n, R n-by-n. If m <= n: Q will be m-by-m, R m-by-n.

    • UnpackFullQR - Q will be m-by-m, R m-by-n. If m is large, this style easily eats up all memory. Use with care.

  • enum SvdOption

Function details

  • template<class T>

    T abs

    ()
    [inline]

    #include <PiiMath.h>

    A generic template for absolute value.

    Specializations use fabs() derivatives for floating point and abs() derivatives for integer types. For any other type, it calls a class member function called abs and returns its result.

    This function retains the input type and its signedness. Behavior is different from std::abs for some types.

     char a = -128;
     // char(128) = char(-128)
     int b = Pii::abs(a); //b == -128
     b = std::abs(a); //b == 128

  • template<class T>

    T abs

    (
    • const std::complex< T > & value
    )
    [inline]

    #include <PiiMath.h>

    Calculates the absolute value of a complex number.

  • char abs

    (
    • char value
    )
    [inline]

    #include <PiiMath.h>

  • short abs

    (
    • short value
    )
    [inline]

    #include <PiiMath.h>

  • int abs

    (
    • int value
    )
    [inline]

    #include <PiiMath.h>

  • long abs

    (
    • long value
    )
    [inline]

    #include <PiiMath.h>

  • long long abs

    (
    • long long value
    )
    [inline]

    #include <PiiMath.h>

  • unsigned char abs

    (
    • unsigned char value
    )
    [inline]

    #include <PiiMath.h>

  • unsigned short abs

    (
    • unsigned short value
    )
    [inline]

    #include <PiiMath.h>

  • unsigned int abs

    (
    • unsigned int value
    )
    [inline]

    #include <PiiMath.h>

  • unsigned long abs

    (
    • unsigned long value
    )
    [inline]

    #include <PiiMath.h>

  • unsigned long long abs

    (
    • unsigned long long value
    )
    [inline]

    #include <PiiMath.h>

  • float abs

    (
    • float value
    )
    [inline]

    #include <PiiMath.h>

  • double abs

    (
    • double value
    )
    [inline]

    #include <PiiMath.h>

  • long double abs

    (
    • long double value
    )
    [inline]

    #include <PiiMath.h>

  • bool abs

    (
    • bool value
    )
    [inline]

    #include <PiiMath.h>

  • template<class T>

    T abs2

    ()
    [inline]

    #include <PiiMath.h>

    Returns the absolute value ov value squared.

    The result is equal to the square of value with real types, and the the norm of value with complex types.

  • template<class T>

    T abs2

    (
    • const std::complex< T > & value
    )
    [inline]

    #include <PiiMath.h>

  • template<class InputIterator, class BinaryFunction, class T>

    T accumulate

    (
    • InputIterator begin
    • InputIterator end
    • BinaryFunction func
    • T initialValue
    )

    #include <PiiAlgorithm.h>

    Loops through all values in the range [begin, end) and applies func to each element and the current value of initialValue.

    Returns the final value of initialValue.

     // Sum up all entries in a matrix
     PiiMatrix<int> mat(1,2, -1, 2);
     std::cout << Pii::accumulate(mat.begin(), mat.end(),
                                  std::plus<int>(), 0);
     // Outputs 1

  • template<class InputIterator, class BinaryFunction, class UnaryPredicate, class T>

    T accumulateIf

    (
    • InputIterator begin
    • InputIterator end
    • UnaryPredicate predicate
    • BinaryFunction func
    • T initialValue
    )

    #include <PiiAlgorithm.h>

    Loops through all values in the range [begin, end) and applies func to each element and the current value of initialValue, if predicate returns a non-zero value for the element.

    Returns the final value of initialValue.

     // Sum up all positive entries in a matrix
     PiiMatrix<int> mat(1,3, -1, 2);
     std::cout << Pii::accumulate(mat.begin(), mat.end(),
                                  std::bind2nd(std::greater<int>(), 0),
                                  std::plus<int>(),
                                  0);
     // Outputs 3

  • template<class InputIterator, class BinaryFunction, class T>

    T accumulateN

    ()

    #include <PiiAlgorithm.h>

    This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. This fuction works in the range [begin, begin + n).

  • template<class T>

    double acos

    (
    • T value
    )
    [inline]

    #include <PiiMath.h>

    This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

  • float acos

    (
    • float value
    )
    [inline]

    #include <PiiMath.h>

    This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

  • template<class T>

    T alignAddress

    (
    • T address
    • size_t bitMask
    )
    [inline]

    #include <PiiBits.h>

    Align a memory address.

    Memory alignment is useful when you want to speed up access to a certain memory location.

    Parameters
    address

    the memory address to be aligned

    bitMask

    create a new memory address in which all bits set in this mask are zero. To align an address to a 16-byte boundary, use 0xf as the bit mask. 0xff aligns to a 256-byte boundary etc. Different values can be used to align memory to word and/or cache boundaries. The actual values of these depend on the underlying processor architecture.

    Returns

    a new memory address rounded up to the next address divisible by bitMask + 1. If address is already aligned, it'll be returned unmodified.

  • template<class InputIterator1, class InputIterator2>

    bool almostEqual

    (
    • InputIterator1 begin1
    • InputIterator1 end1
    • InputIterator2 begin2
    • typename std::iterator_traits< InputIterator1 >::value_type tolerance
    )

    #include <PiiMath.h>

    Compares each element in the range [begin, end) to the corresponding element in the range starting at begin2.

    If the absolute difference between any pair of elements is larger than tolerance, returns false. Otherwise returns true.

  • template<class Matrix1, class Matrix2>

    bool almostEqual

    ()

    #include <PiiMath.h>

    Check if the absolute value of the difference between corresponding elements in two matrices are within the given tolerance.

    This function is useful if one needs to compare matrices with floating-point values.

     PiiMatrix<double> mat1(1,1, 1.0), mat2(1,1, 1.01);
     Pii::almostEqual(mat1, mat2, 0.1); //returns true

  • template<class T>

    T angleDiff

    ()
    [inline]

    #include <PiiMath.h>

    Returns the difference between two angles (in radians).

    This function always returns a value in [-pi, pi].

  • PII_CORE_EXPORT QVariantList argsToList

    (
    • const QList< int > & types
    • void ** args
    )

    #include <PiiMetaTypeUtil.h>

    Converts args to to a QVariantList, assuming that each argument is a valid pointer of the type specified by types.

     int i;
     double d;
     void* args[2] = { &i, &d };
     QList<int> lstTypes;
     lstTypes << QMetaType::Int << QMetaType::Double;
     QVariantList lstArgs(PiiUniversalSlot::argsToList(lstTypes, args);

  • PII_CORE_EXPORT QStringList argsToList

    (
    • int argc
    • char * argv
    )

    #include <PiiUtil.h>

    Converts C-style argument list to a QStringList.

  • template<class T, class size_type>

    void arrayCopy

    (
    • T * to
    • const T * from
    • const size_type itemCount
    )
    [inline]

    #include <PiiUtil.h>

    Performs array copy of non-overlapping arrays.

    If used with primitive type, uses memcpy, else uses operator= one by one.

    Behavior is undefined if arrays to and from overlap.

    Parameters
    to

    Pointer to destination array.

    from

    Pointer to source array.

    itemCount

    Number of items of type T to copy.

  • float asin

    (
    • float value
    )
    [inline]

    #include <PiiMath.h>

    This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

  • template<class T>

    double asin

    (
    • T value
    )
    [inline]

    #include <PiiMath.h>

    This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

  • float atan

    (
    • float value
    )
    [inline]

    #include <PiiMath.h>

    This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

  • template<class T>

    double atan

    (
    • T value
    )
    [inline]

    #include <PiiMath.h>

    This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

  • float atan2

    (
    • float y
    • float x
    )
    [inline]

    #include <PiiMath.h>

    A fast (but slower than fastAtan2()) approximation to four-quadrant arctan.

    This implementation uses a third-degree polynomial to approximate arctan. The accuracy is 0.01 rad (about 0.6 degrees) at worst. The output range is .

  • template<class Real>

    void bdDecompose

    ()

    #include <PiiBdDecomposition.h>

    Reduces a rectangular matrix to a bidiagonal form.

    This algorithm decomposes an m-by-n matrix A into three matrices Q, B, and P so that A = QBP. Q and P are orthogonal matrices and B is a bidiagonal matrix. If m < n, B will be a lower bidiagonal matrix, otherwise it will be an upper bidiagonal matrix.

    The algorithm uses a two-sided series of Householder reflections to reduce the input matrix to a bidiagonal form. The generated elementary reflectors will be stored in a compact form to A upon return. The lower triangle will store the left-hand reflectors just as with the QR decomposition. The upper triangle will store the right-hand reflectors as row vectors. In the illustration below, column (left-hand) reflectors are denoted by v, row (right-hand) reflectors by u, the main diagonal by d, and the super/subdiagonal by e.

    m >= n                       m < n
    ( d   e   u1  u1  u1 )      ( d   u1  u1  u1  u1  u1 )
    ( v1  d   e   u2  u2 )      ( e   d   u2  u2  u2  u2 )
    ( v1  v2  d   e   u3 )      ( v1  e   d   u3  u3  u3 )
    ( v1  v2  v3  d   e  )      ( v1  v2  e   d   u4  u4 )
    ( v1  v2  v3  v4  d  )      ( v1  v2  v3  e   d   u5 )
    ( v1  v2  v3  v4  v5 )
    

     PiiMatrix<double> matA(10,10); // input matrix
     PiiMatrix<double> matTauQ, matTauP;
     Pii::bdDecompose(matA, matTauQ, matTauP);
     PiiMatrix<double> matQ = Pii::bdUnpackQ(matA, matTauQ[0]);
     PiiMatrix<double> matP = Pii::bdUnpackP(matA, matTauP[0]);
     // since A = Q * B * P,
     // inverse(matQ) * matA * inverse(matP) is a bidiagonal matrix
     // note that since Q and P are orthogonal,
     // inverse(matQ) = transpose(matQ) and
     // inverse(matP) = transpose(matP) and

    Parameters
    A

    the input matrix. This matrix will be modified to store Q, B, and P in a compact form as described above.

    tauQ

    an output-value matrix that will store the coefficients for building Q.

    tauP
    See also
  • template<class Real>

    void bdUnpackB

    ()

    #include <PiiBdDecomposition.h>

    Unpacks the result of bidiagonal decomposition.

    This function modifies A so that it contains the bidiagonal part of the decomposition result, B.

    Parameters
    A

    the result of bidiagonal decomposition in a compact form. The reflector vectors will be nulled out, retaining only the two diagonals.

    See also
  • template<class Real>

    void bdUnpackDiagonals

    ()

    #include <PiiBdDecomposition.h>

    Unpacks the result of bidiagonal decomposition.

    Fills the two non-zero diagonals into the given arrays.

    Parameters
    A

    the result of bidiagonal decomposition in a compact form (m by n matrix).

    d

    an array of at least min(m,n) entries. This will be filled with the values on the main diagonal.

    e

    an array of at least min(m,n)-1 entries. This will be filled with the values on the sub/superdiagonal, depending on the size of A.

    See also
  • template<class Real>

    void bdUnpackP

    ()

    #include <PiiBdDecomposition.h>

    Unpacks the result of bidiagonal decomposition.

    This function returns the components of the right reflector matrix P as .

    Parameters
    V

    the result of bidiagonal decomposition in a compact form. This matrix will be modified so that it contains contains V.

    tauP

    the coefficients needed for reconstructing P

    diagonal

    0, if reflector vectors start on the main diagonal, 1 if they start at the first superdiagonal.

    T

    a return-value matrix that will store the triangular component of P as an upper diagonal matrix.

    See also
  • template<class Real>

    PiiMatrix< Real > bdUnpackP

    ()

    #include <PiiBdDecomposition.h>

    Unpacks the result of bidiagonal decomposition.

    This function returns the right reflector matrix P.

    Parameters
    A

    the result of bidiagonal decomposition in a compact form.

    tauP

    the coefficients needed for reconstructing P

    Returns

    the left reflector matrix P

    See also
  • template<class Real>

    void bdUnpackQ

    ()

    #include <PiiBdDecomposition.h>

    Unpacks the result of bidiagonal decomposition.

    This function returns the components of the left reflector matrix Q as .

    Parameters
    V

    the result of bidiagonal decomposition in a compact form. This matrix will be modified so that it contains contains V.

    tauQ

    the coefficients needed for reconstructing Q

    diagonal

    0, if reflector vectors start on the main diagonal, 1 if they start at the first sub-diagonal.

    T

    a return-value matrix that will store the triangular component of Q as an upper triangular matrix.

    See also
  • template<class Real>

    PiiMatrix< Real > bdUnpackQ

    ()

    #include <PiiBdDecomposition.h>

    Unpacks the result of bidiagonal decomposition.

    This function returns the left reflector matrix Q.

    Parameters
    A

    the result of bidiagonal decomposition in a compact form.

    tauQ

    the coefficients needed for reconstructing Q

    Returns

    the left reflector matrix Q

    See also
  • double PII_CORE_EXPORT calculateArea

    (
    • double a
    • double b
    • double c
    )

    #include <PiiMath.h>

    Calculates the area of a triangle, given the lenghts of its sides.

    Parameters
    a

    the known length of side a

    b

    the known length of side b

    c

    the known length of side c

    Returns

    the area of the triangle

  • double PII_CORE_EXPORT calculateInterveningAngle

    (
    • double a
    • double b
    • double angle
    )

    #include <PiiMath.h>

    Calculates the angle between sides a and b, given the known lengths of the sides and the angle opposite to side a.

    Parameters
    a

    the known length of side a

    b

    the known length of side b

    angle

    the known angle opposite to a, in radians

    Returns

    the angle between sides a and b, in radians

  • double PII_CORE_EXPORT calculateOppositeAngle

    (
    • double a
    • double b
    • double c
    )

    #include <PiiMath.h>

    Calculates the angle opposite to side a, given the known lengths of all sides of a triangle.

    Parameters
    a

    the known length of side a

    b

    the known length of side b

    c

    the known length of side c

    Returns

    the angle opposite to a, in radians

  • double PII_CORE_EXPORT calculateThirdSide

    (
    • double a
    • double b
    • double angle
    )

    #include <PiiMath.h>

    Calculates the length of the third side of a triangle, given the lengths of two adjacent sides and the angle between them.

    Parameters
    a

    the known length of side a

    b

    the known length of side b

    angle

    the known angle between sides a and b, in radians

    Returns

    the length of the third side

  • template<class T>

    double ceil

    ()
    [inline]

    #include <PiiMath.h>

    Returns ceil(value).

  • float ceil

    (
    • float value
    )
    [inline]

    #include <PiiMath.h>

    This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

  • template<class T, class U>

    PiiMatrix< T > centralDiff

    ()

    #include <PiiMath.h>

    Calculates two-point central difference.

    The difference to diff() is that this function calculates the difference to two directions and uses the average as an estimate for the central point. On matrix boundaries, the difference between the two bordermost values will be used. This function is essentially the same as diff(mat, 2)/2 except that it handles the end points differently.

    Remember to provide the result type as a template parameter.

     PiiMatrix<int> input(3,5,
                          1,2,3,2,0,
                          1,3,2,2,1,
                          2,4,1,2,0);
    
     PiiMatrix<double> result =  Pii::centralDiff<double>(input, Pii::Horizontally);
     // 1.0  1.0, 0.0 -1.5 -2.0
     // 2.0  0.5 -0.5 -0.5 -1.0
     // 2.0 -0.5 -1.0 -0.5 -2.0

  • template<class T, class Collection>

    QVariantList collectionToVariants

    (
    • const Collection & lst
    )

    #include <PiiUtil.h>

    Convert any collection to a QVariantList that contains the same values as QVariant objects.

  • template<class Collection, class T>

    Collection columnToList

    ()

    #include <PiiMatrixUtil.h>

    Get a column from a matrix as a collection (QList, QVector)

     PiiMatrix<int> mat(2,2, 1,2, 3,4);
     QList<int> lst = Pii::columnToList<QList<int> >(mat, 0);
     // lst = { 1, 3 }

    Parameters
    matrix

    input matrix

    column

    column index (positive value)

  • template<class UnaryFunction, class Storage>

    void combinations

    ()

    #include <PiiMath.h>

    This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

    Parameters
    n
    k
    func
    storage

    an array/vector of ints with space for at least k elements to store the current combination. The algorithm will use storage's operator[] to access the elements.

  • template<class UnaryFunction>

    void combinations

    ()

    #include <PiiMath.h>

    Calculates all k-element subsets out of n elements and apply func to each.

    There will be subsets in total. Since this implementation uses int* as the storage type, the unary operator must be a function or functor that accepts a int* as input. The current combination is stored in the k first elements in the array.

     void function(const int* c)
     {
       cout << "[" << c[0] << " " << c[1] << " " << c[2] << "]
    ";
     }
    
     // ...
    
     // Find all combinations of 2 values in {0,1,2}.
     Pii::combinations(3, 2, function);
    
     // Prints:
     // [ 1 2 ]
     // [ 0 2 ]
     // [ 0 1 ]

     PiiMatrix<int> combinations(0,2);
     // Find all combinations of 2 elements among 5 elements. Store
     // the combinations as rows into the combinations matrix.
     Pii::RowAdder<int> adder(combinations);
     Pii::combinations(5, 2, adder);
     Pii::matlabPrint(std::cout, combinations);
     // Prints:
     // [ 3 4; ...
     //   2 4; ...
     //   1 4; ...
     //   0 4; ...
     //   2 3; ...
     //   1 3; ...
     //   0 3; ...
     //   1 2; ...
     //   0 2; ...
     //   0 1 ];

    Be sure not to pass arguments as copy if you intend to use a reference:

     struct Combinator
     {
       Combinator() : counter(0) {}
       void operator() (int*) { ++counter; }
       void func()
         {
           Pii::combinations(3,2,*this);
           // Counter is 0 because *this is passed as a copy.
           // This forces the template to use a reference argument
           Pii::combinations<Combinator&>(3,2,*this);
           // Now, counter is 3.
         }
       int counter;
     };

  • template<class Matrix1, class Matrix2>

    PiiMatrix< typename Matrix1::value_type > concatenate

    ()

    #include <PiiMatrixUtil.h>

    Concatenate two matrices.

    The rows/columns of mat2 are appended to those of mat1. If either matrix is empty, the other one is returned.

    Parameters
    mat1
    mat2
    direction

    Vertically means that mat2 will be added to the bottom of mat1. In this case the number of columns in the matrices must be the same. Horizontally means mat2 will be added to the right side of mat1. In this case the number of rows must be equal in both matrices.

    Exceptions
    PiiMathException&

    if matrix sizes don't match

  • template<class T>

    T conj

    ()
    [inline]

    #include <PiiMath.h>

    Calculates the complex conjugate of a real number.

    This function returns the input argument as such.

  • template<class T>

    std::complex< T > conj

    (
    • const std::complex< T > & value
    )
    [inline]

    #include <PiiMath.h>

    Calculates the conjugate of a complex scalar.

    This function is a wrapper to std::conj() allowing one to always use Pii::conj() regardless of the type.

  • PII_CORE_EXPORT void convertToGray

    ()

    #include <PiiQImage.h>

    Converts any color image (rgb/indexed) to gray scale.

  • PII_CORE_EXPORT void convertToRgba

    ()

    #include <PiiQImage.h>

    Converts any image to 32-bit rgb.

  • template<class InputIterator, class OutputIterator>

    OutputIterator copy

    (
    • InputIterator begin
    • InputIterator end
    • OutputIterator output
    )

    #include <PiiAlgorithm.h>

    Copies all elements in the range [begin, end) to output.

    Returns output + (end - begin).

  • PII_CORE_EXPORT void copyMetaType

    (
    • QVariant::Type type
    • const void * source
    • void * target
    )

    #include <PiiMetaTypeUtil.h>

    Copies the object pointed to by source to the memory location at target.

    Both source and target must point to an object whose type matches type.

     int iSource = 1, iTarget = 0;
     Pii::copyMetaType(QVariant::Int, &iSource, &iTarget);
     // iTarget == 1

    Parameters
    type

    the type ID of the objects. See QMetaType::Type.

    source

    the source object

    target

    the target object

  • template<class InputIterator, class OutputIterator>

    OutputIterator copyN

    (
    • InputIterator begin
    • int n
    • OutputIterator output
    )

    #include <PiiAlgorithm.h>

    Copies n elements starting at begin to output.

    Returns output + n.

  • template<class T>

    T copySign

    (
    • T value
    • T sign
    )
    [inline]

    #include <PiiMath.h>

  • template<class Iterator>

    void copyVaArgs

    (
    • Iterator begin
    • Iterator end
    • typename Pii::VaArg< typename std::iterator_traits< Iterator >::value_type >::Type first
    • ...
    )

    #include <PiiAlgorithm.h>

    Copies a variable number of arguments to a range of elements bounded by the iterators begin and end.

     QVector<int> vec(5);
     // Set vector contents to [ 1, 2, 3, 4, 5 ]
     Pii::copyVaArgs(vec.begin(), vec.end(), 1, 2, 3, 4, 5);

  • template<class Iterator>

    void copyVaList

    (
    • Iterator begin
    • Iterator end
    • typename Pii::VaArg< typename std::iterator_traits< Iterator >::value_type >::Type first
    • va_list rest
    )

    #include <PiiAlgorithm.h>

    Copies a variable argument list to a range of elements.

    This function is for copyVaArgs() what vprintf() is for printf(). The caller is responsible for invoking va_end() on rest.

    See also
  • template<class T>

    double cos

    ()
    [inline]

    #include <PiiMath.h>

    Returns cos(value).

  • float cos

    (
    • float value
    )
    [inline]

    #include <PiiMath.h>

    This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

  • PII_CORE_EXPORT int countOnes

    (
    • unsigned int c
    • const unsigned char bits = INTBITS
    )

    #include <PiiBits.h>

    Get the number of ones in a binary number.

    Parameters
    c

    the number

    bits

    the number of bits to consider

  • template<unsigned char>

    int countOnes

    (
    • unsigned int c
    )

    #include <PiiBits.h>

    This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

  • PII_CORE_EXPORT int countTransitions

    (
    • unsigned int c
    • const unsigned char bits = INTBITS
    )

    #include <PiiBits.h>

    Get the number of 0-to-1 or 1-to-0 transitions in a binary number.

    The number of transitions is calculated circularly. For example, the number of transitions in the 8-bit number "00011001" is four.

    Parameters
    c

    the number

    bits

    the number of bits to consider

  • template<unsigned char>

    int countTransitions

    (
    • unsigned int c
    )

    #include <PiiBits.h>

    This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

  • template<class T>

    PiiMatrix< double > covariance

    ()

    #include <PiiMath.h>

    Calculates the covariance matrix for a set of measurements.

    Each measurement is represented as a row in the input matrix mat.

    Parameters
    mat

    a NxM input matrix. Contains N measurements with M dimensions each. Make sure the matrix has at least two rows.

    mean

    a pointer to a mean matrix. The mean of all M dimensions will be calculated as a side product of covariance. If you need this value later, provide a placeholder for it here. The mean will be a 1xM row matrix.

    Returns

    a MxM covariance matrix. Diagonal elements represent the variances of the M dimensions. The covariance matrix is symmetric.

  • template<class T>

    QImage * createQImage

    ()

    #include <PiiQImage.h>

  • template<class T>

    QImage * createQImage

    ()

    #include <PiiQImage.h>

  • template<class T>

    QImage * createQImage

    ()

    #include <PiiQImage.h>

  • template<class T>

    PiiMatrix< T > crossProduct

    ()

    #include <PiiMath.h>

    Calculates the cross product of two vectors m1 and m2.

    The matrices must be either 3-by-1 or 1-by-3 matrices, i.e. 3-dimensional vectors. The function works with both row and column vectors. The orientation of the result vector will be the same as that of the inputs.

  • template<class UnaryFunction, class Matrix>

    PiiMatrix< typename UnaryFunction::result_type > cumulativeSum

    ()

    #include <PiiMath.h>

    Calculates two-dimensional cumulative sum of a matrix.

    The cumulative sum X(r,c) of an input matrix x(r,c) can be formally defined as

    where is a user-defined function.

     using namespace Pii;
    
     PiiMatrix<int> mat;
     // Calculate cumulative sum of squares. Note that it is very easy
     // to overflow such a large sum.
     PiiMatrix<long long> result = cumulativeSum(mat, Square<long long>());

    Parameters
    matrix

    the input matrix

    func

    the function to apply to the input

    mode

    calculation mode

  • template<class U, class Matrix>

    PiiMatrix< U > cumulativeSum

    ()
    [inline]

    #include <PiiMath.h>

    Calculates two-dimensional cumulative sum of a matrix.

    In OrdinaryCumulativeSum, the size of the returned matrix equals that of the input. In ZeroBorderCumulativeSum, the output will be larger. Each element stores the sum of all elements whose row and column coordinates are not larger than those of the element. The cumulative sum X(r,c) of an input matrix x(r,c) can be formally defined as

    The returned type can be different from the input type. For example, the sum over unsigned char matrices requires an integer output type.

    In image processing, the cumulative sum of an image is called an integral image. It is typically used in speeding up moving average calculations.

    The cumulative sum easily overflows with large images. If the input type is unsigned char and the output type is int, the input matrix may have no more than elements (about 8 megapixels) to prevent overflows.

     using namespace Pii;
    
     PiiMatrix<int> matrix(3,3,
                           1, 2, 3,
                           2, 3, 4,
                           3, 4, 5);
     PiiMatrix<int> sum = cumulativeSum<int>(matrix);
    
     // sum =
     // 1  3  6
     // 3  8 15
     // 6 15 27
    
     sum = cumulativeSum<int>(matrix, ZeroBorderCumulativeSum);
    
     // sum =
     // 0  0  0  0
     // 0  1  3  6
     // 0  3  8 15
     // 0  6 15 27

    Parameters
    mat

    the input matrix

    mode

    calculation mode

  • template<class U, class Matrix>

    PiiMatrix< U > cumulativeSum

    ()

    #include <PiiMath.h>

    Calculates the cumulative sum of matrix elements in the specified direction.

    The size of the returned matrix equals that of the input. Each element stores the sum of all elements left to it (MatrixRows) or above it (MatrixColumns). The last row/column of the matrix equals the result of sum(). The returned type can be different from the input type. For example, the sum over unsigned char matrices may require an integer output type.

     PiiMatrix<int> A(2 , 2,
                      1 , 2,
                      -1,-2);
     PiiMatrix<int> B(cumulativeSum<int>(A, Pii::Horizontally));
     //B =  1 3
     //    -1 -3
     PiiMatrix<int> C(cumulativeSum<int>(A, Pii::Vertically));
     //C = 1 2
     //    0 0

  • PII_CORE_EXPORT QVariantMap decodeProperties

    (
    • const QString & encodedProperties
    • QChar propertySeparator = '\n'
    • QChar valueSeparator = '='
    • QChar escape = '\\'
    • PropertyDecodingFlags flags = TrimPropertyName|TrimPropertyValue|RemoveQuotes
    )

    #include <PiiUtil.h>

    Decode string-encoded properties into a variant map.

    This function can be used to parse ini files, css-style properties or anything similar to a map of name-value pairs. All values will be QStrings, but they are stored as QVariants for easy cooperation with setProperties().

     QVariantMap props = Pii::decodeProperties("color: #fff;font-size: 5pt", ';', ':');
     // props now has two values:
     // "color" -> "#fff"
     // "font-size" -> "5pt"

    Parameters
    encodedProperties

    the string to decode

    propertySeparator

    a character that separates name-value pairs

    valueSeparator

    a character that separates name from value

    escape

    escape character

    flags

    flags for controlling the decoding

    Returns

    a map of name-value pairs

  • double degToRad

    (
    • double deg
    )
    [inline]

    #include <PiiMath.h>

    Convert an angle from degrees to radians.

  • template<class Collection>

    void deleteAll

    (
    • Collection & c
    )

    #include <PiiUtil.h>

    Delete all members of a collection.

    This function works for any stl or Qt collection. It goes through all members of the collection and deletes each.

    Parameters
    c

    the collection. Any collection (e.g. QList, QMap, or std::list) containing pointers.

  • template<class T>

    T determinant

    ()

    #include <PiiMath.h>

    calculate the determinant of a matrix.

    This function can be used with floating-point types only. Integer matrices can be used only if the size of the matrix is either 2-by-2 or 3-by-3.

    Exceptions
    PiiMathException&

    if the matrix is non-square

  • template<class T>

    T determinant2x2

    ()

    #include <PiiMath.h>

    Calculates determinant of 2x2 matrix with direct calculation.

    Does not check matrix size.

  • template<class T>

    T determinant3x3

    ()

    #include <PiiMath.h>

    Calculates determinant of 3x3 matrix with direct calculation.

    Does not check matrix size.

  • template<class T>

    PiiMatrix< T > diff

    ()

    #include <PiiMath.h>

    Difference and approximate derivative.

    Calculates the nth order difference of the given matrix in the specified direction.

     PiiMatrix<int> a(2,4,
                      1,   2,  4,   8,
                      16, 32, 64, 128);
     PiiMatrix<int> b(Pii::diff(a));
     // b = 1   2  4
            16 32 64
     PiiMatrix<int> c(Pii::diff(a,2));
     // c = 3   6
            48 96
     PiiMatrix<int> d(Pii::diff(a,1,1,Pii::Vertically));
     // d = 15 30 60 120
     PiiMatrix<int> e(Pii::diff(a,1,2));
     // e = 1   2
     //     16 32

    Parameters
    mat

    the input matrix. Must have at least step*order + 1 elements in the calculation direction.

    step

    the "difference step". Calculates difference over this many elements.

    order

    the order of the derivative.

    direction

    direction of calculation. By default rows are treated as vectors, and the difference is calculated horizontally. Use Pii::Vertically to change the default behaviour.

    Returns

    a matrix whose size depends on both step and order. Specifically, the size will be decreased step*order elements in the calculation direction.

  • template<class Matrix1, class Matrix2>

    void divide

    ()
    [inline]

    #include <PiiMath.h>

    Divide the elements in m1 by the corresponding elements in m2.

  • template<class Matrix1, class Matrix2>

    PiiBinaryMatrixTransform< Matrix1, Matrix2, std::divides< PII_COMBINE_TYPES(typename Matrix1::value_type, typename Matrix2::value_type)> > divided

    ()

    #include <PiiMath.h>

    Divide the elements in m1 by the corresponding elements in m2.

    Returns a new matrix.

  • template<class Real>

    Real epsilon

    ()

    #include <PiiMath.h>

    Calculates the distance from abs(value) to the next real number larger in magnitude.

    The return value can be seen as the accuracy of the number type at the given magnitude. A crude approximation of epsilon(x) can be obtained with epsilon(1.0)*abs(x).

    Parameters
    value

    the value whose accuracy is to be measured. If value == 1.0, returns std::numeric_limits<Real>::epsilon().

  • template<class Matrix1, class Matrix2>

    bool equals

    ()

    #include <PiiConceptualMatrix.h>

    Compare two matrices.

    Matrices are equal if all of their entries are equal. All entries are equal if the memory allocated by them matches byte-by-byte.

  • double erf

    (
    • double p
    )

    #include <PiiMath.h>

    Returns the value of the inverse normal cumulative distribution function (a.k.a the error function, erf) at p.

    The absolute value of the relative error is less than in the entire region.

    Parameters
    p

    a probability, in the range [0,1]

    Returns

    erf(p). If p < 0 or p > 1, NaN will be returned. If p == 0, -Inf will be returned. If p == 1, Inf will be returned.

  • template<class T>

    double exp

    ()
    [inline]

    #include <PiiMath.h>

    Returns exp(value).

  • float exp

    (
    • float value
    )
    [inline]

    #include <PiiMath.h>

    Returns exp(value).

  • template<class T>

    PiiMatrix< T > extend

    ()

    #include <PiiMatrixUtil.h>

    Extend a matrix by adding new rows/columns to its sides.

    Calls extend(PiiMatrix,int,int,int,int,ExtendMode).

    Parameters
    mat

    the matrix to be extended

    amount

    the number of rows/columns to add on each side

    mode

    the extension mode

    sides

    a bit mask that tells which sides of the matrix are extended. Use a composition of MatrixBorder values, e.g. MatrixTop | MatrixBottom.

    Returns

    the extended matrix

  • template<class T>

    PiiMatrix< T > extend

    (
    • const PiiMatrix< T > & mat
    • int topRows
    • int bottomRows
    • int leftCols
    • int rightCols
    • ExtendMode mode
    )

    #include <PiiMatrixUtil.h>

    Extend a matrix by adding new rows/columns to its sides.

    This version of the function adds a different number of rows/columns to each side.

    Parameters
    mat

    the matrix to be extended

    topRows

    the number of rows to add on top of the matrix

    bottomRows

    the number of rows to add to the bottom of the matrix

    leftCols

    the number of columns to add to the left of the matrix

    rightCols

    the number of columns to add to the right of the matrix

    mode

    the extension mode

    Returns

    the extended matrix. If mode is ExtendNot, the input matrix will be returned.

  • template<class T>

    T factorial

    (
    • T n
    )

    #include <PiiMath.h>

    Returns the factorial of n (n!).

    n doesn't need to be integer: for example factorial(2.5) returns 2.5*1.5.

  • float fastAtan2

    (
    • float y
    • float x
    )
    [inline]

    #include <PiiMath.h>

    A very fast approximation to four-quadrant arctan.

    This implementation requires (at most) five comparisons, two subtractions, one addition, one multiplication and one division. The accuracy is 0.07 rad (about 4 degrees) at worst. The output range is .

  • template<class Iterator>

    std::iterator_traits< Iterator >::value_type fastMedian

    (
    • Iterator data
    • int len
    )

    #include <PiiMath.h>

    Returns the median of all elements in data.

    This function modifies data.

    Parameters
    data

    a random access iterator to the beginning of the data. Will be modified during calculation.

    len

    the number of elements in data

  • template<class U, class T>

    PiiMatrix< U > fastMovingAverage

    (
    • const PiiMatrix< T > & cumulativeSum
    • int windowRows
    • int windowColumns = 0
    )

    #include <PiiMath.h>

    Fast 2-D moving average.

    This function uses the cumulative sum of a matrix to calculate the moving average over mat.

    The overall cumulative sum given as input is used to calculate local cumulative sum around each element. The local sum is divided by the number of elemements within the window. In the example below, three is used as the window size in both directions.

    Original   Cumulative sum (input)
               0  0  0  0
    1 2 3      0  1  3  6 
    2 3 4  ->  0  3  8  15  
    3 4 5      0  6  15 27
    Upper left:
    (8 + 0 - 0 - 0) / 4 = 2
    Lower right:
    (27 + 1 - 6 - 6) / 4 = 4
    

    The calculation time is independent of the size of the averaging window.

     PiiMatrix<int> matSum = cumulativeSum<int>(matInput, ZeroBorderCumulativeSum);
     // Calculate mean as float
     PiiMatrix<float> matSmooth = fastMovingAverage<float>(matSum, 7);

    Parameters
    cumulativeSum

    the cumulative sum of the original input matrix. This function assumes that ZeroBorderCumulativeSum was used as the calculation mode.

    windowRows

    the vertical size of the averaging window

    windowColumns

    the horizontal size of the averaging window. If this value is non-positive, windowRows will be used.

  • template<class InputIterator, class OutputIterator>

    void fastMovingAverage

    (
    • InputIterator input
    • int n
    • OutputIterator output
    • int windowSize
    )

    #include <PiiMath.h>

    Fast moving average.

    This function shrinks the averaging window on boundaries. If the window is longer than the input, all output elements will be set to the mean value of the input.

     int aInput[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
     double aOutput[8];
     Pii::fastMovingAverage(aInput, iCnt, aOutput, 5);
     // aOutput = { 2, 2, 2, 4, 5, 6, 6, 6 }

    Parameters
    input

    an input iterator of at least n elements

    n

    the number of elements to process

    output

    an output iterator of at least n elements. The result of the calculation will be placed here.

    windowSize

    the size of the averaging window.

  • PII_CORE_EXPORT QStringList fileList

    (
    • const QString & pattern
    • QDir::Filters filters = QDir::Files|QDir::Readable|QDir::CaseSensitive
    • QDir::SortFlags sort = QDir::Name
    )

    #include <PiiUtil.h>

    Fetch a list of files matching a wildcard.

    Parameters
    pattern

    a wildcard pattern, e.g. "<code>/usr/share/icons/</code><code>*.xpm</code>"

    filters

    a filter for file attributes

    sort

    sort order

    Returns

    all matching file names with full paths, sorted according to sort.

  • template<class Iterator>

    Iterator fill

    (
    • Iterator begin
    • Iterator end
    • typename std::iterator_traits< Iterator >::value_type value
    )

    #include <PiiAlgorithm.h>

    Sets all values in the range [begin, end) to value.

    Returns end.

  • template<class Iterator, class UnaryPredicate>

    Iterator fillIf

    (
    • Iterator begin
    • Iterator end
    • UnaryPredicate predicate
    • typename std::iterator_traits< Iterator >::value_type value
    )

    #include <PiiAlgorithm.h>

    Sets all values in the range [begin, end) for which predicate returns a non-zero value to value.

    Returns end.

  • template<class Iterator>

    Iterator fillN

    (
    • Iterator begin
    • int n
    • typename std::iterator_traits< Iterator >::value_type value
    )

    #include <PiiAlgorithm.h>

    Sets all values in the range [begin, begin + b) to value.

    Returns begin + n.

  • template<class T, class UnaryPredicate>

    PiiMatrix< int > find

    (
    • const PiiMatrix< T > & mat
    • UnaryPredicate predicate
    • int cnt = 0
    )

    #include <PiiMath.h>

    Find the row and column coordinates of all elements in mat that match predicate.

    If mat is a row or column vector, indices are returned in a row matrix. If mat is not a vector, the row and column index for each entry are stored as row vectors in the returned matrix, in this order.

     PiiMatrix<int> mat(3,3,
                        1,2,3
                        4,5,6,
                        7,8,9);
     find(mat, std::bind2nd(std::less<int>(), 3));
     // returns
     // 0,0
     // 0,1

    Parameters
    mat

    the input matrix.

    predicate
    cnt

    the maximum number of indices returned. Zero means all, a negative value means "all but the @p -cnt last ones". That is, a negative value omits the last non-zero entries.

  • template<class T>

    PiiMatrix< int > find

    ()
    [inline]

    #include <PiiMath.h>

    Find the row and column coordinates of all non-zero elements in mat.

    If mat is a row or column vector, indices are returned in a row matrix. If mat is not a vector, the row and column index for each entry are stored as row vectors in the returned matrix, in this order. This is a convenience function that works analogously to its Matlab counterpart.

     PiiMatrix<int> mat(3,3,
                        1,2,3
                        4,5,6,
                        7,8,9);
     find(mat < 3);
     // returns
     // 0,0
     // 0,1

    Parameters
    mat

    the matrix to find non-zero entries in. Typically a result of a comparison operator as in find(mat > 1).

    cnt

    the maximum number of indices returned. Zero means all, a negative value means "all but the @p -cnt last ones". That is, a negative value omits the last non-zero entries.

  • template<class T>

    QList< T > findAllParents

    (
    • const QObject * obj
    • unsigned int maxParents = < unsigned int >::maxValue()
    )

    #include <PiiUtil.h>

    Find all parent objects of obj up to maxParents parent objects.

    Find all parents independent of their type.

    By default, all parents are returned. If a template parameter is specified, only parents matching the given type are returned.

     QList<MyObj*> parents = Pii::findAllParents<MyObj*>(obj);
     // Returns all parents of obj whose type is MyObj*

  • PII_CORE_EXPORT QObject * findCommonParent

    ()

    #include <PiiUtil.h>

    Find the object that is the closest common ancestor of obj1 and obj2 in the object hierarchy.

    Parameters
    obj1

    first object

    obj2
    parentIndex

    if non-zero, the index of the closest parent object in obj1's parent list is stored here.

    Returns

    a pointer to the parent found, or zero if the objects don't have a common parent.

  • template<class Rule, class T>

    void findFirst

    (
    • const PiiMatrix< T > & matrix
    • T value
    • int & r
    • int & c
    )
    [inline]

    #include <PiiMatrixUtil.h>

    Find the first occurrence of an element that matches Rule.

    Stores the row and column coordinates to r and c. If no such value is not found, both coordinates will be set to -1.

     PiiMatrix<int> mat(2,2,
                        1,2,
                        3,4);
     int r,c;
     Pii::findFirst<std::equal_to<int> >(mat,5, r, c);
     // r = -1, c = -1

    Find the first occurrence of an element that matches Rule.

    Stores the row and column coordinates to r and c. If the value is not found, both coordinates will be set to -1.

  • template<class T>

    void findFirst

    (
    • const PiiMatrix< T > & matrix
    • T value
    • int & r
    • int & c
    )
    [inline]

    #include <PiiMatrixUtil.h>

    Find the first occurrence (top to bottom, left to right) of value in matrix.

    Find the first occurrence of an element that matches Rule.

    Stores the row and column coordinates to r and c. If the value is not found, both coordinates will be set to -1.

  • template<class T>

    T findFirstParent

    ()

    #include <PiiUtil.h>

    Find the first parent of obj whose type matches T.

    Equivalent to findAllParents(obj,1), but faster.

  • template<class T>

    void findLast

    (
    • const PiiMatrix< T > & matrix
    • T value
    • int & r
    • int & c
    )

    #include <PiiMatrixUtil.h>

    Find the last occurrence (bottom to top, right to left) of value in matrix.

    Find the last occurrence of an element that matches Rule.

    Stores the row and column coordinates to r and c. If the value is not found, both coordinates will be set to -1.

  • template<class Rule, class T>

    void findLast

    (
    • const PiiMatrix< T > & matrix
    • T value
    • int & r
    • int & c
    )

    #include <PiiMatrixUtil.h>

    Find the last occurrence of an element that matches Rule.

    Stores the row and column coordinates to r and c. If no such value is not found, both coordinates will be set to -1.

     PiiMatrix<int> mat(2,2,
                        1,2,
                        3,4);
     int r,c;
     Pii::findLast<std::greater<int> >(mat, 2, r, c);
     // r = 1, c = 0

    Find the last occurrence of an element that matches Rule.

    Stores the row and column coordinates to r and c. If the value is not found, both coordinates will be set to -1.

  • template<class T>

    PiiHeap< PiiMatrixValue< T >, 16 > findMaxima

    ()

    #include <PiiMath.h>

    Find cnt largest values in mat.

     PiiMatrix<int> mat(5,5); // Assume this is non-zero
     PiiHeap<PiiMatrixValue<int>,16> maxima = Pii::findMaxima(mat, 5);
     // maxima now contains the five largest values in mat

  • template<class T>

    PiiHeap< PiiMatrixValue< T >, 16 > findMinima

    ()

    #include <PiiMath.h>

    Find cnt smallest values in mat.

    See also
  • PII_CORE_EXPORT QList< QList< int > > findNeighbors

    (
    • QLinkedList< QPair< int, int > > & pairs
    )

    #include <PiiUtil.h>

    Recursively connects neighbors given as a list of pairs.

    The input contains a list of index pairs, each indicating a "neighbor" relationship. The function scans through the list and forms chains of neighbors. Finally, it returns a list in which each entry contains a list of indices that were chained. Each list is sorted in ascending order.

     QLinkedList<QPair<int,int> > lstPairs;
     lstPairs << qMakePair(0,1) << qMakePair(0,3) << qMakePair(0,4) << qMakePair(3,4) << qMakePair(3,5);
     lstPairs << qMakePair(2,6) << qMakePair(6,8) << qMakePair(7,8);
    
     QList<QList<int> > lstNeighbors(Pii::findNeighbors(lstPairs));
     // ((0, 1, 3, 4, 5), (2, 6, 7, 8))

  • PII_CORE_EXPORT int findSeparator

    ()

    #include <PiiUtil.h>

    Returns the index of the first occurrence of separator in str, starting at startIndex.

    This function ignores occurrences that are preceded by an odd number of escape characters. If the separator is not found, returns -1.

     Pii::findSeparator("\"Test \\"string\"", '"', 1); // returns 14

  • template<class InputIterator, class UnaryFunction, class BinaryPredicate>

    InputIterator findSpecialValue

    (
    • InputIterator begin
    • InputIterator end
    • BinaryPredicate op
    • UnaryFunction f
    )

    #include <PiiAlgorithm.h>

    Find a special value such as maximum or minimum in the range specified by begin and end.

    The "speciality" is defined by the given function objects. Specifically, the algorithm increases begin until it equals end, and sets x to *begin whenever op(f(*begin), f(*x)) returns a non-zero value. Returns *x on success, or end if the range is empty.

     double* values[] = { 1, 2.0, -5.3, 4.2 };
     // Find the maximum absolute value
     using namespace Pii;
     double dMaxAbs = abs(*findSpecialValue(values, values + 4, std::greater<double>(), Abs<double>()));

  • template<class T>

    int firstOneBit

    (
    • T c
    )

    #include <PiiBits.h>

    Find the index of the first bit set to one.

    The function returns 0 if a one is found on the first bit position and so on. If the number is zero, -1 is returned.

  • PII_CORE_EXPORT PiiMatrix< double > fitPolynomial

    (
    • unsigned int order
    • const PiiMatrix< double > & x
    • const PiiMatrix< double > & y = < double >()
    )

    #include <PiiMath.h>

    Fit a polynomial curve to data.

    This function fits an Nth order polynomial function into the given data points. The solution is optimal in least squares sense. Note that the result is optimal arithmetically, not geometrically. Fitting a polynomial geometrically requires non-linear optimization methods, for which tools are provided in the PiiOptimization namespace. The arithmetic fit calculated by this function can be used as an initial guess for iterative optimization.

     // y = -2x^2 + 3.5x - 1
     // y2 = -1.75x^2 + 3.25x - 1
     PiiMatrix<double> coeffs = Pii::fitPolynomial(2,
                                                   PiiMatrix<double>(2,3,
                                                                     0.0, 1.0, 2.0,
                                                                     0.0, 1.0, 2.0),
                                                   PiiMatrix<double>(2,3,
                                                                     -1.0, 0.5, -2.0,
                                                                     -1.0, 0.5, -1.5));
    
     // coeffs = [-1.0 3.5  -2.0 ]
     //          [-1.0 3.25 -1.75]
    
    
     // y = 2.5x^3 + 2x^2 - 8x + 0.5
     coeffs = Pii::fitPolynomial(3, PiiMatrix<double>(4,2,
                                                      -1.0, 8.0,
                                                      0.0, 0.5,
                                                      1.0, -3.0,
                                                      2.0, 12.5));
     // coeffs = [0.5 -8.0 2.0 2.5]

    The numerical accuracy of the algorithm can be improved by normalizing x coordinates before calling this function:

     PiiMatrix<double> x(1,100);
     // ... fill x somehow ...
     x = (x - Pii::meanAll<double>(x)) / Pii::stdAll<double>(x);
     // And remember to denormalize when you need the original X:
     // x = mean + std * x;

    Parameters
    order

    the order of the polynomial.

    x

    the x coordinates of measurements as row vectors or both x and y coordinates as a N-by-2 matrix. The number of measurements must be larger than order.

    y

    the y coordinates of measurements as row vectors, or an empty matrix if x contains both coordinates.

    Returns

    coefficients of the fitted polynomials as a M-by-N+1 matrix, where M is the number of rows in x and y, if both are provided, or 1 if only x is given. N is the order of the polynomial. The colum index in the result matrix corresponds to the order of the polynomial.

    Exceptions
    PiiMathException&

    if the least squares problem turns out to be singular.

    PiiInvalidArgumentException&

    input arguments are illegally formed.

  • template<class T>

    void flip

    (
    • PiiMatrix< T > & matrix
    • Pii::MatrixDirections directions
    )

    #include <PiiMatrixUtil.h>

    Flip matrix in place either horizontally, vertically or both.

     PiiMatrix<int> mat(3, 3,
                        1, 2, 3,
                        4, 5, 6,
                        7, 8, 9);
     Pii::flip(mat, Pii::Vertically);
     // mat = [ 7 8 9; 4 5 6; 1 2 3 ]
     Pii::flip(mat, Pii::Horizontally);
     // mat = [ 9 8 7; 6 5 4; 3 2 1 ]
     Pii::flip(mat, Pii::Horizontally | Pii::Vertically);
     // mat = [ 1 2 3; 4 5 6; 7 8 9 ]

  • template<class T>

    PiiMatrix< T > flipped

    (
    • const PiiMatrix< T > & mat
    • Pii::MatrixDirections directions
    )

    #include <PiiMatrixUtil.h>

    This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. This function doesn't modify the source matrix, but returns a copy.

  • unsigned int floatSignBit

    (
    • double value1
    • float value2
    )
    [inline]

    #include <PiiBits.h>

    Returns the sign bit of value1 - value2.

    This function always uses the floating point version of signBit().

  • template<class T>

    unsigned int floatSignBit

    (
    • T value1
    • float value2
    )
    [inline]

    #include <PiiBits.h>

    Returns the sign bit of value1 - value2.

    This function always uses the floating point version of signBit().

  • template<class T>

    double floor

    ()
    [inline]

    #include <PiiMath.h>

    Returns floor(value).

  • float floor

    (
    • float value
    )
    [inline]

    #include <PiiMath.h>

    This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

  • template<class InputIterator, class UnaryFunction>

    UnaryFunction forEach

    ()

    #include <PiiAlgorithm.h>

    Applies func to each element in the range [begin, end).

    The return value of the unary function func (if any) is ignored. Returns func.

     // Calculate the mean of all entries
     PiiMatrix<float> matrix(3,3);
     std::cout << Pii::forEach(matrix.begin(), matrix.end(),
                               Pii::Mean<float>()).mean();

  • template<class InputIterator, class UnaryPredicate, class UnaryFunction>

    UnaryFunction forEachIf

    (
    • InputIterator begin
    • InputIterator end
    • UnaryPredicate predicate
    • UnaryFunction func
    )

    #include <PiiAlgorithm.h>

    Applies func to each element in the range [begin, end) for which predicate returns a non-zero value.

    The return value of the unary function func (if any) is ignored. Returns func.

     // Calculate the mean of non-zero entries
     PiiMatrix<float> matrix(3,3);
     std::cout << Pii::forEachIf(matrix.begin(), matrix.end(),
                                 std::bind2nd(std::not_equal_to<float>(), 0.0),
                                 Pii::Mean<float>()).mean();

  • template<class T>

    T gaussian

    (
    • T x
    • double mu
    • double sigma
    )

    #include <PiiMath.h>

    A Gaussian function.

    Returns gaussian function value on given point x, with given expected value mu and variance sigma.

    sigma is not a .

    Parameters
    x

    is point where gaussian function value is wanted to calcualte.

    mu

    is distribution expected value.

    sigma

    is variance of distribution.

  • template<class T>

    T gcd

    (
    • T number1
    • T number2
    )

    #include <PiiMath.h>

    Find the greatest common divisor (gcd) for the given two numbers using Euclid's algorithm.

    If either of the numbers is zero, the other one is returned. The gcd is always positive, or zero if both arguments are zero.

  • template<class Iterator, class Generator>

    Iterator generate

    (
    • Iterator begin
    • Iterator end
    • Generator generator
    )

    #include <PiiAlgorithm.h>

    Sets all values in the range [begin, end) to the value returned by generator.

    Returns end.

  • template<class Iterator, class Generator>

    Iterator generateN

    ()

    #include <PiiAlgorithm.h>

    Sets all values in the range [begin, begin + n) to the value returned by generatore.

    Returns begin + n.

  • PII_CORE_EXPORT const QVector< QRgb > & grayColorTable

    ()

    #include <PiiColorTable.h>

    Returns a color table with shades of gray from zero to 255.

    PiiQImage uses this color table when initialized with a PiiMatrix, because there is no color table in matrices.

  • PII_CORE_EXPORT int hammingDistance

    (
    • unsigned int a
    • unsigned int b
    • const unsigned char bits = INTBITS
    )

    #include <PiiBits.h>

    Calculate the Hamming distance between two binary numbers.

    Parameters
    a

    a number

    b

    another number

    bits

    the number of bits to consider

  • template<unsigned char>

    int hammingDistance

    (
    • unsigned int a
    • unsigned int b
    )

    #include <PiiBits.h>

    This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

  • template<class Iterator>

    void householderTransform

    (
    • Iterator x
    • int n
    • typename std::iterator_traits< Iterator >::value_type * tau
    • typename std::iterator_traits< Iterator >::value_type * beta = 0
    )

    #include <PiiHouseholderTransform.h>

    Generates an elementary reflector (a.k.a the Householder transformation).

    The Householder transformation of an n-dimensional vector x is an n-by-n matrix H for which the following equation holds:

    In other words, H is a matrix that effectively transforms x into a scalar. The transformation matrix H can be represented as

    where v is an n-dimensional vector whose first component equals one. (If complex numbers were involved, the transpose should be replaced with a Hermitian transpose, but this routine only supports real input.)

    Parameters
    x

    an n-dimensional input/output vector. This vector will be modified by the algorithm so that it contains the vector v.

    n

    the length of x

    tau

    a return-value parameter that will store the value of . If x is a null vector, tau will be zero. Otherwise, .

    beta

    an optional return-value parameter that will store the value of . If x is a null vector, beta will be set to zero.

    See also
  • template<class T>

    T hypotenuse

    (
    • T a
    • T b
    )
    [inline]

    #include <PiiMath.h>

    Calculates the hypotenuse given two orthogonal sides of a triangle.

    Returns

  • template<class T>

    T imag

    ()
    [inline]

    #include <PiiMath.h>

    Returns the imaginary part of a real number, i.e.

    zero.

  • template<class T>

    T imag

    (
    • const std::complex< T > & value
    )
    [inline]

    #include <PiiMath.h>

    Returns the imaginary part of a complex number.

  • template<class T, int>

    T innerProduct

    ()
    [inline]

    #include <PiiVector.h>

    This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

  • template<class T>

    T innerProduct

    ()
    [inline]

    #include <PiiVector.h>

    This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

  • template<class T>

    T innerProduct

    ()
    [inline]

    #include <PiiVector.h>

    This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

  • template<class T>

    T innerProduct

    ()

    #include <PiiMath.h>

    Calculates the inner product of two vectors m1 and m2.

    The matrices must be vectors of the same size.

  • template<class InputIterator1, class InputIterator2, class T>

    T innerProduct

    (
    • InputIterator1 begin1
    • InputIterator1 end1
    • InputIterator2 begin2
    • T initialValue
    )

    #include <PiiAlgorithm.h>

    Returns the inner product of two vectors v1 and v2.

     PiiMatrix<double> m(2, 1, 1.0, -1.0);
     double dot = Pii::innerProduct(m.columnBegin(0),
                                    m.columnEnd(0),
                                    m.columnBegin(0),
                                    0.0);
     QCOMPARE(dot, 2.0);

    Parameters
    begin1

    an interator the beginning of v1

    end1

    an interator to the end of v1

    begin2

    an interator the beginning of v2

    initialValue

    initial value for the inner product, usually 0. Used to determine the return type.

    Returns

  • template<class InputIterator1, class InputIterator2, class T>

    T innerProductN

    (
    • InputIterator1 begin1
    • int n
    • InputIterator2 begin2
    • T initialValue
    )

    #include <PiiAlgorithm.h>

    This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Returns the inner product of two n-dimensional vectors.

  • template<class T>

    void insertionSort

    (
    • T * data
    • int size
    )

    #include <PiiMath.h>

    Classical insertion sort.

    Sorts elements in array (in-place) to ascending order. Complexity class is O(n^2) where, n is number of elements in array.

     int array[10] = {1,3,2,0,4,5,7,6,9,8};
     Pii::insertionSort<int>(array, 10);
     //Now array elements are order :  0,1,2,3,4,5,6,7,8,9

    Parameters
    data

    is array which will be sorted.

    size

    is length of array.

  • template<class Collection>

    Collection intersect

    (
    • const Collection & list1
    • const Collection & list2
    )

    #include <PiiUtil.h>

    Find the intersection of two lists.

    The result contains the elements that are present in both lists, or an empty list if the intersection is empty. Any collection defining size(), contains(), and append() functions can be used as a parameter.

  • template<class T>

    PiiMatrix< T > inverse

    ()

    #include <PiiMath.h>

    Invert a matrix.

    Only square, non-singular matrices can be inverted. Gauss-Jordan elimination is used as the inversion algorithm.

    Is not implemented properly for interger type matrix.

    Returns

    the inverted matrix.

    Exceptions
    PiiMathException&

    if the matrix is non-square or singular

  • template<class T>

    bool isAntiSymmetric

    ()

    #include <PiiMath.h>

    Tests if a matrix is antisymmetric.

    The transpose of an antisymmetric matrix is equal to its negation.

    Does exact comparison (no difference tolerance).

  • template<class T>

    bool isDiagonal

    ()

    #include <PiiMath.h>

    Test if a matrix is diagonal.

    Diagonal matrices have zeros everywhere but on the diagonal.

    Does exact comparison (no difference tolerance).

  • template<class T>

    bool isInf

    (
    • T f
    )
    [inline]

    #include <PiiMathDefs.h>

    Returns true if f equals Inf.

  • template<class T>

    bool isNan

    (
    • T f
    )
    [inline]

    #include <PiiMathDefs.h>

    Returns true if f is NaN.

  • template<class T>

    bool isOrthogonalLike

    (
    • const PiiMatrix< T > & mat
    • const T & tolerance
    )

    #include <PiiMath.h>

    Tests whether the given real matrix is "orthogonal-like".

    For square matrices returns true iff matrix is orthogonal, meaning that . It also implies that row vectors (and column vectors respectively) form orthonormal basis, i.e. vectors are mutually perpendicular and length of every vector is 1.

    For non-square m*n matrices, returns true iff. either row vectors(m<n) or columns vectors(m>n) are orthonormal. The former case implies , the latter case

    Parameters
    mat

    Real matrix.

    tolerance

    Defines the numerical tolerance in comparison.

  • template<class T>

    bool isOrthogonalLike

    ()

    #include <PiiMath.h>

    Overloaded function which calls isOrthogonalLike() with default numerical difference tolerance for type T.

  • PII_CORE_EXPORT bool isParent

    ()

    #include <PiiUtil.h>

    Returns true if parent is a parent of child.

  • template<class T>

    bool isSingular

    ()

    #include <PiiMath.h>

    Test if a matrix is singular.

    Matrix is singular if it is square and its determinant equals zero. With the exception of matrix sizes 2x2 and 3x3, singularity can be accurately detected with floating point types only.

    Comparison of determinant and zero has difference tolerance.

  • template<class T>

    bool isSquare

    ()

    #include <PiiMath.h>

    Tests whether the given matrix is square matrix.

  • template<class T>

    bool isSymmetric

    ()

    #include <PiiMath.h>

    Test if a matrix is symmetric about the diagonal.

    Does exact comparison (no difference tolerance).

  • template<class Collection>

    Collection join

    (
    • const Collection & list1
    • const Collection & list2
    )

    #include <PiiUtil.h>

    Find the union of two lists.

    The result contains the elements that are present in either list, ignoring duplicates. Any collection defining size(), contains(), and append() functions can be used as a parameter.

  • template<class T>

    T kthSmallest

    (
    • T * data
    • int size
    • int k
    )

    #include <PiiMath.h>

    Returns the k:th smallest element from array.

    now k = 0 means smallest, k = 1 second smallest etc.

     int array[8] = {0,2,3,9,4,5,6,8};
     int element = Pii::kthSmallest<int>(array, 8, 2);
     //now element is 3. 

    Parameters
    data

    the array in which k:th smallest value is to be found.

    size

    is array size

    k

    is ordinal number.

  • template<class T>

    int lastOneBit

    (
    • T c
    )

    #include <PiiBits.h>

    Find the index of the last bit set to one.

    The function returns 0 if a one is found on the first bit position and so on. If the number is zero, -1 is returned.

  • template<class T, class Collection>

    PiiMatrix< T > listToMatrix

    ()

    #include <PiiMatrixUtil.h>

    Converts a collection to a row matrix.

     QList<double> lst = QList<double>() << 1.0 << 2.0;
     PiiMatrix<double> mat = Pii::listToMatrix<double>(lst);
     // mat = [ 1.0 2.0 ]

    Parameters
    lst

    a list of values (QList, QVector, ...)

    direction

    store values int this direction. By default, values are stored horizontally, single-row matrix.

    Returns

    a row matrix with lst.size() columns.

  • template<class T>

    QVariantList listToVariants

    ()
    [inline]

    #include <PiiUtil.h>

    Convert a QList to a QVariantList that contains the same values as QVariant objects.

  • template<class T>

    double log

    ()
    [inline]

    #include <PiiMath.h>

    Returns log(value).

  • float log

    (
    • float value
    )
    [inline]

    #include <PiiMath.h>

    Returns log(value).

  • template<class Iterator, class UnaryFunction>

    Iterator map

    ()

    #include <PiiAlgorithm.h>

    Applies a unary function func to all elements in the range [begin, end), and stores the result in place.

    The map algorithm is equal to std::transform except that it always modifies the elements in place. Returns end.

     // Subtract one from all elements of a QVector
     QVector<double> vec(6);
     Pii::map(vec.begin(), vec.end(), std::bind2nd(std::minus<double>(), 1));

  • template<class Iterator1, class Iterator2, class BinaryFunction>

    void map

    (
    • Iterator1 begin1
    • Iterator1 end1
    • Iterator2 begin2
    • BinaryFunction func
    )

    #include <PiiAlgorithm.h>

    Applies a binary function func to all elements in the range [begin1, end1), and stores the result in place.

    The second argument to the binary function is taken from begin2. The map algorithm is equal to transform() except that it always modifies the elements in place and works slightly faster.

     // Add the elements of lst2 to lst1
     QList<int> lst1, lst2;
     lst1 << 1 << 2;
     lst2 << -1 << -2;
     Pii::map(lst1.begin(), lst2.end(), lst2.begin(), std::plus<int>());
     // lst1 is now (0, 0)

  • template<class Iterator, class UnaryPredicate, class UnaryFunction>

    Iterator mapIf

    (
    • Iterator begin
    • Iterator end
    • UnaryPredicate predicate
    • UnaryFunction func
    )

    #include <PiiAlgorithm.h>

    Applies a unary function func to all elements in the range [begin, end) for which predicate returns a non-zero value.

    The returned value will be stored in place. Returns end.

  • template<class Matrix, class UnaryFunction>

    Matrix & mapMatrix

    ()
    [inline]

    #include <PiiMath.h>

    Applies the unary function func to all elements of matrix.

    Returns matrix.

     PiiMatrix<int> matInput(1, 3, -1, 2, 3);
     // Negate all numbers
     Pii::mapMatrixIf(matInput, std::negate<int>());
     // matInput = -1 -2 -3

  • template<class Matrix, class UnaryPredicate, class UnaryFunction>

    Matrix & mapMatrixIf

    ()
    [inline]

    #include <PiiMath.h>

    Applies the unary function func to all elements of matrix that match the given predicate.

    Analogous to PiiMatrix::map() except for the predicate parameter. Returns matrix.

     PiiMatrix<int> matInput(1, 3, -1, 2, 3);
     // Negate all positive numbers
     Pii::mapMatrixIf(matInput,
                      std::bind2nd(std::greater<int>(), 0),
                      std::negate<int>());
     // matInput = -1 -2 -3

    Parameters
    matrix

    input matrix, modified in place

    predicate

    a checker function that determines if func will be applied to the current element

    func

    the operation to apply to matched elements

  • template<class Iterator1, class Iterator2, class BinaryFunction>

    void mapN

    ()

    #include <PiiAlgorithm.h>

    Applies a binary function func to all elements in the range [begin1, begin1 + n), and stores the result in place.

    The second argument to the binary function is taken from begin2. The map algorithm is equal to transform() except that it always modifies the elements in place and works slightly faster.

  • template<class Iterator, class UnaryFunction>

    Iterator mapN

    ()

    #include <PiiAlgorithm.h>

    Applies a unary function func to all elements in the range [begin, begin + n), and stores the result in place.

    Returns begin + n.

  • template<class Matrix, class UnaryFunction>

    Matrix & mappedMatrix

    ()
    [inline]

    #include <PiiMath.h>

    Applies the unary function func to all elements of matrix.

    Returns a new matrix.

  • template<class Matrix, class UnaryPredicate, class UnaryFunction>

    PiiMatrix< typename UnaryFunction::result_type > mappedMatrixIf

    ()
    [inline]

    #include <PiiMath.h>

    Applies the unary function func to all elements of matrix that match the given predicate.

    Same as mapMatrixIf(), but returns a copy.

  • PII_CORE_EXPORT bool matchCrontab

    ()

    #include <PiiUtil.h>

    Match a list of crontab-like strings against the given time stamp.

    Each string in list represents a rule with a syntax similar but not equivalent to crontab (man crontab). Each rule contains six fields separated by spaces. The fields are (in this order): minute, hour, day, month, day of week, and week number. Each field may contain a comma-separated list of values or value ranges, or an asterisk (*) that denotes "all". A rule matches if all of its fields match. A set of rules matches if any of its rules matches.

     // Returns true during the first minute after midnight every day and
     // 4:00-6:00 on the first day of every month
     matchCrontab(QStringList() <<
                  "0 0 * * * *" <<
                  "* 4-5 1 * * *");
    
     // Returns true between 8:30 and 8:31 on Monday, Wednesday, and
     // Friday on weeks 1, 2, 3, 5, 6, 7, 8, and 9
     matchCrontab(QStringList() <<
                  "30 8 * * 1,3,5 1-3,5-9);

    Parameters
    list

    a list of crontab entries.

    timeStamp

    the time to match the entries against

    Returns

    true if any of the entries match the time stamp.

  • PII_CORE_EXPORT PiiMatrix< double > matlabParse

    ()

    #include <PiiMatrixUtil.h>

    Parse a string that describes a matrix in Matlab syntax.

    The parser accepts non-complex numbers, and does not require newlines to be prefixed with "...". Enclosing square brackets are optional. Separate elements with commas or spaces and rows with semicolons.

     PiiMatrix<double> mat1 = matlabParse("[1 2 3; 4 5 6; 7 8 9]");
     PiiMatrix<double> mat2 = matlabParse("1.0, 2.0, 3.5; ...
     4 5 6.8");

  • template<class Stream, class Matrix>

    void matlabPrint

    ()

    #include <PiiMatrixUtil.h>

    Print out a matrix in a matlab-friendly format.

    The output can be copied and pasted to create a matrix in Matlab.

    Parameters
    out

    an output stream to write the matrix to. Any class implementing operator<<(const char*) and operator<<(T) can act as the output stream. Examples of such classes are stl output streams (std::cout and relatives) and QTextStream. Even a QVariantList works in most cases.

    mat

    the matrix to be written

  • template<class T>

    PiiMatrix< T > matrix

    ()
    [inline]

    #include <PiiMatrix.h>

    This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. This specialization just returns mat.

  • template<class T>

    PiiMatrix< T > max

    ()

    #include <PiiMath.h>

    Calculates the maximum among all elements in the specified direction.

  • template<class T>

    T max

    ()
    [inline]

    #include <PiiMath.h>

    Returns the maximum of two arguments.

  • template<class T>

    T max

    (
    • T a
    • T b
    • T c
    )
    [inline]

    #include <PiiMath.h>

    Returns the maximum of three arguments.

  • template<class T>

    T max

    (
    • T a
    • T b
    • T c
    • T d
    )
    [inline]

    #include <PiiMath.h>

    Returns the maximum of four arguments.

  • template<class T, class R>

    R maxAbsAll

    (
    • const PiiMatrix< T > & mat
    • int * r = 0
    • int * c = 0
    )
    [inline]

    #include <PiiMath.h>

    Like maxAll(), but finds the maximum absolute value.

  • template<class Collection>

    Collection::value_type maxAll

    (
    • const Collection & collection
    )
    [inline]

    #include <PiiMath.h>

    Shorthand for maxAll(collection.begin(), collection.end()).

  • template<class InputIterator>

    std::iterator_traits< InputIterator >::value_type maxAll

    (
    • InputIterator begin
    • InputIterator end
    )
    [inline]

    #include <PiiMath.h>

    Returns the maximum value in [begin, end).

  • template<class T>

    T maxAll

    (
    • const PiiMatrix< T > & mat
    • int * r = 0
    • int * c = 0
    )
    [inline]

    #include <PiiMath.h>

    Calculates the maximum of all elements in a matrix.

    Parameters
    mat

    the source matrix

    r

    store the row of the maximum value to this memory location (if non-zero)

    c

    store the column of the maximum value to this memory location (if non-zero)

  • template<class U, class Matrix>

    PiiMatrix< U > mean

    ()
    [inline]

    #include <PiiMath.h>

    Calculates the mean of matrix elements in the specified direction.

    If Pii::Horizontally is specified, a column matrix returned and vice versa.

  • template<class U, class Matrix>

    U meanAll

    ()
    [inline]

    #include <PiiMath.h>

    Calculates the mean of all entries in a matrix.

    Returns the value as a (possibly) different type, denoted by the template parameter U.

     PiiMatrix<int> mat(1,2, 1, 0);
     double mean = Pii::meanAll<double>(mat); //returns 0.5

  • template<class Iterator>

    std::iterator_traits< Iterator >::value_type median

    (
    • Iterator data
    • int len
    )

    #include <PiiMath.h>

    Returns the median of all elements in data.

    This function does not modify data. It is slower than the intrusive fastMedian(), but retains data intact.

    Parameters
    data

    a random access iterator to the beginning of the data. Will be modified during calculation.

    len

    the number of elements in data

  • template<class Iterator>

    std::iterator_traits< Iterator >::value_type median25

    (
    • Iterator data
    )

    #include <PiiMath.h>

    Median of 25 values optimized to the theoretical maximum efficiency.

    Parameters
    data

    pointer to 25 successive values. The array will be modified.

  • template<class Iterator>

    std::iterator_traits< Iterator >::value_type median3

    (
    • Iterator data
    )

    #include <PiiMath.h>

    Median of three values optimized to the theoretical maximum efficiency.

    Parameters
    data

    pointer to 3 successive values. The array will be modified.

  • template<class Iterator>

    std::iterator_traits< Iterator >::value_type median5

    (
    • Iterator data
    )

    #include <PiiMath.h>

    Median of five values optimized to the theoretical maximum efficiency.

    Parameters
    data

    pointer to 5 successive values. The array will be modified.

  • template<class Iterator>

    std::iterator_traits< Iterator >::value_type median7

    (
    • Iterator data
    )

    #include <PiiMath.h>

    Median of seven values optimized to the theoretical maximum efficiency.

    Parameters
    data

    pointer to 7 successive values. The array will be modified.

  • template<class Iterator>

    std::iterator_traits< Iterator >::value_type median9

    (
    • Iterator data
    )

    #include <PiiMath.h>

    Median of nine values optimized to the theoretical maximum efficiency.

    Parameters
    data

    pointer to 9 successive values. The array will be modified.

  • template<class T>

    T medianAll

    ()

    #include <PiiMath.h>

    Returns the median of all elements in mat.

  • template<class T>

    PiiMatrix< T > min

    ()

    #include <PiiMath.h>

    Calculates the minimum among all elements in the specified direction.

  • template<class T>

    T min

    ()
    [inline]

    #include <PiiMath.h>

    Returns the minimum of two arguments.

  • template<class T>

    T min

    (
    • T a
    • T b
    • T c
    )
    [inline]

    #include <PiiMath.h>

    Returns the minimum of three arguments.

  • template<class T>

    T min

    (
    • T a
    • T b
    • T c
    • T d
    )
    [inline]

    #include <PiiMath.h>

    Returns the minimum of four arguments.

  • template<class T>

    T minAll

    (
    • const PiiMatrix< T > & mat
    • int * r = 0
    • int * c = 0
    )
    [inline]

    #include <PiiMath.h>

    Calculates the minimum of all elements in a matrix.

    Parameters
    mat

    the source matrix

    r

    store the row of the minimum value to this memory location (if non-zero)

    c

    store the column of the minimum value to this memory location (if non-zero)

  • template<class InputIterator>

    std::iterator_traits< InputIterator >::value_type minAll

    (
    • InputIterator begin
    • InputIterator end
    )
    [inline]

    #include <PiiMath.h>

    Returns the minimum value in [begin, end).

  • template<class Collection>

    Collection::value_type minAll

    (
    • const Collection & collection
    )
    [inline]

    #include <PiiMath.h>

    Shorthand for minAll(collection.begin(), collection.end()).

  • template<class T>

    void minMax

    (
    • const PiiMatrix< T > & mat
    • T * minimum
    • T * maximum
    • int * minR = 0
    • int * minC = 0
    • int * maxR = 0
    • int * maxC = 0
    )

    #include <PiiMath.h>

    Find the maximum and maximum of all elements in a matrix.

    Parameters
    mat

    the source matrix

    minimum

    store the minimum value to this memory location

    maximum

    store the maximum value to this memory location

    minR

    store the row of the minimum value to this memory location (if non-zero)

    minC

    store the column of the minimum value to this memory location (if non-zero)

    maxR

    store the row of the maximum value to this memory location (if non-zero)

    maxC

    store the column of the maximum value to this memory location (if non-zero)

  • template<class T>

    T mod

    ()
    [inline]

    #include <PiiMath.h>

    Returns the "modulus" of a floating point number.

    This function can be used in folding a floating point number to a predefined range. Its most typical use is in handling angles.

     double dAngle = Pii::mod(M_PI*3, M_PI*2); // returns M_PI

  • template<class CalculationType, class Iterator>

    void movingAverage

    (
    • Iterator begin
    • Iterator end
    • int width
    )
    [inline]

    #include <PiiMath.h>

    Calculates the moving average of a sequence bounded by begin and end.

    This is a utility function that uses windowSum(). The CalculationType template parameter determines the intermediate type used to calculate the sum.

     unsigned char data[2] = { 128, 128 };
     Pii::movingAverage<unsigned int>(data, data+2, 2);
     // data = 126, 64

  • template<class T, class U>

    PiiMatrix< T > movingAverage

    ()

    #include <PiiMath.h>

    Calculates moving average over the rows/columns of a matrix.

     PiiMatrix<int> input(4,4,
                          1,2,3,4,
                          3,4,5,6,
                          5,6,7,8,
                          7,8,9,10);
    
     PiiMatrix<double> avg = Pii::movingAverage<double>(input, 4,
                                                        Pii::Horizontally,
                                                        Pii::ShrinkWindow);
     // Result:
     // 1.5, 2.0, 2.5, 3.0
     // 3.5, 4.0, 4.5, 5.0
     // 5.5, 6.0, 6.5, 7.0
     // 7.5, 8.0, 8.5, 9.0

    Parameters
    mat

    the input matrix

    width

    the width of the averaging window. Typically an odd number, but can be even in all but ShrinkWindowSymmetrically modes.

    direction

    direction of calculation

    endPointHandling

    the way row/column end points are handled.

    Returns

    if direction is Pii::Horizontally, returns a matrix with the same number of rows than the input. Otherwise returns a matrix with the same number of columns. If width is too large, an empty matrix will be returned.

  • template<class Matrix1, class Matrix2>

    PiiBinaryMatrixTransform< Matrix1, Matrix2, std::multiplies< PII_COMBINE_TYPES(typename Matrix1::value_type, typename Matrix2::value_type)> > multiplied

    ()

    #include <PiiMath.h>

    Multiplies the elements in m1 and m2.

    Returns a new matrix.

  • template<class Matrix1, class Matrix2>

    void multiply

    ()
    [inline]

    #include <PiiMath.h>

    Multiply the elements in m1 by the corresponding elements in m2.

  • template<class T, class InputIterator, class OutputIterator>

    void multiply

    (
    • const PiiMatrix< T > & matrix
    • InputIterator input
    • OutputIterator output
    )

    #include <PiiMath.h>

    A generic algorithm to multiply a column vector by a matrix from left.

    This function calculates matrix * input and stores the result to output.

     PiiMatrix<int> mat(4,3,
                        1,2,3,
                        4,5,6,
                        7,8,9,
                        0,1,2);
     PiiVector<int,3> vector(1,2,3);
     PiiVector<double,4> result;
     // Calculate mat*(1,2,3)' and store the resulting 4-by-1 vector
     // as doubles.
     Pii::multiply(mat, vector.begin(), result.begin());

    Parameters
    matrix

    the matrix to multiply input with.

    input

    a forward input iterator to the beginning of the column vector. The iterator must be able to access at least matrix.columns() elements.

    output

    an output iterator that must be able to hold at least matrix.rows() elements.

  • template<class InputIterator, class T, class OutputIterator>

    void multiply

    (
    • InputIterator input
    • const PiiMatrix< T > & matrix
    • OutputIterator output
    )

    #include <PiiMath.h>

    A generic algorithm to multiply a row vector by a matrix from right.

    This function calculates input * matrix and stores the result to output.

     PiiMatrix<int> mat(4,3,
                        1,2,3,
                        4,5,6,
                        7,8,9,
                        0,1,2);
     PiiVector<int,4> vector(1,2,3,4);
     PiiVector<double,3> result;
     // Calculate (1,2,3,4) * mat and store the resulting 1-by-3 vector
     // as doubles.
     Pii::multiply(vector.begin(), mat, result.begin());

    Make sure output is initialized with zeros. The functions saves time by not clearing the output first.

    Parameters
    input

    a forward input iterator to the beginning of the column vector. The iterator must be able to access at least matrix.rows() elements.

    matrix

    the matrix to multiply input with.

    output

    an output iterator that must be able to hold at least matrix.columns() elements.

  • template<class Matrix>

    void normalize

    ()

    #include <PiiMath.h>

    Normalizes vectors in a matrix.

    Each row/column of the input matrix is treated as a vector that will be normalized to unit length.

    Parameters
    mat

    the input matrix. Modified in place.

    direction

    direction of calculation. By default rows are treated as vectors. Use Pii::Vertically to change the default behaviour.

  • template<class Matrix>

    PiiMatrix< double > normalized

    (
    • const PiiRandomAccessMatrix & mat
    • MatrixDirection direction = Horizontally
    )

    #include <PiiMath.h>

    Normalizes vectors in a matrix.

    Same as normalize() but returns a copy.

  • PII_CORE_EXPORT double normalRandom

    ()

    #include <PiiRandom.h>

    Returns a random number from a distribution that follows N(0,1) (zero mean, unit variance Gaussian distribution).

    To convert x in N(0,1) to N(m,v), where m is a non-zero mean and v a non-unit variance, calculate x*v+m.

  • PII_CORE_EXPORT PiiMatrix< double > normalRandomMatrix

    (
    • int rows
    • int columns
    )

    #include <PiiRandom.h>

    Returns a rows x columns matrix filled with normally distributed random numbers.

  • std::ostream & operator<<

    (
    • std::ostream & out
    • const QString & str
    )
    [inline]

    #include <PiiUtil.h>

    Write a QString to an std output stream.

  • PII_CORE_EXPORT QList< int > parseTypes

    ()

    #include <PiiMetaTypeUtil.h>

    Converts comma-separated type names to a list of type IDs.

    If any of the types is invalid, or if types is empty, returns an empty list.

     QList<int> lstTypes = Pii::parseTypes("QString,int");
     // lstTypes = (QMetaType::String, QMetaType::Int)

  • template<class T>

    int partition

    (
    • T * data
    • int size
    • int pivot
    )

    #include <PiiMath.h>

    Returns array which is arranged so that; there exist index k which value is restricted to 0 <= k < size.

    Element in array at index k is pivot value and all elements between array begin to k-1 are smaller or equal as pivot value, and all elements between k+1 and array end are at least equal to value or bigger.

     int array[10] = {1,4,0,5,2,3,7,6,8,9};
     int value = 3;
     int k = Pii::partition<int>(array, 10, 5);
     //now at position k there exist value(3) and array is
     //rearranged.  

    Parameters
    data

    the array which is to be arranged (partition).

    size

    array size.

    pivot

    is index to element which will be used in partition.

    Returns

    index to pivot value

  • template<class Matrix>

    PiiMatrix< typename Matrix::value_type > pcaDecorrelate

    (
    • const PiiRandomAccessMatrix & X
    )

    #include <PiiPrincipalComponents.h>

    Decorrelates a possibly correlated set of data.

    This function uses PCA to transform the input data set into a maximally uncorrelated data set. The output data will be uncorrelated only if the input data is jointly normally distributed.

    Parameters
    X

    input data with observation vectors as its rows. Must have zero mean.

    Returns

    decorrelated data

    See also
  • template<class UnaryFunction, class Storage>

    void permutations

    ()

    #include <PiiMath.h>

    This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

    Parameters
    n
    func
    storage

    an array/vector with space for at least k elements to store the current permutation. The algorithm will use storage's operator[] to access the elements. The array must be initialized to 0,1,2,...,n-1.

  • template<class UnaryFunction>

    void permutations

    ()

    #include <PiiMath.h>

    Find all possible permutations of n elements.

    The number of different permutations for n elements is n!. Works analogously to combinations().

     PiiMatrix<int> permutations(0,3);
     Pii::permutations(3, Pii::RowAdder<int>(permutations));
    
     // permutations:
     // 0 1 2
     // 1 0 2
     // 1 2 0
     // 2 1 0
     // 2 0 1
     // 0 2 1

  • PII_DECLARE_EXPORTED_FUNCTION_TEMPLATE

    ()

    #include <PiiUtil.h>

  • PII_DECLARE_EXPORTED_FUNCTION_TEMPLATE

    (
    • void
    • setProperties< QVariantMap >
    • (QObject &obj, const QStringList &properties, const QVariantMap &valueMap, Qt::CaseSensitivity sensitivity, const QString &commentMark)
    • PII_BUILDING_CORE
    )

    #include <PiiUtil.h>

  • PII_MATH_MATRIX_TRANSFORM

    ()

    #include <PiiMath.h>

    Returns a matrix whose elements are absolute values of mat squared.

  • PII_MATH_MATRIX_TRANSFORM

    ()

    #include <PiiMath.h>

    Returns a matrix whose elements are absolute values of mat.

  • template<class T>

    T pow

    ()

    #include <PiiMath.h>

    Raise value to an integer power (n).

  • double pow

    (
    • double value
    • double n
    )
    [inline]

    #include <PiiMath.h>

    Raise value to a floating-point power (n).

  • float pow

    (
    • float value
    • float n
    )
    [inline]

    #include <PiiMath.h>

    Raise value to a floating-point power (n).

  • template<class Matrix>

    PiiMatrix< typename Matrix::value_type > principalComponents

    (
    • const PiiRandomAccessMatrix & X
    • PiiMatrix< typename Matrix::value_type > * S = 0
    )

    #include <PiiPrincipalComponents.h>

    Returns the PCA base vectors for a data set in X.

    Principal component analysis (PCA) produces an orthogonal transformation that transforms the input data to a new coordinate system so that the greatest variance by any projection of the data comes to lie on the first coordinate (called the first principal component), the second greatest variance on the second coordinate, and so on.

    Given an m-by-n input matrix X in which each of the m rows represents an n-dimensional observation. This function returns a n-by-n matrix V that transforms X into a maximally uncorrelated coordinate system when applied from the left: Y = XV.

    Parameters
    X

    the input data, stored as rows. The input data must have a zero mean.

    S

    an optional output parameter that will store the singular values of X as a row vector.

    Returns

    V, a new orthonormal base represented as row vectors.

    See also
  • template<class Stream, class Matrix, class ColSeparator, class RowSeparator>

    void printMatrix

    (
    • Stream & out
    • const PiiConceptualMatrix< Matrix, RandomAccessMatrix > & mat
    • const ColSeparator & columnSeparator
    • const RowSeparator & rowSeparator
    )

    #include <PiiMatrixUtil.h>

    Print matrix in a user-defined format.

     PiiMatrix<double> mat(4,4,
                           1.0, 2.3, 5.4, 8.0,
                           2.3, 5.4, 8.0, 1.0,
                           5.4, 8.0, 1.0, 2.3,
                           8.0, 1.0, 2.3, 5.4);
    
     Pii::printMatrix(std::cout, mat, ", ", "
    ");
      //output:
      1, 2.3, 5.4, 8
      2.3, 5.4, 8, 1
      5.4, 8, 1, 2.3
      8, 1, 2.3, 5.4

    Parameters
    out

    an output stream to write the matrix to. Any class implementing operator<<(Separator) and operator<<(T) can act as the output stream. Examples of such classes are stl output streams (std::cout and relatives) and QTextStream. Even a QVariantList works in most cases.

    mat

    the matrix to be written

    columnSeparator

    separate values on a column with this

    rowSeparator

    separate each row with this

  • PII_CORE_EXPORT QVariantMap properties

    (
    • const QObject & obj
    • int propertyOffset = 0
    • PropertyFlags flags = DynamicProperties
    )

    #include <PiiUtil.h>

    Fetch the properties of a QObject as a map of name-value pairs.

    Parameters
    obj

    the object whose properties are queried

    propertyOffset

    skip this many properties in the beginning. This value can be used to skip the properties of superclasses. For example, using one as the propertyOffset skips the QObject::objectName property.

    flags
  • PII_CORE_EXPORT QList< QPair< QString, QVariant > > propertyList

    (
    • const QObject & obj
    • int propertyOffset = 0
    • PropertyFlags flags = DynamicProperties
    )

    #include <PiiUtil.h>

    Returns the properties of obj as a list.

    This function retains the order of properties.

    See also
  • PII_CORE_EXPORT const char * propertyName

    ()

    #include <PiiUtil.h>

    Finds the name of a property in obj that matches name in a case-insensitive manner.

     QObject obj;
     const char* objName = Pii::propertyName(obj, "objectname");
     // returns "objectName"

    Returns

    the real name of the property or 0 if no such property exists

  • template<class Matrix>

    PiiMatrix< typename Matrix::value_type > pseudoInverse

    (
    • const PiiRandomAccessMatrix & A
    )

    #include <PiiPseudoInverse.h>

    Returns the Moore-Penrose pseudoinverse of an m-by-n matrix.

    Pseudoinverse is the optimal solution (in least squares sense) for an over-determined system of linear equations (i.e. m > n). The Moore-Penrose pseudoinverse of a matrix A has the following properties:

    • (H denotes a Hermitian transpose)

    This function uses SVD to calculate the pseudoinverse in a numerically stable way.

  • Q_DECLARE_FLAGS

    ()

    #include <Pii.h>

  • Q_DECLARE_FLAGS

    (
    • SvdOptions
    • SvdOption
    )

    #include <PiiSvDecomposition.h>

  • Q_DECLARE_FLAGS

    ()

    #include <PiiUtil.h>

  • Q_FLAGS

    ()

    #include <Pii.h>

  • PII_CORE_EXPORT uint qHash

    (
    • const char * key
    )

    #include <PiiUtil.h>

    Hash function for null-terminated C strings.

  • template<class Matrix>

    void qrDecompose

    (
    • PiiRandomAccessMatrix & A
    • PiiMatrix< typename Matrix::value_type > & tau
    )

    #include <PiiQrDecomposition.h>

    QR decomposition.

    The QR algorighm is used to decompose a matrix A into two matrices Q and R so that A = QR. If A is m-by-n, Q is a m-by-m orthogonal matrix, and R is a m-by-n upper triangular matrix.

    This function uses a blockwise version of the method of Householder reflections to perform the decomposition.

    The non-zero elements of R will be stored on and above the main diagonal of A. The lower triangle of A will store a set of elementary reflector vectors (see householderTransform()) that can be used to form Q together with the tau vector. Each column represents one of the vectors, excluding the first dimension, which is always one.

    m >= n                          m < n
    (  r   r   r   r   r  )         (  r   r   r   r   r   r  )
    (  v1  r   r   r   r  )         (  v1  r   r   r   r   r  )
    (  v1  v2  r   r   r  )         (  v1  v2  r   r   r   r  )
    (  v1  v2  v3  r   r  )         (  v1  v2  v3  r   r   r  )
    (  v1  v2  v3  v4  r  )         (  v1  v2  v3  v4  r   r  )
    (  v1  v2  v3  v4  v5 )
    

    Parameters
    A

    a m-by-n matrix to be decomposed. Upon return, this matrix will store the matrices Q and R in a compact form.

    tau

    a vector that can be used to form Q. This matrix will be resized to 1-by-min(m,n).

    See also
  • template<class Matrix>

    void qrDecompose

    (
    • PiiRandomAccessMatrix & A
    • typename Matrix::value_type * tau
    • typename Matrix::value_type * bfr
    )

    #include <PiiQrDecomposition.h>

    QR decomposition.

    This function factorizes A into Q and R using a series of Householder reflections. Upon return, A will be modified so that it holds both Q and R in a compact form.

    Parameters
    A

    a m-by-n matrix to be decomposed. Upon return, this matrix will store the matrices Q and R in a compact form.

    tau

    a vector that can be used to form Q. This array must be at least min(m,n) elements long.

    bfr

    a temporary buffer of at least A.rows() elements.

    See also
  • template<class Matrix>

    PiiMatrix< typename Matrix::value_type > qrDecompose

    (
    • const PiiRandomAccessMatrix & A
    • PiiMatrix< typename Matrix::value_type > * R = 0
    • QrUnpackStyle style = UnpackEconomyQR
    )

    #include <PiiQrDecomposition.h>

    This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. This version does not modify the input A, and returns the Q matrix unpacked.

    Optionally, the R matrix will also be filled.

  • template<class Real>

    void qrUnpack

    ()

    #include <PiiQrDecomposition.h>

    Unpacks the result of QR decomposition.

    Given a set of elementary reflectors in A, this function calculates the reflector matrix Q in the form Q = I + VTV'. This function requires preallocated temporary storage and is intended to be used in nested loops.

    Parameters
    A

    QR decomposed matrix in compact form. This matrix will be modified so that it only contains the reflector vectors below and on the diagonal. That is, A will be converted to V.

    tau

    a pointer to the beginning of the tau vector

    T

    an output-value matrix. This must be a square matrix (columns by columns).

    gram

    a temporary storage for a Gram matrix. Same size as T.

    See also
    • unpackColumns()

  • template<class Real>

    PiiMatrix< Real > qrUnpack

    ()

    #include <PiiQrDecomposition.h>

    Unpacks the result of QR decomposition.

    Given a set of elementary reflectors in A and the tau array, this function calculates the reflector matrix Q as follows:

    where k is either the number of rows or columns in A, whichever is smaller.

    Each H matrix can be represented as

    where represents the ith elementary reflector vector. The elementary reflectors are stored in A under the main diagonal as columns, and the corresponding values of are in tau.

    Parameters
    A

    QR decomposed matrix in compact form (m-by-n). This matrix will be modified so that it only contains the reflector vectors below and on the diagonal.

    tau

    the tau vector as returned by qrDecompose().

    R

    a pointer to a matrix that will store the upper diagonal part of the decomposition result.

    style

    unpacking style

    Returns

    a m-by-m orthogonal matrix Q

  • double radToDeg

    (
    • double rad
    )
    [inline]

    #include <PiiMath.h>

    Convert an angle from radians to degrees.

  • template<class T>

    void randomizeMatrix

    (
    • PiiMatrix< T > & mat
    • const T & lowerBound
    • const T & upperBound
    )

    #include <PiiMatrixUtil.h>

    Set random elements from range specified by parameters lowerBound and upperBound to matrix.

    Might not handle limits properly for integer types.

  • template<class Matrix>

    int rank

    (
    • const PiiRandomAccessMatrix & mat
    • typename Matrix::value_type tolerance = NAN
    )

    #include <PiiMath.h>

    Estimates the number of linearly independent rows or columns of a matrix.

    Parameters
    mat

    the input matrix

    tolerance

    tolerance when comparing values to zero. The default value is epsilon(0).

  • template<class T>

    T real

    (
    • const std::complex< T > & value
    )
    [inline]

    #include <PiiMath.h>

    Returns the real part of a complex number.

  • template<class T>

    T real

    ()
    [inline]

    #include <PiiMath.h>

    Returns the real part of a real number, i.e.

    the number itself.

  • template<class Matrix, class InputIterator>

    void reflectColumns

    (
    • PiiConceptualMatrix< Matrix, Pii::RandomAccessMatrix > & A
    • InputIterator v
    • typename Matrix::value_type tau
    • typename Matrix::value_type * bfr
    )

    #include <PiiHouseholderTransform.h>

    Applies a reflection transform to a rectangular matrix from the left.

    This function uses the vector representation of a reflection matrix (see householderTransform()) to speed up calculations. The algorithm is functionally equivalent to , but the full reflection matrix H is never calculated. Instead, since , we get

    Parameters
    A

    the input matrix storing the vectors to be reflected as its columns. Will be modified in place.

    v

    an iterator to the beginning of the reflector vector. Must have A.rows() elements.

    tau

    the parameter

    bfr

    a buffer of at least A.columns() elements for temporary storage of calculation results.

  • template<class Matrix, class InputIterator>

    void reflectColumns

    (
    • PiiConceptualMatrix< Matrix, Pii::RandomAccessMatrix > & A
    • InputIterator v
    • typename Matrix::value_type tau
    )
    [inline]

    #include <PiiHouseholderTransform.h>

  • template<class Matrix, class InputIterator>

    void reflectRows

    (
    • PiiConceptualMatrix< Matrix, Pii::RandomAccessMatrix > & A
    • InputIterator v
    • typename Matrix::value_type tau
    )

    #include <PiiHouseholderTransform.h>

    Applies a reflection transform to a rectangular matrix from the right.

    The algorithm is functionally equivalent to , where H is the reflection transform uniquely identified by v and tau.

    Parameters
    A

    the input matrix storing the vectors to be reflected as its rows. Will be modified in place.

    v

    an iterator to the beginning of the reflector vector. Must have A.columns() elements.

    tau

    the parameter

    See also
  • template<class VariableMap>

    QString replaceVariables

    (
    • const QString & string
    • const VariableMap & variables
    )

    #include <PiiUtil.h>

    Replaces variables in string and returns a new string.

     QMap<QString,QString> mapVariables;
     mapVariables["foo"] = "bar";
     mapVariables["bar"] = "foo";
     QString strResult = Pii::replaceVariables("$foo ${bar}", mapVariables);
     // strResult == "bar foo"

    Parameters
    string

    the input string with variables. Variables are prefixed with a dollar sign and optionally delimited by curly braces. ($variable or ${variable}).

    variables

    a map of variable values. This can be any type that defines QString operator[] (const QString&).

  • template<class T>

    PiiMatrix< T > replicate

    (
    • const PiiMatrix< T > & matrix
    • int vertical
    • int horizontal
    )

    #include <PiiMatrixUtil.h>

    Replicate a matrix vertical times vertically and horizontal times horizontally.

     PiiMatrix<int> mat(2,2,
                        1,0,
                        0,1);
     PiiMatrix<int> mat2(Pii::replicate(mat,2,3));
     // mat2 = 101010
     //        010101
     //        101010
     //        010101

  • unsigned short rol

    (
    • unsigned short c
    • const unsigned char n
    )
    [inline]

    #include <PiiBits.h>

  • unsigned char rol

    (
    • unsigned char c
    • const unsigned char n
    )
    [inline]

    #include <PiiBits.h>

  • template<unsigned char>

    unsigned int rol

    (
    • unsigned int c
    • const unsigned char n
    )
    [inline]

    #include <PiiBits.h>

    This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

  • unsigned int rol

    (
    • unsigned int c
    • const unsigned char n
    • const unsigned char bits
    )
    [inline]

    #include <PiiBits.h>

    Rotate a binary code left by n positions.

    Parameters
    c

    the number to be rotated

    n

    the number of positions to rotate

    bits

    the number of bits to consider

  • unsigned int rol< INTBITS >

    (
    • unsigned int c
    • const unsigned char n
    )
    [inline]

    #include <PiiBits.h>

    This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

  • unsigned int ror

    (
    • unsigned int c
    • const unsigned char n
    • const unsigned char bits
    )
    [inline]

    #include <PiiBits.h>

    Rotate a binary code right by n positions.

    Parameters
    c

    the number to be rotated

    n

    the number of positions to rotate

    bits

    the number of bits to consider

  • template<unsigned char>

    unsigned int ror

    (
    • unsigned int c
    • const unsigned char n
    )
    [inline]

    #include <PiiBits.h>

    This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

  • unsigned char ror

    (
    • unsigned char c
    • const unsigned char n
    )
    [inline]

    #include <PiiBits.h>

  • unsigned short ror

    (
    • unsigned short c
    • const unsigned char n
    )
    [inline]

    #include <PiiBits.h>

  • unsigned int ror< INTBITS >

    (
    • unsigned int c
    • const unsigned char n
    )
    [inline]

    #include <PiiBits.h>

    This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

  • rotation rotateColumns

    (
    • mat
    • 0
    • 1
    )

    #include <PiiSvDecomposition.h>

  • PII_CORE_EXPORT unsigned int rotateToMinimum

    (
    • unsigned int n
    • const unsigned char bits = INTBITS
    )

    #include <PiiBits.h>

    Rotate a binary number to its minimum value.

    Parameters
    n

    the number

    bits

    the number of bits to consider

  • template<unsigned char>

    unsigned int rotateToMinimum

    (
    • unsigned int n
    )

    #include <PiiBits.h>

    This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

  • double round

    (
    • double value
    )
    [inline]

    #include <PiiMath.h>

    Rounds a double argument to the closest integer.

    Uses the C99 standard round() function if available.

  • template<class U, class T>

    U round

    ()
    [inline]

    #include <PiiMath.h>

    Rounds value (of type T) to the closest integer and returns the result as another type (U).

     int i = Pii::round<int>(1.5); // returns 2

  • template<class Collection, class T>

    Collection rowToList

    ()

    #include <PiiMatrixUtil.h>

    Get a row from a matrix as a collection (QList, QVector)

     PiiMatrix<int> mat(2,2, 1,2, 3,4);
     QList<int> lst = Pii::rowToList<QList<int> >(mat, 1);
     // lst = { 3, 4 }

    Parameters
    matrix

    input matrix

    row

    row index (positive value)

  • PII_CORE_EXPORT int scoreOverload

    (
    • const QVariantList & params
    • const QList< int > & types
    )

    #include <PiiMetaTypeUtil.h>

    Returns a numerical score for the goodness of a parameter set given a list of expected types.

    The returned value is the number of elements in params whose type exactly matches the corresponding type in types. If the length of params is different from that of types, or any of the parameters cannot be converted to the expected type, returns -1.

     QList<int> lstTypes;
     lstTypes << QMetaType::Int << QMetaType::String;
     QVariantList lstParams;
     lstParams << QString("abc") << QString("def");
     int iScore = Pii:scoreOverload(lstParams, lstTypes);
     // iScore == 1 because QVariant allows conversions from QString to int

  • void seedRandom

    (
    • long value
    )
    [inline]

    #include <PiiRandom.h>

    Seeds the random number generator with your favourite value.

  • PII_CORE_EXPORT void seedRandom

    ()

    #include <PiiRandom.h>

    Initializes the random number generator from system clock.

    Note that successive inits within the same millisecond have no effect. Note also that this function must be called before any random numbers are generated if you don't want a similar sequence each time the program is run.

  • void PII_CORE_EXPORT selectRandomly

    (
    • QVector< int > & indices
    • int n
    • int max
    )

    #include <PiiUtil.h>

    This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Randomly selects n distinct integers in [0, max-1] and stores them to indices.

    This version is better suited for selecting a small number of indices in tight loops.

  • template<class Collection>

    void selectRandomly

    (
    • Collection & target
    • const Collection & source
    • int n
    )

    #include <PiiUtil.h>

    Select randomly n elements from source and insert them to target.

    The Collection type must have size() and append() member functions defined.

     QStringList lstNames;
     lstNames << "foo" << "bar" << "etc";
     QStringList selected;
     Pii::selectRandomly(selected, lstNames, 2);

  • QVector< int > PII_CORE_EXPORT selectRandomly

    (
    • int n
    • int max
    )

    #include <PiiUtil.h>

    Select randomly n distinct integers that are smaller than max.

    This function can be used to take a random sample of a collection.

     QStringList lstNames;
     lstNames << "foo" << "bar" << "etc";
     QVector<int> indices = Pii::selectRandomly(2, lstNames.size());
     for (int i=0; i<indices.size(); ++i)
       qDebug(qPrintable(lstNames[indices[i]]));

    Returns

    randomly selected indices. If n is larger than max, max indices will returned.

    See also
  • template<class Iterator>

    Iterator sequence

    (
    • Iterator begin
    • Iterator end
    • typename std::iterator_traits< Iterator >::value_type initialValue
    )
    [inline]

    #include <PiiAlgorithm.h>

    Assigns sequentially increasing values to the range [begin, end).

    The first value will be set to initialValue, which will then be incremented by one on each iteration. Returns end.

  • template<class Iterator>

    Iterator sequence

    (
    • Iterator begin
    • Iterator end
    • typename std::iterator_traits< Iterator >::value_type initialValue
    • typename std::iterator_traits< Iterator >::value_type step
    )

    #include <PiiAlgorithm.h>

    Assigns sequentially increasing or decreasing values to the range [begin, end).

    The first value will be set to initialValue, which will then increase step units on each iteration. Returns end.

  • template<class Iterator>

    Iterator sequenceN

    (
    • Iterator begin
    • int n
    • typename std::iterator_traits< Iterator >::value_type initialValue
    )
    [inline]

    #include <PiiAlgorithm.h>

    Assigns sequentially increasing values to the range [begin, end + n).

    The first value will be set to initialValue, which will then be incremented by one on each iteration. Returns begin + end.

  • template<class Iterator>

    Iterator sequenceN

    (
    • Iterator begin
    • int n
    • typename std::iterator_traits< Iterator >::value_type initialValue
    • typename std::iterator_traits< Iterator >::value_type step
    )

    #include <PiiAlgorithm.h>

    Assigns sequentially increasing or decreasing values to the range [begin, begin + n).

    The first value will be set to initialValue, which will then increase step units on each iteration. Returns begin + n.

  • template<class Matrix, class Iterator>

    void setDiagonal

    (
    • PiiRandomAccessMatrix & matrix
    • Iterator vector
    )

    #include <PiiMath.h>

    Sets diagonal entries in matrix to the values read from vector.

    If the matrix is non-square, the smaller of its two dimensions will determine the length of the diagonal.

    Parameters
    matrix

    an m-by-n output matrix

    vector

    a random-access iterator to the beginning of the diagonal values. Must be valid for at least min(m,n) entries.

  • template<class Matrix>

    void setIdentity

    (
    • PiiRandomAccessMatrix & matrix
    )

    #include <PiiMath.h>

    Sets diagonal entries in matrix to ones and other entries to zero.

    If the matrix is non-square, the smaller of its two dimensions will determine the length of the diagonal.

  • PII_CORE_EXPORT void setProperties

    (
    • QObject & obj
    • const QVariantMap & lstProperties
    )

    #include <PiiUtil.h>

    Sets many properties in a bunch.

    Parameters
    obj

    the object to be modified

    lstProperties
  • template<class Map>

    void setProperties

    (
    • QObject & obj
    • const QStringList & properties
    • const Map & valueMap
    • Qt::CaseSensitivity sensitivity = Qt::CaseSensitive
    • const QString & commentMark = "#"
    )

    #include <PiiUtil.h>

    Sets properties to an object.

    For convenient use with configuration files, the function ignores values starting with a comment marker ('#' by default).

     // Read properties from an ini file (case-sensitive)
     QSettings settings(configFile, QSettings::IniFormat);
     Pii::setProperties(obj, settings.childKeys(), settings);

     // Read string-encoded properties (case-insensitive)
     QVariantMap properties = Pii::decodeProperties("objectname=foobar
    "
                                                    "//comment, ignored");
     Pii::setProperties(obj, properties.keys(), properties, Qt::CaseInsensitive, "//");

    Parameters
    obj
    properties

    a list of property names to set

    valueMap

    a map that stores the actual property values

    sensitivity

    if Qt::CaseSensitive, the property names must match exactly. If Qt::CaseInsensitive, case-insensitive matching will be performed (propertyName()).

    commentMark

    ignore values starting with this string

  • PII_CORE_EXPORT void setPropertyList

    ()

    #include <PiiUtil.h>

  • template<class T>

    void setValueAt

    (
    • T value
    • PiiMatrix< T > & img
    • double dr
    • double dc
    )
    [inline]

    #include <PiiMatrixUtil.h>

  • template<class Collection>

    void shuffle

    (
    • Collection & lst
    )
    [inline]

    #include <PiiUtil.h>

    Randomize the order of elements in a collection.

     QList<int> lst;
     lst << 1 << 2 << 3;
     Pii::shuffle(lst);

  • template<class Iterator>

    void shuffle

    (
    • Iterator begin
    • Iterator end
    )
    [inline]

    #include <PiiAlgorithm.h>

    Randomize the order of elements in [begin, end).

  • template<class Iterator>

    void shuffleN

    (
    • Iterator begin
    • PII_DIFF_TYPE n
    )

    #include <PiiAlgorithm.h>

    Randomize the order of elements in a sequence.

    Parameters
    begin

    an iterator to the beginning of the random access sequence to shuffle

    n
  • template<class T>

    T sign

    ()
    [inline]

    #include <PiiMath.h>

    Returns the sign of value.

    Returns

    1 for positive numbers, -1 for negative numbers, and 0 for zero.

  • template<class T>

    unsigned int signBit

    (
    • T value1
    • T value2
    )
    [inline]

    #include <PiiBits.h>

    Returns the sign bit of value1 - value2.

  • unsigned int signBit

    (
    • float value1
    • float value2
    )
    [inline]

    #include <PiiBits.h>

    Returns the sign bit of value1 - value2.

  • unsigned int signBit

    (
    • double value1
    • double value2
    )
    [inline]

    #include <PiiBits.h>

    Returns the sign bit of value1 - value2.

  • template<class T>

    T signMask

    ()
    [inline]

    #include <PiiBits.h>

    Get a binary mask for the sign bit of any integer type.

    To get the sign bit, do the following:

     int i = -1;
     int sign = i & signMask<int>();

    This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

  • short signMask

    ()
    [inline]

    #include <PiiBits.h>

    Get a binary mask for the sign bit of any integer type.

    This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

  • float sin

    (
    • float value
    )
    [inline]

    #include <PiiMath.h>

    This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

  • template<class T>

    double sin

    ()
    [inline]

    #include <PiiMath.h>

    Returns sin(value).

  • template<class T>

    PiiMatrix< T > sortedRows

    (
    • const PiiMatrix< T > & matrix
    • int column = 0
    )
    [inline]

    #include <PiiMatrixUtil.h>

    Sort matrix rows.

    Same as above but for const input.

  • template<class T, class LessThan>

    PiiMatrix< T > sortedRows

    (
    • const PiiMatrix< T > & matrix
    • LessThan lessThan
    • int column = 0
    )
    [inline]

    #include <PiiMatrixUtil.h>

    Sort matrix rows.

    Same as above but for const input.

  • template<class T, class LessThan>

    void sortRows

    (
    • PiiMatrix< T > & matrix
    • LessThan lessThan
    • int column = 0
    )

    #include <PiiMatrixUtil.h>

    Sort matrix rows into ascending order based on the value on the specified column.

    Use predicate as the comparison function.

     PiiMatrix<int> mat(3,3,
                        -1,2,3,
                        -2,1,3,
                        3,0,3);
     Pii::sortRows(mat, std::greater<int>());
     //  3 0 3
     // -1 2 3
     // -2 1 3

    Parameters
    matrix

    the input matrix

    lessThan

    a binary function used for determining the order

    column

    the matrix column based on which the sort will be done

  • PII_CORE_EXPORT QStringList splitQuoted

    (
    • const QString & str
    • QChar separator = ','
    • QChar quote = '"'
    • QString::SplitBehavior behavior = QString::KeepEmptyParts
    )

    #include <PiiUtil.h>

    Splits a string in which each part may be quoted.

     Pii::splitQuoted("\"a,b,c\",d,e"); // returns ("a,b,c", "d", "e")

  • template<class T>

    double sqrt

    ()
    [inline]

    #include <PiiMath.h>

    Returns the square root of value.

  • float sqrt

    (
    • float value
    )
    [inline]

    #include <PiiMath.h>

    This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

  • template<class T>

    T square

    ()
    [inline]

    #include <PiiMath.h>

    Returns the value * value.

  • template<class U, class T>

    U stdAll

    ()
    [inline]

    #include <PiiMath.h>

    Calculates the standard deviation over all elements in a matrix.

    Parameters
    mat

    the input matrix

    mean

    store mean to this variable (if non-zero) This is an optimization that makes it unnecessary to call meanAll() separately.

  • template<class T>

    T stringTo

    (
    • const QString & number
    • bool * ok = 0
    )
    [inline]

    #include <PiiUtil.h>

    Convert a string to any type.

  • double stringTo< double >

    ()
    [inline]

    #include <PiiUtil.h>

  • float stringTo< float >

    ()
    [inline]

    #include <PiiUtil.h>

  • int stringTo< int >

    ()
    [inline]

    #include <PiiUtil.h>

  • long stringTo< long >

    ()
    [inline]

    #include <PiiUtil.h>

  • long long stringTo< long long >

    ()
    [inline]

    #include <PiiUtil.h>

  • short stringTo< short >

    ()
    [inline]

    #include <PiiUtil.h>

  • unsigned int stringTo< unsigned int >

    ()
    [inline]

    #include <PiiUtil.h>

  • unsigned long stringTo< unsigned long >

    ()
    [inline]

    #include <PiiUtil.h>

  • unsigned long long stringTo< unsigned long long >

    ()
    [inline]

    #include <PiiUtil.h>

  • unsigned short stringTo< unsigned short >

    ()
    [inline]

    #include <PiiUtil.h>

  • template<class Collection>

    Collection subtract

    (
    • const Collection & list1
    • const Collection & list2
    )

    #include <PiiUtil.h>

    Create a list that consists of the elements of list1 that are not present in list2.

    Any collection defining size(), contains(), and append() functions can be used as a parameter.

  • template<class Matrix>

    PiiMatrix< typename Matrix::value_type > subtractMean

    ()

    #include <PiiMath.h>

    Subtracts sample mean from a data set.

    Parameters
    matrix

    the data set to be moved to zero mean. If direction is Pii::Vertically, each row represents an observation vector. If direction is Pii::Horizontally, each column represents an observation vector.

    direction
    Returns

    the mean vector. See mean().

  • template<class U, class Matrix>

    PiiMatrix< U > sum

    ()

    #include <PiiMath.h>

    Calculates the sum of matrix elements in the specified direction.

    If direction is Pii::Horizontally, returns a column matrix. If direction is Pii::Vertically, returns a row matrix. The returned type can be different from the input type. For example, the sum over unsigned char matrices may require an integer output type.

     PiiMatrix<int> A(2 , 2,
                      1 , 2,
                      -1,-2);
     PiiMatrix<int> B(sum<int>(A, Pii::Horizontally));
     //B =  3
     //    -3
     PiiMatrix<int> C(sum<int>(A, Pii::Vertically));
     //C = 0 0

  • template<class T, class Matrix>

    T sumAll

    ()

    #include <PiiMath.h>

    Calculates the sum of all entries in a matrix.

    Returns the value as a (possibly) different type, denoted by the template parameter U.

  • template<class Iterator1, class Iterator2>

    void swap

    (
    • Iterator1 begin1
    • Iterator1 end1
    • Iterator2 begin2
    )

    #include <PiiAlgorithm.h>

  • template<class Iterator1, class Iterator2>

    void swapN

    (
    • Iterator1 begin1
    • int n
    • Iterator2 begin2
    )

    #include <PiiAlgorithm.h>

  • template<class T>

    double tan

    ()
    [inline]

    #include <PiiMath.h>

    Returns tan(value).

  • float tan

    (
    • float value
    )
    [inline]

    #include <PiiMath.h>

    This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

  • PII_CORE_EXPORT double toDouble

    (
    • const QString & number
    • bool * ok = 0
    )

    #include <PiiUtil.h>

    Converts a string into a number.

    This function differs from QString::toDouble() and friends in that it recognizes magnitude suffices.

     Pii::toDouble("10k"); // returns 10000
     Pii::toDouble("-2M"); // returns -2000000
     Pii::toDouble("1.2m"); // returns 0.0012

    The following suffices are recognized:

    Name

    Symbol

    Magnitude

    yotta

    Y

    zetta

    Z

    exa

    E

    peta

    P

    tera

    T

    giga

    G

    mega

    M

    kilo

    k

    hecto

    h

    deka

    e

    deci

    d

    centi

    c

    milli

    m

    micro

    u

    nano

    n

    pico

    p

    femto

    f

    atto

    a

    zepto

    z

    yocto

    y

    Parameters
    number

    the string to convert

    ok

    an optional pointer to a bool that indicates if the conversion was successful.

  • template<class InputIterator1, class InputIterator2, class OutputIterator, class BinaryFunction>

    OutputIterator transform

    (
    • InputIterator1 begin1
    • InputIterator1 end1
    • InputIterator2 begin2
    • OutputIterator output
    • BinaryFunction func
    )

    #include <PiiAlgorithm.h>

    Applies a binary function func to all elements in the range [begin1, end1), using the corresponding element in the range starting at begin2 as the second argument to the function.

    The return value of the function will be stored to output. Returns output + (end1 - begin1).

  • template<class InputIterator, class OutputIterator, class UnaryFunction>

    OutputIterator transform

    (
    • InputIterator begin
    • InputIterator end
    • OutputIterator output
    • UnaryFunction func
    )

    #include <PiiAlgorithm.h>

    Applies a unary function func to all elements in the range [begin, end), and stores the returned value to output.

    Returns output + (end - begin).

  • template<class Matrix, class InputIterator, class BinaryFunction>

    Matrix & transformColumns

    ()

    #include <PiiMath.h>

    Performs func on each column of the given matrix.

     PiiMatrix<int> mat(3,3,
                        1,2,3,
                        4,5,6,
                        7,8,9);
     PiiVector<int,3> vector(1,2,3);
     Pii::transformColumns(mat, vector.begin(), std::minus<int>());
     // mat is now
     // 0,1,2
     // 2,3,4
     // 4,5,6

    Parameters
    matrix

    the matrix to be modified. Each element will be modified by applying func to it.

    input

    an iterator to the beginning of data that works as the second argument to func. Must be valid over at least matrix.rows() elements.

    func

    the binary function to apply

    See also
  • template<class Matrix, class InputIterator, class BinaryFunction>

    PiiMatrix< typename Matrix::value_type > transformedColumns

    (
    • const PiiRandomAccessMatrix & matrix
    • InputIterator input
    • BinaryFunction func
    )
    [inline]

    #include <PiiMath.h>

    This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Returns a new matrix.

  • template<class Matrix, class InputIterator, class BinaryFunction>

    PiiMatrix< typename Matrix::value_type > transformedRows

    ()
    [inline]

    #include <PiiMath.h>

    This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Returns a new matrix.

  • template<class InputIterator, class OutputIterator, class UnaryFunction>

    OutputIterator transformN

    (
    • InputIterator begin
    • int n
    • OutputIterator output
    • UnaryFunction func
    )

    #include <PiiAlgorithm.h>

    Applies a unary function func to all elements in the range [begin, begin + n), and stores the returned value to output.

    Returns output + n.

  • template<class InputIterator1, class InputIterator2, class OutputIterator, class BinaryFunction>

    OutputIterator transformN

    (
    • InputIterator1 begin1
    • int n
    • InputIterator2 begin2
    • OutputIterator output
    • BinaryFunction func
    )

    #include <PiiAlgorithm.h>

    Applies a binary function func to all elements in the range [begin1, begin1 + n), using the corresponding element in the range starting at begin2 as the second argument to the function.

    The return value of the function will be stored to output. Returns output + n.

  • template<class Matrix, class InputIterator, class BinaryFunction>

    Matrix & transformRows

    ()

    #include <PiiMath.h>

    Performs func on each row of the given matrix.

     PiiMatrix<int> mat(3,3,
                        1,2,3,
                        4,5,6,
                        7,8,9);
     PiiVector<int,3> vector(1,2,3);
     Pii::transformRows(mat, vector.begin(), std::minus<int>());
     // mat is now
     // 0,0,0
     // 3,3,3
     // 6,6,6

    Parameters
    matrix

    the matrix to be modified. Each element will be modified by applying func to it.

    input

    an iterator to the beginning of data that works as the second argument to func. Must be valid over at least matrix.columns() elements.

    func

    the binary function to apply

    See also
  • double uniformRandom

    ()
    [inline]

    #include <PiiRandom.h>

    Returns a uniformly distributed random number in [0,1].

  • double uniformRandom

    (
    • double min
    • double max
    )
    [inline]

    #include <PiiRandom.h>

    Returns a uniformly distributed random number in [min, max].

  • PII_CORE_EXPORT PiiMatrix< double > uniformRandomMatrix

    (
    • int rows
    • int columns
    )

    #include <PiiRandom.h>

    Returns a rows x columns matrix filled with uniformly distributed random numbers in [0,1].

  • PII_CORE_EXPORT PiiMatrix< double > uniformRandomMatrix

    (
    • int rows
    • int columns
    • double min
    • double max
    )

    #include <PiiRandom.h>

    Returns a rows x columns matrix filled with uniformly distributed random numbers in [min, max].

  • template<class Matrix>

    void unpackReflectors

    ()

    #include <PiiHouseholderTransform.h>

    Unpacks a matrix in which a series of elementary reflections are represented as row or column vectors.

    Algorithms such as the QR decomposition and bidiagonal decomposition represent the decomposition result in a compact form by storing the elementary reflector vectors only. Given a set of such elementary reflectors in V, this function calculates the components of the left-hand reflector matrix Q in the form (direction = Vertically), or the components of the right-hand reflector matrix P in the form (direction = Horizontally). This function requires preallocated temporary storage and is intended to be used in nested loops.

    direction = Vertically
    Main diagonal        Subdiagonal
    diagonal = 0         diagonal = 1
    Nr = min(m, n)       Nr = min(m-1, n)
    ( 1   x   x   x  )   ( x   x   x   x )
    ( v1  1   x   x  )   ( 1   x   x   x )
    ( v1  v2  1   x  )   ( v1  1   x   x )
    ( v1  v2  v3  1  )   ( v1  v2  1   x )
    direction = Horizontally
    Main diagonal        Superdiagonal
    diagonal = 0         diagonal = 1
    Nr = min(m, n)       Nr = min(m, n-1)
    ( 1   v1  v1  v1 )   ( x   1   v1  v1 )
    ( x   1   v2  v2 )   ( x   x   1   v2 )
    ( x   x   1   v3 )   ( x   x   x   1  )
    

    Note that the number of reflector vectors (Nr) may be smaller than the number of rows/columns as shown in the top right illustration. Generally, the number of reflectors is min(m-diagonal, n) for the case where direction = Vertically, and min(m, n-diagonal) if direction = Horizontally. Here, m and n denote the number of rows and columns in V.

    Parameters
    direction

    specifies whether the reflector vectors are stored as columns (Vertically) or as rows (Horizontally).

    V

    a set of elementary reflector vectors in a compact form (see the illustration above). The diagonal entries must be ones. Entries marked with an "x" in the illustration are ignored. Note that this function does not modify V. To get V, you need to set the entries marked with x to zero.

    tau

    a pointer to the beginning of the tau vector. The number of elements in this array must equal to the number of elementary reflectors considered.

    T

    an output-value matrix. This must be a N-by-N matrix, where N is the number of rows (direction = Horizontally) or columns (direction = Vertically) in V. The algorithm fills in the upper triangle of T.

    gram

    a temporary storage for a Gram matrix. This must be a M-by-M matrix, where M is the number of reflector vectors (Nr).

    diagonal

    the diagonal on which the reflector vectors start. 0 means the main diagonal, 1 is the first super/subdiagonal (see the illustration above) and so on.

  • template<class T>

    Pii::ToFloatingPoint< T >::Type valueAt

    (
    • const PiiMatrix< T > & img
    • double dr
    • double dc
    )
    [inline]

    #include <PiiMatrixUtil.h>

    Sample a matrix (typically an image) at continuous positions.

    This function uses bi-linear interpolation for values that don't match pixels.

     PiiMatrix<int> mat(3,3,
                        1,1,2,
                        2,1,3,
                        2,1,4);
    
      float a = Pii::valueAt(mat,0.5,0.5);
      float b = Pii::valueAt(mat,1.0,0.5);
      float c = Pii::valueAt(mat,1.0,1.5);
      //a = 1.25 b = 1.5 c = 2.0

    Parameters
    img

    the input image

    dr

    double precision row coordinate

    dc

    double precision column coordinate

  • template<class T>

    T valueAt

    ()
    [inline]

    #include <PiiMatrixUtil.h>

    This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Returns img(r,c).

    This function is provided for convenience to allow valueAt() to be easily used in template code.

  • template<class U, class T>

    PiiMatrix< U > var

    ()

    #include <PiiMath.h>

    Calculates the variance of matrix elements in the specified direction.

    See sum() for more information.

    Parameters
    mat

    the source matrix

    direction

    calculate variance in this direction

  • template<class U, class T>

    U varAll

    ()

    #include <PiiMath.h>

    Calculates the variance over all elements in a matrix.

    Parameters
    mat

    the input matrix

    mean

    store mean to this variable (if non-zero) This is an optimization that makes it unnecessary to call meanAll() separately.

  • template<class T>

    QList< T > variantsToList

    (
    • const QVariantList & variants
    )

    #include <PiiUtil.h>

    Converts a list of QVariant objects into a QList of type T.

     QVariantList lst;
     lst << 1.0 << 2.3;
     QList<double> dLst = Pii::variantsToList<double>(lst);

  • template<class T>

    QVector< T > variantsToVector

    (
    • const QVariantList & variants
    )

    #include <PiiUtil.h>

    Convert a list of QVariant objects into a QVector of type T.

     QVariantList lst;
     lst << 1.0 << 2.3;
     QVector<double> dLst = Pii::variantsToVector<double>(lst);

  • template<class T>

    QVariantList vectorToVariants

    ()
    [inline]

    #include <PiiUtil.h>

    Convert a QVector to a QVariantList that contains the same values as QVariant objects.

  • template<class Iterator, class UnaryFunction>

    void windowSum

    ()

    #include <PiiMath.h>

    Calculates the sum of neighbors in a sequence bounded by begin and end.

    Modify the sequence in place. This function assumes zeros outside of the iterator range.

    This function can be used to calculate not only the sum of neighboring values but any function of the sum. A typical use is to calculate a moving average.

    The data type used in calculating the local sum is the argument_type of the given unary function object.

     float data[5] = { 1, 2, 3, 4, 5 };
    
     // Calculate moving average over three neighbors
     Pii::windowSum(data, data+5, 3, std::bind2nd(std::divides<float>(), 3));
     // data = 1, 2, 3, 4, 3
    
     // Calculate the sum of two neighbors
     Pii::windowSum(data, data+5, 2, Pii::Identity<float>());
     // data = 3, 5, 7, 7, 3 (1+2 2+3 3+4 4+3 3+0)
    
     unsigned char data2[2] = { 128, 128 };
     // This overflows due to limited range of data type.
     Pii::windowSum(data2, data2+2, 2, std::bind2nd(std::divides<unsigned char>(), 2));
     // data2 = 0, 64 ((128+128)/2 (128+0)/2)
    
     data2[0] = data2[1] = 128;
     // Sum values as unsigned ints and cast the result to unsigned char
     Pii::windowSum(data2, data2+2, 2, Pii::unaryCompose(Pii::Cast<unsigned int, unsigned char>(),
                                                         std::bind2nd(std::divides<unsigned int>(), 2)));
     // data2 = 128, 64

    Parameters
    begin

    an iterator to the beginning of a range

    end

    an iterator to the end of the range

    width

    the width of the local window

    function

    apply this function to the sum before storing to the sequence

    See also

Variable details

  • leftRotation

  • rightRotation

  • PII_CORE_EXPORT const QMetaObject staticMetaObject

Notes (0)

Add a note

Not a single note added yet. Be the first, add yours.