MikeInnes / Charlotte.jl

Charlotte's Web Scale
Other
113 stars 13 forks source link

Multi dim arrays (currently only 2 dim) working. #26

Closed sjorn3 closed 6 years ago

sjorn3 commented 6 years ago

I was trying to get this to work with the assembly script implementation of arrays, but actually wasm-ffi makes it fairly easy to define new structs, so a new array struct containing the shape and the data is being used.

const Array = new ffi.Struct({
  shape: ffi.assemblyscript.array('int32'),
  data:  ffi.assemblyscript.array('int32')
})

Wasm sees this as a vector of i32's in the following format: [pointer to shape array, length of shape array, pointer to data array, length of data array]

Summing the following 2 dimensional array gives the correct result (using compiled code):

new Array({ shape:[2, 5], data:[1, 123, 2, 3, 3, 23, 4, 45, 5, 6] })

Produced from the Julia equivalent:

julia> as
2×5 Array{Int64,2}:
   1  2   3   4  5
 123  3  23  45  6

I think all array operations should use this data type from now on, and at some point helper functions can be created on the js side to make it less of a chore to define multi dimensional arrays in this format. (We could probably compile some Julia code that does this too)

Most attempts to try anything more complicated, such as matrix multiplication, result in missing ssavalue errors, which I'm generally assuming are due to the gcd bug, so the next step is to get the master branch onto julia 0.7 and update each branch.

Also anything above 2 dim arrays are making calls to Core.getfield. There is an implementation for this on the structs branch, though I don't know if that would actually work or why the calls are being made as yet. Apart from this there's no reason why the summing example shouldn't work for any number of dimensions.

sjorn3 commented 6 years ago

Now part of #27