<commit_before>(ns tensorflow-clj.core-test
  (:require [clojure.test :refer :all]
            [tensorflow-clj.core :refer :all]))

(deftest scalar-tensor
  (testing "Scalar tensor"
    (let [t (org.tensorflow.Tensor/create 123.0)]
      (is (= org.tensorflow.DataType/DOUBLE (.dataType t)))
      (is (= 0 (.numDimensions t)))
      (is (= [] (vec (.shape t)))))))

(deftest vector-tensor
  (testing "Vector tensor"
    (let [t (org.tensorflow.Tensor/create (into-array [1.0 2.0 3.0]))]
      (is (= org.tensorflow.DataType/DOUBLE (.dataType t)))
      (is (= 1 (.numDimensions t)))
      (is (= [3] (vec (.shape t)))))))

(deftest graph-variable
  (testing "Graph variable"
    (with-graph
      (variable :x))))

(deftest graph-constant
  (testing "Graph constant"
    (with-graph
      (constant :k 123.0))))

;; (deftest session
;;   (testing "Session"
;;     (with-graph
;;       (constant :k 123.0)
;;       (run-feed-and-fetch :k))))

(deftest protobuf-session
  (testing "Session from Protocol Buffers file"
    (with-graph-file "misc/constant.pb"
      (let [t (run-graph {} :Const)]
        (is (= org.tensorflow.Tensor (type t)))
        (is (= [] (vec (.shape t))))
        (is (= 123.0 (.floatValue t)))))))<commit_msg>Feed variable to loaded graph and get result back<commit_after>(ns tensorflow-clj.core-test
  (:require [clojure.test :refer :all]
            [tensorflow-clj.core :refer :all]))

(deftest scalar-tensor
  (testing "Scalar tensor"
    (let [t (org.tensorflow.Tensor/create 123.0)]
      (is (= org.tensorflow.DataType/DOUBLE (.dataType t)))
      (is (= 0 (.numDimensions t)))
      (is (= [] (vec (.shape t)))))))

(deftest vector-tensor
  (testing "Vector tensor"
    (let [t (org.tensorflow.Tensor/create (into-array [1.0 2.0 3.0]))]
      (is (= org.tensorflow.DataType/DOUBLE (.dataType t)))
      (is (= 1 (.numDimensions t)))
      (is (= [3] (vec (.shape t)))))))

(deftest graph-variable
  (testing "Graph variable"
    (with-graph
      (variable :x))))

(deftest graph-constant
  (testing "Graph constant"
    (with-graph
      (constant :k 123.0))))

;; (deftest session
;;   (testing "Session"
;;     (with-graph
;;       (constant :k 123.0)
;;       (run-feed-and-fetch :k))))

(deftest protobuf-session
  (testing "Session from Protocol Buffers file"
    (with-graph-file "misc/constant.pb"
      (let [t (run-graph {} :Const)]
        (is (= org.tensorflow.Tensor (type t)))
        (is (= [] (vec (.shape t))))
        (is (= 123.0 (.floatValue t)))))))

(deftest protobuf-feed
  (testing "Variable feed to loaded graph"
    (with-graph-file "misc/addconst.pb"
      (let [t (run-graph {:Placeholder (tensor (float 123.0))} :mul)]
        (is (= org.tensorflow.Tensor (type t)))
        (is (= [] (vec (.shape t))))
        (is (= 369.0 (.floatValue t)))))))
{'fraction_non_alphanumeric': 0.18988243676522978, 'fraction_numerical': 0.020662629141432135, 'mean_word_length': 2.8152173913043477, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '502840', 'n_tokens_mistral': 1041, 'n_tokens_neox': 969, 'n_words': 253}