Public Vars

Back

object-array (clj)

(source)

function

(object-array size-or-seq)
Creates an array of objects

Examples

mikera/core.matrix
(ns clojure.core.matrix.test-arrays
  (:refer-clojure :exclude [vector?])
  (:require [clojure.core.matrix.compliance-tester :as compliance]
            [clojure.core.matrix :as m]
            ;[clojure.core.matrix.utils :refer :all]
            [clojure.test :refer [deftest testing is]]
            [clojure.core.matrix.macros :refer [array?]]))

(deftest array-slicing
  (let [a (long-array [1 2 3])]
    (is (== 1 (first (m/slices a)))))
  (let [a (object-array [1 2 3])]
    (is (array? (first (m/slice-views a))))))

(deftest compliance-tests
  (compliance/instance-test (int-array [1 2 3]))
  (compliance/instance-test (float-array [1 2 3]))
  (compliance/instance-test (long-array []))
  (compliance/instance-test (char-array [\a \b \c]))
  (compliance/instance-test (object-array [(double-array [1 2 3])]))
  (compliance/instance-test (object-array [(short-array (map short [1 2 3]))]))
  (compliance/instance-test (into-array (Class/forName "[D")
                                        [(double-array [1 2])
                                         (double-array [3 4])])))
mikera/core.matrix
(ns clojure.core.matrix.test-object-array
  (:require [clojure.core.matrix.compliance-tester :as compliance]
            [clojure.core.matrix :refer :all]
            [clojure.test :refer :all]))

(deftest regressions
  (is (= [2] (seq (emap inc (object-array [1]))))))

;; seems to be problem with CLJ-1790 ?
;(deftest test-mget
;  (is (= [2] (mget (object-array [1 2 3]) 1))))

