File: bli_part.c

package info (click to toggle)
python-cython-blis 0.9.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 43,648 kB
  • sloc: ansic: 645,510; sh: 2,354; asm: 1,466; python: 820; cpp: 585; makefile: 14
file content (861 lines) | stat: -rw-r--r-- 24,778 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
/*

   BLIS
   An object-based framework for developing high-performance BLAS-like
   libraries.

   Copyright (C) 2014, The University of Texas at Austin

   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions are
   met:
    - Redistributions of source code must retain the above copyright
      notice, 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(s) of the copyright holder(s) 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
   HOLDER 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.

*/

#include "blis.h"


// -- Matrix partitioning ------------------------------------------------------


void bli_acquire_mpart
     (
       dim_t     i,
       dim_t     j,
       dim_t     bm,
       dim_t     bn,
       obj_t*    parent,
       obj_t*    child
     )
{
	// Query the dimensions of the parent object.
	const dim_t m_par = bli_obj_length( parent );
	const dim_t n_par = bli_obj_width( parent );

	// If either i or j is already beyond what exists of the parent matrix,
	// slide them back to the outer dimensions. (What will happen in this
	// scenario is that bm and bn and/or will be reduced to zero so that the
	// child matrix does not refer to anything beyond the bounds of the
	// parent. (Note: This is a safety measure and generally should never
	// be needed if the caller is passing in sane arguments.)
	if ( i > m_par ) i = m_par;
	if ( j > n_par ) j = n_par;

	// If either bm or bn spills out over the edge of the parent matrix,
	// reduce them so that the child matrix fits within the bounds of the
	// parent. (Note: This is a safety measure and generally should never
	// be needed if the caller is passing in sane arguments, though this
	// code is somewhat more likely to be needed than the code above.)
	if ( bm > m_par - i ) bm = m_par - i;
	if ( bn > n_par - j ) bn = n_par - j;

	// Alias the parent object's contents into the child object.
	bli_obj_alias_to( parent, child );

	// Set the offsets and dimensions of the child object. Note that we
	// increment, rather than overwrite, the offsets of the child object
	// in case the parent object already had non-zero offsets (usually
	// because the parent was itself a child a larger grandparent object).
	bli_obj_inc_offs( i, j, child );
	bli_obj_set_dims( bm, bn, child );
}


void bli_acquire_mpart_t2b
     (
       subpart_t req_part,
       dim_t     i,
       dim_t     b,
       obj_t*    obj,
       obj_t*    sub_obj
     )
{
	bli_acquire_mpart_mdim( BLIS_FWD, req_part, i, b, obj, sub_obj );
}


void bli_acquire_mpart_b2t
     (
       subpart_t req_part,
       dim_t     i,
       dim_t     b,
       obj_t*    obj,
       obj_t*    sub_obj
     )
{
	bli_acquire_mpart_mdim( BLIS_BWD, req_part, i, b, obj, sub_obj );
}


