Back
int-array (clj)
(source)function
(int-array size-or-seq)
(int-array size init-val-or-seq)
Creates an array of ints
Examples
mikera/core.matrix
Indexes are intended to be used to specify elements, ranges or sub-arrays of core.matrix arrays.
As such they can be considered as a 1D vector of integer values."
(:require [clojure.core.matrix.protocols :as mp]
[clojure.core.matrix.macros :refer [error]])
(:import [clojure.lang IPersistentVector]))
(extend-protocol mp/PIndexImplementation
(Class/forName "[J")
(index? [m]
true)
(index-to-longs [m]
m)
(index-to-ints [m]
(int-array m))
(index-from-longs [m xs]
xs)
(index-from-ints [m xs]
(long-array xs))
(index-coerce [m a]
(mp/index-to-longs a)))
(extend-protocol mp/PIndexImplementation
(Class/forName "[I")
(index? [m]
true)
(index-to-longs [m]
(long-array m))
(index-to-ints [m]
m)
(index-from-longs [m xs]
(int-array xs))
(index-from-ints [m xs]
xs)
(index-coerce [m a]
(mp/index-to-ints a)))
(extend-protocol mp/PIndexImplementation
IPersistentVector
(index? [m]
(every? integer? m))
(index-to-longs [m]
(long-array m))
(index-to-ints [m]
(int-array m))
(index-from-longs [m xs]
(vec xs))
(index-from-ints [m xs]
(vec xs))
(index-coerce [m a]
(cond
(mp/index? a)
(mp/persistent-vector-coerce a)
(== 1 (long (mp/dimensionality a)))
(vec (mp/index-to-longs a))
:else
(error "Can't make a 1D index from array of shape " (mp/get-shape a)))))
uncomplicate/fluokitten
(ns uncomplicate.fluokitten.core-test
(:use [uncomplicate.fluokitten algo jvm core test utils])
(:use [midje.sweet :exclude [just]])
(:require [clojure.string :as s]
[clojure.core.reducers :as r]))
(fmap-keeps-type inc (int-array [77 0 -39]))
(applicative-law2-identity (int-array [1 445 -4]))
(applicative-law5-interchange (int-array 0) inc 1)
(applicative-law5-interchange (int-array 0) + 1 54 -2)
(monad-law1-left-identity (int-array 0) (comp (pure (int-array 0)) +) 1 2 3)
(semigroup-op-associativity (int-array [1 2]) (int-array [3 4]))
(facts "How Foldable arrays work."
(fold (double-array [1 2 3 4 5])) => 15.0
(fold (long-array (range 999))) => 498501
(fold (short-array [])) => 0
(fold (int-array [1 2 3 4 5]))= > 15
(fold (float-array [1 2 3 4 5])) => 15.0
(fold + (double-array [1 2 3 4])) => 10.0
(fold * (float-array [1 2 3 4])) => 24.0
(fold + 0 (int-array [1 2 3]) (int-array [4 5 6])) => 21
(fold * 1 (short-array [1 2 3]) (short-array [4 5 6])) => 315
(fold * 2 (long-array [1 2 3]) (long-array [4 5 6]) (long-array [7 8 9])
(long-array [1 2 1]) (long-array [3 2 1])) => (throws UnsupportedOperationException)
(fold * 2 (double-array [1 2 3 4]) (double-array [4 5 6]) (double-array [7 8 9])
(double-array [1 2 1]) (double-array [3 2 1])) => (throws UnsupportedOperationException)
typedclojure/typedclojure
(ns ^:no-doc typed.ann.clojure
"Type annotations for the base Clojure distribution."
#?(:cljs (:require-macros [typed.ann-macros.clojure :as macros]))
(:require [clojure.core :as cc]
[typed.clojure :as t]
#?(:clj [typed.ann-macros.clojure :as macros])
#?(:clj typed.ann.clojure.jvm) ;; jvm annotations
#?(:clj clojure.core.typed))
#?(:clj
(:import (clojure.lang PersistentHashSet PersistentList
APersistentMap #_IPersistentCollection
#_ITransientSet
IRef)
(java.util Comparator Collection))))
;array ctors
#?@(:cljs [] :default [
cc/boolean-array (t/IFn [(t/U t/Num (t/Seqable t/Bool)) :-> (Array boolean)]
[t/Num (t/U t/Bool (t/Seqable t/Bool)) :-> (Array boolean)])
cc/byte-array (t/IFn [(t/U t/Num (t/Seqable Byte)) :-> (Array byte)]
[t/Num (t/U Byte (t/Seqable Byte)) :-> (Array byte)])
cc/char-array (t/IFn [(t/U t/Num (t/Seqable Character)) :-> (Array char)]
[t/Num (t/U t/Num (t/Seqable Character)) :-> (Array char)])
cc/short-array (t/IFn [(t/U t/Num (t/Seqable Short)) :-> (Array short)]
[t/Num (t/U Short (t/Seqable Short)) :-> (Array short)])
cc/int-array (t/IFn [(t/U t/Num (t/Seqable t/Num)) :-> (Array int)]
[t/Num (t/U t/Num (t/Seqable t/Num)) :-> (Array int)])
cc/double-array (t/IFn [(t/U t/Num (t/Seqable t/Num)) :-> (Array double)]
[t/Num (t/U t/Num (t/Seqable t/Num)) :-> (Array double)])
])
uncomplicate/clojurecl
(ns uncomplicate.clojurecl.examples.openclinaction.ch07
(:require [midje.sweet :refer :all]
[clojure.java.io :as io]
[clojure.core.async :refer [<!! chan timeout <! go]]
[uncomplicate.commons
[core :refer [with-release]]
[utils :refer [direct-buffer]]]
[uncomplicate.clojurecl
[core :refer :all]
[info :refer [profiling-info durations end opencl-c-version]]
[toolbox :refer [decent-platform]]]))
(facts
"Listing 7.6. Page 155."
(let [program-source
(slurp (io/resource "examples/openclinaction/ch07/profile-read.cl"))
bytesize (Math/pow 2 20)
notifications (chan)
follow (register notifications)
data (direct-buffer bytesize)
num (int-array [(/ (long bytesize) 16)])
work-sizes (work-size [1])]
(with-release [cl-data (cl-buffer ctx bytesize :write-only)
prog (build-program! (program-with-source ctx [program-source]))
profile-read (kernel prog "profile_read")
profile-event (event)]
(facts
(set-args! profile-read cl-data num) => profile-read
(facts
"Listing 7.7. Page 157."
(let [program-source
(slurp (io/resource "examples/openclinaction/ch07/profile-items.cl"))
num-ints 65536
data (int-array (range num-ints))
notifications (chan)
follow (register notifications)
work-sizes (work-size [512] [1])]
(with-release [cl-x (cl-buffer ctx (* num-ints Integer/BYTES 4) :write-only)
prog (build-program! (program-with-source ctx [program-source]))
profile-items (kernel prog "profile_items")
profile-event (event)]
(facts
(set-args! profile-items cl-x (int-array [num-ints])) => profile-items
(enq-kernel! cqueue profile-items work-sizes nil profile-event)
(follow profile-event)
uncomplicate/clojurecl
(ns uncomplicate.clojurecl.examples.openclinaction.ch11
(:require [midje.sweet :refer :all]
[clojure.java.io :as io]
[clojure.core.async :refer [chan <!!]]
[uncomplicate.commons.core :refer [with-release info]]
[uncomplicate.clojurecl
[core :refer :all]
[info :refer [durations profiling-info opencl-c-version]]
[toolbox :refer [decent-platform]]]))
(facts
"Chapter 11, Listing 11.1, Page 243."
(let [program-source
(slurp (io/resource "examples/openclinaction/ch11/string-search.cl"))
kafka (byte-array
(map byte
(slurp (io/resource "examples/openclinaction/ch11/kafka.txt"))))
text-size (alength kafka)
local-size (info dev :max-work-group-size)
global-size (* local-size (info dev :max-compute-units))
work-size (work-size [global-size] [local-size])
pattern (byte-array (map byte "thatwithhavefrom"))
chars-per-item (int-array [(inc (/ text-size global-size))])
result (int-array 4)]
(with-release [cl-text (cl-buffer ctx text-size :read-only)
cl-result (cl-buffer ctx (* 4 Integer/BYTES) :write-only)
prog (build-program! (program-with-source ctx [program-source])
"-cl-std=CL2.0" nil)
string-search (kernel prog "string_search")]
(facts
;; ============ Naive reduction ======================================
(set-args! string-search pattern cl-text chars-per-item
(* 4 Integer/BYTES) cl-result)
=> string-search
(enq-write! cqueue cl-text kafka) => cqueue
(enq-write! cqueue cl-result result) => cqueue
(enq-kernel! cqueue string-search work-size) => cqueue
(enq-read! cqueue cl-result result) => cqueue
(finish! cqueue) => cqueue
(vec result) => [330 237 110 116])))))