Skip to content

Commit f231642

Browse files
committed
Fixes
1 parent d37f06c commit f231642

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

topics/Usage.md

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ user> (py/$.. numpy random shuffle)
264264
<built-in method shuffle of numpy.random.mtrand.RandomState object at 0x7fa66410cca8>
265265
```
266266

267-
##### Extra sugar
267+
##### Extra sugar
268268

269269
`libpython-clj` offers syntactic forms similar to those offered by
270270
Clojure for interacting with Python classes and objects.
@@ -340,23 +340,26 @@ user=> (py.. requests (get "http://www.google.com") -content (decode "latin-1"))
340340
Speaking of numpy, you can move data between numpy and java easily.
341341

342342
```clojure
343-
(require '[tech.v3.tensor :refer [as-tensor]])
344-
user> (def tens-data (as-tensor ones-ary))
343+
(require '[tech.v3.tensor :as dtt])
344+
;;includes the appropriate protocols and multimethod overloads
345+
(require '[libpython-clj2.python.np-array]
346+
;;python objects created now for numpy arrays will be different. So you have to require
347+
;;np-array *before* you create your numpy data.
348+
user> (def ones-ary (py/py. np ones [2 3]))
349+
#'user/ones-ary
350+
user> (def tens-data (dtt/as-tensor ones-ary))
345351
#'user/tens-data
346-
user> (println tens-data)
347-
#tech.v2.tensor<float64>[2 3]
352+
user> tens-data
353+
#tech.v3.tensor<float64>[2 3]
348354
[[1.000 1.000 1.000]
349355
[1.000 1.000 1.000]]
350-
nil
351356

352357

353358
user> (require '[tech.v3.datatype :as dtype])
354359
nil
355-
user> (def ignored (dtype/copy! (repeat 6 5) tens-data))
360+
;;Only constant-time count items can be copied, so vectors and arrays and such.
361+
user> (def ignored (dtype/copy! (vec (repeat 6 5)) tens-data))
356362
#'user/ignored
357-
user> (.put main-globals "ones_ary" ones_ary)
358-
Syntax error compiling at (*cider-repl cnuernber/libpython-clj:localhost:39019(clj)*:191:7).
359-
Unable to resolve symbol: ones_ary in this context
360363
user> (.put main-globals "ones_ary" ones-ary)
361364
nil
362365

0 commit comments

Comments
 (0)