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
48b7a7e0
There was an error fetching the commit references. Please try again later.
Commit
48b7a7e0
authored
5 years ago
by
Tomáš Oberhuber
Browse files
Options
Downloads
Patches
Plain Diff
Fixed ArrayViewExample to run in parallel with other examples.
parent
bea4d91e
No related branches found
No related tags found
1 merge request
!41
Tutorials
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Documentation/Examples/Containers/ArrayViewExample.cpp
+18
-18
18 additions, 18 deletions
Documentation/Examples/Containers/ArrayViewExample.cpp
with
18 additions
and
18 deletions
Documentation/Examples/Containers/ArrayViewExample.cpp
+
18
−
18
View file @
48b7a7e0
...
...
@@ -14,60 +14,60 @@ void arrayViewExample()
using
ArrayType
=
Containers
::
Array
<
int
,
Device
>
;
using
IndexType
=
typename
ArrayType
::
IndexType
;
using
ViewType
=
Containers
::
ArrayView
<
int
,
Device
>
;
ArrayType
_
a1
(
size
),
_
a2
(
size
);
ViewType
a1
=
_
a1
.
getView
();
ViewType
a2
=
_
a2
.
getView
();
ArrayType
a1
(
size
),
a2
(
size
);
ViewType
a1
_view
=
a1
.
getView
();
ViewType
a2
_view
=
a2
.
getView
();
/***
* You may initiate the array view using setElement
*/
for
(
int
i
=
0
;
i
<
size
;
i
++
)
a1
.
setElement
(
i
,
i
);
a1
_view
.
setElement
(
i
,
i
);
/***
* You may also assign value to all array view elements ...
*/
a2
=
0
;
a2
_view
=
0
;
/***
* Simple array view values checks can be done as follows ...
*/
if
(
a1
.
containsValue
(
1
)
)
if
(
a1
_view
.
containsValue
(
1
)
)
std
::
cout
<<
"a1 contains value 1."
<<
std
::
endl
;
if
(
a1
.
containsValue
(
size
)
)
if
(
a1
_view
.
containsValue
(
size
)
)
std
::
cout
<<
"a1 contains value "
<<
size
<<
"."
<<
std
::
endl
;
if
(
a1
.
containsOnlyValue
(
0
)
)
if
(
a1
_view
.
containsOnlyValue
(
0
)
)
std
::
cout
<<
"a2 contains only value 0."
<<
std
::
endl
;
/***
* More efficient way of array view elements manipulation is with the lambda functions
*/
ArrayType
_
a3
(
size
);
ViewType
a3
=
_
a3
.
getView
();
ArrayType
a3
(
size
);
ViewType
a3
_view
=
a3
.
getView
();
auto
f1
=
[]
__cuda_callable__
(
IndexType
i
)
->
int
{
return
2
*
i
;
};
a3
.
evaluate
(
f1
);
a3
_view
.
evaluate
(
f1
);
for
(
int
i
=
0
;
i
<
size
;
i
++
)
if
(
a3
.
getElement
(
i
)
!=
2
*
i
)
if
(
a3
_view
.
getElement
(
i
)
!=
2
*
i
)
std
::
cerr
<<
"Something is wrong!!!"
<<
std
::
endl
;
/***
* You may swap array view data with the swap method.
*/
a1
.
swap
(
a3
);
a1
_view
.
swap
(
a3
_view
);
/***
* You may save it to file and load again
*/
File
(
"a1.tnl"
,
std
::
ios_base
::
out
)
<<
a1
;
File
(
"a1.tnl"
,
std
::
ios_base
::
in
)
>>
a2
;
File
(
"a1
_view
.tnl"
,
std
::
ios_base
::
out
)
<<
a1
_view
;
File
(
"a1
_view
.tnl"
,
std
::
ios_base
::
in
)
>>
a2
_view
;
std
::
remove
(
"a1.tnl"
);
std
::
remove
(
"a1
_view
.tnl"
);
if
(
a2
!=
a1
)
if
(
a2
_view
!=
a1
_view
)
std
::
cerr
<<
"Something is wrong!!!"
<<
std
::
endl
;
std
::
cout
<<
"a2 = "
<<
a2
<<
std
::
endl
;
std
::
cout
<<
"a2
_view
= "
<<
a2
_view
<<
std
::
endl
;
}
int
main
()
...
...
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