Commit 63fe23a1 authored by André Anjos's avatar André Anjos 💬

Always returns numpy.ndarray, never blitz arrays

parent b97c952a
Subproject commit 224853f72bee58d9dc075ee8fc3f228c89124392
Subproject commit 0d673b4ee902a13de8806236410e1aabb7188898
Subproject commit c5ea8b026b195c0da1da4b090d5061dcbceb59f2
Subproject commit ed54add3001e4608cc7474dcf9a7319e67afc43f
/**
* @author Andre Anjos <andre.anjos@idiap.ch>
* @date Wed 11 Dec 08:42:53 2013
*
* @brief Some C++ tricks to make our life dealing with Python references a bit
* easier
*/
#include <Python.h>
#include <memory>
/**
* Calls Py_DECREF(x) on the input object x. Usage pattern:
*
* PyObject* x = ... // builds x with a new python reference
* auto protected_x = make_safe(x);
*
* After this point, no need to worry about DECREF'ing x anymore.
* You can still use `x' inside your code, or protected_x.get().
*/
template <typename T> std::shared_ptr<T> make_safe(T* o) {
return std::shared_ptr<T>(o, [&](T* p){Py_DECREF(p);});
}
/**
* Calls Py_XDECREF(x) on the input object x. Usage pattern:
*
* PyObject* x = ... // builds x with a new python reference, x may be NULL
* auto protected_x = make_xsafe(x);
*
* After this point, no need to worry about XDECREF'ing x anymore.
* You can still use `x' inside your code, or protected_x.get(). Note
* `x' may be NULL with this method.
*/
template <typename T> std::shared_ptr<T> make_xsafe(T* o) {
return std::shared_ptr<T>(o, [&](T* p){Py_XDECREF(p);});
}
This diff is collapsed.
......@@ -55,8 +55,7 @@ def roc(negatives, positives, npoints=100, CAR=False, **kwargs):
raise
from . import roc as calc
import numpy
out = numpy.array(calc(negatives, positives, npoints))
out = calc(negatives, positives, npoints)
if not CAR:
return mpl.plot(100.0*out[0,:], 100.0*out[1,:], **kwargs)
else:
......@@ -174,10 +173,8 @@ def epc(dev_negatives, dev_positives, test_negatives, test_positives,
raise
from . import epc as calc
import numpy
out = numpy.array(calc(dev_negatives, dev_positives,
test_negatives, test_positives, npoints))
out = calc(dev_negatives, dev_positives, test_negatives, test_positives, npoints)
return mpl.plot(out[0,:], 100.0*out[1,:], **kwargs)
def det(negatives, positives, npoints=100, axisfontsize='x-small', **kwargs):
......@@ -293,9 +290,8 @@ def det(negatives, positives, npoints=100, axisfontsize='x-small', **kwargs):
# this will actually do the plotting
from . import det as calc
from . import ppndf
import numpy
out = numpy.array(calc(negatives, positives, npoints))
out = calc(negatives, positives, npoints)
retval = mpl.plot(out[0,:], out[1,:], **kwargs)
# now the trick: we must plot the tick marks by hand using the PPNDF method
......
......@@ -96,17 +96,17 @@ def test_indexing():
# If the threshold is minimum, we should have all positive samples
# correctly classified and none of the negative samples correctly
# classified.
assert numpy.array(correctly_classified_positives(positives, minimum-0.1)).all()
assert not numpy.array(correctly_classified_negatives(negatives, minimum-0.1)).any()
assert correctly_classified_positives(positives, minimum-0.1).all()
assert not correctly_classified_negatives(negatives, minimum-0.1).any()
# The inverse is true if the threshold is a bit above the maximum.
assert not numpy.array(correctly_classified_positives(positives, maximum+0.1)).any()
assert numpy.array(correctly_classified_negatives(negatives, maximum+0.1)).all()
assert not correctly_classified_positives(positives, maximum+0.1).any()
assert correctly_classified_negatives(negatives, maximum+0.1).all()
# If the threshold separates the sets, than all should be correctly
# classified.
assert numpy.array(correctly_classified_positives(positives, 3)).all()
assert numpy.array(correctly_classified_negatives(negatives, 3)).all()
assert correctly_classified_positives(positives, 3).all()
assert correctly_classified_negatives(negatives, 3).all()
def test_thresholding():
......@@ -115,7 +115,7 @@ def test_thresholding():
def count(array, value=True):
"""Counts occurrences of a certain value in an array"""
return list(numpy.array(array) == value).count(True)
return list(array == value).count(True)
# This example will demonstrate and check the use of eer_threshold() to
# calculate the threshold that minimizes the EER.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment