Skip to content

Commit

Permalink
Merge branch 'branch-0.17' into enh-add-qn-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dantegd authored Nov 16, 2020
2 parents 148f79c + 77da916 commit 0879167
Show file tree
Hide file tree
Showing 108 changed files with 4,872 additions and 1,871 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
- PR #3111: Adding Cython to Code Coverage
- PR #3129: Update notebooks README
- PR #3135: Add QuasiNewton tests
- PR #3040: Improved Array Conversion with CumlArrayDescriptor and Decorators
- PR #3134: Improving the Deprecation Message Formatting in Documentation

## Bug Fixes
- PR #3065: Refactoring prims metrics function names from camelcase to underscore format
Expand Down
Empty file removed docs/source/_static/EMPTY
Empty file.
87 changes: 87 additions & 0 deletions docs/source/_static/infoboxes.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/* This contains code with copyright by the scikit-learn project, subject to
the license in /thirdparty/LICENSES/LICENSE.scikit_learn */

/* info boxes */

div.topic {
padding: 0.5rem;
background-color: #eee;
margin-bottom: 1rem;
border-radius: 0.25rem;
border: 1px solid #CCC;
}

div.topic p {
margin-bottom: 0.25rem;
}

div.topic dd {
margin-bottom: 0.25rem;
}

p.topic-title {
font-weight: bold;
margin-bottom: 0.5rem;
}

div.topic > ul.simple {
margin-bottom: 0.25rem;
}

p.admonition-title {
margin-right: 0.5rem;
font-weight: bold;
display: inline;
}

p.admonition-title:after {
content: ":";
}

div.admonition p.admonition-title + p, div.deprecated p {
display: inline;
}

div.admonition, div.deprecated {
padding: 0.5rem;
border-radius: 0.5rem;
border: 1px solid #ddd;
margin-bottom: 1rem;
}

div.admonition {
background-color: #eee;
}

div.admonition p, div.admonition dl, div.admonition dd {
margin-bottom: 0
}

div.deprecated {
color: #b94a48;
background-color: #F3E5E5;
border: 1px solid #eed3d7;
}

div.seealso {
background-color: #FFFBE8;
border: 1px solid #fbeed5;
color: #AF8A4B;
}

div.versionchanged {
margin-top: 0.5rem;
padding: 0.5rem;
background-color: #FFFBE8;
border: 1px solid #fbeed5;
border-radius: 0.5rem;
}

div.versionchanged p {
margin-bottom: 0;
}

dt.label {
float: left;
padding-right: 0.5rem;
}
1 change: 1 addition & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@

def setup(app):
app.add_css_file('copybutton.css')
app.add_css_file('infoboxes.css')
app.add_css_file('params.css')
app.add_css_file('references.css')

Expand Down
2 changes: 1 addition & 1 deletion python/cuml/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@

# Output type configuration

global_output_type = 'input'
global_output_type = None

from cuml.common.memory_utils import set_global_output_type, using_output_type

Expand Down
3 changes: 2 additions & 1 deletion python/cuml/benchmark/datagen.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ def _convert_to_gpuarray(data, order='F'):
gs = cudf.Series.from_pandas(data)
return cuda.as_cuda_array(gs)
else:
return input_utils.input_to_dev_array(data, order=order)[0]
return input_utils.input_to_cuml_array(
data, order=order)[0].to_output("numba")


def _convert_to_gpuarray_c(data):
Expand Down
54 changes: 27 additions & 27 deletions python/cuml/cluster/dbscan.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ from cuml.common.base import Base
from cuml.common.doc_utils import generate_docstring
from cuml.raft.common.handle cimport handle_t
from cuml.common import input_to_cuml_array
from cuml.common import using_output_type
from cuml.common.array_descriptor import CumlArrayDescriptor

from collections import defaultdict

