1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

cblas_scopy

Posted at

cblas_scopy関数は、1つのベクトルを別のベクトルにコピーする関数です。これをBLASの関数を使わずに実装するには、次のようなC言語のコードを書くことができます。

void my_scopy(const int n, const float *x, const int incx, float *y, const int incy) {
    int i;
    if (incx == 1 && incy == 1) {
        for (i = 0; i < n; ++i) {
            y[i] = x[i];
        }
    } else {
        int ix = (incx > 0) ? 0 : (1 - n) * incx;
        int iy = (incy > 0) ? 0 : (1 - n) * incy;
        for (i = 0; i < n; ++i) {
            y[iy] = x[ix];
            ix += incx;
            iy += incy;
        }
    }
}

この関数は、引数としてコピー元のベクトルx、コピー先のベクトルy、および要素数nを取ります。incxとincyはストライド(要素間のスキップ)を表します。incxとincyが1の場合、連続するメモリ領域にデータが配置されていると仮定して、単純なループで要素をコピーします。それ以外の場合は、incxおよびincyのストライドを考慮してループを実行します。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?