Public Vars

Back

make-array (clj)

(source)

function

(make-array type len) (make-array type dim & more-dims)
Creates and returns an array of instances of the specified class of the specified dimension(s). Note that a class object is required. Class objects can be obtained by using their imported or fully-qualified name. Class objects for the primitive types can be obtained using, e.g., Integer/TYPE.

Examples

hraberg/deuce
(ns deuce.emacs.fileio
  (:use [deuce.emacs-lisp :only (defun defvar) :as el])
  (:require [clojure.core :as c]
            [clojure.string :as s]
            [clojure.java.io :as io]
            [deuce.emacs.buffer :as buffer]
            [deuce.emacs.data :as data]
            [deuce.emacs.eval :as eval]
            [deuce.emacs.editfns :as editfns])
  (:import [java.nio.file Files LinkOption
            NoSuchFileException]
           [deuce.emacs.data Buffer BufferText])
  (:refer-clojure :exclude []))

(defun file-regular-p (filename)
  "Return t if FILENAME names a regular file.
  This is the sort of file that holds an ordinary stream of data bytes.
  Symbolic links to regular files count as regular files.
  See `file-symlink-p' to distinguish symlinks."
  (el/check-type 'stringp filename)
  (Files/isRegularFile (.toPath (io/file (expand-file-name filename))) (make-array LinkOption 0)))

  This function returns t when given the name of a symlink that
  points to a nonexistent file."
  (el/check-type 'stringp filename)
  (let [path (.toPath (io/file (expand-file-name filename)))]
    (when (Files/isSymbolicLink path)
      (try
        (str (.toRealPath path (make-array LinkOption 0)))
        (catch NoSuchFileException _
          true)))))
uncomplicate/clojurecl
(ns uncomplicate.clojurecl.core-test
  (:require [midje.sweet :refer :all]
            [uncomplicate.commons
             [core :refer [release with-release info]]
             [utils :refer [direct-buffer put-float get-float]]]
            [uncomplicate.fluokitten.core :refer [fmap extract]]
            [uncomplicate.clojurecl
             [core :refer :all]
             [info :refer [reference-count mem-base-addr-align opencl-c-version queue-context]]
             [toolbox :refer [decent-platform]]]
            [uncomplicate.clojurecl.internal
             [protocols :refer [size ptr byte-buffer wrap]]
             [impl :refer :all]]
            [clojure.core.async :refer [go >! <! <!! chan]])
  (:import java.nio.ByteBuffer
           [org.jocl CL Pointer cl_device_id cl_context_properties cl_mem cl_event EventCallbackFunction]
           uncomplicate.clojurecl.internal.impl.EventCallback
           clojure.lang.ExceptionInfo))

         (context* nil nil nil nil) => (throws NullPointerException)
         (context* (make-array cl_device_id 0) nil nil nil) => (throws ExceptionInfo)
uncomplicate/clojurecl
(ns uncomplicate.clojurecl.examples.openclinaction.ch04
  (:require [midje.sweet :refer :all]
            [clojure.java.io :as io]
            [clojure.core.async :refer [chan <!!]]
            [uncomplicate.commons
             [core :refer [with-release info]]
             [utils :refer [direct-buffer]]]
            [uncomplicate.clojurecl
             [core :refer :all]
             [info :refer [endian-little]]
             [toolbox :refer [decent-platform]]]))

         (set-args! hello-kernel cl-msg) => hello-kernel
         (enq-kernel! cqueue hello-kernel work-sizes) => cqueue
         (enq-read! cqueue cl-msg host-msg read-complete) => cqueue
         (follow read-complete host-msg) => notifications
         (let [data ^java.nio.ByteBuffer (:data (<!! notifications))
               res ^bytes (make-array Byte/TYPE 16)]
           (dotimes [i 16] (aset res i (.get data i)))
           (apply str (map (comp char) res)))
         => "Hello kernel!!!\0")))
apa512/clj-rethinkdb
(ns rethinkdb.core-test
  (:require [clojure.java.io :as io]
            [byte-streams :as bs]
            [clj-time.core :as t]
            [clj-time.coerce :as c]
            [clojure.test :refer :all]
            [clojure.core.async :as async :refer [go go-loop <! take! <!! close!]]
            [manifold.stream :as s]
            [rethinkdb.query :as r]
            [rethinkdb.test-utils :as utils])
  (:import (clojure.lang ExceptionInfo)
           (java.util UUID Arrays)
           (ch.qos.logback.classic Logger Level)
           (manifold.stream.default Stream)
           (org.slf4j LoggerFactory)))

    (are [args lt-le-eq-ne-ge-gt] (= (r/run (r/make-array
                                              (apply r/lt args)
                                              (apply r/le args)
                                              (apply r/eq args)
                                              (apply r/ne args)
                                              (apply r/ge args)
                                              (apply r/gt args)) conn)
                                     lt-le-eq-ne-ge-gt)
      [1 1] [false true true false true false]
      [0 1] [true true false true false false]
      [0 1 2 3] [true true false true false false]
      [0 1 1 2] [false true false true false false]
      [5 4 3] [false false false true true true]
      [5 4 4 3] [false false false true true false])

    (are [n floor-round-ceil] (= (r/run (r/make-array (r/floor n) (r/round n) (r/ceil n)) conn) floor-round-ceil)
      0 [0 0 0]
      0.1 [0 0 1]
      1.499999999 [1 1 2]
      1.5 [1 2 2]
      1.5M [1 2 2]
      3.99999999 [3 4 4]
      -5.1 [-6 -5 -5]
      1/2 [0 1 1])))