-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from Clonkk/devel
Devel
- Loading branch information
Showing
14 changed files
with
204 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import ../types | ||
import ../functions | ||
import ../conversions | ||
import ../glucose | ||
|
||
import ./interop | ||
|
||
import std/macros | ||
|
||
# Arrays operator | ||
# Comparaison | ||
proc equal*[T](val1, val2: JlArray[T]): bool = | ||
jlCall("==", val1, val2).to(bool) | ||
|
||
template `==`*[T](val1, val2: JlArray[T]): bool = | ||
val1.equal(val2) | ||
|
||
# Dot operators | ||
# Broadcasted addition | ||
template jlBroadcast*[T](f: JlFunc, arr: JlArray[T], args: varargs[untyped]): untyped = | ||
jlCall("broadcast", f, arr, args) | ||
|
||
template jlBroadcast*[T](f: string, arr: JlArray[T], args: varargs[untyped]): untyped = | ||
jlCall("broadcast", getJlFunc(f), arr, args) | ||
|
||
macro jlBroadcast*(f: untyped, args: varargs[untyped]): untyped = | ||
var expr = f.toStrLit.strVal | ||
quote: | ||
let f = getJlFunc(`expr`) | ||
jlCall("broadcast", f, `args`) | ||
|
||
proc `.+`*[T: SomeInteger, U: SomeInteger](val: JlArray[T], factor: U|JlArray[U]): JlArray[T] = | ||
jlBroadcast(`+`, val, factor).toJlArray(T) | ||
|
||
proc `.+`*[T: SomeInteger, U: SomeFloat](val: JlArray[T], factor: U|JlArray[U]): JlArray[U] = | ||
jlBroadcast(`+`, val, factor).toJlArray(U) | ||
|
||
proc `.+`*[T: SomeFloat, U: SomeNumber](val: JlArray[T], factor: U|JlArray[U]): JlArray[T] = | ||
jlBroadcast(`+`, val, factor).toJlArray(T) | ||
|
||
proc `.-`*[T: SomeInteger, U: SomeInteger](val: JlArray[T], factor: U|JlArray[U]): JlArray[T] = | ||
jlBroadcast(`-`, val, factor).toJlArray(T) | ||
|
||
proc `.-`*[T: SomeInteger, U: SomeFloat](val: JlArray[T], factor: U|JlArray[U]): JlArray[U] = | ||
jlBroadcast(`-`, val, factor).toJlArray(U) | ||
|
||
proc `.-`*[T: SomeFloat, U: SomeNumber](val: JlArray[T], factor: U|JlArray[U]): JlArray[T] = | ||
jlBroadcast(`-`, val, factor).toJlArray(T) | ||
|
||
proc `.*`*[T: SomeInteger, U: SomeInteger](val: JlArray[T], factor: U|JlArray[U]): JlArray[T] = | ||
jlBroadcast(`*`, val, factor).toJlArray(T) | ||
|
||
proc `.*`*[T: SomeInteger, U: SomeFloat](val: JlArray[T], factor: U|JlArray[U]): JlArray[U] = | ||
jlBroadcast(`*`, val, factor).toJlArray(U) | ||
|
||
proc `.*`*[T: SomeFloat, U: SomeNumber](val: JlArray[T], factor: U|JlArray[U]): JlArray[T] = | ||
jlBroadcast(`*`, val, factor).toJlArray(T) | ||
|
||
# ./ division is a special case | ||
proc `./`*[T: SomeInteger, U: SomeNumber](val: JlArray[T], factor: U|JlArray[U]): JlArray[float] = | ||
jlBroadcast(`/`, val, factor).toJlArray(float) | ||
|
||
proc `./`*[T: SomeFloat, U: SomeNumber](val: JlArray[T], factor: U|JlArray[U]): JlArray[T] = | ||
jlBroadcast(`/`, val, factor).toJlArray(T) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,4 +37,3 @@ proc julia_box(x: pointer): JlValue = jl_box_voidpointer(x) | |
proc jlBox*[T](val: T): JlValue = | ||
julia_box(val) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import ../types | ||
import std/strformat | ||
|
||
proc to*(t: JlDataType) : typedesc = | ||
case t | ||
of jlType(char): | ||
return typedesc[char] | ||
|
||
of jlType(int8): | ||
return typedesc[int8] | ||
of jlType(int16): | ||
return typedesc[int16] | ||
of jlType(int32): | ||
return typedesc[int32] | ||
of jlType(int64): | ||
return typedesc[int64] | ||
|
||
of jlType(uint8): | ||
return typedesc[uint8] | ||
of jlType(uint16): | ||
return typedesc[uint16] | ||
of jlType(uint32): | ||
return typedesc[uint32] | ||
of jlType(uint64): | ||
return typedesc[uint64] | ||
|
||
of jlType(float32): | ||
return typedesc[float32] | ||
of jlType(float64): | ||
return typedesc[float64] | ||
|
||
else: | ||
raise newException(JlError, &"Type conversion from Nim to Julia not support for type {T}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.