Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dune-istl
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
Show more breadcrumbs
Core Modules
dune-istl
Commits
c921e1fa
Commit
c921e1fa
authored
7 years ago
by
Martin Nolte
Browse files
Options
Downloads
Patches
Plain Diff
[blockvector] enhance method __getitem__ to work on sequences
parent
3c2deb2b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!369
Feature/add python bindings
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bvector.hh
+27
-7
27 additions, 7 deletions
bvector.hh
with
27 additions
and
7 deletions
bvector.hh
+
27
−
7
View file @
c921e1fa
...
...
@@ -66,6 +66,22 @@ namespace Dune
copy
(
static_cast
<
const
char
*
>
(
info
.
ptr
),
info
.
shape
.
data
(),
info
.
strides
.
data
(),
v
);
}
// blockVectorGetItem
// ------------------
template
<
class
BlockVector
>
inline
static
pybind11
::
object
blockVectorGetItem
(
const
pybind11
::
object
&
vObj
,
BlockVector
&
v
,
typename
BlockVector
::
size_type
index
)
{
auto
pos
=
v
.
find
(
index
);
if
(
pos
==
v
.
end
()
)
throw
pybind11
::
index_error
(
"Index "
+
std
::
to_string
(
index
)
+
" does not exist in block vector."
);
pybind11
::
object
result
=
pybind11
::
cast
(
*
pos
,
pybind11
::
return_value_policy
::
reference
);
pybind11
::
detail
::
keep_alive_impl
(
result
,
vObj
);
return
result
;
}
}
// namespace detail
...
...
@@ -98,13 +114,17 @@ namespace Dune
cls
.
def
(
"copy"
,
[]
(
const
BlockVector
&
self
)
{
return
new
BlockVector
(
self
);
}
);
cls
.
def
(
"__getitem__"
,
[]
(
BlockVector
&
self
,
size_type
index
)
->
block_type
&
{
auto
pos
=
self
.
find
(
index
);
if
(
pos
!=
self
.
end
()
)
return
*
pos
;
else
throw
pybind11
::
index_error
();
},
pybind11
::
return_value_policy
::
reference
,
pybind11
::
keep_alive
<
0
,
1
>
()
);
cls
.
def
(
"__getitem__"
,
[]
(
const
pybind11
::
object
&
self
,
size_type
index
)
{
return
detail
::
blockVectorGetItem
(
self
,
pybind11
::
cast
<
BlockVector
&
>
(
self
),
index
);
}
);
cls
.
def
(
"__getitem__"
,
[]
(
const
pybind11
::
object
&
self
,
pybind11
::
iterable
index
)
{
BlockVector
&
v
=
pybind11
::
cast
<
BlockVector
&
>
(
self
);
pybind11
::
tuple
refs
(
pybind11
::
len
(
index
)
);
std
::
size_t
j
=
0
;
for
(
pybind11
::
handle
i
:
index
)
refs
[
j
++
]
=
detail
::
blockVectorGetItem
(
self
,
v
,
pybind11
::
cast
<
size_type
>
(
i
)
);
return
refs
;
}
);
cls
.
def
(
"__setitem__"
,
[]
(
BlockVector
&
self
,
size_type
index
,
block_type
value
)
{
auto
pos
=
self
.
find
(
index
);
...
...
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