LSSTApplications  10.0-2-g4f67435,11.0.rc2+1,11.0.rc2+12,11.0.rc2+3,11.0.rc2+4,11.0.rc2+5,11.0.rc2+6,11.0.rc2+7,11.0.rc2+8
LSSTDataManagementBasePackage
Namespaces | Classes | Functions
MainGroup

Namespaces

 ndarray::detail
 

Classes

struct  ndarray::ArrayTraits< T, N, C >
 Dimension-specialized traits shared by Array and ArrayRef. More...
 
struct  ndarray::ExpressionTraits< Expression_ >
 Traits for expressions. More...
 
class  ndarray::NumericTraits< T, U, is_complex, is_arithmetic >
 Numeric type traits. More...
 
class  ndarray::Promote< T1, T2, winner, is_complex >
 Metafunction to compute numeric promotions. More...
 
struct  ndarray::ApproximatelyEqual< T1, T2 >
 Binary predicate for floating point equality comparison with tolerance. More...
 
struct  ndarray::ApproximatelyEqual< std::complex< U1 >, std::complex< U2 > >
 Binary predicate for complex floating point equality comparison with tolerance. More...
 
class  ndarray::ArrayBase< Derived >
 CRTP implementation for Array and ArrayRef. More...
 
class  ndarray::ExpressionBase< Derived >
 CRTP base class for all multidimensional expressions. More...
 
class  ndarray::FormatOptions
 Options for controlling stream output of ExpressionBase. More...
 

Functions

template<typename T_ , typename T , int N, int C>
Array< T_, N, C > ndarray::const_array_cast (Array< T, N, C > const &array)
 
template<int C_, typename T , int N, int C>
Array< T, N, C_ > ndarray::static_dimension_cast (Array< T, N, C > const &array)
 
template<int C_, typename T , int N, int C>
Array< T, N, C_ > ndarray::dynamic_dimension_cast (Array< T, N, C > const &array)
 
template<typename Array_ >
detail::ComplexExtractor
< Array_ >::Result 
ndarray::getReal (Array_ const &array)
 Return an ArrayRef view into the real part of a complex array. More...
 
template<typename Array_ >
detail::ComplexExtractor
< Array_ >::Result 
ndarray::getImag (Array_ const &array)
 Return an ArrayRef view into the imaginary part of a complex array. More...
 
template<int Nf, typename T , int N, int C>
boost::enable_if_c< ((C+Nf-N)>
=1), ArrayRef< T, Nf,(C+Nf-N)>
>::type 
ndarray::flatten (Array< T, N, C > const &input)
 Create a view into an array with trailing contiguous dimensions merged. More...
 
template<int Nf, typename T , int N, int C>
boost::enable_if_c< ((C+Nf-N)>
=1), ArrayRef< T, Nf,(C+Nf-N)>
>::type 
ndarray::flatten (ArrayRef< T, N, C > const &input)
 Create a view into an array with trailing contiguous dimensions merged. More...
 
template<int N>
detail::SimpleInitializer< N > ndarray::allocate (Vector< int, N > const &shape)
 Create an expression that allocates uninitialized memory for an array. More...
 
detail::SimpleInitializer< 1 > ndarray::allocate (int n)
 Create an expression that allocates uninitialized memory for a 1-d array. More...
 
detail::SimpleInitializer< 2 > ndarray::allocate (int n1, int n2)
 Create an expression that allocates uninitialized memory for a 2-d array. More...
 
detail::SimpleInitializer< 3 > ndarray::allocate (int n1, int n2, int n3)
 Create an expression that allocates uninitialized memory for a 3-d array. More...
 
template<typename Derived >
ArrayRef< typename
boost::remove_const< typename
Derived::Element >::type,
Derived::ND::value,
Derived::ND::value > 
ndarray::copy (ExpressionBase< Derived > const &expr)
 Create a new Array by copying an Expression. More...
 
template<int N>
Vector< int, N > ndarray::computeStrides (Vector< int, N > const &shape, DataOrderEnum order=ROW_MAJOR)
 Compute row- or column-major strides for the given shape. More...
 
template<typename T , int N, typename Owner >
detail::ExternalInitializer< T,
N, Owner > 
ndarray::external (T *data, Vector< int, N > const &shape, Vector< int, N > const &strides, Owner const &owner)
 Create an expression that initializes an Array with externally allocated memory. More...
 
template<typename T , int N>
detail::ExternalInitializer< T,
N, detail::NullOwner > 
ndarray::external (T *data, Vector< int, N > const &shape, Vector< int, N > const &strides)
 Create an expression that initializes an Array with externally allocated memory. More...
 
