fml
0.1-0
Fused Matrix Library
univec.hh
1
// This file is part of fml which is released under the Boost Software
2
// License, Version 1.0. See accompanying file LICENSE or copy at
3
// https://www.boost.org/LICENSE_1_0.txt
4
5
#ifndef FML__INTERNALS_UNIVEC_H
6
#define FML__INTERNALS_UNIVEC_H
7
#pragma once
8
9
10
#include <stdexcept>
11
12
#include "types.hh"
13
14
15
namespace
fml
16
{
21
template
<
typename
T>
22
class
univec
23
{
24
public
:
26
len_t
size
()
const
{
return
_size;};
28
T*
data_ptr
() {
return
data;};
29
T*
data_ptr
()
const
{
return
data;};
30
31
protected
:
32
len_t _size;
33
T *data;
34
bool
free_data;
35
36
bool
should_free()
const
{
return
free_data;};
37
void
check_index(
const
len_t i)
const
;
38
void
printval(
const
T val, uint8_t ndigits)
const
;
39
};
40
}
41
42
43
44
template
<
typename
REAL>
45
void
fml::univec<REAL>::check_index
(
const
len_t i)
const
46
{
47
if
(i < 0 || i >= this->_size)
48
throw
std::runtime_error(
"index out of bounds"
);
49
}
50
51
52
53
template
<>
54
inline
void
fml::univec<int>::printval
(
const
int
val, uint8_t ndigits)
const
55
{
56
(void)ndigits;
57
fml::print::printf(
"%d "
, val);
58
}
59
60
template
<
typename
T>
61
void
fml::univec<T>::printval
(
const
T val, uint8_t ndigits)
const
62
{
63
fml::print::printf(
"%.*f "
, ndigits, val);
64
}
65
66
67
#endif
fml::univec
Base vector class. Not meant for direct use. Instead see cpuvec and gpuvec.
Definition:
univec.hh:22
fml::univec::data_ptr
T * data_ptr()
Pointer to the internal array.
Definition:
univec.hh:28
fml
Core namespace.
Definition:
dimops.hh:10
fml::univec::size
len_t size() const
Number of elements in the vector.
Definition:
univec.hh:26
fml
src
fml
_internals
univec.hh
Generated by
1.8.17