Compare commits

...
Author SHA1 Message Date
Celine Mercier 1a2d552567 Abandoned beginning of functions to apply comparisons to whole columns
(not worth it for now as comparisons are already fast enough)
2016-05-04 13:39:55 +02:00
6 changed files with 74 additions and 22 deletions
+20 -20
View File
@@ -118,6 +118,9 @@ cdef class OBIDMS_column :
lines_used = (self.pointer)[0].header.lines_used
for line_nb in range(lines_used):
yield self.get_line(line_nb)
def __richcmp__(self, object value, int comp):
return self.compare(value, comp)
cpdef update_pointer(self):
self.pointer = <OBIDMS_column_p*> obi_view_get_pointer_on_column_in_view(self.view, str2bytes(self.column_name))
@@ -240,14 +243,14 @@ cdef class OBIView :
def __init__(self, OBIDMS dms, str view_name, bint new=False, object view_to_clone=None, list line_selection=None, str comments=""):
cdef Obiview_p view = NULL
cdef int i
cdef list col_list
cdef str col_name
cdef OBIDMS_column column
cdef OBIDMS_column_p column_p
cdef Obiview_p view = NULL
cdef int i
cdef list col_list
cdef str col_name
cdef OBIDMS_column column
cdef OBIDMS_column_p column_p
cdef OBIDMS_column_header_p header
cdef index_t* line_selection_p
cdef index_t* line_selection_p
self.dms = dms
@@ -295,11 +298,8 @@ cdef class OBIView :
def __repr__(self) :
cdef str s
cdef OBIDMS_column column
cdef OBIDMS_column_p column_p
s = self.name
s = s + ", " + self.comments + ", " + str(self.pointer.line_count) + " lines\n"
s = str(self.name) + ", " + str(self.comments) + ", " + str(self.pointer.line_count) + " lines\n"
for column_name in self.columns :
s = s + self.columns[column_name].__repr__() + '\n'
return s
@@ -336,7 +336,7 @@ cdef class OBIView :
str indexer_name="",
str comments="",
bint create=True
) :
) :
cdef bytes column_name_b
cdef bytes elements_names_b
@@ -646,14 +646,14 @@ cdef class OBIDMS :
cpdef dict read_views(self) : # TODO function that prints the dic nicely and function that prints 1 view nicely. Add column type in col ref
cdef Obiviews_infos_all_p all_views_p
cdef Obiview_infos_p view_p
cdef Column_reference_p column_refs
cdef int nb_views
cdef int i, j
cdef str view_name
cdef str column_name
cdef dict views
cdef bytes name_b
cdef Obiview_infos_p view_p
cdef Column_reference_p column_refs
cdef int nb_views
cdef int i, j
cdef str view_name
cdef str column_name
cdef dict views
cdef bytes name_b
views = {}
all_views_p = obi_read_view_infos(self.pointer)
@@ -1,12 +1,13 @@
#cython: language_level=3
from .capi.obitypes cimport index_t
from .capi.obitypes cimport index_t, obifloat_t
from ._obidms cimport OBIDMS_column, OBIDMS_column_multi_elts
cdef class OBIDMS_column_float(OBIDMS_column):
cpdef object get_line(self, index_t line_nb)
cpdef set_line(self, index_t line_nb, object value)
cpdef list bool_list_from_compare(self, obifloat_t value, int comp)
cdef class OBIDMS_column_multi_elts_float(OBIDMS_column_multi_elts):
cpdef object get_item(self, index_t line_nb, str element_name)
@@ -5,7 +5,9 @@ from .capi.obiview cimport obi_column_get_obifloat_with_elt_name_in_view, \
obi_column_set_obifloat_with_elt_name_in_view, \
obi_column_set_obifloat_with_elt_idx_in_view
from .capi.obierrno cimport obi_errno
from .capi.obitypes cimport OBIFloat_NA, obifloat_t
from .capi.obitypes cimport OBIFloat_NA, obifloat_t, byte_t
from .capi.obidmscolumn cimport obi_float_column_greater_than # TODO need to be in view...
from obitools3.utils cimport str2bytes
@@ -30,6 +32,22 @@ cdef class OBIDMS_column_float(OBIDMS_column):
if obi_column_set_obifloat_with_elt_idx_in_view(self.view, (self.pointer)[0], line_nb, 0, <obifloat_t> value) < 0:
raise Exception("Problem setting a value in a column")
cpdef list bool_list_from_compare(self, obifloat_t value, int comp):
cdef list result_p
cdef byte_t* result_c
cdef int i
result_p = []
if comp == 4 :
result_c = obi_float_get_bool_list_from_compare_in_view(self.view, (self.pointer)[0], value, GREATER_THAN)
else :
raise Exception("Comparison not handled")
for i in range(self.get_nb_lines_used()) :
result_p.append(<int> result_c[i])
print(result_p[i])
free(result_c)
return result_p
cdef class OBIDMS_column_multi_elts_float(OBIDMS_column_multi_elts):
+24
View File
@@ -63,3 +63,27 @@ obifloat_t obi_column_get_obifloat_with_elt_name(OBIDMS_column_p column, index_t
return obi_column_get_obifloat_with_elt_idx(column, line_nb, element_idx);
}
small_bool_t* obi_float_get_bool_list_from_compare(OBIDMS_column_p column, obifloat_t value, OBIDMS_column_p line_selection, Comp_type_t comp) // TODO openMP, get index or bool list
{
small_bool_t* bool_vector;
index_t i;
index_t nb_elements;
nb_elements = (column->header)->lines_used * (column->header)->nb_elements_per_line; // TODO how are vector lines handled?
bool_vector = (small_bool_t*) malloc(nb_elements * sizeof(small_bool_t));
// TODO check if line_selection == NULL
// Check and case comps
if (comp == GREATER_THAN)
{
for (i=0; i<nb_elements; i++)
{
bool_vector[i] = (*(((obifloat_t*) (column->data)) + i)) > value; // TODO get through function, depends on vector lines problem
}
}
return bool_vector;
}
+3
View File
@@ -95,5 +95,8 @@ int obi_column_set_obifloat_with_elt_name(OBIDMS_column_p column, index_t line_n
obifloat_t obi_column_get_obifloat_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name);
small_bool_t* obi_float_get_bool_list_from_compare(OBIDMS_column_p column, obifloat_t value, OBIDMS_column_p line_selection, Comp_type_t comp);
#endif /* OBIDMSCOLUMN_FLOAT_H_ */
+6
View File
@@ -1401,6 +1401,12 @@ obifloat_t obi_column_get_obifloat_with_elt_name_in_view(Obiview_p view, OBIDMS_
return obi_column_get_obifloat_with_elt_idx_in_view(view, column, line_nb, element_idx);
}
small_bool_t* obi_float_get_bool_list_from_compare_in_view(Obiview_p view, OBIDMS_column_p column, obifloat_t value, Comp_type_t comp)
{
return obi_float_get_bool_list_from_compare(view, column, value, view->line_selection, comp);
}
/****************************************/