template<typename T , int N, typename Owner >
detail::ExternalInitializer< T,
N, Owner > 
ndarray::external (T *data, Vector< int, N > const &shape, DataOrderEnum order, Owner const &owner)
 Create an expression that initializes an Array with externally allocated memory. More...
 
template<typename T , int N>
detail::ExternalInitializer< T,
N, detail::NullOwner > 
ndarray::external (T *data, Vector< int, N > const &shape, DataOrderEnum order=ROW_MAJOR)
 Create an expression that initializes an Array with externally allocated memory. More...
 
template<typename Derived >
bool ndarray::any (ExpressionBase< Derived > const &expr)
 Return true if any of the elements of the given expression are true. More...
 
template<typename Derived >
bool ndarray::all (ExpressionBase< Derived > const &expr)
 Return true if all of the elements of the given expression are true. More...
 
template<typename Derived >
Derived::Element ndarray::sum (ExpressionBase< Derived > const &expr)
 Return the sum of all elements of the given expression. More...
 

Detailed Description

Function Documentation

template<typename Derived >
bool ndarray::all ( ExpressionBase< Derived > const &  expr)
inline

Return true if all of the elements of the given expression are true.

Definition at line 1197 of file operators.h.

1197  {
1198  typename Derived::Iterator const i_end = expr.end();
1199  for (typename Derived::Iterator i = expr.begin(); i != i_end; ++i) {
1200  if (!all(*i)) return false;
1201  }
1202  return true;
1203 }
bool all(CoordinateExpr< N > const &expr)
Return true if all elements are true.
template<int N>
detail::SimpleInitializer<N> ndarray::allocate ( Vector< int, N > const &  shape)
inline

Create an expression that allocates uninitialized memory for an array.

Returns
A temporary object convertible to an Array with fully contiguous row-major strides.

Definition at line 115 of file initialization.h.

115  {
116  return detail::SimpleInitializer<N>(shape);
117 }
detail::SimpleInitializer<1> ndarray::allocate ( int  n)
inline

Create an expression that allocates uninitialized memory for a 1-d array.

Returns
A temporary object convertible to an Array with fully contiguous row-major strides.

Definition at line 124 of file initialization.h.

124  {
125  return detail::SimpleInitializer<1>(ndarray::makeVector(n));
126 }
Vector< T, N > makeVector(T v1, T v2,..., T vN)
Variadic constructor for Vector.
detail::SimpleInitializer<2> ndarray::allocate ( int  n1,
int  n2 
)
inline

Create an expression that allocates uninitialized memory for a 2-d array.

Returns
A temporary object convertible to an Array with fully contiguous row-major strides.

Definition at line 133 of file initialization.h.

133  {
134  return detail::SimpleInitializer<2>(ndarray::makeVector(n1, n2));
135 }
Vector< T, N > makeVector(T v1, T v2,..., T vN)
Variadic constructor for Vector.
detail::SimpleInitializer<3> ndarray::allocate ( int  n1,
int  n2,
int  n3 
)
inline

Create an expression that allocates uninitialized memory for a 3-d array.

Returns
A temporary object convertible to an Array with fully contiguous row-major strides.

Definition at line 142 of file initialization.h.

142  {
143  return detail::SimpleInitializer<3>(ndarray::makeVector(n1, n2, n3));
144 }
Vector< T, N > makeVector(T v1, T v2,..., T vN)
Variadic constructor for Vector.
template<typename Derived >
bool ndarray::any ( ExpressionBase< Derived > const &  expr)
inline

Return true if any of the elements of the given expression are true.

Definition at line 1176 of file operators.h.

1176  {
1177  typename Derived::Iterator const i_end = expr.end();
1178  for (typename Derived::Iterator i = expr.begin(); i != i_end; ++i) {
1179  if (any(*i)) return true;
1180  }
1181  return false;
1182 }
bool any(CoordinateExpr< N > const &expr)
Return true if any elements are true.
template<int N>
Vector<int,N> ndarray::computeStrides ( Vector< int, N > const &  shape,
DataOrderEnum  order = ROW_MAJOR 
)

Compute row- or column-major strides for the given shape.

Definition at line 163 of file initialization.h.

163  {
164  Vector<int,N> r(1);
165  if (order == ROW_MAJOR) {
166  for (int n=N-1; n > 0; --n) r[n-1] = r[n] * shape[n];
167  } else {
168  for (int n=1; n < N; ++n) r[n] = r[n-1] * shape[n-1];
169  }
170  return r;
171 }
template<typename T_ , typename T , int N, int C>
Array<T_,N,C> ndarray::const_array_cast ( Array< T, N, C > const &  array)

