def test_isclose(): x = np.array([0, np.nan, 1, 1.5]) y = np.array([1e-9, np.nan, 1, 2]) a = da.from_array(x, chunks=(2,)) b = da.from_array(y, chunks=(2,)) assert_eq(da.isclose(a, b, equal_nan=True), np.isclose(x, y, equal_nan=True))
def test_isclose(): x = np.array([0, np.nan, 1, 1.5]) y = np.array([1e-9, np.nan, 1, 2]) a = from_array(x, chunks=(2,)) b = from_array(y, chunks=(2,)) assert eq(da.isclose(a, b, equal_nan=True), np.isclose(x, y, equal_nan=True))
def test_isclose(): x = np.array([0, np.nan, 1, 1.5]) y = np.array([1e-9, np.nan, 1, 2]) a = from_array(x, blockshape=(2, )) b = from_array(y, blockshape=(2, )) assert eq(da.isclose(a, b, equal_nan=True), np.isclose(x, y, equal_nan=True))
def var_equal(*args): for iarg in args[1:]: if iarg is args[0]: continue if iarg.shape != args[0].shape: return False if iarg.dtype.kind == 'f': if da.any(~da.isclose(iarg._values, args[0]._values)): return False else: if da.any(iarg._values != args[0]._values): return False return True
# this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # * Neither the name of Intel Corporation nor the names of its contributors # may be used to endorse or promote products derived from this software # without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import dask, time import dask.array as da x = da.random.random((100000, 2000), chunks=(10000, 2000)) t0 = time.time() q, r = da.linalg.qr(x) test = da.all(da.isclose(x, q.dot(r))) test.compute() # compute(get=dask.threaded.get) by default print(time.time() - t0)
case = cases[case_number] U = U_list[case_number] a = a_list[case_number] p0 = p0_list[case_number] x0 = x0_list[case_number] ## Set paths filename = f"{pressure_dir}/exp_{case:02.0f}" figurename = f"{pressure_dir}/fig_exp_{case:02.0f}" ## Compute pressure print(f"\nComputing pressure field for {case=} ({U=}, {a=}, {p0=}, {x0=})") p = pressure(xx, yy, tt, t0, U, a, p0, x0).astype(np.float32) ## Remove zero-columns and zero-rows ix = da.where(~da.all(da.isclose(p, 0), axis=(0, 1)))[0] iy = da.where(~da.all(da.isclose(p, 0), axis=(0, 2)))[0] _x = x[ix] _y = y[iy] p = p[:, :, ix][:, iy, :] ## Write field data = fp.convert_to_xarray(t, _x, _y, p.compute()) print(f"Process pressure field for {case=}") del _x, _y, p print(f"Writing pressure field for {case=}") fp.write_pressure(data, filename) ## Write forcing file print(f"Overwriting forcing file for {case=}") with open(f"{current_dir}/pressure/forcing_exp_{case:02.0f}.ext",
def _bench(self, get): q, r = da.linalg.qr(self.x) test = da.all(da.isclose(self.x, q.dot(r))) test.compute(get=get)
def _transform_array(image: da.Array, scale: Tuple[float, ...], offset: Tuple[float, ...], shape: Tuple[int, ...], chunks: Optional[Tuple[int, ...]], spline_order: int, recover_nan: bool) -> da.Array: """ Apply affine transformation to ND-image. :param image: ND-image with shape (..., size_y, size_x) :param scale: Scaling factors (1, ..., 1, sy, sx) :param offset: Offset values (0, ..., 0, oy, ox) :param shape: (..., size_y, size_x) :param chunks: (..., chunk_size_y, chunk_size_x) :param spline_order: 0 ... 5 :param recover_nan: True/False :return: Transformed ND-image. """ assert_true(len(scale) == image.ndim, 'invalid scale') assert_true(len(offset) == image.ndim, 'invalid offset') assert_true(len(shape) == image.ndim, 'invalid shape') assert_true(chunks is None or len(chunks) == image.ndim, 'invalid chunks') if _is_no_op(image, scale, offset, shape): return image # As of scipy 0.18, matrix = scale is no longer supported. # Therefore we use the diagonal matrix form here, # where scale is the diagonal. matrix = np.diag(scale) at_kwargs = dict( offset=offset, order=spline_order, output_shape=shape, output_chunks=chunks, mode='constant', ) if recover_nan and spline_order > 0: # We can "recover" values that are neighbours to NaN values # that would otherwise become NaN too. mask = da.isnan(image) # First check if there are NaN values ar all if da.any(mask): # Yes, then # 1. replace NaN by zero filled_im = da.where(mask, 0.0, image) # 2. transform the zeo-filled image scaled_im = ndinterp.affine_transform(filled_im, matrix, **at_kwargs, cval=0.0) # 3. transform the inverted mask scaled_norm = ndinterp.affine_transform(1.0 - mask, matrix, **at_kwargs, cval=0.0) # 4. put back NaN where there was zero, # otherwise decode using scaled mask return da.where(da.isclose(scaled_norm, 0.0), np.nan, scaled_im / scaled_norm) # No dealing with NaN required return ndinterp.affine_transform(image, matrix, **at_kwargs, cval=np.nan)
def qr(x): t0 = time.time() q, r = da.linalg.qr(x) test = da.all(da.isclose(x, q.dot(r))) test.compute() print(time.time() - t0)