/// Copy a matrix "matra" into this matrix. Note that /// the destination matrix will be resized if necessary. //template<class doubleB> public void CopyFromMatrix(ChMatrix matra) { Resize(matra.GetRows(), matra.GetColumns()); for (int i = 0; i < rows * columns; ++i) { address[i] = matra.GetAddress()[i]; } }
/// Copy constructor from all types of base matrices public ChMatrixDynamic(ChMatrix msource)//:this() { matrix = new ChMatrix(); this.matrix.rows = msource.GetRows(); this.matrix.columns = msource.GetColumns(); this.matrix.address = new double[this.matrix.rows * this.matrix.columns]; /*this.address = (double*)Marshal.AllocHGlobal(this.rows * this.columns * sizeof(double)); * double[] array = new double[this.rows * this.columns]; * for (int i = 0; i < array.Length; i++) * { * this.address[i] = array[i]; * }*/ for (int i = 0; i < this.matrix.rows * this.matrix.columns; ++i) { this.matrix.address[i] = msource.GetAddress()[i]; } }
/// Copy constructor from all types of base matrices (only with same size) public ChMatrix33(ChMatrix msource) //: this() { nm = new ChMatrixNM <IntInterface.Three, IntInterface.Three>(0); //nm.matrix = new ChMatrix(); // Debug.Assert(msource.GetColumns() == 3 && msource.GetRows() == 3); this.nm.matrix.rows = 3; this.nm.matrix.columns = 3; this.nm.matrix.address = this.nm.buffer; /* this.address = (double*)Marshal.AllocHGlobal(this.buffer.Length * sizeof(double)); * for (int i = 0; i < this.buffer.Length; i++) * { * this.address[i] = this.buffer[i]; * }*/ // ElementsCopy(this.address, msource.GetAddress(), 9); for (int i = 0; i < 9; ++i) { this.nm.matrix.address[i] = msource.GetAddress()[i]; } }
/// Copy constructor from all types of base matrices /// Note! Assumes that the source matrix has one column only! There is no run-time check for the one-column sizing. public ChVectorDynamic(ChMatrix msource) { // Debug.Assert(msource.GetColumns() == 1); matrix = new ChMatrix(); this.matrix.rows = msource.GetRows(); this.matrix.columns = 1; this.matrix.address = new double[this.matrix.rows]; /*this.address = (double*)Marshal.AllocHGlobal(this.rows * sizeof(double)); * double[] array = new double[this.rows]; * for (int i = 0; i < array.Length; i++) * { * this.address[i] = array[i]; * }*/ // ElementsCopy(this->address, msource.GetAddress(), this->rows); for (int i = 0; i < this.matrix.rows; ++i) { this.matrix.address[i] = msource.GetAddress()[i]; } }