Convert an Array with a const data type to an array with a non-const data type.

Definition at line 76 of file casts.h.

76  {
77  return detail::ArrayAccess< Array<T_,N,C> >::construct(
78  const_cast<T_*>(array.getData()),
79  detail::ArrayAccess< Array<T,N,C> >::getCore(array)
80  );
81 }
template<typename Derived >
ArrayRef<typename boost::remove_const<typename Derived::Element>::type, Derived::ND::value, Derived::ND::value> ndarray::copy ( ExpressionBase< Derived > const &  expr)
inline

Create a new Array by copying an Expression.

Definition at line 152 of file initialization.h.

152  {
153  ArrayRef<typename boost::remove_const<typename Derived::Element>::type,
154  Derived::ND::value,Derived::ND::value> r(
155  allocate(expr.getShape())
156  );
157  r = expr;
158  return r;
159 }
detail::SimpleInitializer< N > allocate(Vector< int, N > const &shape)
Create an expression that allocates uninitialized memory for an array.
template<int C_, typename T , int N, int C>
Array<T,N,C_> ndarray::dynamic_dimension_cast ( Array< T, N, C > const &  array)

Convert an Array to a type with more guaranteed row-major-contiguous dimensions, if the strides of the array match the desired number of RMC dimensions. If the cast fails, an empty Array is returned.

Definition at line 105 of file casts.h.

105  {
106  Vector<int,N> shape = array.getShape();
107  Vector<int,N> strides = array.getStrides();
108  if (C_ >= 0) {
109  int n = 1;
110  for (int i=1; i <= C_; ++i) {
111  if (strides[N-i] != n) return Array<T,N,C_>();
112  n *= shape[N-i];
113  }
114  } else {
115  int n = 1;
116  for (int i=0; i < -C_; ++i) {
117  if (strides[i] != n) return Array<T,N,C_>();
118  n *= strides[i];
119  }
120  }
121  return static_dimension_cast<C_>(array);
122 }
Array< T, N, C_ > static_dimension_cast(Array< T, N, C > const &array)
Definition: casts.h:89
template<typename T , int N, typename Owner >
detail::ExternalInitializer<T,N,Owner> ndarray::external ( T *  data,
Vector< int, N > const &  shape,
Vector< int, N > const &  strides,
Owner const &  owner 
)
inline

Create an expression that initializes an Array with externally allocated memory.

No checking is done to ensure the shape, strides, and data pointers are sensible.

Parameters
[in]dataA raw pointer to the first element of the Array.
[in]shapeA Vector of dimensions for the new Array.
[in]stridesA Vector of strides for the new Array.
[in]ownerA copy-constructable object with an internal reference count that owns the memory pointed at by 'data'.
Returns
A temporary object convertible to an Array.

Definition at line 187 of file initialization.h.

192  {
193  return detail::ExternalInitializer<T,N,Owner>(data, shape, strides, owner);
194 }
template<typename T , int N>
detail::ExternalInitializer<T,N,detail::NullOwner> ndarray::external ( T *  data,
Vector< int, N > const &  shape,
Vector< int, N > const &  strides 
)
inline

Create an expression that initializes an Array with externally allocated memory.

No checking is done to ensure the shape, strides, and data pointers are sensible. Memory will not be managed at all; the user must ensure the data pointer remains valid for the lifetime of the array.

Parameters
[in]dataA raw pointer to the first element of the Array.
[in]shapeA Vector of dimensions for the new Array.
[in]stridesA Vector of strides for the new Array.
Returns
A temporary object convertible to an Array.

Definition at line 209 of file initialization.h.

213  {
214  return detail::ExternalInitializer<T,N,detail::NullOwner>(data, shape, strides, detail::NullOwner());
215 }
template<typename T , int N, typename Owner >
detail::ExternalInitializer<T,N,Owner> ndarray::external ( T *  data,
Vector< int, N > const &  shape,
DataOrderEnum  order,
Owner const &  owner 
)
inline

Create an expression that initializes an Array with externally allocated memory.

No checking is done to ensure the shape and data pointers are sensible.

Parameters
[in]dataA raw pointer to the first element of the Array.
[in]shapeA Vector of dimensions for the new Array.
[in]orderWhether the strides are row- or column-major.
[in]ownerA copy-constructable object with an internal reference count that owns the memory pointed at by 'data'.
Returns
A temporary object convertible to an Array.

Definition at line 231 of file initialization.h.

