Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
kwant
tinyarray
Commits
35434ab5
Commit
35434ab5
authored
May 26, 2016
by
Christoph Groth
Browse files
fix small style issues
parent
0f717e83
Pipeline
#449
passed with stage
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/array.cc
View file @
35434ab5
// Copyright 2012-201
5
Tinyarray authors.
// Copyright 2012-201
6
Tinyarray authors.
//
// This file is part of Tinyarray. It is subject to the license terms in the
// file LICENSE.rst found in the top-level directory of this distribution and
...
...
@@ -11,7 +11,6 @@
#include
<cstddef>
#include
<sstream>
#include
<limits>
#include
<assert.h>
#include
"array.hh"
#include
"arithmetic.hh"
#include
"functions.hh"
...
...
@@ -920,8 +919,8 @@ bool compare_scalar(const int op, const T a, const T b) {
case
Py_LT
:
return
a
<
b
;
case
Py_GT
:
return
a
>
b
;
default:
assert
(
false
);
//
i
f we get here something is very wrong
return
false
;
//
s
top the compiler complaining
assert
(
false
);
//
I
f we get here something is very wrong
.
return
false
;
//
S
top the compiler complaining
.
}
}
...
...
@@ -931,15 +930,15 @@ bool compare_scalar<Complex>(const int op, const Complex a, const Complex b) {
switch
(
op
){
case
Py_EQ
:
return
a
==
b
;
case
Py_NE
:
return
a
!=
b
;
//
t
his function is never called in a context where
// the following code path is run -- fall through
//
T
his function is never called in a context where
// the following code path is run -- fall through
.
case
Py_LE
:
case
Py_GT
:
case
Py_LT
:
case
Py_GE
:
default:
assert
(
false
);
return
false
;
//
s
top the compiler complaining
return
false
;
//
S
top the compiler complaining
.
}
}
...
...
@@ -951,23 +950,19 @@ bool compare_data(int op, PyObject *a_, PyObject *b_, size_t size)
assert
(
Array
<
T
>::
check_exact
(
b_
));
Array
<
T
>
*
b
=
(
Array
<
T
>*
)
b_
;
const
T
*
data_a
=
a
->
data
();
const
T
*
data_b
=
b
->
data
();
//
s
equences are ordered the same as their first differing elements, see:
//
S
equences are ordered the same as their first differing elements, see:
// https://docs.python.org/2/reference/expressions.html#not-in
// comparison for "multidimensional" sequences is identical to comparing
// the flattened sequences when they have the same shape (the present case)
// the flattened sequences when they have the same shape (the present case)
.
size_t
i
=
0
;
for
(;
i
<
size
;
++
i
)
if
(
data_a
[
i
]
!=
data_b
[
i
])
break
;
//
a
ny of these operations should return true when objects are equal
//
A
ny of these operations should return true when objects are equal
.
if
(
i
==
size
)
return
((
op
==
Py_EQ
)
||
(
op
==
Py_LE
)
||
(
op
==
Py_GE
));
// encapsulate this into a function to handle the COMPLEX case
return
compare_scalar
<
T
>
(
op
,
data_a
[
i
],
data_b
[
i
]);
}
// don't generate dispatch table for COMPLEX datatype as it will never be used
// in `rich_compare` (COMPLEX is unorderable), and the compiler complains about
// generating `compare_scalar<complex>` because some operations are undefined
bool
(
*
compare_data_dtable
[])(
int
,
PyObject
*
,
PyObject
*
,
size_t
)
=
DTYPE_DISPATCH
(
compare_data
);
...
...
@@ -984,10 +979,10 @@ PyObject *richcompare(PyObject *a, PyObject *b, int op)
PyObject
*
result
;
const
bool
equality_comparison
=
(
op
==
Py_EQ
||
op
==
Py_NE
);
//
s
hort circuit when we are comparing the same object
//
S
hort circuit when we are comparing the same object
.
bool
equal
=
(
a
==
b
);
if
(
equal
)
{
//
a
ny of these operations should return true when objects are equal
//
A
ny of these operations should return true when objects are equal
equal
=
(
op
==
Py_EQ
)
||
(
op
==
Py_GE
)
||
(
op
==
Py_LE
);
result
=
equal
?
Py_True
:
Py_False
;
goto
done
;
...
...
@@ -996,8 +991,8 @@ PyObject *richcompare(PyObject *a, PyObject *b, int op)
Dtype
dtype
;
if
(
coerce_to_arrays
(
&
a
,
&
b
,
&
dtype
)
<
0
)
return
0
;
//
o
bviate the need for `compare_scalar<Complex` to
// handle the case of an undefined comparison
//
O
bviate the need for `compare_scalar<Complex` to
// handle the case of an undefined comparison
.
if
(
dtype
==
COMPLEX
&&
!
equality_comparison
)
{
PY2_RAISE_TYPEERROR
(
"unorderable type: complex()"
);
result
=
Py_NotImplemented
;
...
...
@@ -1009,13 +1004,13 @@ PyObject *richcompare(PyObject *a, PyObject *b, int op)
reinterpret_cast
<
Array_base
*>
(
a
)
->
ndim_shape
(
&
ndim_a
,
&
shape_a
);
reinterpret_cast
<
Array_base
*>
(
b
)
->
ndim_shape
(
&
ndim_b
,
&
shape_b
);
// TODO:
e
nable array comparisons between arrays of differing dimensions
// TODO:
E
nable array comparisons between arrays of differing dimensions
.
if
(
ndim_a
!=
ndim_b
)
{
if
(
equality_comparison
)
{
goto
equality_then_done
;
}
else
{
PY2_RAISE_TYPEERROR
(
"
u
norderable type: only arrays with"
"the same shape can be ordered"
);
PY2_RAISE_TYPEERROR
(
"
U
norderable type: only arrays with"
"the same shape can be ordered
.
"
);
result
=
Py_NotImplemented
;
goto
decref_then_done
;
}
...
...
@@ -1025,20 +1020,20 @@ PyObject *richcompare(PyObject *a, PyObject *b, int op)
if
(
equality_comparison
)
{
goto
equality_then_done
;
}
else
{
PY2_RAISE_TYPEERROR
(
"
u
norderable type: only arrays with"
"the same shape can be ordered"
);
PY2_RAISE_TYPEERROR
(
"
U
norderable type: only arrays with"
"the same shape can be ordered
.
"
);
result
=
Py_NotImplemented
;
goto
decref_then_done
;
}
}
}
//
a
ctually compare the data
//
A
ctually compare the data
.
equal
=
compare_data_dtable
[
int
(
dtype
)](
op
,
a
,
b
,
calc_size
(
ndim_a
,
shape_a
));
result
=
equal
?
Py_True
:
Py_False
;
goto
decref_then_done
;
//
n
on error-path exit points from this function
//
N
on error-path exit points from this function
equality_then_done:
result
=
((
op
==
Py_EQ
)
==
equal
)
?
Py_True
:
Py_False
;
decref_then_done:
...
...
Write
Preview
Supports
Markdown
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