void bli_acquire_mpart_mdim
     (
       dir_t     direct,
       subpart_t req_part,
       dim_t     i,
       dim_t     b,
       obj_t*    obj,
       obj_t*    sub_obj
     )
{
	dim_t  m;
	dim_t  n;
	dim_t  m_part   = 0;
	dim_t  n_part   = 0;
	inc_t  offm_inc = 0;
	inc_t  offn_inc = 0;
	doff_t diag_off_inc;


	// Call a special function for partitioning packed objects. (By only
	// catching those objects packed to panels, we omit cases where the
	// object is packed to row or column storage, as such objects can be
	// partitioned through normally.) Note that the function called below
	// assumes forward partitioning.
	if ( bli_obj_is_panel_packed( obj ) )
	{
		bli_packm_acquire_mpart_t2b( req_part, i, b, obj, sub_obj );
		return;
	}


	// Check parameters.
	if ( bli_error_checking_is_enabled() )
		bli_acquire_mpart_t2b_check( req_part, i, b, obj, sub_obj );


	// Query the m and n dimensions of the object (accounting for
	// transposition, if indicated).
	if ( bli_obj_has_notrans( obj ) )
	{
		m = bli_obj_length( obj );
		n = bli_obj_width( obj );
	}
	else // if ( bli_obj_has_trans( obj ) )
	{
		m = bli_obj_width( obj );
		n = bli_obj_length( obj );
	}


	// Foolproofing: do not let b exceed what's left of the m dimension at
	// row offset i.
	if ( b > m - i ) b = m - i;


	// NOTE: Most of this function implicitly assumes moving forward.
	// When moving backward, we have to relocate i.
	if ( direct == BLIS_BWD )
	{
		// Modify i to account for the fact that we are moving backwards.
		i = m - i - b;
	}


	// Support SUBPART1B (behind SUBPART1) and SUBPART1A (ahead of SUBPART1),
	// to refer to subpartitions 0 and 2 when moving forward, and 2 and 0 when
	// moving backward.
	subpart_t subpart0_alias;
	subpart_t subpart2_alias;

	if ( direct == BLIS_FWD ) { subpart0_alias = BLIS_SUBPART1B;
	                            subpart2_alias = BLIS_SUBPART1A; }
	else                      { subpart0_alias = BLIS_SUBPART1A;
	                            subpart2_alias = BLIS_SUBPART1B; }


	// Compute offset increments and dimensions based on which
	// subpartition is being requested, assuming no transposition.
	if      ( req_part == BLIS_SUBPART0 ||
	          req_part == subpart0_alias )
	{
		// A0 (offm,offn) unchanged.
		// A0 is i x n.
		offm_inc = 0;
		offn_inc = 0;
		m_part   = i;
		n_part   = n;
	}
	else if ( req_part == BLIS_SUBPART1AND0 )
	{
		// A1+A0 (offm,offn) unchanged.
		// A1+A0 is (i+b) x n.
		offm_inc = 0;
		offn_inc = 0;
		m_part   = i + b;
		n_part   = n;
	}
	else if ( req_part == BLIS_SUBPART1 )
	{
		// A1 (offm,offn) += (i,0).
		// A1 is b x n.
		offm_inc = i;
		offn_inc = 0;
		m_part   = b;
		n_part   = n;
	}
	else if ( req_part == BLIS_SUBPART1AND2 )
	{
		// A1+A2 (offm,offn) += (i,0).
		// A1+A2 is (m-i) x n.
		offm_inc = i;
		offn_inc = 0;
		m_part   = m - i;
		n_part   = n;
	}
	else if ( req_part == BLIS_SUBPART2 ||
	          req_part == subpart2_alias )
	{
		// A2 (offm,offn) += (i+b,0).
		// A2 is (m-i-b) x n.
		offm_inc = i + b;
		offn_inc = 0;
		m_part   = m - i - b;
		n_part   = n;
	}


	// Compute the diagonal offset based on the m and n offsets.
	diag_off_inc = ( doff_t )offm_inc - ( doff_t )offn_inc;


	// Begin by copying the info, elem size, buffer, row stride, and column
	// stride fields of the parent object. Note that this omits copying view
	// information because the new partition will have its own dimensions
	// and offsets.
	bli_obj_init_subpart_from( obj, sub_obj );


	// Modify offsets and dimensions of requested partition based on
	// whether it needs to be transposed.
	if ( bli_obj_has_notrans( obj ) )
	{
		bli_obj_set_dims( m_part, n_part, sub_obj );
		bli_obj_inc_offs( offm_inc, offn_inc, sub_obj );
		bli_obj_inc_diag_offset( diag_off_inc, sub_obj );
	}
	else // if ( bli_obj_has_trans( obj ) )
	{
		bli_obj_set_dims( n_part, m_part, sub_obj );
		bli_obj_inc_offs( offn_inc, offm_inc, sub_obj );
		bli_obj_inc_diag_offset( -diag_off_inc, sub_obj );
	}


	// If the root matrix is not general (ie: has structure defined by the
	// diagonal), and the subpartition does not intersect the root matrix's
	// diagonal, then set the subpartition structure to "general"; otherwise
	// we let the subpartition inherit the storage structure of its immediate
	// parent.
	if ( !bli_obj_root_is_general( sub_obj ) &&
	      bli_obj_is_outside_diag( sub_obj ) )
	{
		// NOTE: This comment may be out-of-date since we now distinguish
		// between uplo properties for the current and root objects...
		// Note that we cannot mark the subpartition object as general/dense
		// here since it makes sense to preserve the existing uplo information
		// a while longer so that the correct kernels are invoked. (Example:
		// incremental packing/computing in gemmt produces subpartitions that
		// appear general/dense, but their uplo fields are needed to be either
		// lower or upper, to determine which macro-kernel gets called in the
		// gemmt_int() back-end.)

		// If the subpartition lies entirely in an "unstored" triangle of the
		// root matrix, then we need to tweak the subpartition. If the root
		// matrix is Hermitian or symmetric, then we reflect the partition to
		// the other side of the diagonal, toggling the transposition bit (and
		// conjugation bit if the root matrix is Hermitian). Or, if the root
		// matrix is triangular, the subpartition should be marked as zero.
		if ( bli_obj_is_unstored_subpart( sub_obj ) )
		{
			if ( bli_obj_root_is_hermitian( sub_obj ) )
			{
				bli_obj_reflect_about_diag( sub_obj );
				bli_obj_toggle_conj( sub_obj );
			}
			else if ( bli_obj_root_is_symmetric( sub_obj ) )
			{
				bli_obj_reflect_about_diag( sub_obj );
			}
			else if ( bli_obj_root_is_triangular( sub_obj ) )
			{
				bli_obj_set_uplo( BLIS_ZEROS, sub_obj );
			}
		}
	}
}


void bli_acquire_mpart_l2r
     (
       subpart_t req_part,
       dim_t     i,
       dim_t     b,
       obj_t*    obj,
       obj_t*    sub_obj
     )
{
	bli_acquire_mpart_ndim( BLIS_FWD, req_part, i, b, obj, sub_obj );
}


void bli_acquire_mpart_r2l
     (
       subpart_t req_part,
       dim_t     j,
       dim_t     b,
       obj_t*    obj,
       obj_t*    sub_obj
     )
{
	bli_acquire_mpart_ndim( BLIS_BWD, req_part, j, b, obj, sub_obj );
}


void bli_acquire_mpart_ndim
     (
       dir_t     direct,
       subpart_t req_part,
       dim_t     j,
       dim_t     b,
       obj_t*    obj,
       obj_t*    sub_obj
     )
{
	dim_t  m;
	dim_t  n;
	dim_t  m_part   = 0;
	dim_t  n_part   = 0;
	inc_t  offm_inc = 0;
	inc_t  offn_inc = 0;
	doff_t diag_off_inc;


	// Call a special function for partitioning packed objects. (By only
	// catching those objects packed to panels, we omit cases where the
	// object is packed to row or column storage, as such objects can be
	// partitioned through normally.) Note that the function called below
	// assumes forward partitioning.
	if ( bli_obj_is_panel_packed( obj ) )
	{
		bli_packm_acquire_mpart_l2r( req_part, j, b, obj, sub_obj );
		return;
	}


	// Check parameters.
	if ( bli_error_checking_is_enabled() )
		bli_acquire_mpart_l2r_check( req_part, j, b, obj, sub_obj );


	// Query the m and n dimensions of the object (accounting for
	// transposition, if indicated).
	if ( bli_obj_has_notrans( obj ) )
	{
		m = bli_obj_length( obj );
		n = bli_obj_width( obj );
	}
	else // if ( bli_obj_has_trans( obj ) )
	{
		m = bli_obj_width( obj );
		n = bli_obj_length( obj );
	}


	// Foolproofing: do not let b exceed what's left of the n dimension at
	// column offset j.
	if ( b > n - j ) b = n - j;


	// NOTE: Most of this function implicitly assumes moving forward.
	// When moving backward, we have to relocate j.
	if ( direct == BLIS_BWD )
	{
		// Modify j to account for the fact that we are moving backwards.
		j = n - j - b;
	}


	// Support SUBPART1B (behind SUBPART1) and SUBPART1A (ahead of SUBPART1),
	// to refer to subpartitions 0 and 2 when moving forward, and 2 and 0 when
	// moving backward.
	subpart_t subpart0_alias;
	subpart_t subpart2_alias;

	if ( direct == BLIS_FWD ) { subpart0_alias = BLIS_SUBPART1B;
	                            subpart2_alias = BLIS_SUBPART1A; }
	else                      { subpart0_alias = BLIS_SUBPART1A;
	                            subpart2_alias = BLIS_SUBPART1B; }


	// Compute offset increments and dimensions based on which
	// subpartition is being requested, assuming no transposition.
	if      ( req_part == BLIS_SUBPART0 ||
	          req_part == subpart0_alias )
	{
		// A0 (offm,offn) unchanged.
		// A0 is m x j.
		offm_inc = 0;
		offn_inc = 0;
		m_part   = m;
		n_part   = j;
	}
	else if ( req_part == BLIS_SUBPART1AND0 )
	{
		// A1+A0 (offm,offn) unchanged.
		// A1+A0 is m x (j+b).
		offm_inc = 0;
		offn_inc = 0;
		m_part   = m;
		n_part   = j + b;
	}
	else if ( req_part == BLIS_SUBPART1 )
	{
		// A1 (offm,offn) += (0,j).
		// A1 is m x b.
		offm_inc = 0;
		offn_inc = j;
		m_part   = m;
		n_part   = b;
	}
	else if ( req_part == BLIS_SUBPART1AND2 )
	{
		// A1+A2 (offm,offn) += (0,j).
		// A1+A2 is m x (n-j).
		offm_inc = 0;
		offn_inc = j;
		m_part   = m;
		n_part   = n - j;
	}
	else if ( req_part == BLIS_SUBPART2 ||
	          req_part == subpart2_alias )
	{
		// A2 (offm,offn) += (0,j+b).
		// A2 is m x (n-j-b).
		offm_inc = 0;
		offn_inc = j + b;
		m_part   = m;
		n_part   = n - j - b;
	}


	// Compute the diagonal offset based on the m and n offsets.
	diag_off_inc = ( doff_t )offm_inc - ( doff_t )offn_inc;


	// Begin by copying the info, elem size, buffer, row stride, and column
	// stride fields of the parent object. Note that this omits copying view
	// information because the new partition will have its own dimensions
	// and offsets.
	bli_obj_init_subpart_from( obj, sub_obj );


	// Modify offsets and dimensions of requested partition based on
	// whether it needs to be transposed.
	if ( bli_obj_has_notrans( obj ) )
	{
		bli_obj_set_dims( m_part, n_part, sub_obj );
		bli_obj_inc_offs( offm_inc, offn_inc, sub_obj );
		bli_obj_inc_diag_offset( diag_off_inc, sub_obj );
	}
	else // if ( bli_obj_has_trans( obj ) )
	{
		bli_obj_set_dims( n_part, m_part, sub_obj );
		bli_obj_inc_offs( offn_inc, offm_inc, sub_obj );
		bli_obj_inc_diag_offset( -diag_off_inc, sub_obj );
	}


	// If the root matrix is not general (ie: has structure defined by the
	// diagonal), and the subpartition does not intersect the root matrix's
	// diagonal, then we might need to modify some of the subpartition's
	// properties, depending on its structure type.
	if ( !bli_obj_root_is_general( sub_obj ) &&
	      bli_obj_is_outside_diag( sub_obj ) )
	{
		// NOTE: This comment may be out-of-date since we now distinguish
		// between uplo properties for the current and root objects...
		// Note that we cannot mark the subpartition object as general/dense
		// here since it makes sense to preserve the existing uplo information
		// a while longer so that the correct kernels are invoked. (Example:
		// incremental packing/computing in gemmt produces subpartitions that
		// appear general/dense, but their uplo fields are needed to be either
		// lower or upper, to determine which macro-kernel gets called in the
		// gemmt_int() back-end.)

		// If the subpartition lies entirely in an "unstored" triangle of the
		// root matrix, then we need to tweak the subpartition. If the root
		// matrix is Hermitian or symmetric, then we reflect the partition to
		// the other side of the diagonal, toggling the transposition bit (and
		// conjugation bit if the root matrix is Hermitian). Or, if the root
		// matrix is triangular, the subpartition should be marked as zero.
		if ( bli_obj_is_unstored_subpart( sub_obj ) )
		{
			if ( bli_obj_root_is_hermitian( sub_obj ) )
			{
				bli_obj_reflect_about_diag( sub_obj );
				bli_obj_toggle_conj( sub_obj );
			}
			else if ( bli_obj_root_is_symmetric( sub_obj ) )
			{
				bli_obj_reflect_about_diag( sub_obj );
			}
			else if ( bli_obj_root_is_triangular( sub_obj ) )
			{
				bli_obj_set_uplo( BLIS_ZEROS, sub_obj );
			}
		}
	}
}


