.so
(linux) or .dylib
(mac) files next to your Python installation?
Hi all, ive created python module and now I want to call it from scala using ScalaPy.
I started with call the module and the specific function:
val testScalaPy = py.Module("my_module.test_feature")
val res = testScalaPy.TestFeature.extract(payload = 1)
And its works perfectly.
Now, i would like to be able to pass case class to the extract function:
case class Payload(value: Int)
val res = testScalaPy.TestFeature.extract(payload(100))
but im getting:
type mismatch;
found : com.riskified.poc.ScalaPyPocTest.Payload
required: me.shadaj.scalapy.py.Any
error after rewriting to feature.selectDynamic("TestFeature").applyDynamicNamed("extract")(scala.Tuple2("payload", Payload(200)))
possible cause: maybe a wrong Dynamic method signature?
Any ideas on how to implement writer/reader or if this ability exists already?
Writer
derivation)
case class Payload(total: Int, info: Info)
case class Info(firstName: Name, lastName: String)
case class Name(nameVal: String)
@nirdunetz: not in the near future, since unlike JavaScript it's not immediately clear exactly what a case class should map to in Python (an object? a dictionary?)
you'll need to use something like https://github.com/softwaremill/magnolia/tree/scala2, which can extract out info on which fields are in each case class and what are their types, and then write code using ScalaPy APIs to construct a Python dictionary (or whatever type you want) and add the fields to it by recursively converting them
def write(v: Payload): py.Object = {
val out = py.global.dict()
out.bracketUpdate("total", implicitly[Writer[Int]].write(out.total)
...
out
Native library (win32-x86-64/python3.dll) not found in resource path
? It happened when I tried to println the example given on the starting page of ScalaPyval listLengthPython = py.Dynamic.global.len(List(1, 2, 3).toPythonProxy)
println(listLengthPython)
-Ylog-classpath
.scalapy-numpy
is unfortunately quite a bit out of date, but there is active work that will bring back static typing for NumPy and TensorFlow soon! in the meantime, you'll have to use the dynamically-typed APIs or define your own facades
Hi. I know the facadeGen is alpha but i just tried to run it and i get this error. Any suggestion on how to get it running? I just want to generate some facades for some modules and play with it. I am only trying to generate it for the "builtins" module at the moment while testing. I can see in your scalacon-live folder it looks like the facadeGen did work for at that point in time. Thanks.
[info] running (fork) me.shadaj.scalapy.facadegen.Main
[error] Exception in thread "main" me.shadaj.scalapy.py.PythonException: <class 'TypeError'> list object expected; got SequenceProxy
[error] at me.shadaj.scalapy.interpreter.CPythonInterpreter$.$anonfun$throwErrorIfOccured$2(CPythonInterpreter.scala:328)
[error] at me.shadaj.scalapy.interpreter.Platform$.Zone(Platform.scala:10)
[error] at me.shadaj.scalapy.interpreter.CPythonInterpreter$.$anonfun$throwErrorIfOccured$1(CPythonInterpreter.scala:314)
[error] at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
py.local
).finalize
? Because it is deprecated in Java 9, maybe people continue to use it either way?malloc
there is a "better" ( hackish ) way to deal with that and have GC memory managed..Array[Byte]
of a certain dimension. And then with ByteArray.at(0)
you get the pointer to the start of the arrays' data section. When the original Array is GC collected, you have successfully freed the memory. So you don't have to use malloc.import scala.scalanative.runtime.ByteArray
val arr = ByteArray.alloc(size)
arr.at(0) // is your pointer
return arr // you don't want to lose the reference to the `ByteArray`object ahead of time
extern "C"
functions, but it is a bit of work and if the Python library is fast enough and it's not what makes you slow, I don't see the reason to go that route.