- Notifications
You must be signed in to change notification settings - Fork15
Improve construction when inferring sub-array dtype (a.k.a. array subdtype)#381
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -872,7 +872,7 @@ def from_coo( | ||
| """ | ||
| rows = ints_to_numpy_buffer(rows, np.uint64, name="row indices") | ||
| columns = ints_to_numpy_buffer(columns, np.uint64, name="column indices") | ||
| values,dtype = values_to_numpy_buffer(values, dtype, subarray_after=1) | ||
| # Compute nrows and ncols if not provided | ||
| if nrows is None: | ||
| if rows.size == 0: | ||
| @@ -882,11 +882,8 @@ def from_coo( | ||
| if columns.size == 0: | ||
| raise ValueError("No column indices provided. Unable to infer ncols.") | ||
| ncols = int(columns.max()) + 1 | ||
| # Create the new matrix | ||
| C = cls(dtype, nrows, ncols, name=name) | ||
| if values.ndim == 0: | ||
| if dup_op is not None: | ||
| raise ValueError( | ||
| @@ -1004,7 +1001,7 @@ def _from_csx(cls, fmt, indptr, indices, values, dtype, num, check_num, name): | ||
| indices_name = "row indices" | ||
| indptr = ints_to_numpy_buffer(indptr, np.uint64, name="index pointers") | ||
| indices = ints_to_numpy_buffer(indices, np.uint64, name=indices_name) | ||
| values,dtype = values_to_numpy_buffer(values, dtype, subarray_after=1) | ||
| if num is None: | ||
| if indices.size > 0: | ||
| num = int(indices.max()) + 1 | ||
| @@ -1026,9 +1023,6 @@ def _from_csx(cls, fmt, indptr, indices, values, dtype, num, check_num, name): | ||
| "ncols must be None or equal to len(indptr) - 1; " | ||
| f"expected {check_num}, got {ncols}" | ||
| ) | ||
| if values.ndim == 0: | ||
| if backend == "suitesparse": | ||
| # SuiteSparse GxB can handle iso-value | ||
| @@ -1055,21 +1049,21 @@ def _from_csx(cls, fmt, indptr, indices, values, dtype, num, check_num, name): | ||
| ) | ||
| values = np.broadcast_to(values, indices.size) | ||
| new_mat = ffi_new("GrB_Matrix*") | ||
| rv = Matrix._from_obj(new_mat,dtype, nrows, ncols, name=name) | ||
| ifdtype._is_udt: | ||
| dtype_name = "UDT" | ||
| else: | ||
| dtype_name =dtype.name | ||
| call( | ||
| f"GrB_Matrix_import_{dtype_name}", | ||
| [ | ||
| _Pointer(rv), | ||
| dtype, | ||
| _as_scalar(nrows, _INDEX, is_cscalar=True), | ||
| _as_scalar(ncols, _INDEX, is_cscalar=True), | ||
| _CArray(indptr), | ||
| _CArray(indices), | ||
| _CArray(values, dtype=dtype), | ||
| _as_scalar(indptr.size, _INDEX, is_cscalar=True), | ||
| _as_scalar(indices.size, _INDEX, is_cscalar=True), | ||
| _as_scalar(values.shape[0], _INDEX, is_cscalar=True), | ||
| @@ -1436,12 +1430,14 @@ def from_dicts( | ||
| col_indices = np.fromiter(itertools.chain.from_iterable(dicts), np.uint64) | ||
| iter_values = itertools.chain.from_iterable(v.values() for v in dicts) | ||
| if dtype is None: | ||
| values, dtype = values_to_numpy_buffer(list(iter_values), subarray_after=1) | ||
| else: | ||
| # If we know the dtype, then using `np.fromiter` is much faster | ||
| dtype = lookup_dtype(dtype) | ||
| if dtype.np_type.subdtype is not None and np.__version__[:5] in {"1.21.", "1.22."}: | ||
MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I think this is the first time we actually use the version of a dependency. This way is pretty low-tech, and hopefully fine. If we need to do more version-dependent behavior, we'll probably want to use a helper utility such as Also, CI testing of dependency versions FTW! We can drop 1.21 in June, and 1.22 next January. | ||
| values, dtype = values_to_numpy_buffer(list(iter_values), dtype) | ||
| else: | ||
| values = np.fromiter(iter_values, dtype.np_type) | ||
| return getattr(cls, methodname)( | ||
| *args, indptr, col_indices, values, dtype, nrows=nrows, ncols=ncols, name=name | ||
| ) | ||
Uh oh!
There was an error while loading.Please reload this page.