1 #ifndef MSHADOW_TENSOR_IO_H
2 #define MSHADOW_TENSOR_IO_H
26 virtual size_t Read(
void *ptr,
size_t size ) = 0;
32 virtual void Write(
const void *ptr,
size_t size ) = 0;
45 template<
int dim,
typename TStream>
46 inline void SaveBinary( TStream &fo,
const Tensor<cpu,dim> &src );
48 template<
int dim,
typename TStream>
49 inline void SaveBinary( TStream &fo,
const Tensor<gpu,dim> &src );
61 template<
int dim,
typename TStream>
62 inline void LoadBinary( TStream &fi, Tensor<cpu,dim> &dst,
bool pre_alloc );
64 template<
int dim,
typename TStream>
65 inline void LoadBinary( TStream &fi, Tensor<gpu,dim> &dst,
bool pre_alloc );
73 virtual size_t Read(
void *ptr,
size_t size ){
74 return fread( ptr, size, 1, fp_ );
76 virtual void Write(
const void *ptr,
size_t size ){
77 fwrite( ptr, size, 1, fp_ );
91 template<
int dim,
typename TStream>
96 fo.Write( src[i].dptr,
sizeof(
real_t)*src.
shape[0] );
99 template<
int dim,
typename TStream>
109 template<
int dim,
typename TStream>
119 if( dst.
shape[0] == 0 )
return;
124 template<
int dim,
typename TStream>
137 #endif // TENSOR_IO_H
unsigned index_t
type that will be used for index
Definition: tensor_base.h:123
virtual size_t Read(void *ptr, size_t size)
read data from stream
Definition: tensor_io.h:73
virtual size_t Read(void *ptr, size_t size)=0
read data from stream
void FreeSpace(Tensor< cpu, dim > &obj)
CPU/GPU: free the space of tensor, will set obj.dptr to NULL.
Definition: tensor_cpu-inl.hpp:36
void Assert(bool exp)
assert a expression is true
Definition: tensor_base.h:285
implementation of file i/o stream
Definition: tensor_io.h:69
index_t shape_[kMaxShape]
storing the dimension information
Definition: tensor.h:129
float real_t
type that will be used for content
Definition: tensor_base.h:118
header file of tensor data structure and functions covention: this lib requires explicit memory alloc...
FileStream(FILE *fp)
constructor
Definition: tensor_io.h:72
void Close(void)
close file
Definition: tensor_io.h:80
void SaveBinary(TStream &fo, const Tensor< cpu, dim > &src)
CPU/GPU: save a tensor by binary format, for GPU version, a temp Tensor<cpu,dim> storage will be allo...
Definition: tensor_io.h:92
virtual void Write(const void *ptr, size_t size)
write data to stream
Definition: tensor_io.h:76
real_t * dptr
pointer to the data
Definition: tensor.h:215
MSHADOW_XINLINE Tensor< Device, 2 > FlatTo2D(void) const
flatten the tensor to 2 dimension, collapse the higher dimensions together
Definition: tensor.h:229
void Copy(Tensor< cpu, dim > dst, const Tensor< cpu, dim > &src)
copy data from one tensor to another, with same shape
Definition: tensor_cpu-inl.hpp:42
Shape< dimension > shape
shape of the tensor
Definition: tensor.h:217
void AllocSpace(Tensor< cpu, dim > &obj, bool pad=MSHADOW_ALLOC_PAD)
CPU/CPU: allocate space for CTensor, according to the shape in the obj this function is responsible t...
Definition: tensor_cpu-inl.hpp:14
interface of stream I/O, used to serialize data, it is not restricted to only this interface in SaveB...
Definition: tensor_io.h:18
virtual ~IStream(void)
virtual destructor
Definition: tensor_io.h:34
general tensor
Definition: tensor.h:206
void LoadBinary(TStream &fi, Tensor< cpu, dim > &dst, bool pre_alloc)
CPU/GPU: load a tensor by binary format, for GPU version, a temp Tensor<cpu,dim> storage will be allo...
Definition: tensor_io.h:110
virtual void Write(const void *ptr, size_t size)=0
write data to stream