Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dlib
Commits
c88568fc
Commit
c88568fc
authored
Feb 11, 2016
by
Davis King
Browse files
Added asserts to catch a common user error.
parent
d9638f22
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
0 deletions
+21
-0
dlib/matrix/matrix.h
dlib/matrix/matrix.h
+13
-0
dlib/matrix/matrix_abstract.h
dlib/matrix/matrix_abstract.h
+8
-0
No files found.
dlib/matrix/matrix.h
View file @
c88568fc
...
@@ -1435,6 +1435,9 @@ namespace dlib
...
@@ -1435,6 +1435,9 @@ namespace dlib
}
}
else
else
{
{
DLIB_ASSERT
(
size
()
==
0
,
"
\t
const matrix::operator+=(m)"
<<
"
\n\t
You are trying to add two matrices that have incompatible dimensions."
);
*
this
=
m
;
*
this
=
m
;
}
}
return
*
this
;
return
*
this
;
...
@@ -1469,6 +1472,9 @@ namespace dlib
...
@@ -1469,6 +1472,9 @@ namespace dlib
}
}
else
else
{
{
DLIB_ASSERT
(
size
()
==
0
,
"
\t
const matrix::operator-=(m)"
<<
"
\n\t
You are trying to subtract two matrices that have incompatible dimensions."
);
*
this
=
-
m
;
*
this
=
-
m
;
}
}
return
*
this
;
return
*
this
;
...
@@ -1495,6 +1501,10 @@ namespace dlib
...
@@ -1495,6 +1501,10 @@ namespace dlib
}
}
else
else
{
{
DLIB_ASSERT
(
this
->
size
()
==
0
,
"
\t
const matrix::operator+=(m)"
<<
"
\n\t
You are trying to add two matrices that have incompatible dimensions."
);
set_size
(
m
.
nr
(),
m
.
nc
());
set_size
(
m
.
nr
(),
m
.
nc
());
for
(
long
i
=
0
;
i
<
size
;
++
i
)
for
(
long
i
=
0
;
i
<
size
;
++
i
)
data
(
i
)
=
m
.
data
(
i
);
data
(
i
)
=
m
.
data
(
i
);
...
@@ -1514,6 +1524,9 @@ namespace dlib
...
@@ -1514,6 +1524,9 @@ namespace dlib
}
}
else
else
{
{
DLIB_ASSERT
(
this
->
size
()
==
0
,
"
\t
const matrix::operator-=(m)"
<<
"
\n\t
You are trying to subtract two matrices that have incompatible dimensions."
);
set_size
(
m
.
nr
(),
m
.
nc
());
set_size
(
m
.
nr
(),
m
.
nc
());
for
(
long
i
=
0
;
i
<
size
;
++
i
)
for
(
long
i
=
0
;
i
<
size
;
++
i
)
data
(
i
)
=
-
m
.
data
(
i
);
data
(
i
)
=
-
m
.
data
(
i
);
...
...
dlib/matrix/matrix_abstract.h
View file @
c88568fc
...
@@ -492,6 +492,10 @@ namespace dlib
...
@@ -492,6 +492,10 @@ namespace dlib
/*!
/*!
requires
requires
- matrix_exp<EXP>::type == T
- matrix_exp<EXP>::type == T
- One of the following is true:
- nr() == m.nr() && nc() == m.nc()
- size() == 0
(i.e. this matrix must have matching dimensions or it must be empty)
ensures
ensures
- if (nr() == m.nr() && nc() == m.nc()) then
- if (nr() == m.nr() && nc() == m.nc()) then
- #(*this) == *this + m
- #(*this) == *this + m
...
@@ -509,6 +513,10 @@ namespace dlib
...
@@ -509,6 +513,10 @@ namespace dlib
/*!
/*!
requires
requires
- matrix_exp<EXP>::type == T
- matrix_exp<EXP>::type == T
- One of the following is true:
- nr() == m.nr() && nc() == m.nc()
- size() == 0
(i.e. this matrix must have matching dimensions or it must be empty)
ensures
ensures
- if (nr() == m.nr() && nc() == m.nc()) then
- if (nr() == m.nr() && nc() == m.nc()) then
- #(*this) == *this - m
- #(*this) == *this - m
...
...
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