Skip to content

Instantly share code, notes, and snippets.

@RaananHadar
Last active September 23, 2020 04:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RaananHadar/5ec737e61bff827ceae834a2f6c87485 to your computer and use it in GitHub Desktop.
Save RaananHadar/5ec737e61bff827ceae834a2f6c87485 to your computer and use it in GitHub Desktop.
type Dense struct {
cols int
rows int
stride int
data []float64
}
func NewDense(r, c int, v []float64) *Dense {
return &Dense{cols: c, rows: r, stride: c, data: v}
}
func (d *Dense) At(i, j int) float64 {
return d.data[i*d.stride+j]
}
func (d *Dense) Set(i, j int, v float64) {
d.data[i*d.stride+j] = v
}
func (d *Dense) AtMask(mask [][]int) []float64 {
out := make([]float64, len(mask))
for k, v := range mask {
out[k] = d.At(v[0], v[1])
}
return out
}
func (d *Dense) SetMask(mask [][]int, bar []float64) {
for k, v := range mask {
d.Set(v[0], v[1], bar[k])
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment