Bouncer / bouncer / linear_sketches / LinearSketch.c
LinearSketch.c
Raw
/*******************************************************/
/*           Base linear sketch class                  */
/*******************************************************/
static void
LinearSketch_dealloc(LinearSketch *self)
{
    free(self->X);
    Py_TYPE(self)->tp_free((PyObject *) self);
}

static PyObject *
LinearSketch_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
    // initialize attributes to 0
    LinearSketch *self;
    self = (LinearSketch *) type->tp_alloc(type, 0);
    self->epsilon = 0; 
    self->delta = 0; 
    return (PyObject *) self;
}

static int
LinearSketch_init(LinearSketch *self, PyObject *args, PyObject *kwds) // add n as parameter?
{

    Py_ssize_t size = PyObject_Size(args); 
    if(size == 0){
        PyErr_BadArgument();
        return -1;
    } //if no arguments were passed 

    static char *kwlist[] = {"epsilon", "delta", NULL};
    // passing in arguments 
    if (!PyArg_ParseTupleAndKeywords(args, kwds, "ff", kwlist, &self->epsilon, &self->delta)){
        return -1;
    }
    // error check for epsilon val 
    if((self->epsilon >= 1) || (self->epsilon <= 0) ){
        PyErr_SetString(HyperParameterError, "epsilon must set between 0 and 1");
        return -1;
    } 
    // error check for delta val
    if((self->delta >= 1) || (self->delta <= 0)){
        PyErr_SetString(HyperParameterError, "delta must be set between 0 and 1");
        return -1;
    } 
    return 0; 
}