236  {
237  return detail::ExternalInitializer<T,N,Owner>(data, shape, computeStrides(shape, order), owner);
238 }
Vector< int, N > computeStrides(Vector< int, N > const &shape, DataOrderEnum order=ROW_MAJOR)
Compute row- or column-major strides for the given shape.
template<typename T , int N>
detail::ExternalInitializer<T,N,detail::NullOwner> ndarray::external ( T *  data,
Vector< int, N > const &  shape,
DataOrderEnum  order = ROW_MAJOR 
)
inline

Create an expression that initializes an Array with externally allocated memory.

No checking is done to ensure the shape and data pointers are sensible. Memory will not be managed at all; the user must ensure the data pointer remains valid for the lifetime of the array.

Parameters
[in]dataA raw pointer to the first element of the Array.
[in]shapeA Vector of dimensions for the new Array.
[in]orderWhether the strides are row- or column-major.
Returns
A temporary object convertible to an Array.

Definition at line 253 of file initialization.h.

257  {
258  return detail::ExternalInitializer<T,N,detail::NullOwner>(
259  data, shape, computeStrides(shape, order), detail::NullOwner()
260  );
261 }
Vector< int, N > computeStrides(Vector< int, N > const &shape, DataOrderEnum order=ROW_MAJOR)
Compute row- or column-major strides for the given shape.
template<int Nf, typename T , int N, int C>
boost::enable_if_c< ((C+Nf-N)>=1), ArrayRef<T,Nf,(C+Nf-N)> >::type ndarray::flatten ( Array< T, N, C > const &  input)
inline

Create a view into an array with trailing contiguous dimensions merged.

The first template parameter sets the dimension of the output array and must be specified directly. Only row-major contiguous dimensions can be flattened.

Definition at line 150 of file casts.h.

150  {
151  typedef detail::ArrayAccess< ArrayRef<T,Nf,(C+Nf-N)> > Access;
152  typedef typename Access::Core Core;
153  BOOST_STATIC_ASSERT(C+Nf-N >= 1);
154  Vector<int,N> oldShape = input.getShape();
155  Vector<int,Nf> newShape = oldShape.template first<Nf>();
156  for (int n=Nf; n<N; ++n)
157  newShape[Nf-1] *= oldShape[n];
158  Vector<int,Nf> newStrides = input.getStrides().template first<Nf>();
159  newStrides[Nf-1] = 1;
160  return Access::construct(input.getData(), Core::create(newShape, newStrides, input.getManager()));
161 }
template<int Nf, typename T , int N, int C>
boost::enable_if_c< ((C+Nf-N)>=1), ArrayRef<T,Nf,(C+Nf-N)> >::type ndarray::flatten ( ArrayRef< T, N, C > const &  input)
inline

Create a view into an array with trailing contiguous dimensions merged.

The first template parameter sets the dimension of the output array and must be specified directly. Only row-major contiguous dimensions can be flattened.

Definition at line 171 of file casts.h.

171  {
172  return flatten<Nf>(input.shallow());
173 }
template<typename Array_ >
detail::ComplexExtractor<Array_>::Result ndarray::getImag ( Array_ const &  array)

Return an ArrayRef view into the imaginary part of a complex array.

Definition at line 138 of file casts.h.

138  {
139  return detail::ComplexExtractor<Array_>::apply(array, 1);
140 }
template<typename Array_ >
detail::ComplexExtractor<Array_>::Result ndarray::getReal ( Array_ const &  array)

Return an ArrayRef view into the real part of a complex array.

Definition at line 129 of file casts.h.

129  {
130  return detail::ComplexExtractor<Array_>::apply(array, 0);
131 }
template<int C_, typename T , int N, int C>
Array<T,N,C_> ndarray::static_dimension_cast ( Array< T, N, C > const &  array)

Convert an Array to a type with more guaranteed row-major-contiguous dimensions with no checking.

Definition at line 89 of file casts.h.

89  {
90  return detail::ArrayAccess< Array<T,N,C_> >::construct(
91  array.getData(),
92  detail::ArrayAccess< Array<T,N,C> >::getCore(array)
93  );
94 }
template<typename Derived >
Derived::Element ndarray::sum ( ExpressionBase< Derived > const &  expr)
inline

Return the sum of all elements of the given expression.

Definition at line 1260 of file operators.h.

1260  {
1261  typename Derived::Iterator const i_end = expr.end();
1262  typename Derived::Element total = static_cast<typename Derived::Element>(0);
1263  for (typename Derived::Iterator i = expr.begin(); i != i_end; ++i) {
1264  total += sum(*i);
1265  }
1266  return total;
1267 }
boost::enable_if< typename ExpressionTraits< Scalar >::IsScalar, Scalar >::type sum(Scalar const &scalar)
Definition: operators.h:1250