Expand Down Expand Up @@ -186,6 +188,9 @@ class DBSCAN(Base):
<http://scikit-learn.org/stable/modules/generated/sklearn.cluster.DBSCAN.html>`_.
"""

labels_ = CumlArrayDescriptor()
core_sample_indices_ = CumlArrayDescriptor()

def __init__(self, eps=0.5, handle=None, min_samples=5,
verbose=False, max_mbytes_per_batch=None,
output_type=None, calc_core_sample_indices=True):
Expand All @@ -196,18 +201,17 @@ class DBSCAN(Base):
self.calc_core_sample_indices = calc_core_sample_indices

# internal array attributes
self._labels_ = None # accessed via estimator.labels_
self.labels_ = None

# accessed via estimator._core_sample_indices_ when
# self.calc_core_sample_indices == True
self._core_sample_indices_ = None
# One used when `self.calc_core_sample_indices == True`
self.core_sample_indices_ = None

# C++ API expects this to be numeric.
if self.max_mbytes_per_batch is None:
self.max_mbytes_per_batch = 0

@generate_docstring(skip_parameters_heading=True)
def fit(self, X, out_dtype="int32"):
def fit(self, X, out_dtype="int32") -> "DBSCAN":
"""
Perform DBSCAN clustering from features.

Expand All @@ -218,11 +222,6 @@ class DBSCAN(Base):
"int64", np.int64}.

"""
self._set_base_attributes(output_type=X, n_features=X)

if self._labels_ is not None:
del self._labels_

if out_dtype not in ["int32", np.int32, "int64", np.int64]:
raise ValueError("Invalid value for out_dtype. "
"Valid values are {'int32', 'int64', "
Expand All @@ -236,16 +235,16 @@ class DBSCAN(Base):

cdef handle_t* handle_ = <handle_t*><size_t>self.handle.getHandle()

self._labels_ = CumlArray.empty(n_rows, dtype=out_dtype)
cdef uintptr_t labels_ptr = self._labels_.ptr
self.labels_ = CumlArray.empty(n_rows, dtype=out_dtype)
cdef uintptr_t labels_ptr = self.labels_.ptr

cdef uintptr_t core_sample_indices_ptr = <uintptr_t> NULL

# Create the output core_sample_indices only if needed
if self.calc_core_sample_indices:
self._core_sample_indices_ = \
self.core_sample_indices_ = \
CumlArray.empty(n_rows, dtype=out_dtype)
core_sample_indices_ptr = self._core_sample_indices_.ptr
core_sample_indices_ptr = self.core_sample_indices_.ptr

if self.dtype == np.float32:
if out_dtype is "int32" or out_dtype is np.int32:
Expand Down Expand Up @@ -303,20 +302,21 @@ class DBSCAN(Base):
# Finally, resize the core_sample_indices array if necessary
if self.calc_core_sample_indices:

# Temp convert to cupy array only once
core_samples_cupy = self._core_sample_indices_.to_output("cupy")
# Temp convert to cupy array (better than using `cupy.asarray`)
with using_output_type("cupy"):

# First get the min index. These have to monotonically increasing,
# so the min index should be the first returned -1
min_index = cp.argmin(core_samples_cupy).item()
# First get the min index. These have to monotonically
# increasing, so the min index should be the first returned -1
min_index = cp.argmin(self.core_sample_indices_).item()

# Check for the case where there are no -1's
if (min_index == 0 and core_samples_cupy[min_index].item() != -1):
# Nothing to delete. The array has no -1's
pass
else:
self._core_sample_indices_ = \
self._core_sample_indices_[:min_index]
# Check for the case where there are no -1's
if ((min_index == 0 and
self.core_sample_indices_[min_index].item() != -1)):
# Nothing to delete. The array has no -1's
pass
else:
self.core_sample_indices_ = \
self.core_sample_indices_[:min_index]

return self

Expand All @@ -325,7 +325,7 @@ class DBSCAN(Base):
'type': 'dense',
'description': 'Cluster labels',
'shape': '(n_samples, 1)'})
def fit_predict(self, X, out_dtype="int32"):
def fit_predict(self, X, out_dtype="int32") -> CumlArray:
"""
Performs clustering on X and returns cluster labels.

Expand Down
Loading

0 comments on commit 0879167

Please sign in to comment.