@@ -244,6 +244,12 @@ cdef class ObliqueTree(Tree):
244244 self .proj_vec_weights[node_id] = deref(deref(oblique_split_node).proj_vec_weights)
245245 self .proj_vec_indices[node_id] = deref(deref(oblique_split_node).proj_vec_indices)
246246 return 1
247+
248+ cpdef DTYPE_t compute_feature_value(self , object X, SIZE_t node_id):
249+ cdef const DTYPE_t[:] X_vector = X
250+ cdef Node* node = & self .nodes[node_id]
251+ feature_value = self ._compute_feature(X_vector, node, node_id)
252+ return feature_value
247253
248254 cdef DTYPE_t _compute_feature(self , const DTYPE_t[:] X_ndarray, Node * node, SIZE_t node_id) nogil:
249255 """ Compute feature from a given data matrix, X.
@@ -254,11 +260,19 @@ cdef class ObliqueTree(Tree):
254260 cdef vector[DTYPE_t] proj_vec_weights
255261 cdef vector[SIZE_t] proj_vec_indices
256262 cdef DTYPE_t proj_feat = 0.0
263+ cdef DTYPE_t weight = 0.0
264+ cdef SIZE_t j = 0
265+ cdef SIZE_t n_projections = proj_vec_indices.size()
257266
258267 # compute projection of the data based on trained tree
259268 proj_vec_weights = self .proj_vec_weights[node_id]
260269 proj_vec_indices = self .proj_vec_indices[node_id]
261- for j in range (proj_vec_indices.size()):
262- proj_feat += X_ndarray[proj_vec_indices[j]] * proj_vec_weights[j]
270+ for j in range (n_projections):
271+ weight = proj_vec_weights[j]
272+
273+ # skip a multiplication step if there is nothing to be done
274+ if weight == 0 :
275+ continue
276+ proj_feat += X_ndarray[proj_vec_indices[j]] * weight
263277
264278 return proj_feat
0 commit comments