package com.omega.common.utils;
import java.util.Vector;
import org.ejml.simple.SimpleMatrix;
import com.omega.common.task.Task;
import com.omega.common.task.TaskEngine;
import com.omega.engine.gpu.GPUOP;
import com.omega.engine.pooling.PoolingType;
/**
*
* @ClassName: MatrixOperation
*
* @author lijiaming
*
* @date 2020年7月24日
*
* @Description:
* TODO(用一句话描述该文件做什么)
*
*/
public class MatrixOperation {
private static final int threadNum = 8;
/**
*
* @Title: exp
*
* @param x
* @return
*
* @Description:
* TODO(这里用一句话描述这个方法的作用)
*
* @throws
*/
public static float[] exp(float[] x) {
float[] temp = MatrixUtils.zero(x.length);
for(int i = 0;i<x.length;i++) {
temp[i] = (float)Math.exp(x[i]);
}
return temp;
}
public static float[] log(float[] x) {
float[] temp = MatrixUtils.zero(x.length);
for(int i = 0;i<x.length;i++) {
if(x[i] == 0) {
temp[i] = (float)Math.log(1e-47);
}else {
temp[i] = (float)Math.log(x[i]);
}
}
return temp;
}
public static float[] sin(float[] x) {
float[] temp = MatrixUtils.zero(x.length);
for(int i = 0;i<x.length;i++) {
temp[i] = (float)Math.sin(x[i]);
}
return temp;
}
public static float[] cos(float[] x) {
float[] temp = MatrixUtils.zero(x.length);
for(int i = 0;i<x.length;i++) {
temp[i] = (float)Math.cos(x[i]);
}
return temp;
}
public static float[] tan(float[] x) {
float[] temp = MatrixUtils.zero(x.length);
for(int i = 0;i<x.length;i++) {
temp[i] = (float)Math.tan(x[i]);
}
return temp;
}
public static float[] atan(float[] x) {
float[] temp = MatrixUtils.zero(x.length);
for(int i = 0;i<x.length;i++) {
temp[i] = (float)Math.atan(x[i]);
}
return temp;
}
public static float[] tan_back(float[] x) {
float[] temp = MatrixUtils.zero(x.length);
for(int i = 0;i<x.length;i++) {
temp[i] = (float)(1.0f / Math.pow(Math.cos(x[i]), 2));
}
return temp;
}
public static float[] atan_back(float[] x) {
float[] temp = MatrixUtils.zero(x.length);
for(int i = 0;i<x.length;i++) {
temp[i] = 1.0f / (1.0f + x[i] * x[i]);
}
return temp;
}
public static boolean isNaN(float[] x) {
for(float v:x) {
if(Float.isNaN(v)) {
return true;
}
}
return false;
}
public static boolean isInfinite(float[] x) {
for(float v:x) {
if(Float.isInfinite(v)) {
return true;
}
}
return false;
}
/**
*
* @Title: exp
*
* @param x
* @return
*
* @Description:
* TODO(这里用一句话描述这个方法的作用)
*
* @throws
*/
public static float[] pow(float[] x,float e) {
float[] temp = MatrixUtils.zero(x.length);
for(int i = 0;i<x.length;i++) {
temp[i] = (float)Math.pow(x[i],e);
}
return temp;
}
/**
*
* @Title: exp
*
* @param x
* @return
*
* @Description:
* TODO(这里用一句话描述这个方法的作用)
*
* @throws
*/
public static float[][] pow(float[][] x,float e) {
float[][] temp = MatrixUtils.zero(x.length,x[0].length);
for(int i = 0;i<x.length;i++) {
for(int j = 0;j<x[i].length;j++) {
temp[i][j] = (float)Math.pow(x[i][j],e);
}
}
return temp;
}
/**
*
* @Title: add
*
* @param x
* @param b
* @return
*
* @Description:
* TODO(这里用一句话描述这个方法的作用)
*
* @throws
*/
public static float[] add(float[] x,float b) {
float[] temp = MatrixUtils.zero(x.length);
for(int i = 0;i<x.length;i++) {
temp[i] = x[i] + b;
}
return temp;
}
public static float[] addToY(float[] x,float b,int n,int c,int h,int w,int[] position) {
int dims = position[0];
int start= position[1];
int count = position[2];
switch (dims) {
case 0:
return addByNumberToY(x, b, n, c, h, w, start, count);
case 1:
return addByChannelToY(x, b, n, c, h, w, start, count);
}
return null;
}
public static float[] addByNumberToY(float[] x,float b,int n,int c,int h,int w,int start,int count) {
int size = c * h * w;
float[] y = MatrixUtils.clone(x);
for(int i = 0;i<count;i++) {
int tn = i / size + start;
int tc = (i / h / w) % c;
int th = i / w;
int tw = i % h;
int index = tn * size + tc * h * w + th * w + tw;
y[index] = x[index] + b;
}
return y;
}
public static float[] addByChannelToY(float[] x,float b,int n,int c,int h,int w,int start,int count) {
int size = c * h * w;
int bc = count / n / h / w;
float[] y = MatrixUtils.clone(x);
for(int i = 0;i<count;i++) {
int tn = i / size;
int tc = (i / h / w) % bc + start;
int th = i / w;
int tw = i % h;
int index = tn * size + tc * h * w + th * w + tw;
y[index] = x[index] + b;
}
return y;
}
/**
*
* @Title: add
*
* @param x
* @param b
* @return
*
* @Description:
* TODO(这里用一句话描述这个方法的作用)
*
* @throws
*/
public static float[][] add(float[][] x,float b) {
if(x == null) {
new RuntimeException("matrix is null.");
}
float[][] temp = MatrixUtils.zero(x.length,x[0].length);
for(int i = 0;i<x.length;i++) {
for(int j = 0;j<x[i].length;j++) {
temp[i][j] = x[i][j] + b;
}
}
return temp;
}
/**
*
* @Title: add
*
* @param x
* @param b
* @return
*
* @Description:
* TODO(这里用一句话描述这个方法的作用)
*
* @throws
*/
public static float[][][] add(float[][][] x,float b) {
if(x == null) {
new RuntimeException("matrix is null.");
}
float[][][] temp = MatrixUtils.zero(x.length,x[0].length,x[0][0].length);
for(int i = 0;i<x.length;i++) {
for(int j = 0;j<x[i].length;j++) {
for(int n = 0;n<x[i][j].length;n++) {
temp[i][j][n] = x[i][j][n] + b;
}
}
}
return temp;
}
/**
*
* @Title: add
*
* @param x
* @param b
* @return
*
* @Description:
* TODO(这里用一句话描述这个方法的作用)
*
* @throws
*/
public static float[][][][] add(float[][][][] x,float b) {
if(x == null) {
new RuntimeException("matrix is null.");
}
float[][][][] temp = MatrixUtils.zero(x.length,x[0].length,x[0][0].length,x[0][0][0].length);
for(int n = 0;n<x.length;n++) {
for(int c = 0;c<x[n].length;c++) {
for(int h = 0;h<x[n][c].length;h++) {
for(int w = 0;w<x[n][c][h].length;w++) {
temp[n][c][h][w] = x[n][c][h][w] + b;
}
}
}
}
return temp;
}
/**
*
* @Title: add
*
* @param x
* @param b
* @return
*
* @Description:
* TODO(这里用一句话描述这个方法的作用)
*
* @throws
*/
public static float[] add(float[] x,float[] b) {
float[] temp = MatrixUtils.zero(x.length);
for(int i = 0;i<x.length;i++) {
temp[i] = x[i] + b[i];
}
return temp;
}
/**
*
* @Title: add
*
* @param x
* @param b
* @return
*
* @Description:
* TODO(这里用一句话描述这个方法的作用)
*
* @throws
*/
public static void plus(float[] x,float[] b) {
for(int i = 0;i<x.length;i++) {
x[i] = x[i] + b[i];
}
}
/**
*
* @Title: add
*
* @param x
* @param b
* @return
*
* @Description:
* TODO(这里用一句话描述这个方法的作用)
*
* @throws
*/
public static void add(float[] x,float[] b,int n,int c,int h,int w,int[] position) {
int dims = position[0];
int start= position[1];
switch (dims) {
case 0:
addByNumber(x, b, n, c, h, w, start);
break;
case 1:
addByChannel(x, b, n, c, h, w, start);
break;
}
}
public static void addByNumber(float[] x,float[] b,int n,int c,int h,int w,int start) {
int size = c * h * w;
for(int i = 0;i<b.length;i++) {
int tn = i / size + start;
int tc = (i / h / w) % c;
int th = (i / w) % h;
int tw = i % h;
int index = tn * size + tc * h * w + th * w + tw;
x[index] = x[index] + b[i];
}
}
public static void addByChannel(float[] x,float[] b,int n,int c,int h,int w,int start) {
int bc = b.length / n / h / w;
int size = bc * h * w;
for(int i = 0;i<b.lengt
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
Omega-AI:基于java打造的深度学习框架,帮助你快速搭建神经网络,实现模型推理与训练,引擎支持自动求导,多线程与GPU运算,GPU支持CUDA,CUDNN。
资源推荐
资源详情
资源评论
收起资源包目录
基于java打造的深度学习框架,助你快速搭建神经网络,实现模型推理与训练,引擎支持自动求导,多线程与GPU运算GPU支持CUDA (496个子文件)
test_batch.bin 29.31MB
data_batch_1.bin 29.31MB
data_batch_3.bin 29.31MB
data_batch_5.bin 29.31MB
data_batch_2.bin 29.31MB
data_batch_4.bin 29.31MB
yolov7-tiny-sm.cfg 9KB
yolov7-tiny-mask.cfg 9KB
yolov7-tiny-yz.cfg 9KB
yolov7-tiny-helmet.cfg 9KB
yolov1.cfg 4KB
yolov4-tiny-sm.cfg 4KB
yolov4-tiny-helmet.cfg 4KB
yolov4-tiny-yz.cfg 4KB
yolov3-tiny-voc2.cfg 3KB
yolov3-tiny-helmet2.cfg 3KB
yolov3-tiny-sm.cfg 3KB
yolov3-tiny-voc.cfg 3KB
yolov3-tiny-mask.cfg 3KB
yolov3-tiny-helmet.cfg 3KB
yolov3-tiny-yz.cfg 3KB
yolov3-tiny-banana.cfg 3KB
yolov2-tiny-voc.cfg 2KB
yolov2-tiny-banana.cfg 2KB
yolov1-tiny-voc.cfg 2KB
yolov1-tiny.cfg 2KB
vailCodeModel.cfg 843B
styles.css 6KB
style.css 2KB
demo.css 1KB
BNKernel.cu 17KB
BNKernel.cu 17KB
BNKernel2.cu 14KB
BNKernel2.cu 14KB
OPKernel.cu 10KB
OPKernel.cu 7KB
BNKernel3.cu 7KB
BNKernel3.cu 7KB
Im2colKernelTmp.cu 5KB
PoolingV2Kernel.cu 5KB
PoolingV2Kernel.cu 5KB
updater.cu 4KB
MathKernel.cu 4KB
MathKernel.cu 4KB
MathKernel2.cu 4KB
MathKernel2.cu 4KB
activeFunction.cu 4KB
updater.cu 4KB
CrossEntropyKernel.cu 3KB
Col2imKernel.cu 3KB
Col2imKernel.cu 3KB
PoolingKernel.cu 3KB
PoolingKernel.cu 3KB
CrossEntropyKernel.cu 3KB
Im2colKernel.cu 2KB
Im2colKernel.cu 2KB
SoftmaxKernel.cu 2KB
SoftmaxKernel.cu 2KB
BaseKernel.cu 2KB
activeFunction.cu 2KB
BiasKernel.cu 2KB
BaseKernel.cu 1KB
BiasKernel.cu 1KB
BECLossKernel.cu 1KB
RNNKernel.cu 1KB
AVGPoolingKernel.cu 1005B
AVGPoolingKernel.cu 1005B
UpSampleKernel.cu 800B
UpSampleKernel.cu 800B
BCEWithLogitsLossKernel.cu 743B
ShortcutKernel.cu 707B
ShortcutKernel.cu 707B
MSELossKernel.cu 617B
DataNormalization.cu 363B
DataNormalization.cu 363B
BaseMathKernel.cu 245B
JCudaVectorAddKernel.cu 218B
JCudaVectorAddKernel.cu 218B
JCudaVectorAddKernel.cu 181B
test_cuda.dll 141KB
gan-3000.gif 8.97MB
dcgan-20.gif 5.35MB
.gitignore 368B
MNIST_train-images-idx3-ubyte.gz 9.45MB
MNIST_t10k-images-idx3-ubyte.gz 1.57MB
MNIST_train-labels-idx1-ubyte.gz 28KB
MNIST_t10k-labels-idx1-ubyte.gz 4KB
com_omega_engine_gpu_JNITest.h 1011B
AICar.html 22KB
AICarDefautMap.html 22KB
origin2.html 17KB
MapEditor.html 14KB
origin.html 13KB
login.html 5KB
mnist.html 5KB
role.html 5KB
controller.html 5KB
index.html 118B
readme.html 88B
train-labels.idx1-ubyte 59KB
共 496 条
- 1
- 2
- 3
- 4
- 5
资源评论
- zhizhi2050302024-04-06资源内容总结的很到位,内容详实,很受用,学到了~
Java程序员-张凯
- 粉丝: 1w+
- 资源: 6723
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功