MCPcopy
hub / github.com/dask/dask / sfqr

Function sfqr

dask/array/linalg.py:514–619  ·  view source on GitHub ↗

Direct Short-and-Fat QR Currently, this is a quick hack for non-tall-and-skinny matrices which are one chunk tall and (unless they are one chunk wide) have chunks that are wider than they are tall Q [R_1 R_2 ...] = [A_1 A_2 ...] it computes the factorization Q R_1 = A_1, then

(data, name=None)

Source from the content-addressed store, hash-verified

512
513
514def sfqr(data, name=None):
515 """Direct Short-and-Fat QR
516
517 Currently, this is a quick hack for non-tall-and-skinny matrices which
518 are one chunk tall and (unless they are one chunk wide) have chunks
519 that are wider than they are tall
520
521 Q [R_1 R_2 ...] = [A_1 A_2 ...]
522
523 it computes the factorization Q R_1 = A_1, then computes the other
524 R_k's in parallel.
525
526 Parameters
527 ----------
528 data: Array
529
530 See Also
531 --------
532 dask.array.linalg.qr
533 Main user API that uses this function
534 dask.array.linalg.tsqr
535 Variant for tall-and-skinny case
536 """
537 nr, nc = len(data.chunks[0]), len(data.chunks[1])
538 cr, cc = data.chunks[0][0], data.chunks[1][0]
539
540 if not (
541 (data.ndim == 2)
542 and (nr == 1) # Is a matrix
543 and ( # Has exactly one block row
544 (cr <= cc)
545 or (nc == 1) # Chunking dimension on rows is at least that on cols or...
546 )
547 ): # ... only one block col
548 raise ValueError(
549 "Input must have the following properties:\n"
550 " 1. Have two dimensions\n"
551 " 2. Have only one row of blocks\n"
552 " 3. Either one column of blocks or (first) chunk size on cols\n"
553 " is at most that on rows (e.g.: for a 5x20 matrix,\n"
554 " chunks=((5), (8,4,8)) is fine, but chunks=((5), (4,8,8)) is not;\n"
555 " still, prefer something simple like chunks=(5,10) or chunks=5)\n\n"
556 "Note: This function (sfqr) supports QR decomposition in the case\n"
557 "of short-and-fat matrices (single row chunk/block; see qr)"
558 )
559
560 prefix = name or "sfqr-" + tokenize(data)
561 prefix += "_"
562
563 m, n = data.shape
564
565 qq, rr = np.linalg.qr(np.ones(shape=(1, 1), dtype=data.dtype))
566
567 layers = data.__dask_graph__().layers.copy()
568 dependencies = data.__dask_graph__().dependencies.copy()
569
570 # data = A = [A_1 A_rest]
571 name_A_1 = f"{prefix}A_1"

Callers 2

test_sfqrFunction · 0.90
qrFunction · 0.85

Calls 12

HighLevelGraphClass · 0.90
meta_from_arrayFunction · 0.90
ArrayClass · 0.90
concatenateFunction · 0.90
setClass · 0.85
minFunction · 0.85
tokenizeFunction · 0.50
onesMethod · 0.45
copyMethod · 0.45
__dask_graph__Method · 0.45
__dask_layers__Method · 0.45
dotMethod · 0.45

Tested by 1

test_sfqrFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…