% -*- coding: utf-8 -*-
%
% doc/tex/head.tex
%-------------------------------------------------- part of the fastmat demos
%
% Author      : sempersn
% Introduced  :

%------------------------------------------------------------------------------
%
%  Copyright 2016 Sebastian Semper, Christoph Wagner
%      https://www.tu-ilmenau.de/ems/
%
%  Licensed under the Apache License, Version 2.0 (the "License");
%  you may not use this file except in compliance with the License.
%  You may obtain a copy of the License at
%
%      http://www.apache.org/licenses/LICENSE-2.0
%
%  Unless required by applicable law or agreed to in writing, software
%  distributed under the License is distributed on an "AS IS" BASIS,
%  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%  See the License for the specific language governing permissions and
%  limitations under the License.
%

%------------------------------------------------------------------------------

%
% to keep everything in context the included packages are placed above
% the sections where they are used and configured
%


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% PGFPLOTS AND TIKZ
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{tikz}
\usetikzlibrary{external}
\tikzexternalize[prefix=plots/]
\tikzsetfigurename{figure_name}
\tikzset{external/up to date check={md5}}
\usepackage{color}
\usepackage{xcolor,pgf}
\usepackage{pgfplots}
\usepackage{pgfplotstable}

\definecolor{fastmatCol}{rgb}{0.984,0.306,0.184}
\definecolor{numpyCol}{rgb}{0.133,0.494,0.616}
\definecolor{complCol}{rgb}{0.867,0.459,0.031}
\definecolor{forwardCol}{rgb}{0.6,0.3,0.1}
\definecolor{backwardCol}{rgb}{0.1,0.3,0.6}

\pgfplotsset{compat=newest}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{intersections}
\usetikzlibrary{patterns}

\pgfplotscreateplotcyclelist{speed}{
    solid,very thick, name path= sf,color=fastmatCol\\%
    solid,very thick, name path= sb,color=numpyCol\\%
}

\pgfplotscreateplotcyclelist{dtypes}{
    solid,thick, name path= sf,color=fastmatCol\\%
    densely dotted,thick, name path= sf,color=fastmatCol\\%
    solid,thick, name path= sb,color=numpyCol\\%
    densely dotted,thick, name path= sb,color=numpyCol\\%
    solid,thick, name path= sf,color=complCol\\%
    densely dotted,thick, name path= sb,color=complCol\\%
    densely dashed,thick, name path= sf,color=complCol\\%
}

\pgfplotscreateplotcyclelist{overhead}{
    solid, very thick, color=forwardCol, name path=sf\\%
    solid, very thick, color=backwardCol, name path=sb\\%
}

\pgfplotscreateplotcyclelist{mem}{
    solid,very thick, name path= sf,color=fastmatCol\\%
    solid,very thick, name path= sb,color=numpyCol\\%
}

\pgfplotsset{benchmark/.style={%
    legend style={
        font=\tiny,
        at={(0.12,0.7)},
        anchor=west,
        legend columns=1,
        draw=none,
        name=legend,
        fill=none
    },
    minor y tick num = 3,
    width=0.95\columnwidth,
    height=0.66\columnwidth,
    xlabel=$n$,
    ylabel={$\mathrm{time} [s]$},
    xlabel style={font=\tiny},
    ylabel style={font=\tiny},
    xticklabel style={font=\tiny,text height=1.7ex},
    yticklabel style={font=\tiny},
    }
}

\pgfplotsset{dtypes/.style={%
    legend style={
        font=\tiny,
        at={(0.12,0.7)},
        anchor=west,
        legend columns=2,
        draw=none,
        name=legend,
        fill=none
    },
    minor y tick num = 3,
    width=0.95\columnwidth,
    height=0.66\columnwidth,
    xlabel=$n$,
    ylabel={$\mathrm{time} [s]$},
    xlabel style={font=\tiny},
    ylabel style={font=\tiny},
    xticklabel style={font=\tiny,text height=1.7ex},
    yticklabel style={font=\tiny},
    }
}

\pgfplotsset{memory/.style={%
    legend style={
        font=\tiny,
        at={(0.12,0.7)},
        anchor=west,
        legend columns=1,
        draw=none,
        name=legend,
        fill=none
    },
    minor y tick num = 3,
    width=0.95\columnwidth,
    height=0.66\columnwidth,
    xlabel=$n$,
    ylabel={\si{\kilo\byte}},
    xlabel style={font=\tiny},
    ylabel style={font=\tiny},
    xticklabel style={font=\tiny,text height=1.7ex},
    yticklabel style={font=\tiny},
    }}

