Public Vars

Back

long-array (clj)

(source)

function

(long-array size-or-seq) (long-array size init-val-or-seq)
Creates an array of longs

Examples

aphyr/tesser
(ns tesser.simple-test
  (:require [clojure.test :refer :all]
            [clojure.test.check :as tc]
            [clojure.test.check [clojure-test :refer :all]
                                [generators :as gen]
                                [properties :as prop]]
            [multiset.core :refer [multiset]]
            [tesser.simple :as s]
            [clojure.core.reducers :as r]
            [clojure.set :as set]))

(def flat-ints (gen/one-of [(gen/list gen/int)
                            (gen/vector gen/int)
                            (gen/fmap long-array (gen/vector gen/int))]))
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)))))
mikera/core.matrix
(ns clojure.core.matrix.test-utils
  (:refer-clojure :exclude [vector?])
  (:require [clojure.core.matrix.protocols :as mp]
            [clojure.core.matrix :refer :all]
            [clojure.core.matrix.utils :refer [extends-deep? extract-protocols]]
            [clojure.test :refer :all])
  (:import [clojure.lang PersistentVector]
           [mikera.vectorz Vector]))

(deftest test-long-array
  (is (= (type (long-array 0)) (type (long-array nil))))
  (is (= (count (long-array 0)) (count (long-array nil)))))
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-index
  (:require [clojure.core.matrix :as m])
  #?(:clj (:require [clojure.core.matrix.macros-cljs :refer [error?]]
                    [clojure.test :refer [deftest is testing]])
    :cljs (:require-macros
            [clojure.core.matrix.macros-cljs :refer [error?]]
            [cljs.test :refer [deftest is testing]])))

(deftest test-long-index
  (let [xs (long-array [1 2 3])]
    (testing "Index identity"
	    (is (identical? xs (m/index xs xs)))
	    (is (m/index? xs)))))