Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
xerus
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
40
Issues
40
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
xerus
xerus
Commits
68a62241
Commit
68a62241
authored
May 23, 2017
by
Ben Huber
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
export misc::generic_error to python (closes
#199
)
parent
4a5f5726
Pipeline
#728
passed with stages
in 8 minutes and 9 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
95 additions
and
7 deletions
+95
-7
doc/new/_posts/2000-11-28-indices.md
doc/new/_posts/2000-11-28-indices.md
+2
-2
src/unitTests/indices.cxx
src/unitTests/indices.cxx
+81
-0
src/unitTests/tensor.cxx
src/unitTests/tensor.cxx
+1
-0
src/xerus/python/python.cpp
src/xerus/python/python.cpp
+11
-5
No files found.
doc/new/_posts/2000-11-28-indices.md
View file @
68a62241
...
...
@@ -77,8 +77,8 @@ __tabsMid
~~~
python
try
:
c
(
j
)
<<
A
(
i
,
j
)
*
b
(
j
)
# runtime error!
except
xerus
.
misc
.
generic_error
as
err
:
print
(
"something went wrong:"
,
err
.
what
()
)
except
xerus
.
generic_error
as
err
:
print
(
"something went wrong:"
,
err
)
~~~
__
tabsEnd
...
...
src/unitTests/indices.cxx
0 → 100644
View file @
68a62241
// Xerus - A General Purpose Tensor Library
// Copyright (C) 2014-2016 Benjamin Huber and Sebastian Wolf.
//
// Xerus is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License,
// or (at your option) any later version.
//
// Xerus is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with Xerus. If not, see <http://www.gnu.org/licenses/>.
//
// For further information on Xerus visit https://libXerus.org
// or contact us at contact@libXerus.org.
#include<xerus.h>
#include "../../include/xerus/test/test.h"
#include "../../include/xerus/misc/internal.h"
using
namespace
xerus
;
static
misc
::
UnitTest
failtest
(
"Index"
,
"invalid_spans"
,
[](){
#ifdef XERUS_DISABLE_RUNTIME_CHECKS
LOG
(
warning
,
"failtests skipped due to XERUS_DISABLE_RUNTIME_CHECKS"
);
#else
Index
i
,
j
;
Tensor
c
;
Tensor
A
=
Tensor
::
random
({
10
,
10
});
Tensor
b
=
Tensor
::
random
({
10
});
try
{
A
(
i
,
j
^
2
)
=
A
(
j
^
2
,
i
);
MTEST
(
false
,
"A(j^2,i) did not throw!"
);
}
catch
(
misc
::
generic_error
&
_e
)
{
TEST
(
true
);
}
catch
(...)
{
MTEST
(
false
,
"threw a wrong exception class!"
);
}
try
{
A
(
i
,
j
)
=
A
(
j
,
i
&
0
);
MTEST
(
false
,
"A(j^2,i) did not throw!"
);
}
catch
(
misc
::
generic_error
&
_e
)
{
TEST
(
true
);
}
catch
(...)
{
MTEST
(
false
,
"threw a wrong exception class!"
);
}
try
{
A
(
i
,
j
)
=
A
(
j
,
i
/
1
);
MTEST
(
false
,
"A(j^2,i) did not throw!"
);
}
catch
(
misc
::
generic_error
&
_e
)
{
TEST
(
true
);
}
catch
(...)
{
MTEST
(
false
,
"threw a wrong exception class!"
);
}
try
{
A
(
i
,
j
)
=
A
(
j
,
i
/
3
);
MTEST
(
false
,
"A(j^2,i) did not throw!"
);
}
catch
(
misc
::
generic_error
&
_e
)
{
TEST
(
true
);
}
catch
(...)
{
MTEST
(
false
,
"threw a wrong exception class!"
);
}
try
{
c
(
j
)
=
A
(
i
,
j
)
*
b
(
j
);
MTEST
(
false
,
"c(j)=... did not throw!"
);
}
catch
(
misc
::
generic_error
&
_e
)
{
TEST
(
true
);
}
catch
(...)
{
MTEST
(
false
,
"threw a wrong exception class!"
);
}
#endif
});
src/unitTests/tensor.cxx
View file @
68a62241
...
...
@@ -288,3 +288,4 @@ static misc::UnitTest tensor_sparse_dense("Tensor", "Sparse_Dense_Conversions",
});
src/xerus/python/python.cpp
View file @
68a62241
...
...
@@ -1206,9 +1206,15 @@ BOOST_PYTHON_MODULE(xerus) {
// identity returns the cpp name to a python object
// def("identity", identity_);
// the following is probably not necessary because generic_error inherits from std::exception
// register_exception_translator<misc::generic_error>([](const misc::generic_error &_e){
// LOG(pydebug, "custom exception handler called with " << _e.what());
// PyErr_SetString(PyExc_UserWarning, _e.what());
// });
def
(
"xethrow"
,
+
[](){
XERUS_THROW
(
misc
::
generic_error
()
<<
misc
::
get_call_stack
());});
// translate all exceptions thrown inside xerus to own python exception class
static
char
fully_qualified_gen_error_name
[]
=
"xerus.generic_error"
;
static
PyObject
*
py_gen_error
=
PyErr_NewException
(
fully_qualified_gen_error_name
,
PyExc_Exception
,
0
);
py
::
scope
().
attr
(
"generic_error"
)
=
py
::
handle
<>
(
py
::
borrowed
(
py_gen_error
));
register_exception_translator
<
misc
::
generic_error
>
([](
const
misc
::
generic_error
&
_e
){
LOG
(
pydebug
,
"custom exception handler called with "
<<
_e
.
what
());
PyErr_SetString
(
py_gen_error
,
_e
.
what
());
});
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment