Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tnl-dev
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
TNL
tnl-dev
Commits
fa20f0e2
There was an error fetching the commit references. Please try again later.
Commit
fa20f0e2
authored
5 years ago
by
Tomáš Oberhuber
Browse files
Options
Downloads
Patches
Plain Diff
Adding documentation to Vector and VectorView.
parent
17dc58c7
No related branches found
No related tags found
1 merge request
!41
Tutorials
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/TNL/Containers/Vector.h
+108
-16
108 additions, 16 deletions
src/TNL/Containers/Vector.h
src/TNL/Containers/VectorView.h
+88
-12
88 additions, 12 deletions
src/TNL/Containers/VectorView.h
with
196 additions
and
28 deletions
src/TNL/Containers/Vector.h
+
108
−
16
View file @
fa20f0e2
...
@@ -42,11 +42,39 @@ class Vector
...
@@ -42,11 +42,39 @@ class Vector
:
public
Array
<
Real
,
Device
,
Index
,
Allocator
>
:
public
Array
<
Real
,
Device
,
Index
,
Allocator
>
{
{
public:
public:
/**
* \brief Type of elements stored in this vector.
*/
using
RealType
=
Real
;
using
RealType
=
Real
;
/**
* \brief Device where the vector is allocated.
*
* See \ref Devices::Host or \ref Devices::Cuda.
*/
using
DeviceType
=
Device
;
using
DeviceType
=
Device
;
/**
* \brief Type being used for the vector elements indexing.
*/
using
IndexType
=
Index
;
using
IndexType
=
Index
;
/**
* \brief Allocator type used for allocating this vector.
*
* See \ref Allocators::Cuda, \ref Allocators::CudaHost, \ref Allocators::CudaManaged, \ref Allocators::Host or \ref Allocators:Default.
*/
using
AllocatorType
=
Allocator
;
using
AllocatorType
=
Allocator
;
/**
* \brief Defines the same vector type but allocated on host (CPU).
*/
using
HostType
=
Vector
<
Real
,
TNL
::
Devices
::
Host
,
Index
>
;
using
HostType
=
Vector
<
Real
,
TNL
::
Devices
::
Host
,
Index
>
;
/**
* \brief Defines the same vector type but allocated on CUDA device (GPU).
*/
using
CudaType
=
Vector
<
Real
,
TNL
::
Devices
::
Cuda
,
Index
>
;
using
CudaType
=
Vector
<
Real
,
TNL
::
Devices
::
Cuda
,
Index
>
;
using
ViewType
=
VectorView
<
Real
,
Device
,
Index
>
;
using
ViewType
=
VectorView
<
Real
,
Device
,
Index
>
;
using
ConstViewType
=
VectorView
<
std
::
add_const_t
<
Real
>
,
Device
,
Index
>
;
using
ConstViewType
=
VectorView
<
std
::
add_const_t
<
Real
>
,
Device
,
Index
>
;
...
@@ -55,23 +83,44 @@ public:
...
@@ -55,23 +83,44 @@ public:
using
Array
<
Real
,
Device
,
Index
,
Allocator
>::
Array
;
using
Array
<
Real
,
Device
,
Index
,
Allocator
>::
Array
;
using
Array
<
Real
,
Device
,
Index
,
Allocator
>::
operator
=
;
using
Array
<
Real
,
Device
,
Index
,
Allocator
>::
operator
=
;
//! \brief Constructs an empty array with zero size.
/**
* \brief Constructs an empty array with zero size.
*/
Vector
()
=
default
;
Vector
()
=
default
;
//! \brief Copy constructor (makes a deep copy).
/**
* \brief Copy constructor (makes a deep copy).
*/
explicit
Vector
(
const
Vector
&
)
=
default
;
explicit
Vector
(
const
Vector
&
)
=
default
;
//! \brief Copy constructor with a specific allocator (makes a deep copy).
/**
* \brief Copy constructor with a specific allocator (makes a deep copy).
*/
explicit
Vector
(
const
Vector
&
vector
,
const
AllocatorType
&
allocator
);
explicit
Vector
(
const
Vector
&
vector
,
const
AllocatorType
&
allocator
);
//! \brief Default move constructor.
/**
* \brief Default move constructor.
*/
Vector
(
Vector
&&
)
=
default
;
Vector
(
Vector
&&
)
=
default
;
//! \brief Copy-assignment operator for copying data from another vector.
/**
* \brief Copy-assignment operator for copying data from another vector.
*/
Vector
&
operator
=
(
const
Vector
&
)
=
default
;
Vector
&
operator
=
(
const
Vector
&
)
=
default
;
//! \brief Move-assignment operator for acquiring data from \e rvalues.
/**
* \brief Move-assignment operator for acquiring data from \e rvalues.
*/
Vector
&
operator
=
(
Vector
&&
)
=
default
;
Vector
&
operator
=
(
Vector
&&
)
=
default
;
//! \brief Returns a \ref String representation of the vector type in C++ style.
/**
* \brief Returns a \ref String representation of the vector type in C++ style.
*/
static
String
getType
();
static
String
getType
();
//! \brief Returns a \ref String representation of the vector type in C++ style.
/**
* \brief Returns a \ref String representation of the vector type in C++ style.
*/
virtual
String
getTypeVirtual
()
const
;
virtual
String
getTypeVirtual
()
const
;
/**
/**
...
@@ -198,28 +247,71 @@ public:
...
@@ -198,28 +247,71 @@ public:
Vector
&
operator
/=
(
const
VectorExpression
&
expression
);
Vector
&
operator
/=
(
const
VectorExpression
&
expression
);
/**
/**
* \brief
Returns speci
fi
c
sum
s of elements
of th
is
vector.
* \brief
Computes pre
fi
x
sum of th
e
vector
elements
.
*
*
* FIXME: computePrefixSum does not exist
* Computes prefix sum for elements within the index range [ \e begin to \e end ).
* The other elements of this vector remain unchanged.
*
*
* Does the same as \ref computePrefixSum, but computes only sums for elements
* \tparam Type tells the prefix sum type - either \e Inclusive of \e Exclusive.
* with the index in range from \e begin to \e end. The other elements of this
*
* vector remain untouched - with the same value.
* \param begin beginning of the index range
*
* \param end end of the index range.
* \param begin Index of the element in this vector which to begin with.
* \param end Index of the element in this vector which to end with.
*/
*/
template
<
Algorithms
::
ScanType
Type
=
Algorithms
::
ScanType
::
Inclusive
>
template
<
Algorithms
::
ScanType
Type
=
Algorithms
::
ScanType
::
Inclusive
>
void
prefixSum
(
IndexType
begin
=
0
,
IndexType
end
=
0
);
void
prefixSum
(
IndexType
begin
=
0
,
IndexType
end
=
0
);
/**
* \brief Computes segmented prefix sum of the vector elements.
*
* Computes segmented prefix sum for elements within the index range [ \e begin to \e end ).
* The other elements of this vector remain unchanged. Whole vector is assumed
* by default, i.e. when \e begin and \e end are set to zero.
*
* \tparam Type tells the prefix sum type - either \e Inclusive of \e Exclusive.
* \tparam FlagsArray is an array type describing beginnings of the segments.
*
* \param flags is an array having `1` at the beginning of each segment and `0` on any other position
* \param begin beginning of the index range
* \param end end of the index range.
*/
template
<
Algorithms
::
ScanType
Type
=
Algorithms
::
ScanType
::
Inclusive
,
template
<
Algorithms
::
ScanType
Type
=
Algorithms
::
ScanType
::
Inclusive
,
typename
FlagsArray
>
typename
FlagsArray
>
void
segmentedPrefixSum
(
FlagsArray
&
flags
,
IndexType
begin
=
0
,
IndexType
end
=
0
);
void
segmentedPrefixSum
(
FlagsArray
&
flags
,
IndexType
begin
=
0
,
IndexType
end
=
0
);
/**
* \brief Computes prefix sum of the vector expression.
*
* Computes prefix sum for elements within the index range [ \e begin to \e end ).
* The other elements of this vector remain unchanged. Whole vector expression is assumed
* by default, i.e. when \e begin and \e end are set to zero.
*
* \tparam Type tells the prefix sum type - either \e Inclusive of \e Exclusive.
* \tparam VectorExpression is the vector expression.
*
* \param expression is the vector expression.
* \param begin beginning of the index range
* \param end end of the index range.
*/
template
<
Algorithms
::
ScanType
Type
=
Algorithms
::
ScanType
::
Inclusive
,
template
<
Algorithms
::
ScanType
Type
=
Algorithms
::
ScanType
::
Inclusive
,
typename
VectorExpression
>
typename
VectorExpression
>
void
prefixSum
(
const
VectorExpression
&
expression
,
IndexType
begin
=
0
,
IndexType
end
=
0
);
void
prefixSum
(
const
VectorExpression
&
expression
,
IndexType
begin
=
0
,
IndexType
end
=
0
);
/**
* \brief Computes segmented prefix sum of a vector expression.
*
* Computes segmented prefix sum for elements within the index range [ \e begin to \e end ).
* The other elements of this vector remain unchanged. Whole vector expression is assumed
* by default, i.e. when \e begin and \e end are set to zero.
*
* \tparam Type tells the prefix sum type - either \e Inclusive of \e Exclusive.
* \tparam VectorExpression is the vector expression.
* \tparam FlagsArray is an array type describing beginnings of the segments.
*
* \param expression is the vector expression.
* \param flags is an array having `1` at the beginning of each segment and `0` on any other position
* \param begin beginning of the index range
* \param end end of the index range.
*/
template
<
Algorithms
::
ScanType
Type
=
Algorithms
::
ScanType
::
Inclusive
,
template
<
Algorithms
::
ScanType
Type
=
Algorithms
::
ScanType
::
Inclusive
,
typename
VectorExpression
,
typename
VectorExpression
,
typename
FlagsArray
>
typename
FlagsArray
>
...
...
This diff is collapsed.
Click to expand it.
src/TNL/Containers/VectorView.h
+
88
−
12
View file @
fa20f0e2
...
@@ -39,12 +39,41 @@ class VectorView
...
@@ -39,12 +39,41 @@ class VectorView
using
BaseType
=
ArrayView
<
Real
,
Device
,
Index
>
;
using
BaseType
=
ArrayView
<
Real
,
Device
,
Index
>
;
using
NonConstReal
=
typename
std
::
remove_const
<
Real
>::
type
;
using
NonConstReal
=
typename
std
::
remove_const
<
Real
>::
type
;
public:
public:
/**
* \brief Type of elements stored in this vector.
*/
using
RealType
=
Real
;
using
RealType
=
Real
;
/**
* \brief Device where the vector is allocated.
*
* See \ref Devices::Host or \ref Devices::Cuda.
*/
using
DeviceType
=
Device
;
using
DeviceType
=
Device
;
/**
* \brief Type being used for the vector elements indexing.
*/
using
IndexType
=
Index
;
using
IndexType
=
Index
;
using
HostType
=
VectorView
<
Real
,
Devices
::
Host
,
Index
>
;
using
CudaType
=
VectorView
<
Real
,
Devices
::
Cuda
,
Index
>
;
/**
* \brief Defines the same vector type but allocated on host (CPU).
*/
using
HostType
=
VectorView
<
Real
,
TNL
::
Devices
::
Host
,
Index
>
;
/**
* \brief Defines the same vector type but allocated on CUDA device (GPU).
*/
using
CudaType
=
VectorView
<
Real
,
TNL
::
Devices
::
Cuda
,
Index
>
;
/**
* \brief Compatible VectorView type.
*/
using
ViewType
=
VectorView
<
Real
,
Device
,
Index
>
;
using
ViewType
=
VectorView
<
Real
,
Device
,
Index
>
;
/**
* \brief Compatible constant VectorView type.
*/
using
ConstViewType
=
VectorView
<
std
::
add_const_t
<
Real
>
,
Device
,
Index
>
;
using
ConstViewType
=
VectorView
<
std
::
add_const_t
<
Real
>
,
Device
,
Index
>
;
// constructors and assignment operators inherited from the class ArrayView
// constructors and assignment operators inherited from the class ArrayView
...
@@ -58,14 +87,18 @@ public:
...
@@ -58,14 +87,18 @@ public:
__cuda_callable__
__cuda_callable__
VectorView
()
=
default
;
VectorView
()
=
default
;
//! \brief Constructor for the initialization by a base class object.
/**
* \brief Constructor for the initialization by a base class object.
*/
// initialization by base class is not a copy constructor so it has to be explicit
// initialization by base class is not a copy constructor so it has to be explicit
template
<
typename
Real_
>
// template catches both const and non-const qualified Element
template
<
typename
Real_
>
// template catches both const and non-const qualified Element
__cuda_callable__
__cuda_callable__
VectorView
(
const
ArrayView
<
Real_
,
Device
,
Index
>&
view
)
VectorView
(
const
ArrayView
<
Real_
,
Device
,
Index
>&
view
)
:
BaseType
(
view
)
{}
:
BaseType
(
view
)
{}
//! \brief Returns a \ref String representation of the vector view type.
/**
* \brief Returns a \ref String representation of the vector view type.
*/
static
String
getType
();
static
String
getType
();
/**
/**
...
@@ -187,28 +220,71 @@ public:
...
@@ -187,28 +220,71 @@ public:
VectorView
&
operator
/=
(
const
VectorExpression
&
expression
);
VectorView
&
operator
/=
(
const
VectorExpression
&
expression
);
/**
/**
* \brief
Returns speci
fi
c
sum
s of elements
of th
is
vector view.
* \brief
Computes pre
fi
x
sum of th
e
vector view
elements
.
*
*
* FIXME: computePrefixSum does not exist
* Computes prefix sum for elements within the index range [ \e begin to \e end ).
* The other elements of this vector view remain unchanged.
*
*
* Does the same as \ref computePrefixSum, but computes only sums for elements
* \tparam Type tells the prefix sum type - either \e Inclusive of \e Exclusive.
* with the index in range from \e begin to \e end. The other elements of this
*
* vector remain untouched - with the same value.
* \param begin beginning of the index range
*
* \param end end of the index range.
* \param begin Index of the element in this vector view which to begin with.
* \param end Index of the element in this vector view which to end with.
*/
*/
template
<
Algorithms
::
ScanType
Type
=
Algorithms
::
ScanType
::
Inclusive
>
template
<
Algorithms
::
ScanType
Type
=
Algorithms
::
ScanType
::
Inclusive
>
void
prefixSum
(
IndexType
begin
=
0
,
IndexType
end
=
0
);
void
prefixSum
(
IndexType
begin
=
0
,
IndexType
end
=
0
);
/**
* \brief Computes segmented prefix sum of the vector view elements.
*
* Computes segmented prefix sum for elements within the index range [ \e begin to \e end ).
* The other elements of this vector view remain unchanged. Whole vector view is assumed
* by default, i.e. when \e begin and \e end are set to zero.
*
* \tparam Type tells the prefix sum type - either \e Inclusive of \e Exclusive.
* \tparam FlagsArray is an array type describing beginnings of the segments.
*
* \param flags is an array having `1` at the beginning of each segment and `0` on any other position
* \param begin beginning of the index range
* \param end end of the index range.
*/
template
<
Algorithms
::
ScanType
Type
=
Algorithms
::
ScanType
::
Inclusive
,
template
<
Algorithms
::
ScanType
Type
=
Algorithms
::
ScanType
::
Inclusive
,
typename
FlagsArray
>
typename
FlagsArray
>
void
segmentedPrefixSum
(
FlagsArray
&
flags
,
IndexType
begin
=
0
,
IndexType
end
=
0
);
void
segmentedPrefixSum
(
FlagsArray
&
flags
,
IndexType
begin
=
0
,
IndexType
end
=
0
);
/**
* \brief Computes prefix sum of the vector expression.
*
* Computes prefix sum for elements within the index range [ \e begin to \e end ).
* The other elements of this vector remain unchanged. Whole vector expression is assumed
* by default, i.e. when \e begin and \e end are set to zero.
*
* \tparam Type tells the prefix sum type - either \e Inclusive of \e Exclusive.
* \tparam VectorExpression is the vector expression.
*
* \param expression is the vector expression.
* \param begin beginning of the index range
* \param end end of the index range.
*/
template
<
Algorithms
::
ScanType
Type
=
Algorithms
::
ScanType
::
Inclusive
,
template
<
Algorithms
::
ScanType
Type
=
Algorithms
::
ScanType
::
Inclusive
,
typename
VectorExpression
>
typename
VectorExpression
>
void
prefixSum
(
const
VectorExpression
&
expression
,
IndexType
begin
=
0
,
IndexType
end
=
0
);
void
prefixSum
(
const
VectorExpression
&
expression
,
IndexType
begin
=
0
,
IndexType
end
=
0
);
/**
* \brief Computes segmented prefix sum of a vector expression.
*
* Computes segmented prefix sum for elements within the index range [ \e begin to \e end ).
* The other elements of this vector remain unchanged. Whole vector expression is assumed
* by default, i.e. when \e begin and \e end are set to zero.
*
* \tparam Type tells the prefix sum type - either \e Inclusive of \e Exclusive.
* \tparam VectorExpression is the vector expression.
* \tparam FlagsArray is an array type describing beginnings of the segments.
*
* \param expression is the vector expression.
* \param flags is an array having `1` at the beginning of each segment and `0` on any other position
* \param begin beginning of the index range
* \param end end of the index range.
*/
template
<
Algorithms
::
ScanType
Type
=
Algorithms
::
ScanType
::
Inclusive
,
template
<
Algorithms
::
ScanType
Type
=
Algorithms
::
ScanType
::
Inclusive
,
typename
VectorExpression
,
typename
VectorExpression
,
typename
FlagsArray
>
typename
FlagsArray
>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment