Adelsbach/VSIPL
Core Programming Reference Guide
DD-00016-015
Core

This manual is preliminary and incomplete.
While our Core implementation implements all functions given in the standard we are still working on completing this documentation.

Please refer to the VSIPL standard for a complete function reference of the Core profile until we have completed work on this documentation.

1.4.10 vsip_dmdiagview_p - Create a Diagonal Vector View of a Matrix

vsip_vview_f* vsip_mdiagview_f(const vsip_mview_f* matrix, vsip_index diagonal); 
vsip_cvview_f* vsip_cmdiagview_f(const vsip_cmview_f* matrix, vsip_index diagonal);
Description

This function creates a vector view that represents a diagonal of a matrix. The resulting vector view shares the same underlying data block as the matrix but provides access to only the elements along the specified diagonal.

The diagonal is specified by an index where:

The length of the resulting vector depends on the diagonal index and the matrix dimensions. For a diagonal with index d in an m ×n matrix, the length of the vector is:

min(m -max(0, -d),n -max(0,d))
Parameters
Return Value
Example

vsip_mview_f *matrix; 
vsip_vview_f *diag_vector; 
vsip_length i, j; 
 
// Create a 5x5 matrix 
matrix = vsip_mcreate_f(5, 5, VSIP_ROW, VSIP_MEM_NONE); 
 
// Fill the matrix with some values 
for (i = 0; i < 5; i++) { 
    for (j = 0; j < 5; j++) { 
        vsip_mput_f(matrix, i, j, i * 5 + j + 1); 
    } 
} 
 
// Get a vector view of the main diagonal (index 0) 
diag_vector = vsip_mdiagview_f(matrix, 0); 
 
if (diag_vector == NULL) { 
    // Handle error 
}
Notes