\doxysection{Numpy\+File.\+hpp}
\hypertarget{NumpyFile_8hpp_source}{}\label{NumpyFile_8hpp_source}\index{file\_io/include/aare/file\_io/NumpyFile.hpp@{file\_io/include/aare/file\_io/NumpyFile.hpp}}
\mbox{\hyperlink{NumpyFile_8hpp}{Go to the documentation of this file.}}
\begin{DoxyCode}{0}
\DoxyCodeLine{00001\ \textcolor{preprocessor}{\#pragma\ once}}
\DoxyCodeLine{00002\ \textcolor{preprocessor}{\#include\ "{}\mbox{\hyperlink{DType_8hpp}{aare/core/DType.hpp}}"{}}}
\DoxyCodeLine{00003\ \textcolor{preprocessor}{\#include\ "{}\mbox{\hyperlink{core_2include_2aare_2core_2defs_8hpp}{aare/core/defs.hpp}}"{}}}
\DoxyCodeLine{00004\ \textcolor{preprocessor}{\#include\ "{}\mbox{\hyperlink{FileInterface_8hpp}{aare/file\_io/FileInterface.hpp}}"{}}}
\DoxyCodeLine{00005\ \textcolor{preprocessor}{\#include\ "{}\mbox{\hyperlink{NumpyHelpers_8hpp}{aare/file\_io/NumpyHelpers.hpp}}"{}}}
\DoxyCodeLine{00006\ \textcolor{preprocessor}{\#include\ <filesystem>}}
\DoxyCodeLine{00007\ \textcolor{preprocessor}{\#include\ <iostream>}}
\DoxyCodeLine{00008\ \textcolor{preprocessor}{\#include\ <numeric>}}
\DoxyCodeLine{00009\ }
\DoxyCodeLine{00010\ \textcolor{keyword}{namespace\ }\mbox{\hyperlink{namespaceaare}{aare}}\ \{}
\DoxyCodeLine{00011\ }
\DoxyCodeLine{00018\ \textcolor{keyword}{class\ }\mbox{\hyperlink{classaare_1_1NumpyFile}{NumpyFile}}\ :\ \textcolor{keyword}{public}\ \mbox{\hyperlink{classaare_1_1FileInterface}{FileInterface}}\ \{}
\DoxyCodeLine{00019\ }
\DoxyCodeLine{00020\ \ \ \textcolor{keyword}{public}:}
\DoxyCodeLine{00027\ \ \ \ \ \mbox{\hyperlink{classaare_1_1NumpyFile}{NumpyFile}}(\textcolor{keyword}{const}\ std::filesystem::path\ \&fname,\ \textcolor{keyword}{const}\ std::string\ \&mode\ =\ \textcolor{stringliteral}{"{}r"{}},\ \mbox{\hyperlink{structaare_1_1FileConfig}{FileConfig}}\ cfg\ =\ \{\});}
\DoxyCodeLine{00028\ }
\DoxyCodeLine{00029\ \ \ \ \ \textcolor{keywordtype}{void}\ \mbox{\hyperlink{classaare_1_1NumpyFile_a12b0ddf6334dfab4ac0993cd9c45f738}{write}}(\mbox{\hyperlink{classaare_1_1Frame}{Frame}}\ \&frame)\ \textcolor{keyword}{override};}
\DoxyCodeLine{00030\ \ \ \ \ \mbox{\hyperlink{classaare_1_1Frame}{Frame}}\ \mbox{\hyperlink{classaare_1_1NumpyFile_a81e1a331ece6681bbfe9437e049d3b3a}{read}}()\textcolor{keyword}{\ override\ }\{\ \textcolor{keywordflow}{return}\ \mbox{\hyperlink{classaare_1_1NumpyFile_ac0e88af0f3793ef18302db5c503bd3d7}{get\_frame}}(this-\/>\mbox{\hyperlink{classaare_1_1NumpyFile_a080973acac90ab8e6d0552b282e2d73c}{current\_frame}}++);\ \}}
\DoxyCodeLine{00031\ }
\DoxyCodeLine{00032\ \ \ \ \ std::vector<Frame>\ \mbox{\hyperlink{classaare_1_1NumpyFile_a81e1a331ece6681bbfe9437e049d3b3a}{read}}(\textcolor{keywordtype}{size\_t}\ n\_frames)\ \textcolor{keyword}{override};}
\DoxyCodeLine{00033\ \ \ \ \ \textcolor{keywordtype}{void}\ \mbox{\hyperlink{classaare_1_1NumpyFile_a8b25fc8fa2e0ab9e38b0388504d60962}{read\_into}}(std::byte\ *image\_buf)\textcolor{keyword}{\ override\ }\{\ \textcolor{keywordflow}{return}\ \mbox{\hyperlink{classaare_1_1NumpyFile_add05576e7b9256474c104553f0856c80}{get\_frame\_into}}(this-\/>\mbox{\hyperlink{classaare_1_1NumpyFile_a080973acac90ab8e6d0552b282e2d73c}{current\_frame}}++,\ image\_buf);\ \}}
\DoxyCodeLine{00034\ \ \ \ \ \textcolor{keywordtype}{void}\ \mbox{\hyperlink{classaare_1_1NumpyFile_a8b25fc8fa2e0ab9e38b0388504d60962}{read\_into}}(std::byte\ *image\_buf,\ \textcolor{keywordtype}{size\_t}\ n\_frames)\ \textcolor{keyword}{override};}
\DoxyCodeLine{00035\ \ \ \ \ \textcolor{keywordtype}{size\_t}\ \mbox{\hyperlink{classaare_1_1NumpyFile_abe5817c47fa552b7d6de72a4b59d290a}{frame\_number}}(\textcolor{keywordtype}{size\_t}\ frame\_index)\textcolor{keyword}{\ override\ }\{\ \textcolor{keywordflow}{return}\ frame\_index;\ \};}
\DoxyCodeLine{00036\ \ \ \ \ \textcolor{keywordtype}{size\_t}\ \mbox{\hyperlink{classaare_1_1NumpyFile_a35c1b49a469ba8e261d4e675a816b5f2}{bytes\_per\_frame}}()\ \textcolor{keyword}{override};}
\DoxyCodeLine{00037\ \ \ \ \ \textcolor{keywordtype}{size\_t}\ \mbox{\hyperlink{classaare_1_1NumpyFile_a2a40aebcb9b25ad36f1ecd75699c47d0}{pixels}}()\ \textcolor{keyword}{override};}
\DoxyCodeLine{00038\ \ \ \ \ \textcolor{keywordtype}{void}\ \mbox{\hyperlink{classaare_1_1NumpyFile_ae4f669f86fb614e446540638d8efe1b8}{seek}}(\textcolor{keywordtype}{size\_t}\ \mbox{\hyperlink{classaare_1_1NumpyFile_abe5817c47fa552b7d6de72a4b59d290a}{frame\_number}})\textcolor{keyword}{\ override\ }\{\ this-\/>\mbox{\hyperlink{classaare_1_1NumpyFile_a080973acac90ab8e6d0552b282e2d73c}{current\_frame}}\ =\ \mbox{\hyperlink{classaare_1_1NumpyFile_abe5817c47fa552b7d6de72a4b59d290a}{frame\_number}};\ \}}
\DoxyCodeLine{00039\ \ \ \ \ \textcolor{keywordtype}{size\_t}\ \mbox{\hyperlink{classaare_1_1NumpyFile_a022af0b9d792abb00a9dc661beb3e9a2}{tell}}()\textcolor{keyword}{\ override\ }\{\ \textcolor{keywordflow}{return}\ this-\/>\mbox{\hyperlink{classaare_1_1NumpyFile_a080973acac90ab8e6d0552b282e2d73c}{current\_frame}};\ \}}
\DoxyCodeLine{00040\ \ \ \ \ \textcolor{keywordtype}{size\_t}\ \mbox{\hyperlink{classaare_1_1NumpyFile_afec228003225dcc91b16227d24c58d37}{total\_frames}}()\textcolor{keyword}{\ const\ override\ }\{\ \textcolor{keywordflow}{return}\ \mbox{\hyperlink{classaare_1_1NumpyFile_aa2d11ec505dc7c3b4918e194d24d00fe}{m\_header}}.\mbox{\hyperlink{structaare_1_1NumpyHeader_a9715508b7135198e1dd6d705ea189b99}{shape}}[0];\ \}}
\DoxyCodeLine{00041\ \ \ \ \ ssize\_t\ \mbox{\hyperlink{classaare_1_1NumpyFile_a24c0cad439c52b77886c862b8093b91a}{rows}}()\textcolor{keyword}{\ const\ override\ }\{\ \textcolor{keywordflow}{return}\ \mbox{\hyperlink{classaare_1_1NumpyFile_aa2d11ec505dc7c3b4918e194d24d00fe}{m\_header}}.\mbox{\hyperlink{structaare_1_1NumpyHeader_a9715508b7135198e1dd6d705ea189b99}{shape}}[1];\ \}}
\DoxyCodeLine{00042\ \ \ \ \ ssize\_t\ \mbox{\hyperlink{classaare_1_1NumpyFile_ae1558b1ab6fbea54f853cdfad9363d31}{cols}}()\textcolor{keyword}{\ const\ override\ }\{\ \textcolor{keywordflow}{return}\ \mbox{\hyperlink{classaare_1_1NumpyFile_aa2d11ec505dc7c3b4918e194d24d00fe}{m\_header}}.\mbox{\hyperlink{structaare_1_1NumpyHeader_a9715508b7135198e1dd6d705ea189b99}{shape}}[2];\ \}}
\DoxyCodeLine{00043\ \ \ \ \ ssize\_t\ \mbox{\hyperlink{classaare_1_1NumpyFile_afcdc40fcc15f5a3a470e23033ad1323c}{bitdepth}}()\textcolor{keyword}{\ const\ override\ }\{\ \textcolor{keywordflow}{return}\ \mbox{\hyperlink{classaare_1_1NumpyFile_aa2d11ec505dc7c3b4918e194d24d00fe}{m\_header}}.\mbox{\hyperlink{structaare_1_1NumpyHeader_a686bc8e00746ae1ea90c1cc64e1553b6}{dtype}}.\mbox{\hyperlink{classaare_1_1DType_ab097410b8d43b58061b1d64682ff8ac4}{bitdepth}}();\ \}}
\DoxyCodeLine{00044\ }
\DoxyCodeLine{00049\ \ \ \ \ \mbox{\hyperlink{classaare_1_1DType}{DType}}\ \mbox{\hyperlink{classaare_1_1NumpyFile_ae0f029f5e1c09875533962a9ee957a98}{dtype}}()\textcolor{keyword}{\ const\ }\{\ \textcolor{keywordflow}{return}\ \mbox{\hyperlink{classaare_1_1NumpyFile_aa2d11ec505dc7c3b4918e194d24d00fe}{m\_header}}.\mbox{\hyperlink{structaare_1_1NumpyHeader_a686bc8e00746ae1ea90c1cc64e1553b6}{dtype}};\ \}}
\DoxyCodeLine{00050\ }
\DoxyCodeLine{00055\ \ \ \ \ std::vector<size\_t>\ \mbox{\hyperlink{classaare_1_1NumpyFile_a060d3bc922d3a759aabb3716e9c97791}{shape}}()\textcolor{keyword}{\ const\ }\{\ \textcolor{keywordflow}{return}\ \mbox{\hyperlink{classaare_1_1NumpyFile_aa2d11ec505dc7c3b4918e194d24d00fe}{m\_header}}.\mbox{\hyperlink{structaare_1_1NumpyHeader_a9715508b7135198e1dd6d705ea189b99}{shape}};\ \}}
\DoxyCodeLine{00056\ }
\DoxyCodeLine{00063\ \ \ \ \ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ T,\ \textcolor{keywordtype}{size\_t}\ NDim>\ \mbox{\hyperlink{classaare_1_1NDArray}{NDArray<T,\ NDim>}}\ \mbox{\hyperlink{classaare_1_1NumpyFile_ab16bb0e1a3c4d17b137c9c8708b9031c}{load}}()\ \{}
\DoxyCodeLine{00064\ \ \ \ \ \ \ \ \ \mbox{\hyperlink{classaare_1_1NDArray}{NDArray<T,\ NDim>}}\ arr(make\_shape<NDim>(\mbox{\hyperlink{classaare_1_1NumpyFile_aa2d11ec505dc7c3b4918e194d24d00fe}{m\_header}}.\mbox{\hyperlink{structaare_1_1NumpyHeader_a9715508b7135198e1dd6d705ea189b99}{shape}}));}
\DoxyCodeLine{00065\ \ \ \ \ \ \ \ \ fseek(\mbox{\hyperlink{classaare_1_1NumpyFile_a1b3f50636674e919e54b7d61e11ed03a}{fp}},\ \mbox{\hyperlink{classaare_1_1NumpyFile_a5aed02e400e44d7fbc5356365f421c5b}{header\_size}},\ SEEK\_SET);}
\DoxyCodeLine{00066\ \ \ \ \ \ \ \ \ fread(arr.data(),\ \textcolor{keyword}{sizeof}(T),\ arr.size(),\ \mbox{\hyperlink{classaare_1_1NumpyFile_a1b3f50636674e919e54b7d61e11ed03a}{fp}});}
\DoxyCodeLine{00067\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ arr;}
\DoxyCodeLine{00068\ \ \ \ \ \}}
\DoxyCodeLine{00069\ }
\DoxyCodeLine{00070\ \ \ \ \ \mbox{\hyperlink{classaare_1_1NumpyFile_af8d6ace67f7880e6b2cd12da568fbead}{\string~NumpyFile}}();}
\DoxyCodeLine{00071\ }
\DoxyCodeLine{00072\ \ \ \textcolor{keyword}{private}:}
\DoxyCodeLine{00073\ \ \ \ \ FILE\ *\mbox{\hyperlink{classaare_1_1NumpyFile_a1b3f50636674e919e54b7d61e11ed03a}{fp}}\ =\ \textcolor{keyword}{nullptr};}
\DoxyCodeLine{00074\ \ \ \ \ \textcolor{keywordtype}{size\_t}\ \mbox{\hyperlink{classaare_1_1NumpyFile_a85400183bf0f1fdc43fd9a37e3f10a2d}{initial\_header\_len}}\ =\ 0;}
\DoxyCodeLine{00075\ \ \ \ \ \textcolor{keywordtype}{size\_t}\ \mbox{\hyperlink{classaare_1_1NumpyFile_a080973acac90ab8e6d0552b282e2d73c}{current\_frame}}\{\};}
\DoxyCodeLine{00076\ \ \ \ \ uint32\_t\ \mbox{\hyperlink{classaare_1_1NumpyFile_aff59772a6f221edd2606e483ef4ed8ee}{header\_len}}\{\};}
\DoxyCodeLine{00077\ \ \ \ \ uint8\_t\ \mbox{\hyperlink{classaare_1_1NumpyFile_a50d19cf61c165c609c1b707abbe13cbd}{header\_len\_size}}\{\};}
\DoxyCodeLine{00078\ \ \ \ \ \textcolor{keywordtype}{size\_t}\ \mbox{\hyperlink{classaare_1_1NumpyFile_a5aed02e400e44d7fbc5356365f421c5b}{header\_size}}\{\};}
\DoxyCodeLine{00079\ \ \ \ \ \mbox{\hyperlink{structaare_1_1NumpyHeader}{NumpyHeader}}\ \mbox{\hyperlink{classaare_1_1NumpyFile_aa2d11ec505dc7c3b4918e194d24d00fe}{m\_header}};}
\DoxyCodeLine{00080\ \ \ \ \ uint8\_t\ \mbox{\hyperlink{classaare_1_1NumpyFile_a58feea4735fdf9599d810427785266ea}{major\_ver\_}}\{\};}
\DoxyCodeLine{00081\ \ \ \ \ uint8\_t\ \mbox{\hyperlink{classaare_1_1NumpyFile_a2ca45b371f1c56e6b74eaca1852c5ffc}{minor\_ver\_}}\{\};}
\DoxyCodeLine{00082\ }
\DoxyCodeLine{00083\ \ \ \ \ \textcolor{keywordtype}{void}\ \mbox{\hyperlink{classaare_1_1NumpyFile_a1c4bfd5eefa5ac19ecf2aa96c0dbdae3}{load\_metadata}}();}
\DoxyCodeLine{00084\ \ \ \ \ \textcolor{keywordtype}{void}\ \mbox{\hyperlink{classaare_1_1NumpyFile_add05576e7b9256474c104553f0856c80}{get\_frame\_into}}(\textcolor{keywordtype}{size\_t},\ std::byte\ *);}
\DoxyCodeLine{00085\ \ \ \ \ \mbox{\hyperlink{classaare_1_1Frame}{Frame}}\ \mbox{\hyperlink{classaare_1_1NumpyFile_ac0e88af0f3793ef18302db5c503bd3d7}{get\_frame}}(\textcolor{keywordtype}{size\_t}\ \mbox{\hyperlink{classaare_1_1NumpyFile_abe5817c47fa552b7d6de72a4b59d290a}{frame\_number}});}
\DoxyCodeLine{00086\ \};}
\DoxyCodeLine{00087\ }
\DoxyCodeLine{00088\ \}\ \textcolor{comment}{//\ namespace\ aare}}

\end{DoxyCode}
