当前位置:网站首页>ncnn Mat矩阵类
ncnn Mat矩阵类
2022-07-17 00:17:00 【HySmiley】
ncnn-mat.h
class NCNN_EXPORT Mat
构造函数
// empty
Mat();
// vec
Mat(int w, size_t elemsize = 4u, Allocator* allocator = 0);
// image
Mat(int w, int h, size_t elemsize = 4u, Allocator* allocator = 0);
// dim
Mat(int w, int h, int c, size_t elemsize = 4u, Allocator* allocator = 0);
// cube
Mat(int w, int h, int d, int c, size_t elemsize = 4u, Allocator* allocator = 0);
// packed vec
Mat(int w, size_t elemsize, int elempack, Allocator* allocator = 0);
// packed image
Mat(int w, int h, size_t elemsize, int elempack, Allocator* allocator = 0);
// packed dim
Mat(int w, int h, int c, size_t elemsize, int elempack, Allocator* allocator = 0);
// packed cube
Mat(int w, int h, int d, int c, size_t elemsize, int elempack, Allocator* allocator = 0);
// copy
Mat(const Mat& m);
// external vec
Mat(int w, void* data, size_t elemsize = 4u, Allocator* allocator = 0);
// external image
Mat(int w, int h, void* data, size_t elemsize = 4u, Allocator* allocator = 0);
// external dim
Mat(int w, int h, int c, void* data, size_t elemsize = 4u, Allocator* allocator = 0);
// external cube
Mat(int w, int h, int d, int c, void* data, size_t elemsize = 4u, Allocator* allocator = 0);
// external packed vec
Mat(int w, void* data, size_t elemsize, int elempack, Allocator* allocator = 0);
// external packed image
Mat(int w, int h, void* data, size_t elemsize, int elempack, Allocator* allocator = 0);
// external packed dim
Mat(int w, int h, int c, void* data, size_t elemsize, int elempack, Allocator* allocator = 0);
// external packed cube
Mat(int w, int h, int d, int c, void* data, size_t elemsize, int elempack, Allocator* allocator = 0);
// release
~Mat();
// assign
Mat& operator=(const Mat& m);
。。。
。。。
。。。参数:
w:图像宽
h:图像高
c:通道数
elemsize:元素字节数 // 4 = float32/int32, // 2 = float16, // 1 = int8/uint8, // 0 = empty
elempack
构造函数实现内部调用create重载函数
NCNN_FORCEINLINE Mat::Mat()
: data(0), refcount(0), elemsize(0), elempack(0), allocator(0), dims(0), w(0), h(0), d(0), c(0), cstep(0)
{
}
NCNN_FORCEINLINE Mat::Mat(int _w, size_t _elemsize, Allocator* _allocator)
: data(0), refcount(0), elemsize(0), elempack(0), allocator(0), dims(0), w(0), h(0), d(0), c(0), cstep(0)
{
create(_w, _elemsize, _allocator);
}
NCNN_FORCEINLINE Mat::Mat(int _w, int _h, size_t _elemsize, Allocator* _allocator)
: data(0), refcount(0), elemsize(0), elempack(0), allocator(0), dims(0), w(0), h(0), d(0), c(0), cstep(0)
{
create(_w, _h, _elemsize, _allocator);
}
NCNN_FORCEINLINE Mat::Mat(int _w, int _h, int _c, size_t _elemsize, Allocator* _allocator)
: data(0), refcount(0), elemsize(0), elempack(0), allocator(0), dims(0), w(0), h(0), d(0), c(0), cstep(0)
{
create(_w, _h, _c, _elemsize, _allocator);
}
NCNN_FORCEINLINE Mat::Mat(int _w, int _h, int _d, int _c, size_t _elemsize, Allocator* _allocator)
: data(0), refcount(0), elemsize(0), elempack(0), allocator(0), dims(0), w(0), h(0), d(0), c(0), cstep(0)
{
create(_w, _h, _d, _c, _elemsize, _allocator);
}
...
...
...
创建Mat对象后,根据构造函数重载对应调用create重载函数,实现数据内存空间申请,字节对齐等操作,没有赋值,默认值是?
void Mat::create(int _w, int _h, int _d, int _c, size_t _elemsize, int _elempack, Allocator* _allocator)
{
if (dims == 4 && w == _w && h == _h && d == _d && c == _c && elemsize == _elemsize && elempack == _elempack && allocator == _allocator)
return;
release();
elemsize = _elemsize;
elempack = _elempack;
allocator = _allocator;
dims = 4;
w = _w;
h = _h;
d = _d;
c = _c;
cstep = alignSize((size_t)w * h * d * elemsize, 16) / elemsize;
if (total() > 0)
{
size_t totalsize = alignSize(total() * elemsize, 4);
if (allocator)
data = allocator->fastMalloc(totalsize + (int)sizeof(*refcount));
else
data = fastMalloc(totalsize + (int)sizeof(*refcount));
refcount = (int*)(((unsigned char*)data) + totalsize);
*refcount = 1;
}
}边栏推荐
猜你喜欢
随机推荐
Squid agent service deployment
yolov5 opencv DNN 推理
责任链模式的高级用法
Reflection and Discussion on time management methods
从MySQL架构看一条SQL语句是如何执行的?
FTP service
MySQL backup and recovery
HCIA第一次静态路由实验
Redis之简单动态字符串SDS
SQL之CASE WHEN用法详解
Binary installation kubernetes 1.24.1
HCIP第一天_HCIA复习
一文搞懂JVM内存结构
Echo -e usage
Conditional statement of shell script
Firewall firewall
All dates in Oracle query time period
Rhce8 Study Guide Chapter 7 service management
Arm cross compiler naming rules
Understand the switch and its role








