[bug #68091] Inefficient Integer Data Loading from MAT-Files
"Dmitri A. Sergatskov" <[email protected]> Wed, 29 Apr 2026 13:13:57 -0400 (EDT)
| Newsgroups | gmane.comp.gnu.octave.bugs |
|---|---|
| Message-ID | <[email protected]> |
Please use the bug tracker to post updates to a bug report. The mailing list is intended as a read-only notification stream. Info posted to this mailing list address won't appear in the tracker database where it is most useful.
Follow-up Comment #19, bug #68091 (group octave):
I do not think you want to change signature, but you can try something like:
template <typename T> struct mat5_underlying { using type = T; };
template <typename T> struct mat5_underlying<octave_int<T>> { using type =
T; };
template <typename storageT, typename T>
static void
read_mat5_integer_data_storage (std::istream& is, T *m,
octave_idx_type count, bool swap)
{
if (count <= 0)
return;
using underlyingT = typename mat5_underlying<T>::type;
static_assert (sizeof (T) == sizeof (underlyingT));
static_assert (std::is_standard_layout_v<T>);
std::streamsize n_bytes
= sizeof (storageT) * static_cast<std::streamsize> (count);
if constexpr (std::is_same_v<storageT, underlyingT>)
{
auto *raw = reinterpret_cast<storageT *> (m);
is.read (reinterpret_cast<char *> (raw), n_bytes);
if (swap)
swap_bytes<sizeof (storageT)> (raw, count);
}
else
{
OCTAVE_LOCAL_BUFFER (storageT, ptr, count);
is.read (reinterpret_cast<char *> (ptr), n_bytes);
if (swap)
swap_bytes<sizeof (storageT)> (ptr, count);
for (octave_idx_type i = 0; i < count; i++)
m[i] = ptr[i];
}
}
(I have not even tried to compile it.)
Dmitri.
--
_______________________________________________________
Reply to this item at:
<https://savannah.gnu.org/bugs/?68091>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/
signature.asc
(application/pgp-signature, 228 B)
-----BEGIN PGP SIGNATURE----- iHUEABYIAB0WIQQk97aszIMMAvLLwm6qLAuaBUf3TgUCafI8VQAKCRCqLAuaBUf3 TjDAAQCpX6a+CZzlq8wOCkjKARUy2r1P9+3zkflhprzKcTAzsgEAxUWihFpkp7bC pdyU2zaiK1MUzJZvrBS+IL5+QJd8bAA= =o/U/ -----END PGP SIGNATURE-----