void PathBuilderCairo::LineTo(const Point &aPoint) { PrepareForWrite(); CairoTempMatrix tempMatrix(*mPathContext, mTransform); cairo_line_to(*mPathContext, aPoint.x, aPoint.y); }
Point PathBuilderCairo::CurrentPoint() const { CairoTempMatrix tempMatrix(*mPathContext, mTransform); double x, y; cairo_get_current_point(*mPathContext, &x, &y); return Point((Float)x, (Float)y); }
void PathBuilderCairo::BezierTo(const Point &aCP1, const Point &aCP2, const Point &aCP3) { PrepareForWrite(); CairoTempMatrix tempMatrix(*mPathContext, mTransform); cairo_curve_to(*mPathContext, aCP1.x, aCP1.y, aCP2.x, aCP2.y, aCP3.x, aCP3.y); }
void CairoPathContext::CopyPathTo(cairo_t* aToContext, Matrix& aTransform) { if (aToContext != mContext) { CairoTempMatrix tempMatrix(mContext, aTransform); cairo_path_t* path = cairo_copy_path(mContext); cairo_new_path(aToContext); cairo_append_path(aToContext, path); cairo_path_destroy(path); } }
vector<vector<int> > rotateMatrix(vector<vector<int> > mat, int n) { // write code here vector<vector<int> > tempMatrix(n,vector<int>(n)); for(int i = 0;i < n;++i){ for(int j = n-1;j >= 0;--j){ tempMatrix[i][(n - 1) - j] = mat[j][i]; } } return tempMatrix; }
already_AddRefed<DOMPoint> DOMMatrixReadOnly::TransformPoint(const DOMPointInit& point) const { RefPtr<DOMPoint> retval = new DOMPoint(mParent); if (mMatrix3D) { gfx::Point4D transformedPoint; transformedPoint.x = point.mX; transformedPoint.y = point.mY; transformedPoint.z = point.mZ; transformedPoint.w = point.mW; transformedPoint = *mMatrix3D * transformedPoint; retval->SetX(transformedPoint.x); retval->SetY(transformedPoint.y); retval->SetZ(transformedPoint.z); retval->SetW(transformedPoint.w); } else if (point.mZ != 0 || point.mW != 1.0) { gfx::Matrix4x4 tempMatrix(gfx::Matrix4x4::From2D(*mMatrix2D)); gfx::Point4D transformedPoint; transformedPoint.x = point.mX; transformedPoint.y = point.mY; transformedPoint.z = point.mZ; transformedPoint.w = point.mW; transformedPoint = tempMatrix * transformedPoint; retval->SetX(transformedPoint.x); retval->SetY(transformedPoint.y); retval->SetZ(transformedPoint.z); retval->SetW(transformedPoint.w); } else { gfx::Point transformedPoint; transformedPoint.x = point.mX; transformedPoint.y = point.mY; transformedPoint = *mMatrix2D * transformedPoint; retval->SetX(transformedPoint.x); retval->SetY(transformedPoint.y); retval->SetZ(point.mZ); retval->SetW(point.mW); } return retval.forget(); }
V3R SymmetryOperation::getReducedVector(const Kernel::IntMatrix &matrix, const V3R &vector) const { Kernel::IntMatrix translationMatrix(3, 3, false); for (size_t i = 0; i < order(); ++i) { Kernel::IntMatrix tempMatrix(3, 3, true); for (size_t j = 0; j < i; ++j) { tempMatrix *= matrix; } translationMatrix += tempMatrix; } return (translationMatrix * vector) * RationalNumber(1, static_cast<int>(order())); }
void PathBuilderCairo::QuadraticBezierTo(const Point &aCP1, const Point &aCP2) { PrepareForWrite(); CairoTempMatrix tempMatrix(*mPathContext, mTransform); // We need to elevate the degree of this quadratic Bézier to cubic, so we're // going to add an intermediate control point, and recompute control point 1. // The first and last control points remain the same. // This formula can be found on http://fontforge.sourceforge.net/bezier.html Point CP0 = CurrentPoint(); Point CP1 = (CP0 + aCP1 * 2.0) / 3.0; Point CP2 = (aCP2 + aCP1 * 2.0) / 3.0; Point CP3 = aCP2; cairo_curve_to(*mPathContext, CP1.x, CP1.y, CP2.x, CP2.y, CP3.x, CP3.y); }
/** * @brief Overrides *= operator for IntMatrix to multiply a matrix with current matrix. * @param IntMatrix we wish to multiply the current matrix. * @return IntMatrix& reference to the IntMatrix we updated */ IntMatrix& IntMatrix :: operator*= (const IntMatrix &other) { assert (getCol() == other.getRow()); // initialize and empty matrix of the proper size IntMatrix tempMatrix(getRow(), other.getCol()); // initialize each index in that matrix to be the dot product between a row and column for (int i = 0; i < tempMatrix.getRow(); i++) { for (int j = 0; j < tempMatrix.getCol(); j++) { tempMatrix.getArr()[(i * tempMatrix.getCol()) + j] = dotProduct(&getArr()[i * _colNum], &other.getArr()[j], _colNum, other.getCol()); } } // set our matrix to equal this matrix and return its reference *this = tempMatrix; return *this; }
void DTW::smoothData(MatrixDouble &data,UINT smoothFactor,MatrixDouble &resultsData){ const UINT M = data.getNumRows(); const UINT C = data.getNumCols(); const UINT N = (UINT) floor(double(M)/double(smoothFactor)); resultsData.resize(N,C); if(smoothFactor==1 || M<smoothFactor){ resultsData = data; return; } for(UINT i=0; i<N; i++){ for(UINT j=0; j<C; j++){ double mean = 0.0; int index = i*smoothFactor; for(UINT x=0; x<smoothFactor; x++){ mean += data[index+x][j]; } resultsData[i][j] = mean/smoothFactor; } } //Add on the data that does not fit into the window if(M%smoothFactor!=0.0){ VectorDouble mean(C,0.0); for(UINT j=0; j<C; j++){ for(UINT i=N*smoothFactor; i<M; i++) mean[j] += data[i][j]; mean[j]/=M-(N*smoothFactor); } //Add one row to the end of the Matrix MatrixDouble tempMatrix(N+1,C); for(UINT i=0; i<N; i++) for(UINT j=0; j<C; j++) tempMatrix[i][j] = resultsData[i][j]; for(UINT j=0; j<C; j++) tempMatrix[N][j] = mean[j]; resultsData = tempMatrix; } }
//************This method could be used only when there are many steps, otherwise it might be removed*******************************************// //Create a combined mxb matrix for trajectories from A to B to A Eigen::MatrixXf CreateCombinedMXBMatrix(Eigen::MatrixXf matrixA, Eigen::MatrixXf matrixB, float increment, int i, int j, int offset) { //Create a matrix with zmp trajectory from A to B Eigen::MatrixXf mxbMatrixBA = MXB(matrixA.row(i), matrixB.row(j), increment, offset); Eigen::MatrixXf noZMPMovement(mxbMatrixBA.rows(), mxbMatrixBA.cols()); for(int i = 0; i < mxbMatrixBA.rows(); i++) { noZMPMovement.row(i) = mxbMatrixBA.bottomRows(1); } Eigen::MatrixXf tempMatrix(2*mxbMatrixBA.rows(), mxbMatrixBA.cols()); tempMatrix << mxbMatrixBA, noZMPMovement; mxbMatrixBA.swap(tempMatrix); //Append both step trajectories if(matrixA.rows() > i+1) { //Create a matrix with zmp trajectory from B to A Eigen::MatrixXf mxbMatrixAB = MXB(matrixB.row(j), matrixA.row(i+1), increment, offset); for(int i = 0; i < mxbMatrixAB.rows(); i++) { noZMPMovement.row(i) = mxbMatrixAB.bottomRows(1); } Eigen::MatrixXf tempMatrix2(2*mxbMatrixAB.rows(), mxbMatrixAB.cols()); tempMatrix2 << mxbMatrixAB, noZMPMovement; mxbMatrixAB.swap(tempMatrix2); Eigen::MatrixXf mxbMatrix(mxbMatrixBA.rows()+mxbMatrixAB.rows(), mxbMatrixBA.cols()); mxbMatrix << mxbMatrixBA, mxbMatrixAB; return mxbMatrix; } else { return mxbMatrixBA; } }
void Matrix4x4::Transformation(Matrix4x4 matrix) { Matrix4x4 tempMatrix(_11, _12, _13, _14, _21, _22, _23, _24, _31, _32, _33, _34, _41, _42, _43, _44); _11 = (tempMatrix._11 * matrix._11) + (tempMatrix._12 * matrix._21) + (tempMatrix._13 * matrix._31) + (tempMatrix._14 * matrix._41); _12 = (tempMatrix._11 * matrix._12) + (tempMatrix._12 * matrix._22) + (tempMatrix._13 * matrix._32) + (tempMatrix._14 * matrix._42); _13 = (tempMatrix._11 * matrix._13) + (tempMatrix._12 * matrix._23) + (tempMatrix._13 * matrix._33) + (tempMatrix._14 * matrix._43); _14 = (tempMatrix._11 * matrix._14) + (tempMatrix._12 * matrix._24) + (tempMatrix._13 * matrix._34) + (tempMatrix._14 * matrix._44); _21 = (tempMatrix._21 * matrix._11) + (tempMatrix._22 * matrix._21) + (tempMatrix._23 * matrix._31) + (tempMatrix._24 * matrix._41); _22 = (tempMatrix._21 * matrix._12) + (tempMatrix._22 * matrix._22) + (tempMatrix._23 * matrix._32) + (tempMatrix._24 * matrix._42); _23 = (tempMatrix._21 * matrix._13) + (tempMatrix._22 * matrix._23) + (tempMatrix._23 * matrix._33) + (tempMatrix._24 * matrix._43); _24 = (tempMatrix._21 * matrix._14) + (tempMatrix._22 * matrix._24) + (tempMatrix._23 * matrix._34) + (tempMatrix._24 * matrix._44); _31 = (tempMatrix._31 * matrix._11) + (tempMatrix._32 * matrix._21) + (tempMatrix._33 * matrix._31) + (tempMatrix._34 * matrix._41); _32 = (tempMatrix._31 * matrix._12) + (tempMatrix._32 * matrix._22) + (tempMatrix._33 * matrix._32) + (tempMatrix._34 * matrix._42); _33 = (tempMatrix._31 * matrix._13) + (tempMatrix._32 * matrix._23) + (tempMatrix._33 * matrix._33) + (tempMatrix._34 * matrix._43); _34 = (tempMatrix._31 * matrix._14) + (tempMatrix._32 * matrix._24) + (tempMatrix._33 * matrix._34) + (tempMatrix._34 * matrix._44); _41 = (tempMatrix._41 * matrix._11) + (tempMatrix._42 * matrix._21) + (tempMatrix._43 * matrix._31) + (tempMatrix._44 * matrix._41); _42 = (tempMatrix._41 * matrix._12) + (tempMatrix._42 * matrix._22) + (tempMatrix._43 * matrix._32) + (tempMatrix._44 * matrix._42); _43 = (tempMatrix._41 * matrix._13) + (tempMatrix._42 * matrix._23) + (tempMatrix._43 * matrix._33) + (tempMatrix._44 * matrix._43); _44 = (tempMatrix._41 * matrix._14) + (tempMatrix._42 * matrix._24) + (tempMatrix._43 * matrix._34) + (tempMatrix._44 * matrix._44); }
//Returns a full matrix containing the density matrix at the final time inline matrix<std::complex<double> > RobustGrape::GetPopulations (const size_t point, size_t initial_level){ //the measure implemented, phi (PHI_0) is phi = trace[rho_desired* UN-1....U_0 rho_initial U_0\dg ... U_N-1\dg] char outfile[50]; //Some flags to make sure all parameters are set size_t test=0; for(size_t k = 0; k < num_controls_; ++k) { test+=controlsetflag_[k]; if(verbose==yes) { std::cout << k << "th control flag is " << controlsetflag_[k] << std::endl; } } if(test != 0) UFs::MyError("Grape::StateTransfer(): you have not set the drift and all control hamiltonians:\n"); //Set the counters to zero count_ =0; pos_count_ =0; //the power scale for epsilot (epsilon = base_a^power_) power_ =0; // fidelity ranges from 0 to 1 with 0 be orthogonal and 1 being the same time double current_fidelity=0.0, current_delta_fidelity=1.0, last_fidelity=-1.0; // the propagators and the foraward evolution for(size_t j = 0; j < num_time_; ++j){ Htemp_ = H_drift_[point]; for(size_t k = 0; k < num_controls_; ++k){ Htemp_ += controls_[k][j]*H_controls_[point][k]; } // std::cout << Htemp_ << std::endl; Unitaries_[point][j]=ExpM::EigenMethod(Htemp_,-i*h_); if(j==0){ rho_[point][0] = Unitaries_[point][0]*rho_initial_*MOs::Dagger(Unitaries_[point][0]); } else{ rho_[point][j] = Unitaries_[point][j]*rho_[point][j-1]*MOs::Dagger(Unitaries_[point][j]); } } //Initialize the matrices used to compute the populations matrix<std::complex<double> > populations; populations.initialize(num_time_,dim_); matrix<std::complex<double> > level, propagator, currentLevel, level2, step, tempMatrix, tempMatrix2; level.initialize(dim_,dim_); MOs::Null(level); propagator.initialize(dim_,dim_); MOs::Null(propagator); currentLevel.initialize(dim_, 1); MOs::Null(currentLevel); level2.initialize(dim_, 1); MOs::Null(level2); step.initialize(dim_, 1); MOs::Null(step); tempMatrix.initialize(1, 1); MOs::Null(tempMatrix); tempMatrix2.initialize(1, dim_); MOs::Null(tempMatrix2); for (int i=0; i < dim_; i++) { level(i, dim_-i-1)=1; } //Create the initial state selection vector level2(dim_ - initial_level -1, 0)=1; for (int k=0; k < num_time_; k++) //Go through each time step { step=propagator*level2; for (int j=0; j < dim_; j++) //Go through each quantum level { MOs::Null(currentLevel); currentLevel(dim_ -j -1, 0)=1; tempMatrix2=MOs::Dagger(currentLevel * step); tempMatrix=MOs::Dagger(currentLevel * step)*(currentLevel * step); populations(k,j)=tempMatrix(0,0); //Time=row, Level=col //This is the occupancy of each level //populations[j](0,k)=tempMatrix(0,0); //Time=Columns, Level=row } if (k!=num_time_) propagator = rho_[point][k] * propagator; if (verbose==yes) { std::cout << "--------------------Propogator------------------------------" << std::endl; USs::OutputMatrix(propagator); std::cout << "------------------------------------------------------------" << std::endl; } } return populations; //Output the populations to file // string line; // ofstream moredataout (outfile, ios::app); // for(size_t j = 0; j < num_time_; ++j) //Go through each time step // { // line=j*h_; // for (size_t i=0; i < dim_; i++) //Go through each dimension of the Hilbert space // { // line=line "\t" + populations[i](0,j); // } // //Output line to file // moredataout << line << '\n'; // } // dataout.close(); }