Fix MatrixSlice scalar mode bug.
This commit is contained in:
@@ -335,8 +335,8 @@ namespace Aurora {
|
|||||||
double *startPointer = getData() + (rowStride * rowOffset
|
double *startPointer = getData() + (rowStride * rowOffset
|
||||||
+ colStride * colOffset
|
+ colStride * colOffset
|
||||||
+ sliceStride * sliceOffset) * getValueType();
|
+ sliceStride * sliceOffset) * getValueType();
|
||||||
int size1 = getDimSize(allDimIndex[0]);
|
int size1 = allDimIndex.empty()?1:getDimSize(allDimIndex[0]);
|
||||||
int stride1 = strides[allDimIndex[0]];
|
int stride1 = allDimIndex.empty()?1:strides[allDimIndex[0]];
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
//matrix mode
|
//matrix mode
|
||||||
case 2:{
|
case 2:{
|
||||||
@@ -479,6 +479,49 @@ namespace Aurora {
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Matrix::MatrixSlice &Matrix::MatrixSlice::operator=(double value) {
|
||||||
|
if(!mData){
|
||||||
|
std::cerr <<"Assign value fail!Des data pointer is null!";
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
if (mSliceMode!=0) {
|
||||||
|
std::cerr <<"Assign value fail!Des slicemode is"<<mSliceMode<<", not scalar mode!";
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
if (mSize!=1) {
|
||||||
|
std::cerr <<"Assign value fail!Des size:"<<mSize<<", not scalar mode!";
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
if (mType!=Normal) {
|
||||||
|
std::cerr <<"Assign value fail!Des type is complex!";
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
mData[0]=value;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
Matrix::MatrixSlice &Matrix::MatrixSlice::operator=(std::complex<double> value) {
|
||||||
|
if(!mData){
|
||||||
|
std::cerr <<"Assign value fail!Des data pointer is null!";
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
if (mSliceMode!=0) {
|
||||||
|
std::cerr <<"Assign value fail!Des slicemode is"<<mSliceMode<<", not scalar mode!";
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
if (mSize!=1) {
|
||||||
|
std::cerr <<"Assign value fail!Des size:"<<mSize<<", not scalar mode!";
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
if (mType!=Complex) {
|
||||||
|
std::cerr <<"Assign value fail!Des type is not complex!";
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
mData[0]=value.real();
|
||||||
|
mData[1]=value.imag();
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
Matrix Matrix::MatrixSlice::toMatrix() const {
|
Matrix Matrix::MatrixSlice::toMatrix() const {
|
||||||
double * data = (double *) mkl_malloc(mSize*(mSize2>0?mSize2:1) * sizeof(double)*mType, 64);
|
double * data = (double *) mkl_malloc(mSize*(mSize2>0?mSize2:1) * sizeof(double)*mType, 64);
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#define MATRIX_H
|
#define MATRIX_H
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <complex>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
|
||||||
@@ -22,6 +23,8 @@ namespace Aurora {
|
|||||||
MatrixSlice(int aSize,int aStride, double* aData,ValueType aType = Normal,int SliceMode = 1,int aSize2 = 0, int aStride2 = 0);
|
MatrixSlice(int aSize,int aStride, double* aData,ValueType aType = Normal,int SliceMode = 1,int aSize2 = 0, int aStride2 = 0);
|
||||||
MatrixSlice& operator=(const MatrixSlice& slice);
|
MatrixSlice& operator=(const MatrixSlice& slice);
|
||||||
MatrixSlice& operator=(const Matrix& matrix);
|
MatrixSlice& operator=(const Matrix& matrix);
|
||||||
|
MatrixSlice& operator=(double value);
|
||||||
|
MatrixSlice& operator=(std::complex<double> value);
|
||||||
Matrix toMatrix() const;
|
Matrix toMatrix() const;
|
||||||
private:
|
private:
|
||||||
int mSliceMode = 0;//0 scalar, 1 vector, 2 Matrix
|
int mSliceMode = 0;//0 scalar, 1 vector, 2 Matrix
|
||||||
|
|||||||
39
src/main.cxx
39
src/main.cxx
@@ -16,56 +16,53 @@
|
|||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
{
|
{
|
||||||
double * dataA =new double[8];
|
double *dataA = new double[8];
|
||||||
double * dataB =new double[8];
|
double *dataB = new double[8];
|
||||||
double * dataC =new double[4];
|
double *dataC = new double[4];
|
||||||
for (int i = 0; i < 8; ++i) {
|
for (int i = 0; i < 8; ++i) {
|
||||||
dataA[i]=(double)(i-3);
|
dataA[i] = (double) (i - 3);
|
||||||
dataB[i]=(double)(i+2);
|
dataB[i] = (double) (i + 2);
|
||||||
dataC[i/2]=(double)(i+9);
|
dataC[i / 2] = (double) (i + 9);
|
||||||
}
|
}
|
||||||
Aurora::Matrix A = Aurora::Matrix::New(dataA,2,2,2);
|
Aurora::Matrix A = Aurora::Matrix::New(dataA, 2, 2, 2);
|
||||||
printf("A:\r\n");
|
printf("A:\r\n");
|
||||||
A.printf();
|
A.printf();
|
||||||
Aurora::Matrix B = Aurora::Matrix::New(dataB,2,2,2);
|
Aurora::Matrix B = Aurora::Matrix::New(dataB, 2, 2, 2);
|
||||||
printf("B:\r\n");
|
printf("B:\r\n");
|
||||||
B.printf();
|
B.printf();
|
||||||
printf("A slice 1 = B slice 0\r\n");
|
printf("A slice 1 = B slice 0\r\n");
|
||||||
A(Aurora::$,Aurora::$,1) = B(Aurora::$,Aurora::$,0);
|
A(Aurora::$, Aurora::$, 1) = B(Aurora::$, Aurora::$, 0);
|
||||||
printf("B:\r\n");
|
printf("B:\r\n");
|
||||||
B.printf();
|
B.printf();
|
||||||
printf("New A:\r\n");
|
printf("New A:\r\n");
|
||||||
A.printf();
|
A.printf();
|
||||||
printf("A Row slice 1 = B Row slice 0\r\n");
|
printf("A Row slice 1 = B Row slice 0\r\n");
|
||||||
A(1,Aurora::$,Aurora::$) = B(0,Aurora::$,Aurora::$);
|
A(1, Aurora::$, Aurora::$) = B(0, Aurora::$, Aurora::$);
|
||||||
printf("B:\r\n");
|
printf("B:\r\n");
|
||||||
B.printf();
|
B.printf();
|
||||||
printf("New A:\r\n");
|
printf("New A:\r\n");
|
||||||
A.printf();
|
A.printf();
|
||||||
|
|
||||||
printf("A Col slice 1 = B Col slice 0\r\n");
|
printf("A Col slice 1 = B Col slice 0\r\n");
|
||||||
A(Aurora::$,1,Aurora::$) = B(Aurora::$,0,Aurora::$);
|
A(Aurora::$, 1, Aurora::$) = B(Aurora::$, 0, Aurora::$);
|
||||||
printf("B:\r\n");
|
printf("B:\r\n");
|
||||||
B.printf();
|
B.printf();
|
||||||
printf("New A:\r\n");
|
printf("New A:\r\n");
|
||||||
A.printf();
|
A.printf();
|
||||||
|
|
||||||
printf("New A col slice 1 toMatrix:\r\n");
|
printf("New A col slice 1 toMatrix:\r\n");
|
||||||
auto Ds = A(Aurora::$,1,Aurora::$);
|
auto Ds = A(Aurora::$, 1, Aurora::$);
|
||||||
auto D = Ds.toMatrix();
|
auto D = Ds.toMatrix();
|
||||||
D.printf();
|
D.printf();
|
||||||
|
|
||||||
|
|
||||||
Aurora::Matrix C = Aurora::Matrix::New(dataC,2,2);
|
Aurora::Matrix C = Aurora::Matrix::New(dataC, 2, 2);
|
||||||
printf("C:\r\n");
|
printf("C:\r\n");
|
||||||
C.printf();
|
C.printf();
|
||||||
A(Aurora::$,Aurora::$,0) = C;
|
A(1, 1, 1) = 1024.0;
|
||||||
printf("New A:\r\n");
|
printf("New A:\r\n");
|
||||||
A.printf();
|
A.printf();
|
||||||
return 0;
|
}{
|
||||||
|
|
||||||
}
|
|
||||||
{
|
|
||||||
double * dataA =new double[9];
|
double * dataA =new double[9];
|
||||||
double * dataB =new double[9];
|
double * dataB =new double[9];
|
||||||
for (int i = 0; i < 9; ++i) {
|
for (int i = 0; i < 9; ++i) {
|
||||||
|
|||||||
Reference in New Issue
Block a user