\newcommand{\overhead}[3]{
\hfill\begin{tikzpicture}
    \begin{axis}[
    benchmark,
    ymode=log,
    xmode=log,
    cycle list name=overhead,
    ylabel={#3},
    ]
    #1
    \end{axis}
    \node[anchor=south] at (legend.north) {\footnotesize #2};
\end{tikzpicture}
}

\newcommand{\speed}[3]{
\hfill\begin{tikzpicture}
    \begin{axis}[
    benchmark,
    ymode=log,
    xmode=log,
    cycle list name=speed,
    ylabel={#3},
    ]
    #1
    \end{axis}
    \node[anchor=south] at (legend.north) {\footnotesize #2};
\end{tikzpicture}
}

\newcommand{\dtypes}[3]{
\hfill\begin{tikzpicture}
    \begin{axis}[
    dtypes,
    ymode=log,
    xmode=log,
    cycle list name=dtypes,
    ylabel={#3},
    ]
    #1
    \end{axis}
    \node[anchor=south] at (legend.north) {\footnotesize #2};
\end{tikzpicture}
}

\newcommand{\mem}[3]{
\hfill\begin{tikzpicture}
    \begin{axis}[
    memory,
    ymode=log,
    xmode=log,
    cycle list name=mem,
    ylabel={#3}
    ]
    #1
    \end{axis}
    \node[anchor=south] at (legend.north) {\footnotesize #2};
\end{tikzpicture}
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% CODE SNIPPET DISPLAY
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{listings}

\definecolor{mygreen}{rgb}{0,0.6,0}
\definecolor{mygray}{rgb}{0.5,0.5,0.5}
\definecolor{mymauve}{rgb}{0.58,0,0.82}
\definecolor{shadecolor}{rgb}{0.95,0.95,0.95}
\definecolor{numbercol}{rgb}{0.4,0.1,0.1}

\lstset{ %
    backgroundcolor=\color{white},
    basicstyle=\linespread{0.9}\ttfamily\small,
    breakatwhitespace=true,					
    breaklines=true,						
    captionpos=b,							
    commentstyle=\color{mygreen},			
    deletekeywords={...},					
    escapeinside={\%*}{*)},					
    extendedchars=true,						
    frame=single,							
    keepspaces=true,						
    keywordstyle=\color{blue},				
    language=Python, 						
    otherkeywords={*,...},					
    numbers=left,							
    numbersep=2pt,							
    numberstyle=\tiny\ttfamily\color{numbercol}, 
    rulecolor=\color{white},			
    showspaces=false,						
    showstringspaces=false,					
    showtabs=false,							
    stepnumber=2,							
    stringstyle=\color{mymauve},
    tabsize=2,								
    title=\lstname,							
    belowskip=-10pt,
}

\newenvironment{snippet}[1][Usage Example]{
\vspace{3mm plus0mm minus3mm}
\large \textbf{#1}
\vspace{2mm}
\hrule
\vspace{3mm}
\small
}{
\vspace{8mm plus0mm minus3mm}
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% LAYOUT FORMATTING
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
\usepackage[headheight=12pt,top=0.7in, bottom=0.9in, left=0.5in, 
right=0.5in]{geometry}
\usepackage{fancyhdr}
\usepackage{multicol}
\usepackage[keeplastbox]{flushend}
\usepackage{titletoc}
\usepackage[raggedright]{titlesec}

\usepackage[activate={true,nocompatibility},final,tracking=true,kerning=true,
spacing=true,factor=1100,stretch=10,shrink=10]{microtype}
\microtypecontext{spacing=nonfrench}

% paragraph formatting
\setlength\columnsep{5mm}
\setlength{\parindent}{0mm}
\setlength{\parskip}{1.5mm plus1mm minus1mm}

% table of contents formatting
\setcounter{tocdepth}{2}
\titlecontents{section}
[3.8em]
{\vspace{-.3em}}
{\contentslabel{2.3em}}
{\hspace*{-2.3em}}
{\titlerule*[1pc]{.}\contentspage}
\titlecontents{subsection}
[5em]
{\vspace{-.3em}}
{\contentslabel{2.3em}}
{\hspace*{-2.3em}}
{\titlerule*[1pc]{.}\contentspage}

% heading formatting
\titlespacing\section{0pt}{2pt plus 4pt minus 2pt}{2pt plus 2pt minus 2pt}
\titlespacing\subsection{0pt}{2pt plus 4pt minus 2pt}{2pt plus 2pt minus 
2pt}
\titlespacing\subsubsection{0pt}{2pt plus 2pt minus 2pt}{2pt plus 2pt minus 
2pt}

% header formatting
\pagestyle{fancy}
\lhead[]{}
\chead{}
\rhead[]{}
\rfoot[]{{\sffamily \textbf{\thepage}}}
\cfoot{}
\lfoot[{\sffamily \textbf{\thepage}}]{}
\renewcommand{\headrulewidth}{0.0pt}
\renewcommand{\footrulewidth}{0.0pt}

% page formatting
\fancypagestyle{plain}{
    \fancyhf{}
    \fancyfoot[LE,RO]{{\sffamily \thepage}}
    \renewcommand{\headrulewidth}{0pt}
    \renewcommand{\footrulewidth}{0.2pt}
}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% CONVENIENT MAKROS FOR TEXT AND MATH
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{bm}

\newcommand{\fm}{\texttt{fastmat}}
\newcommand{\np}{\texttt{numpy}}
\newcommand{\scip}{\texttt{scipy}}

\newcommand{\trans}{\mathrm{T}}
\newcommand{\herm}{\mathrm{H}}
\newcommand{\R}{\mathbb{R}}
\newcommand{\C}{\mathbb{C}}
\newcommand{\K}{\mathbb{K}}
\newcommand{\N}{\mathbb{N}}
\newcommand{\PP}{\mathbb{P}}
\newcommand{\Ps}[1]{{\mathfrak{P}\left( #1\right)}}
\newcommand{\Hs}{\mathcal{H}}
\newcommand{\Fs}{\mathcal{F}}
\newcommand{\Gs}{\mathcal{G}}
\newcommand{\Li}{\mathcal{L}}
\newcommand{\RT}{{\mathscr{R}}}
\newcommand{\FT}{{\mathscr{F}}}
\newcommand{\BT}{{\mathscr{B}}}
\newcommand{\HT}{{\mathscr{H}}}
\newcommand{\ScPr}[2]{{\left\langle #1,#2 \right\rangle}}
\newcommand{\Norm}[1]{{\left\Vert #1\right\Vert}}
\newcommand{\Abs}[1]{{\left| #1 \right|}}
\newcommand{\Text}[1]{{\hspace{3mm} \text{#1} \hspace{3mm}}}
\newcommand{\brac}[2]{{\left(\frac{#1}{#2}\right)}}
\newcommand{\br}[1]{{\left(#1\right)}}
\newcommand{\Int}[4]{{\int\limits_{#1}^{#2}{#3}\,\mathrm{d}{#4}}}
\newcommand{\Sum}[3]{{\sum\limits_{#1}^{#2}{#3}}}
\newcommand{\Prod}[3]{{\prod\limits_{#1}^{#2}{#3}}}
\newcommand{\SumB}[3]{{\left(\sum\limits_{#1}^{#2}{#3}\right)}}
\newcommand{\ProdB}[3]{{\left(\prod\limits_{#1}^{#2}{#3}\right)}}
\newcommand{\ConvA}[2]{{\xrightarrow[]{#1 \rightarrow #2}}}
\newcommand{\RA}[1]{\overset{#1}{\Rightarrow}}
\newcommand{\LRA}[1]{\overset{#1}{\Leftrightarrow}}
\newcommand{\V}[0]{\hspace{1.2mm}\vert\hspace{1.5mm}}
\newcommand{\D}[0]{\hspace{0.5mm}:\hspace{1.0mm}}
\DeclareMathOperator*{\argmin}{argmin}
\DeclareMathOperator*{\diag}{diag}
\DeclareMathOperator*{\Span}{span}
\DeclareMathOperator*{\Max}{max}
\DeclareMathOperator*{\Min}{min}
\DeclareMathOperator*{\sign}{sign}
\DeclareMathOperator*{\Mod}{Mod}
\DeclareMathOperator*{\Tr}{tr}
\DeclareMathOperator*{\Rk}{rk}
\DeclareMathOperator*{\ran}{ran}
\DeclareMathOperator*{\Supp}{supp}
\DeclareMathOperator*{\Vol}{Vol}
\DeclareMathOperator*{\pack}{pack}
\DeclareMathOperator*{\Dom}{dom}
\DeclareMathOperator*{\Vectorize}{vec}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% HELPER PACKAGES
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{calc}
\usepackage{newclude}
\usepackage[binary-units=true]{siunitx}
\usepackage{hyperref}
\hypersetup{
    colorlinks,
    linkcolor={red!50!black},
    citecolor={blue!50!black},
    urlcolor={blue!80!black}
}
