Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import numpy as np

from ._clean_x import unify_columns, categorical_encode
from ._clean_x import categorical_encode, unify_columns
from ._native import Native

_log = logging.getLogger(__name__)
Expand Down
23 changes: 15 additions & 8 deletions python/interpret-core/interpret/utils/_native.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import platform
import struct
import sys
import math
from contextlib import AbstractContextManager
from math import prod

Expand All @@ -17,6 +16,14 @@
_log = logging.getLogger(__name__)


def _boolebm(val):
"""Convert `bool` to `np.int32` used by libebm to represents `bool`."""
if not isinstance(val, (bool, np.bool_)):
msg = f"Native EBM functions expect boolean, got f{type(val)}"
raise TypeError(msg)
return np.int32(val)


class Native:
# see notes in libebm.h on the maximum representable int64 in float64 format
FLOAT64_TO_INT64_MAX = 9223372036854774784
Expand Down Expand Up @@ -574,7 +581,7 @@ def cut_quantile(self, X_col, min_samples_bin, is_rounded, max_cuts):
X_col.shape[0],
Native._make_pointer(X_col, np.float64),
min_samples_bin,
is_rounded,
_boolebm(is_rounded),
ct.byref(count_cuts),
Native._make_pointer(cuts, np.float64),
)
Expand Down Expand Up @@ -657,9 +664,9 @@ def measure_dataset_header(self, n_features, n_weights, n_targets):
def measure_feature(self, n_bins, is_missing, is_unseen, is_nominal, bin_indexes):
n_bytes = self._unsafe.MeasureFeature(
n_bins,
is_missing,
is_unseen,
is_nominal,
_boolebm(is_missing),
_boolebm(is_unseen),
_boolebm(is_nominal),
len(bin_indexes),
Native._make_pointer(bin_indexes, np.int64),
)
Expand Down Expand Up @@ -711,9 +718,9 @@ def fill_feature(
):
return_code = self._unsafe.FillFeature(
n_bins,
is_missing,
is_unseen,
is_nominal,
_boolebm(is_missing),
_boolebm(is_unseen),
_boolebm(is_nominal),
len(bin_indexes),
Native._make_pointer(bin_indexes, np.int64),
dataset.nbytes,
Expand Down
Loading