void bli_acquire_mpart_tl2br
     (
       subpart_t req_part,
       dim_t     i,
       dim_t     b,
       obj_t*    obj,
       obj_t*    sub_obj
     )
{
	bli_acquire_mpart_mndim( BLIS_FWD, req_part, i, b, obj, sub_obj );
}


void bli_acquire_mpart_br2tl
     (
       subpart_t req_part,
       dim_t     j,
       dim_t     b,
       obj_t*    obj,
       obj_t*    sub_obj
     )
{
	bli_acquire_mpart_mndim( BLIS_BWD, req_part, j, b, obj, sub_obj );
}


void bli_acquire_mpart_mndim
     (
       dir_t     direct,
       subpart_t req_part,
       dim_t     ij,
       dim_t     b,
       obj_t*    obj,
       obj_t*    sub_obj
     )
{
	dim_t  m;
	dim_t  n;
	dim_t  min_m_n;
	dim_t  m_part   = 0;
	dim_t  n_part   = 0;
	inc_t  offm_inc = 0;
	inc_t  offn_inc = 0;
	doff_t diag_off_inc;


	// Call a special function for partitioning packed objects. (By only
	// catching those objects packed to panels, we omit cases where the
	// object is packed to row or column storage, as such objects can be
	// partitioned through normally.) Note that the function called below
	// assumes forward partitioning.
	if ( bli_obj_is_panel_packed( obj ) )
	{
		bli_packm_acquire_mpart_tl2br( req_part, ij, b, obj, sub_obj );
		return;
	}


	// Check parameters.
	if ( bli_error_checking_is_enabled() )
		bli_acquire_mpart_tl2br_check( req_part, ij, b, obj, sub_obj );


	// Query the m and n dimensions of the object (accounting for
	// transposition, if indicated).
	if ( bli_obj_has_notrans( obj ) )
	{
		m = bli_obj_length( obj );
		n = bli_obj_width( obj );
	}
	else // if ( bli_obj_has_trans( obj ) )
	{
		m = bli_obj_width( obj );
		n = bli_obj_length( obj );
	}


	// Foolproofing: do not let b exceed what's left of min(m,n) at
	// row/column offset ij.
	min_m_n = bli_min( m, n );
	if ( b > min_m_n - ij ) b = min_m_n - ij;


	// NOTE: Most of this function implicitly assumes moving forward.
	// When moving backward, we have to relocate ij.
	if ( direct == BLIS_BWD )
	{
		// Modify ij to account for the fact that we are moving backwards.
		ij = min_m_n - ij - b;
	}


	// Compute offset increments and dimensions based on which
	// subpartition is being requested, assuming no transposition.

	// Left column of subpartitions
	if      ( req_part == BLIS_SUBPART00 )
	{
		// A00 (offm,offn) unchanged.
		// A00 is ij x ij.
		offm_inc = 0;
		offn_inc = 0;
		m_part   = ij;
		n_part   = ij;
	}
	else if ( req_part == BLIS_SUBPART10 )
	{
		// A10 (offm,offn) += (ij,0).
		// A10 is b x ij.
		offm_inc = ij;
		offn_inc = 0;
		m_part   = b;
		n_part   = ij;
	}
	else if ( req_part == BLIS_SUBPART20 )
	{
		// A20 (offm,offn) += (ij+b,0).
		// A20 is (m-ij-b) x ij.
		offm_inc = ij + b;
		offn_inc = 0;
		m_part   = m - ij - b;
		n_part   = ij;
	}

	// Middle column of subpartitions.
	else if ( req_part == BLIS_SUBPART01 )
	{
		// A01 (offm,offn) += (0,ij).
		// A01 is ij x b.
		offm_inc = 0;
		offn_inc = ij;
		m_part   = ij;
		n_part   = b;
	}
	else if ( req_part == BLIS_SUBPART11 )
	{
		// A11 (offm,offn) += (ij,ij).
		// A11 is b x b.
		offm_inc = ij;
		offn_inc = ij;
		m_part   = b;
		n_part   = b;
	}
	else if ( req_part == BLIS_SUBPART21 )
	{
		// A21 (offm,offn) += (ij+b,ij).
		// A21 is (m-ij-b) x b.
		offm_inc = ij + b;
		offn_inc = ij;
		m_part   = m - ij - b;
		n_part   = b;
	}

	// Right column of subpartitions.
	else if ( req_part == BLIS_SUBPART02 )
	{
		// A02 (offm,offn) += (0,ij+b).
		// A02 is ij x (n-ij-b).
		offm_inc = 0;
		offn_inc = ij + b;
		m_part   = ij;
		n_part   = n - ij - b;
	}
	else if ( req_part == BLIS_SUBPART12 )
	{
		// A12 (offm,offn) += (ij,ij+b).
		// A12 is b x (n-ij-b).
		offm_inc = ij;
		offn_inc = ij + b;
		m_part   = b;
		n_part   = n - ij - b;
	}
	else // if ( req_part == BLIS_SUBPART22 )
	{
		// A22 (offm,offn) += (ij+b,ij+b).
		// A22 is (m-ij-b) x (n-ij-b).
		offm_inc = ij + b;
		offn_inc = ij + b;
		m_part   = m - ij - b;
		n_part   = n - ij - b;
	}


	// Compute the diagonal offset based on the m and n offsets.
	diag_off_inc = ( doff_t )offm_inc - ( doff_t )offn_inc;


	// Begin by copying the info, elem size, buffer, row stride, and column
	// stride fields of the parent object. Note that this omits copying view
	// information because the new partition will have its own dimensions
	// and offsets.
	bli_obj_init_subpart_from( obj, sub_obj );


	// Modify offsets and dimensions of requested partition based on
	// whether it needs to be transposed.
	if ( bli_obj_has_notrans( obj ) )
	{
		bli_obj_set_dims( m_part, n_part, sub_obj );
		bli_obj_inc_offs( offm_inc, offn_inc, sub_obj );
		bli_obj_inc_diag_offset( diag_off_inc, sub_obj );
	}
	else // if ( bli_obj_has_trans( obj ) )
	{
		bli_obj_set_dims( n_part, m_part, sub_obj );
		bli_obj_inc_offs( offn_inc, offm_inc, sub_obj );
		bli_obj_inc_diag_offset( -diag_off_inc, sub_obj );
	}

	// If the root matrix is not general (ie: has structure defined by the
	// diagonal), and the subpartition does not intersect the root matrix's
	// diagonal, then set the subpartition structure to "general"; otherwise
	// we let the subpartition inherit the storage structure of its immediate
	// parent.
	if ( !bli_obj_root_is_general( sub_obj ) &&
	     req_part != BLIS_SUBPART00 &&
	     req_part != BLIS_SUBPART11 &&
	     req_part != BLIS_SUBPART22 )
	{
		// FGVZ: Fix me. This needs to be cleaned up. Either non-diagonal
		// intersecting subpartitions should inherit their root object's
		// uplo field, or it should not. Right now, they DO inherit the
		// uplo (because they are not set to BLIS_DENSE when the diagonal
		// does not intersect). But the whole point of being able to query
		// the root object's properties (e.g. uplo field) was so that we
		// COULD mark such subpartitions as dense, to make it easier for
		// certain subproblems on those subpartitions--subproblems that
		// are agnostic to where the subpartition came from.

		// NOTE: This comment may be out-of-date since we now distinguish
		// between uplo properties for the current and root objects...
		// Note that we cannot mark the subpartition object as general/dense
		// here since it makes sense to preserve the existing uplo information
		// a while longer so that the correct kernels are invoked. (Example:
		// incremental packing/computing in gemmt produces subpartitions that
		// appear general/dense, but their uplo fields are needed to be either
		// lower or upper, to determine which macro-kernel gets called in the
		// gemmt_int() back-end.)

		// If the subpartition lies entirely in an "unstored" triangle of the
		// root matrix, then we need to tweak the subpartition. If the root
		// matrix is Hermitian or symmetric, then we reflect the partition to
		// the other side of the diagonal, toggling the transposition bit (and
		// conjugation bit if the root matrix is Hermitian). Or, if the root
		// matrix is triangular, the subpartition should be marked as zero.
		if ( bli_obj_is_unstored_subpart( sub_obj ) )
		{
			if ( bli_obj_root_is_hermitian( sub_obj ) )
			{
				bli_obj_reflect_about_diag( sub_obj );
				bli_obj_toggle_conj( sub_obj );
			}
			else if ( bli_obj_root_is_symmetric( sub_obj ) )
			{
				bli_obj_reflect_about_diag( sub_obj );
			}
			else if ( bli_obj_root_is_triangular( sub_obj ) )
			{
				bli_obj_set_uplo( BLIS_ZEROS, sub_obj );
			}
		}
	}
}


