资源简介
这是一个基于 C++的HOSVD源代码,经过测试,不过只能分解3阶张量

代码片段和文件信息
#include “StdAfx.h“
#include “HOSVD.h“
#include
#include “math.h“
CHOSVD::CHOSVD(void)
{
}
CHOSVD::~CHOSVD(void)
{
}
inline void* CHOSVD::AlignPtr( const void* ptr int align=32 )
{
// assert( (align & (align-1)) == 0 );
return (void*)( ((size_t)ptr + align - 1) & ~(size_t)(align-1) );
}
inline int CHOSVD::Align( int size int align )
{
// assert( (align & (align-1)) == 0 && size < INT_MAX );
return (size + align - 1) & -align;
}
Matrix* CHOSVD::CreateMatHeader( int rows int cols int type )
{
Matrix* arr = 0;
int min_step;
type = MAT_TYPE(type);
min_step = ELEM_SIZE(type)*cols;
arr = (Matrix*)malloc( sizeof(*arr));
arr->step = rows == 1 ? 0 : Align(min_step DEFAULT_MAT_ROW_ALIGN);
arr->type = MAT_MAGIC_VAL | type |
(arr->step == 0 || arr->step == min_step ? MAT_CONT_FLAG : 0);
arr->rows = rows;
arr->cols = cols;
arr->data.ptr = 0;
arr->refcount = 0;
arr->hdr_refcount = 1;
return arr;
}
void CHOSVD::CreateData( CvArr* arr )
{
//if( CV_IS_MAT_HDR( arr ))
//{
size_t step total_size;
Matrix* mat = (Matrix*)arr;
step = mat->step;
//if( mat->data.ptr != 0 )
// CV_ERROR( CV_StsError “Data is already allocated“ );
if( step == 0 )
step = ELEM_SIZE(mat->type)*mat->cols;
total_size = step*mat->rows + sizeof(int) + MALLOC_ALIGN;
mat->refcount = (int*)malloc( (size_t)total_size );
mat->data.ptr = (uchar*)AlignPtr( mat->refcount + 1 MALLOC_ALIGN );
*mat->refcount = 1;
//}
}
Matrix* CHOSVD::CreateMat( int height int width int type )
{
Matrix* arr = 0;
arr = CreateMatHeader( height width type );
CreateData( arr );
return arr;
}
/* y[0:m0:n] += diag(a[0:10:m]) * x[0:m0:n] */
void CHOSVD::iMatrAXPY_64f( int m int n const double* x int dx
const double* a double* y int dy )
{
int i j;
for( i = 0; i < m; i++ x += dx y += dy )
{
double s = a[i];
for( j = 0; j <= n - 4; j += 4 )
{
double t0 = y[j] + s*x[j];
double t1 = y[j+1] + s*x[j+1];
y[j] = t0;
y[j+1] = t1;
t0 = y[j+2] + s*x[j+2];
t1 = y[j+3] + s*x[j+3];
y[j+2] = t0;
y[j+3] = t1;
}
for( ; j < n; j++ ) y[j] += s*x[j];
}
}
/* y[1:m-1] = h*y[1:m0:n]*x[0:10:n]‘*x[-1] (this is used for U&V reconstruction)
y[1:m0:n] += h*y[1:m0:n]*x[0:10:n]‘*x[0:10:n] */
void CHOSVD::iMatrAXPY3_64f( int m int n const double* x int l double* y double h )
{
int i j;
for( i = 1; i < m; i++ )
{
double s = 0;
y += l;
for( j = 0; j <= n - 4; j += 4 )
s += x[j]*y[j] + x[j+1]*y[j+1] + x[j+2]*y[j+2] + x[j+3]*y[j+3];
for( ; j < n; j++ ) s += x[j]*y[j];
s *= h;
y[-1] = s*x[-1];
for( j = 0; j <= n - 4; j += 4 )
{
double t0 = y[j] + s*x[j];
double t1 = y[j+1] + s*x[j+1];
y[j] = t0;
y[j+1] = t1;
t0 = y[j+2] + s*x[j+2];
t1 = y[j+3] + s*x[j+3];
y[j+2] = t0;
y[j+3] =
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 32739 2009-03-04 22:28 HOSVD.cpp
文件 4343 2009-03-04 22:24 HOSVD.h
文件 5315 2009-03-04 22:24 HosvdView.cpp
文件 1140 2009-03-04 21:01 HosvdView.h
----------- --------- ---------- ----- ----
43537 4
- 上一篇:C语言 机房收费管理系统
- 下一篇:MFC 多线程之间通过消息传递数据
相关资源
- 基于MFC的TCP调试助手源码95706
- 国际象棋的qt源代码
- C语言开发实战宝典
- 移木块游戏,可以自编自玩,vc6.0编写
- C++纯文字DOS超小RPG游戏
- 小甲鱼C语言课件 源代码
- 安科瑞智能电能表MODBUS通讯程序 VC6
- c语言看发的网络协议 ,源代码
- C语言实现的DES对称加密算法
- 数据结构,迷宫问题C语言版源代码
- C语言 学生信息管理系统 源代码
- C语言版3D魔方游戏源代码
- QT5开发及源代码
- 九齐单片机源码
- Qt画图工具源码(qgraphics draw)
- qt 串口助手源码
- modbus 主机源码
- 《LINUX C编程从初学到精通》光盘源码
- USB CAN Tool 源代码(LabVIEW 2011环境)
- 超声波水表源代码
- OLED驱动源码
- 一个模糊PID温度控制算法源代码
- tm1650+stm32f103源码(board_tm1650.c)
- cheat engine 7.2源码
- CrySearch内存搜索器源码
- 数据结构 图的遍历源代码
- 数据结构实验源代码集
- TCP/IP客户端和服务器端源代码,好用
- FTP客户端源码(c++)
- MFC视频播放器源码(支持avi/wma/mp3等格
评论
共有 条评论