Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Clojureで多次元配列
Search
ichisemasashi
December 23, 2020
Programming
0
440
Clojureで多次元配列
ClojureでJavaの配列を利用して数値計算を扱う。
ichisemasashi
December 23, 2020
Tweet
Share
Other Decks in Programming
See All in Programming
Node-RED を(HTTP で)つなげる MCP サーバーを作ってみた
highu
0
120
ISUCON研修おかわり会 講義スライド
arfes0e2b3c
1
450
スタートアップの急成長を支えるプラットフォームエンジニアリングと組織戦略
sutochin26
1
6.2k
テストから始めるAgentic Coding 〜Claude Codeと共に行うTDD〜 / Agentic Coding starts with testing
rkaga
13
4.9k
設計やレビューに悩んでいるPHPerに贈る、クリーンなオブジェクト設計の指針たち
panda_program
6
2.2k
git worktree × Claude Code × MCP ~生成AI時代の並列開発フロー~
hisuzuya
1
590
20250628_非エンジニアがバイブコーディングしてみた
ponponmikankan
0
700
「テストは愚直&&網羅的に書くほどよい」という誤解 / Test Smarter, Not Harder
munetoshi
0
180
Google Agent Development Kit でLINE Botを作ってみた
ymd65536
2
260
ペアプロ × 生成AI 現場での実践と課題について / generative-ai-in-pair-programming
codmoninc
2
19k
#kanrk08 / 公開版 PicoRubyとマイコンでの自作トレーニング計測装置を用いたワークアウトの理想と現実
bash0c7
1
790
Composerが「依存解決」のためにどんな工夫をしているか #phpcon
o0h
PRO
1
270
Featured
See All Featured
The Illustrated Children's Guide to Kubernetes
chrisshort
48
50k
We Have a Design System, Now What?
morganepeng
53
7.7k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
2.9k
For a Future-Friendly Web
brad_frost
179
9.8k
The Cost Of JavaScript in 2023
addyosmani
51
8.5k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
6
310
Git: the NoSQL Database
bkeepers
PRO
430
65k
Designing for Performance
lara
610
69k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
jQuery: Nuts, Bolts and Bling
dougneiner
63
7.8k
A Modern Web Designer's Workflow
chriscoyier
695
190k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
32
2.4k
Transcript
@ichisemasashi 202012݄23 ClojureͰଟ࣍ݩྻ
࠷ۙؾ͍ͨɺ͕ࣗίϯϐϡʔλʔͰΓ͔ͨͬͨ͜ͱ => ʮܭࢉʯ - ͱΓ͋͑ͣɺJuliaΛͬͯษڧΛ͍͕ͯͨ͠ɺͰ͖ΕClojureͰษڧ Λ͔ͨͬͨ͠ɻ - ͰClojureʹଟ࣍ݩྻ͕ͳ͍ͱࢥ͍ͬͯͨɻ -> JavaͷྻΛ͑ྑ͍ɻ
-> tnoda͞ΜͷʮJava ͷྻΛར༻ͯ͠ϝϞϦͱ࣌ؒͷนΛಥ ഁ͢ΔɽʯʹɺJavaͷྻͷ͍ํ͕ཧ͞Ε͍ͯͨɻ
ClojureͰJavaͷྻΛར༻͢Δ ྻͷੜ user=> (def my-array (make-array Integer/TYPE 2 2)) #'user/my-array
ClojureͰJavaͷྻΛར༻͢Δ ྻͷදࣔ user=> (pprint my-array) [[0, 0], [0, 0]] nil
ClojureͰJavaͷྻΛར༻͢Δ ྻͷཁૉΛࢀর user=> (aget ^ints my-array 0 0) 0
ClojureͰJavaͷྻΛར༻͢Δ ྻͷཁૉʹσʔλΛઃఆ user=> (aset ^ints my-array 0 0 (int 100))
100 user=> (aget ^ints my-array 0 0) 100 user=> (pprint my-array) [[100, 0], [0, 0]] nil
࣮ྫɿΨε-βΠσϧ๏ʹΑΔ࿈ཱ1࣍ํఔࣜͷղ๏ Ψε-βΠσϧ๏ͷ֓ཁ 5x + y + z = 10 x
+ 4y + z = 12 2x + y + 3z = 13 }
࣮ྫɿΨε-βΠσϧ๏ʹΑΔ࿈ཱ1࣍ํఔࣜͷղ๏ Ψε-βΠσϧ๏ͷ֓ཁ 5x + y + z = 10 x
+ 4y + z = 12 2x + y + 3z = 13 } x = (10 − y − z)/5 y = (12 − x − z)/4 z = (13 − 2x − y)/3 }
࣮ྫɿΨε-βΠσϧ๏ʹΑΔ࿈ཱ1࣍ํఔࣜͷղ๏ Ψε-βΠσϧ๏ͷ֓ཁ 5x + y + z = 10 x
+ 4y + z = 12 2x + y + 3z = 13 } x = (10 − y − z)/5 y = (12 − x − z)/4 z = (13 − 2x − y)/3 } x y z ॳظ 1 1 1 1८ 1.600 2.350 2.483 2८ 1.033 2.121 2.938 3८ 0.988 2.019 3.002 4८ 0.996 2.001 3.002 5८ 0.999 1.999 3.001
࣮ྫɿΨε-βΠσϧ๏ʹΑΔ࿈ཱ1࣍ํఔࣜͷղ๏ Ψε-βΠσϧ๏ͷ࣮ (def an-eq (make-array Double/TYPE 3 4)) (def N
(alength an-eq)) (defn set-eq [arr n x y z w] (aset ^doubles arr n 0 (double x)) (aset ^doubles arr n 1 (double y)) (aset ^doubles arr n 2 (double z)) (aset ^doubles arr n 3 (double w))) (set-eq an-eq 0 5 1 1 10) (set-eq an-eq 1 1 4 1 12) (set-eq an-eq 2 2 1 3 13) (pprint an-eq)
࣮ྫɿΨε-βΠσϧ๏ʹΑΔ࿈ཱ1࣍ํఔࣜͷղ๏ Ψε-βΠσϧ๏ͷ࣮(ଓ) (def res-arr (make-array Double/TYPE 3)) (dotimes [i N]
(aset ^doubles res-arr i (double 1))) (pprint res-arr) (def tmp-arr (make-array Double/TYPE 3)) (pprint tmp-arr) (defn eq-elm [x y] (aget ^doubles an-eq x y)) (defn res-elm [x] (aget ^doubles res-arr x)) (defn tmp-elm [x] (aget ^doubles tmp-arr x))
࣮ྫɿΨε-βΠσϧ๏ʹΑΔ࿈ཱ1࣍ํఔࣜͷղ๏ Ψε-βΠσϧ๏ͷ࣮(ଓ) (def MAX_LOOP 30) (def EPS (double 0.0001)) (def
q (atom (double 1.0))) (def ll (atom 0)) (defn display-result [] (dotimes [i N] (let [res (res-elm i)] (println (format "x%d = %9.6f" i res)))))
࣮ྫɿΨε-βΠσϧ๏ʹΑΔ࿈ཱ1࣍ํఔࣜͷղ๏ Ψε-βΠσϧ๏ͷ࣮(ଓ) (defn computing [] (let [s (atom (double 0.0))]
(dotimes [i N] (reset! s (double 0.0)) (dotimes [j N] (if (not= i j) (reset! s (+ @s (* (eq-elm i j) (res-elm j)))))) (aset ^doubles tmp-arr i (/ (- (eq-elm i N) @s) (eq-elm i i))) (reset! q (+ @q (Math/abs (- (res-elm i) (tmp-elm i))))) (aset ^double res-arr i (tmp-elm i)))))
࣮ྫɿΨε-βΠσϧ๏ʹΑΔ࿈ཱ1࣍ํఔࣜͷղ๏ Ψε-βΠσϧ๏ͷ࣮(ଓ) (while (and (< EPS @q) (>= MAX_LOOP @ll))
(do (swap! ll inc) (reset! q (double 0.0)) (computing))) (if (>= @ll MAX_LOOP) (println "ऩଋͤͣɻ") (display-result))