// -- Vector partitioning ------------------------------------------------------


void bli_acquire_vpart_f2b
     (
       subpart_t req_part,
       dim_t     i,
       dim_t     b,
       obj_t*    obj,
       obj_t*    sub_obj
     )
{
	if ( bli_obj_is_col_vector( obj ) )
		bli_acquire_mpart_mdim( BLIS_FWD, req_part, i, b, obj, sub_obj );
	else // if ( bli_obj_is_row_vector( obj ) )
		bli_acquire_mpart_ndim( BLIS_FWD, req_part, i, b, obj, sub_obj );
}


void bli_acquire_vpart_b2f
     (
       subpart_t req_part,
       dim_t     i,
       dim_t     b,
       obj_t*    obj,
       obj_t*    sub_obj
     )
{
	if ( bli_obj_is_col_vector( obj ) )
		bli_acquire_mpart_mdim( BLIS_BWD, req_part, i, b, obj, sub_obj );
	else // if ( bli_obj_is_row_vector( obj ) )
		bli_acquire_mpart_ndim( BLIS_BWD, req_part, i, b, obj, sub_obj );
}


// -- Scalar acquisition -------------------------------------------------------


void bli_acquire_mij
     (
       dim_t     i,
       dim_t     j,
       obj_t*    obj,
       obj_t*    sub_obj
     )
{
	obj_t tmp_obj;

	bli_acquire_mpart_ndim( BLIS_FWD, BLIS_SUBPART1, j, 1,      obj, &tmp_obj );
	bli_acquire_mpart_mdim( BLIS_FWD, BLIS_SUBPART1, i, 1, &tmp_obj,  sub_obj );
}


void bli_acquire_vi
     (
       dim_t     i,
       obj_t*    obj,
       obj_t*    sub_obj
     )
{
	if ( bli_obj_is_col_vector( obj ) )
		bli_acquire_mpart_mdim( BLIS_FWD, BLIS_SUBPART1, i, 1, obj, sub_obj );
	else // if ( bli_obj_is_row_vector( obj ) )
		bli_acquire_mpart_ndim( BLIS_FWD, BLIS_SUBPART1, i, 1, obj, sub_obj );
}