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
Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
home
lsstsw
stack
Linux64
ndarray
11.0.rc2+1
include
ndarray
arange.h
Go to the documentation of this file.
1
// -*- c++ -*-
2
/*
3
* LSST Data Management System
4
* Copyright 2008, 2009, 2010, 2011 LSST Corporation.
5
*
6
* This product includes software developed by the
7
* LSST Project (http://www.lsst.org/).
8
*
9
* This program is free software: you can redistribute it and/or modify
10
* it under the terms of the GNU General Public License as published by
11
* the Free Software Foundation, either version 3 of the License, or
12
* (at your option) any later version.
13
*
14
* This program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU General Public License for more details.
18
*
19
* You should have received a copy of the LSST License Statement and
20
* the GNU General Public License along with this program. If not,
21
* see <http://www.lsstcorp.org/LegalNotices/>.
22
*/
23
#ifndef NDARRAY_arange_h_INCLUDED
24
#define NDARRAY_arange_h_INCLUDED
25
32
#include "
ndarray/vectorize.h
"
33
34
#include <boost/iterator/counting_iterator.hpp>
35
36
namespace
ndarray {
37
43
template
<>
44
struct
ExpressionTraits
<detail::CountingExpression> {
45
typedef
int
Element
;
46
typedef
boost::mpl::int_<1>
ND
;
47
typedef
boost::counting_iterator<int>
Iterator
;
48
typedef
int
Value
;
49
typedef
int
Reference
;
50
};
51
52
namespace
detail {
53
60
class
CountingExpression
:
public
ExpressionBase
<CountingExpression> {
61
public
:
62
typedef
ExpressionTraits<CountingExpression>::Element
Element
;
63
typedef
ExpressionTraits<CountingExpression>::ND
ND
;
64
typedef
ExpressionTraits<CountingExpression>::Iterator
Iterator
;
65
typedef
ExpressionTraits<CountingExpression>::Value
Value
;
66
typedef
ExpressionTraits<CountingExpression>::Reference
Reference
;
67
typedef
Vector<int,1>
Index
;
68
69
CountingExpression
(
int
stop=0) :
_stop
(stop) {
NDARRAY_ASSERT
(stop >= 0); }
70
71
Reference
operator[]
(
int
n)
const
{
72
return
n;
73
}
74
75
Iterator
begin
()
const
{
76
return
Iterator
(0);
77
}
78
79
Iterator
end
()
const
{
80
return
Iterator
(
_stop
);
81
}
82
83
template
<
int
P>
int
getSize
()
const
{
84
BOOST_STATIC_ASSERT(P==0);
85
return
_stop
;
86
}
87
88
Index
getShape
()
const
{
89
return
makeVector
(
_stop
);
90
}
91
92
private
:
93
int
_stop
;
94
};
95
96
template
<
typename
T>
97
class
RangeTransformer
{
98
T
_offset
;
99
T
_scale
;
100
public
:
101
typedef
int
argument_type
;
102
typedef
T
result_type
;
103
104
explicit
RangeTransformer
(T
const
& offset, T
const
&
scale
) :
_offset
(offset),
_scale
(scale) {}
105
106
T
operator()
(
int
n)
const
{
return
static_cast<
T
>
(n) *
_scale
+
_offset
; }
107
};
108
109
}
// namespace detail
110
112
inline
detail::CountingExpression
arange
(
int
stop) {
113
return
detail::CountingExpression
(stop);
114
}
115
117
inline
detail::UnaryOpExpression< detail::CountingExpression, detail::RangeTransformer<int> >
118
arange
(
int
start,
int
stop,
int
step = 1) {
119
NDARRAY_ASSERT
(step != 0);
120
int
size = stop - start;
121
if
(step < -1) ++size;
122
if
(step > 1) --size;
123
size /= step;
124
return
vectorize
(
125
detail::RangeTransformer<int>
(start,step),
126
detail::CountingExpression
(size)
127
);
128
}
129
130
}
// namespace ndarray
131
132
#endif // !NDARRAY_arange_h_INCLUDED
ndarray::detail::CountingExpression::CountingExpression
CountingExpression(int stop=0)
Definition:
arange.h:69
ndarray::detail::CountingExpression::getShape
Index getShape() const
Definition:
arange.h:88
ndarray::detail::RangeTransformer::_scale
T _scale
Definition:
arange.h:99
ndarray::detail::CountingExpression::_stop
int _stop
Definition:
arange.h:93
ndarray::detail::RangeTransformer::_offset
T _offset
Definition:
arange.h:98
ndarray::ExpressionTraits< detail::CountingExpression >::Reference
int Reference
Definition:
arange.h:49
ndarray::detail::CountingExpression::Reference
ExpressionTraits< CountingExpression >::Reference Reference
Definition:
arange.h:66
vectorize.h
Code to apply arbitrary scalar functors to arrays.
ndarray::detail::CountingExpression::getSize
int getSize() const
Definition:
arange.h:83
ndarray::detail::RangeTransformer
Definition:
arange.h:97
ndarray::arange
detail::CountingExpression arange(int stop)
Create 1D Expression that contains integer values in the range [0,stop).
Definition:
arange.h:112
NDARRAY_ASSERT
#define NDARRAY_ASSERT(ARG)
Definition:
ndarray_fwd.h:51
ndarray::ExpressionTraits< detail::CountingExpression >::Value
int Value
Definition:
arange.h:48
ndarray::ExpressionTraits< detail::CountingExpression >::Iterator
boost::counting_iterator< int > Iterator
Definition:
arange.h:47
ndarray::detail::CountingExpression::end
Iterator end() const
Definition:
arange.h:79
ndarray::Vector
A fixed-size 1D array class.
Definition:
Vector.h:93
ndarray::detail::CountingExpression::Value
ExpressionTraits< CountingExpression >::Value Value
Definition:
arange.h:65
ndarray::detail::CountingExpression
Definition:
arange.h:60
ndarray::detail::CountingExpression::Iterator
ExpressionTraits< CountingExpression >::Iterator Iterator
Definition:
arange.h:64
ndarray::makeVector
Vector< T, N > makeVector(T v1, T v2,..., T vN)
Variadic constructor for Vector.
ndarray::ExpressionTraits
Traits for expressions.
Definition:
ExpressionTraits.h:42
ndarray::detail::RangeTransformer::argument_type
int argument_type
Definition:
arange.h:101
ndarray::detail::CountingExpression::ND
ExpressionTraits< CountingExpression >::ND ND
Definition:
arange.h:63
ndarray::detail::RangeTransformer::operator()
T operator()(int n) const
Definition:
arange.h:106
ndarray::detail::CountingExpression::operator[]
Reference operator[](int n) const
Definition:
arange.h:71
ndarray::detail::CountingExpression::Element
ExpressionTraits< CountingExpression >::Element Element
Definition:
arange.h:62
ndarray::vectorize
UnaryFunction::result_type vectorize(UnaryFunction const &functor, Scalar const &scalar)
Apply a non-mutating unary function object to a scalar.
Definition:
vectorize.h:85
lsst.afw.display.ds9.scale
def scale
Definition:
ds9.py:91
ndarray::detail::CountingExpression::begin
Iterator begin() const
Definition:
arange.h:75
ndarray::ExpressionTraits< detail::CountingExpression >::Element
int Element
Definition:
arange.h:45
ndarray::detail::RangeTransformer::result_type
T result_type
Definition:
arange.h:102
ndarray::ExpressionTraits< detail::CountingExpression >::ND
boost::mpl::int_< 1 > ND
Definition:
arange.h:46
ndarray::detail::RangeTransformer::RangeTransformer
RangeTransformer(T const &offset, T const &scale)
Definition:
arange.h:104
ndarray::detail::CountingExpression::Index
Vector< int, 1 > Index
Definition:
arange.h:67
ndarray::ExpressionBase
CRTP base class for all multidimensional expressions.
Definition:
ExpressionBase.h:52
Generated on Wed Sep 16 2015 13:35:33 for LSSTApplications by
1.8.5