Skip to content

Commit

Permalink
add basic JS support by using custom Tensor replacement
Browse files Browse the repository at this point in the history
The replacement is just a `seq[T]`
  • Loading branch information
Vindaar committed Feb 15, 2024
1 parent 38c255a commit f16123e
Show file tree
Hide file tree
Showing 7 changed files with 2,096 additions and 1,975 deletions.
8 changes: 6 additions & 2 deletions src/datamancer.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
## .. include:: ./docs/datamancer.rst

import datamancer / [dataframe, io]
export dataframe, io
when not defined(js):
import datamancer / [dataframe, io]
export dataframe, io
else:
import datamancer / [dataframe, io]
export dataframe, io
6 changes: 5 additions & 1 deletion src/datamancer/column.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import arraymancer/tensor
when not defined(js):
import arraymancer/tensor
else:
import seq_tensor

import std / [sugar, strformat, tables, macros, strutils]
import value

Expand Down
10 changes: 7 additions & 3 deletions src/datamancer/dataframe.nim
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import std / [macros, tables, strutils, options, sets, hashes, math,
sequtils, stats, strformat, algorithm, typetraits]

import arraymancer/tensor
export tensor
when not defined(js):
import arraymancer/tensor
export tensor
else:
import seq_tensor
export seq_tensor

import value
export value
Expand Down Expand Up @@ -1989,7 +1993,7 @@ proc innerJoin*[C: ColumnLike](df1, df2: DataTable[C], by: string): DataTable[C]
for k in getKeys(result):
if result[k].kind != colConstant: # if constant nothing to short
withNativeTensor(result[k], t):
result.asgn(k, toColumn(t[_ ..< result.len]))
result.asgn(k, toColumn(t[0 ..< result.len]))
result[k].len = result.len

proc innerJoin*[C: ColumnLike](dfs: varargs[DataTable[C]], by: string): DataTable[C] =
Expand Down
8 changes: 6 additions & 2 deletions src/datamancer/formulaExp.nim
Original file line number Diff line number Diff line change
Expand Up @@ -709,8 +709,11 @@ proc convertLoop(p: Preface, dtype, fctColResType, loop: NimNode,
fnKind: FormulaKind,
generateLoop: bool): NimNode =
let memCopyable = ["float", "int", "bool"]
let isMemCopyable = dtype.strVal in memCopyable and
p.args.allIt(it.colType.strVal in memCopyable)
when defined(js):
let isMemcopyable = false
else:
let isMemCopyable = dtype.strVal in memCopyable and
p.args.allIt(it.colType.strVal in memCopyable)
proc genForLoop(p: Preface, loop: NimNode, fkKind: FormulaKind): NimNode =
var mpreface = p
let loopIndexed = fixupTensorIndices(loop, mpreface,
Expand Down Expand Up @@ -765,6 +768,7 @@ proc convertLoop(p: Preface, dtype, fctColResType, loop: NimNode,
rbKind = rbColumn)
let resultId = ident(ResultIdent)
let resId = ident(ResIdent)
echo p
if generateLoop:
## raise error if no `Assign` known as `ResIdent`
if not p.hasResIdent:
Expand Down
Loading

0 comments on commit f16123e

Please sign in to comment.