(deftest test-functional-ops
  (testing "map"
    (let [oa  (object-array [1 2])
          oa2 (object-array [3 4])
          oa3 (object-array [5 6])]
      (is (= [2 3] (seq (emap inc oa))))
      (is (= [4 6] (seq (emap + oa oa2))))
      (is (= [9 12] (seq (emap + oa oa2 oa3))))))
  (testing "map indexed"
    (let [oa  (object-array [4 5])
          oa2 (object-array [6 7])
          oa3 (object-array [8 9])]
      (is (= [5 7]   (seq (emap-indexed #(+ (reduce + %1) (inc %2)) oa))))
      (is (= [10 13] (seq (emap-indexed #(apply + (reduce + %1) %&) oa oa2))))
      (is (= [18 22] (seq (emap-indexed #(apply + (reduce + %1) %&) oa oa2 oa3)))))))

(deftest to-objects
  (is (equals [0 1 2] (to-object-array (range 3))))
  (is (e= [1 2 3 :foo] (to-object-array [[1 2] [3 :foo]]))))

(deftest instance-tests
  ;(clojure.core.matrix.compliance-tester/instance-test (object-array []))
  (compliance/instance-test (object-array [1]))
  (compliance/instance-test (object-array [1 :foo]))
  (compliance/instance-test (object-array [-1 4 2 7 -3])))

(deftest compliance-tests
  (compliance/compliance-test (object-array [0.23])))
mikera/core.matrix
(ns clojure.core.matrix.test-api
  (:refer-clojure :exclude [vector?])
;  (:use [clojure.core.matrix])
  (:require [clojure.core.matrix.protocols :as mp]
            [clojure.core.matrix.linear :as li]
           ; [clojure.core.matrix :refer [:all]]
            [clojure.core.matrix.operators :as op]
            [clojure.core.matrix :as m
             :refer [abs abs! acos acos! add add! add-inner-product! add-outer-product! add-product add-product! add-row add-scaled add-scaled! add-scaled-product add-scaled-product! array array? as-vector asin asin! assign assign! assign-array! atan atan! block-diagonal-matrix broadcast broadcast-coerce broadcast-like cbrt cbrt! ceil ceil! clamp clone cmp coerce column-count column-matrix column-matrix? columns compute-matrix conforming? conjoin conjoin-along cos cos! cosh cosh! cross cross! current-implementation current-implementation-object dense density det diagonal diagonal-matrix diagonal? dimension-count dimensionality distance div div! dot e* e= e== ecount eif element-type emap emap! emap-indexed emap-indexed! emax emin emul emul! ensure-mutable eq equals ereduce eseq esum exp exp! fill fill! floor floor! ge get-column get-row gt identity-matrix identity-matrix? immutable index index-seq index-seq-for-shape index? inner-product inverse join join-along label label-index labels le length length-squared lerp lerp! log log! log10 log10! logistic logistic! lower-triangular? lt magnitude magnitude-squared main-diagonal matrix matrix? maximum mget minimum mmul mset mset! mul mul! multiply-row mutable mutable? native native? ne negate negate! new-array new-matrix new-scalar-array new-sparse-array new-vector non-zero-count non-zero-indices normalise normalise! numerical? order orthogonal? outer-product pack permutation-matrix pow pow! rank relu relu! reshape rotate round round! row-count row-matrix row-matrix? rows same-shape? scalar scalar-array scalar? scale scale! scale-add scale-add! select select-indices select-view set-column set-column! set-current-implementation set-indices set-indices! set-inner-product! set-row set-row! set-selection set-selection! shape shift signum signum! sin sin! sinh sinh! slice slice-count slice-map slice-view slice-views slices softmax softmax! softplus softplus! sparse sparse-array sparse-matrix sparse? sqrt sqrt! square square? sub sub! submatrix subvector supports-dimensionality? supports-shape? swap-rows symmetric? tan tan! tanh tanh! to-degrees to-degrees! to-double-array to-nested-vectors to-object-array to-radians to-radians! to-vector trace transform transform! transpose transpose! upper-triangular? vec? zero-array zero-count zero-dimensional? zero-matrix zero-matrix? zero-vector validate-shape]]
            [clojure.core.matrix.implementations :as imp]
            [clojure.core.matrix.utils :refer [broadcast-shape]]
            #?@(:clj [[clojure.core.matrix.macros :refer [error doseq-indexed]]
             [clojure.core.matrix.macros-clj :refer [error?]]
             [clojure.test :refer [deftest is testing run-tests]]
             [clojure.core.matrix.demo.examples]]
                :cljs [[cljs.test :refer-macros [deftest is testing run-tests]]
                       [thinktopic.aljabr.core :as aljabr]
             ;[clojure.core.matrix :refer-macros [with-implementation]]
             [clojure.core.matrix.macros :refer-macros [error]]
             [clojure.core.matrix.macros-cljs :refer-macros [error?]]]))
  #?(:clj (:import [java.io StringWriter])))

(deftest test-validate-shape
  (testing "Error cases for invalid shapes"
    (is (error? (validate-shape [[1] [2 3]])))
    (is (error? (validate-shape [[1 2] [2]])))
    (is (error? (validate-shape [[1 2] 4 [2 2]])))
    (is (error? (validate-shape (object-array [[1 2] 4 [2 2]]))))
    (is (error? (validate-shape [1 [2 3]]))))
  (testing "Error cases for unexpected shapes shapes"
    (is (error? (validate-shape [[1 2] [2 3]] [2 3])))
    (is (error? (validate-shape [7] [1 1])))
    (is (error? (validate-shape [7] [])))
    (is (error? (validate-shape (object-array [7]) [])))
    (is (error? (validate-shape 1 [1])))
    (is (error? (validate-shape 1 [])))
    (is (error? (validate-shape [2 3] nil)))))

(deftest test-object-array
  (is (e= [:a :b] (coerce [] (object-array [:a :b]))))
  (let [a (to-object-array [1 2 3])]
    (is (= 2 (aget a 1)))))
hraberg/deuce
(ns deuce.emacs.alloc
  (:use [deuce.emacs-lisp :only (defun defvar) :as el]
        [taoensso.timbre :as timbre
         :only (trace debug info warn error fatal spy)])
  (:require [clojure.core :as c]
            [clojure.walk :as w]
            [deuce.emacs-lisp.cons :as cons])
  (:refer-clojure :exclude [vector cons list])
  (:import [java.util Arrays]
           [java.lang.management ManagementFactory MemoryNotificationInfo MemoryType MemoryPoolMXBean]
           [javax.management NotificationListener NotificationEmitter Notification]))

(defun vector (&rest objects)
  "Return a newly created vector with specified arguments as elements.
  Any number of arguments, even zero arguments, are allowed."
  (object-array objects))

(defun make-vector (length init)
  "Return a newly created vector of length LENGTH, with each element being INIT.
  See also the function `vector'."
  (doto (object-array length)
    (Arrays/fill init)))
clojure/core.rrb-vector
(ns clojure.core.rrb-vector.transients
  (:require [clojure.core.rrb-vector.parameters :as p]
            [clojure.core.rrb-vector.nodes :refer [ranges last-range
                                                   overflow?]])
  (:import (clojure.core.rrb_vector.nodes NodeManager)
           (clojure.core ArrayManager)
           (java.util.concurrent.atomic AtomicReference)))

    (newPath [this nm am tail edit shift current-node]
      (if (== (.alength am tail) 32)
        (loop [s 0 n current-node]
          (if (== s shift)
            n
            (let [arr (object-array 32)
                  ret (.node nm edit arr)]
              (aset ^objects arr 0 n)
              (recur (unchecked-add s (int 5)) ret))))
        (loop [s 0 n current-node]
          (if (== s shift)
            n
            (let [arr  (object-array 33)
                  rngs (int-array 33)
                  ret  (.node nm edit arr)]
              (aset ^objects arr 0 n)
              (aset ^objects arr 32 rngs)
              (aset rngs 32 1)
              (aset rngs 0 (.alength am tail))
              (recur (unchecked-add s (int 5)) ret))))))))