|
95 | 95 | try_miniexpr = True |
96 | 96 | if blosc2.IS_WASM: |
97 | 97 | try_miniexpr = False |
98 | | -if sys.platform == "win32": |
99 | | - # Although miniexpr has support for windows, the integration with Blosc2 |
100 | | - # still has some rough edges. |
101 | | - try_miniexpr = False |
| 98 | + |
| 99 | +_MINIEXPR_WINDOWS_OVERRIDE = os.environ.get("BLOSC2_ENABLE_MINIEXPR_WINDOWS", "").strip().lower() |
| 100 | +_MINIEXPR_WINDOWS_OVERRIDE = _MINIEXPR_WINDOWS_OVERRIDE not in ("", "0", "false", "no", "off") |
102 | 101 |
|
103 | 102 |
|
104 | 103 | def ne_evaluate(expression, local_dict=None, **kwargs): |
@@ -1326,14 +1325,34 @@ def fast_eval( # noqa: C901 |
1326 | 1325 | use_miniexpr = False |
1327 | 1326 | if not (all_ndarray and out is None): |
1328 | 1327 | use_miniexpr = False |
| 1328 | + has_complex = any( |
| 1329 | + isinstance(op, blosc2.NDArray) and blosc2.isdtype(op.dtype, "complex floating") |
| 1330 | + for op in operands.values() |
| 1331 | + ) |
| 1332 | + if isinstance(expression, str) and has_complex: |
| 1333 | + if sys.platform == "win32": |
| 1334 | + # On Windows, miniexpr has issues with complex numbers |
| 1335 | + use_miniexpr = False |
| 1336 | + if any(tok in expression for tok in ("!=", "==", "<=", ">=", "<", ">")): |
| 1337 | + use_miniexpr = False |
| 1338 | + if sys.platform == "win32" and use_miniexpr and not _MINIEXPR_WINDOWS_OVERRIDE: |
| 1339 | + # Work around Windows miniexpr issues for integer outputs and dtype conversions. |
| 1340 | + if blosc2.isdtype(dtype, "integral"): |
| 1341 | + use_miniexpr = False |
| 1342 | + else: |
| 1343 | + dtype_mismatch = any( |
| 1344 | + isinstance(op, blosc2.NDArray) and op.dtype != dtype for op in operands.values() |
| 1345 | + ) |
| 1346 | + if dtype_mismatch: |
| 1347 | + use_miniexpr = False |
1329 | 1348 |
|
1330 | 1349 | if use_miniexpr: |
1331 | 1350 | cparams = kwargs.pop("cparams", blosc2.CParams()) |
1332 | 1351 | # All values will be overwritten, so we can use an uninitialized array |
1333 | 1352 | res_eval = blosc2.uninit(shape, dtype, chunks=chunks, blocks=blocks, cparams=cparams, **kwargs) |
1334 | 1353 | try: |
1335 | 1354 | res_eval._set_pref_expr(expression, operands, fp_accuracy=fp_accuracy) |
1336 | | - print("expr->miniexpr:", expression, fp_accuracy) |
| 1355 | + # print("expr->miniexpr:", expression, fp_accuracy) |
1337 | 1356 | # Data to compress is fetched from operands, so it can be uninitialized here |
1338 | 1357 | data = np.empty(res_eval.schunk.chunksize, dtype=np.uint8) |
1339 | 1358 | # Exercise prefilter for each chunk |
@@ -2036,6 +2055,18 @@ def reduce_slices( # noqa: C901 |
2036 | 2055 | isinstance(op, blosc2.NDArray) and blosc2.isdtype(op.dtype, "complex floating") |
2037 | 2056 | for op in operands.values() |
2038 | 2057 | ) |
| 2058 | + if has_complex and sys.platform == "win32": |
| 2059 | + # On Windows, miniexpr has issues with complex numbers |
| 2060 | + use_miniexpr = False |
| 2061 | + if sys.platform == "win32" and use_miniexpr and not _MINIEXPR_WINDOWS_OVERRIDE: |
| 2062 | + if blosc2.isdtype(dtype, "integral"): |
| 2063 | + use_miniexpr = False |
| 2064 | + else: |
| 2065 | + dtype_mismatch = any( |
| 2066 | + isinstance(op, blosc2.NDArray) and op.dtype != dtype for op in operands.values() |
| 2067 | + ) |
| 2068 | + if dtype_mismatch: |
| 2069 | + use_miniexpr = False |
2039 | 2070 | if has_complex and any(tok in expression for tok in ("!=", "==", "<=", ">=", "<", ">")): |
2040 | 2071 | use_miniexpr = False |
2041 | 2072 | if where is not None and len(where) != 2: |
@@ -2073,7 +2104,7 @@ def reduce_slices( # noqa: C901 |
2073 | 2104 | else: |
2074 | 2105 | expression_miniexpr = f"{reduce_op_str}({expression})" |
2075 | 2106 | res_eval._set_pref_expr(expression_miniexpr, operands, fp_accuracy, aux_reduc) |
2076 | | - print("expr->miniexpr:", expression, reduce_op, fp_accuracy) |
| 2107 | + # print("expr->miniexpr:", expression, reduce_op, fp_accuracy) |
2077 | 2108 | # Data won't even try to be compressed, so buffers can be unitialized and reused |
2078 | 2109 | data = np.empty(res_eval.schunk.chunksize, dtype=np.uint8) |
2079 | 2110 | chunk_data = np.empty(res_eval.schunk.chunksize + blosc2.MAX_OVERHEAD, dtype=np.uint8) |
|
0 commit comments