MCPcopy Create free account
hub / github.com/numpy/numpy / slogdet

Function slogdet

numpy/linalg/umath_linalg.cpp:1145–1194  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1143
1144template<typename typ, typename basetyp>
1145static void
1146slogdet(char **args,
1147 npy_intp const *dimensions,
1148 npy_intp const *steps,
1149 void *NPY_UNUSED(func))
1150{
1151 fortran_int m;
1152 char *tmp_buff = NULL;
1153 size_t matrix_size;
1154 size_t pivot_size;
1155 size_t safe_m;
1156 /* notes:
1157 * matrix will need to be copied always, as factorization in lapack is
1158 * made inplace
1159 * matrix will need to be in column-major order, as expected by lapack
1160 * code (fortran)
1161 * always a square matrix
1162 * need to allocate memory for both, matrix_buffer and pivot buffer
1163 */
1164 INIT_OUTER_LOOP_3
1165 m = (fortran_int) dimensions[0];
1166 /* avoid empty malloc (buffers likely unused) and ensure m is `size_t` */
1167 safe_m = m != 0 ? m : 1;
1168 matrix_size = safe_m * safe_m * sizeof(typ);
1169 pivot_size = safe_m * sizeof(fortran_int);
1170 tmp_buff = (char *)malloc(matrix_size + pivot_size);
1171
1172 if (tmp_buff) {
1173 LINEARIZE_DATA_t lin_data;
1174 /* swapped steps to get matrix in FORTRAN order */
1175 init_linearize_data(&lin_data, m, m, steps[1], steps[0]);
1176 BEGIN_OUTER_LOOP_3
1177 linearize_matrix((typ*)tmp_buff, (typ*)args[0], &lin_data);
1178 slogdet_single_element(m,
1179 (typ*)tmp_buff,
1180 (fortran_int*)(tmp_buff+matrix_size),
1181 (typ*)args[1],
1182 (basetyp*)args[2]);
1183 END_OUTER_LOOP
1184
1185 free(tmp_buff);
1186 }
1187 else {
1188 /* TODO: Requires use of new ufunc API to indicate error return */
1189 NPY_ALLOW_C_API_DEF
1190 NPY_ALLOW_C_API;
1191 PyErr_NoMemory();
1192 NPY_DISABLE_C_API;
1193 }
1194}
1195
1196template<typename typ, typename basetyp>
1197static void

Callers

nothing calls this directly

Calls 2

init_linearize_dataFunction · 0.85
slogdet_single_elementFunction · 0.85

Tested by

no test coverage detected