@@ -187,6 +187,15 @@ MatrixPtr Matrix::subMatrix(size_t startRow, size_t endRow, size_t startCol,
187
187
trans_, useGpu_);
188
188
}
189
189
190
+ void Matrix::setDiag (real value) {
191
+ CHECK (data_ != NULL );
192
+ CHECK_EQ (height_, width_);
193
+
194
+ zeroMem ();
195
+ BaseMatrix diag (height_, 1 , stride_ + 1 , data_, false , useGpu_);
196
+ diag.assign (value);
197
+ }
198
+
190
199
GpuMatrix::GpuMatrix (size_t height, size_t width, bool trans)
191
200
: Matrix(std::make_shared<GpuMemoryHandle>(height * width * sizeof (real)),
192
201
height, width, trans, true) {}
@@ -203,16 +212,6 @@ void GpuMatrix::resetOne() {
203
212
one ();
204
213
}
205
214
206
- void GpuMatrix::setDiag (real value) {
207
- CHECK (data_ != NULL );
208
- CHECK_EQ (height_, width_);
209
-
210
- zeroMem ();
211
- for (size_t i = 0 ; i < height_; i++) {
212
- hl_memcpy_host2device (&data_[i * stride_ + i], &value, sizeof (real));
213
- }
214
- }
215
-
216
215
void GpuMatrix::resize (size_t newHeight, size_t newWidth) {
217
216
size_t newSize = newHeight * newWidth;
218
217
if (NULL == memoryHandle_.get () ||
@@ -1255,16 +1254,6 @@ void CpuMatrix::resetOne() {
1255
1254
BaseMatrix::one ();
1256
1255
}
1257
1256
1258
- void CpuMatrix::setDiag (real value) {
1259
- CHECK (data_ != NULL );
1260
- CHECK_EQ (height_, width_);
1261
-
1262
- zeroMem ();
1263
- for (size_t i = 0 ; i < height_; i++) {
1264
- data_[i * stride_ + i] = value;
1265
- }
1266
- }
1267
-
1268
1257
void CpuMatrix::copyFrom (const Matrix& src) {
1269
1258
CHECK (isContiguous ());
1270
1259
if (typeid (src) == typeid (GpuMatrix)) {
0 commit comments