Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
2
Help us understand the problem. What are the problem?

More than 3 years have passed since last update.

posted at

[swift]ベクトルの足し算

汚いながらもなんとか、ベクトルの足し算。

var matABuf: [Double] =
    [1, 2, 3,
     4, 5, 6,
     7, 8, 9]
let vecA = la_matrix_from_double_buffer(matABuf,
                                        3,  /* 行数 */
    1,  /* 列数 */
    3,  /* 改行ごとにメモリバッファをスライドさせる幅 */
    la_hint_t(LA_NO_HINT),
    la_attribute_t(LA_DEFAULT_ATTRIBUTES))
print(vecA.matrixDescription)
 
var matBBuf: [Double] =
    [1, 4, 7,
     2, 5, 8,
     3, 6, 9]
let vecB = la_matrix_from_double_buffer(matBBuf,
                                        3,  /* 行数 */
    1,  /* 列数 */
    3,  /* 改行ごとにメモリバッファをスライドさせる幅 */
    la_hint_t(LA_NO_HINT),
    la_attribute_t(LA_DEFAULT_ATTRIBUTES))
print(vecB.matrixDescription)
 
let ans = la_sum(vecA, vecB)
print(ans.matrixDescription)

以下が結果。

1.0
4.0
7.0
 
1.0
2.0
3.0
 
2.0
6.0
10.0

計算できてるじゃん。

関連情報
[iOS 8] Accelerate.Frameworkに加わった新たな線形代数ライブラリ

BLAS

Cocoa Advent Calendar 2017

Cocoa勉強会 BUKURO.swift (connpass)

Cocoa勉強会 BUKURO.swift (ATND)

Cocoa勉強会 BUKURO.swift (Peatix)

【Cocoa練習帳】
http://www.bitz.co.jp/weblog/

http://ameblo.jp/bitz/(ミラー・サイト)

Qiita

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
2
Help us understand the problem. What are the problem?