Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions tensor/projection2d.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@

package tensor

const (
// OddRow is for oddRow arguments to Projection2D functions,
// specifies that the odd dimension goes along the row.
OddRow = true

// OddColumn is for oddRow arguments to Projection2D functions,
// specifies that the odd dimension goes along the column.
OddColumn = false
)

// Projection2DShape returns the size of a 2D projection of the given tensor Shape,
// collapsing higher dimensions down to 2D (and 1D up to 2D).
// For any odd number of dimensions, the remaining outer-most dimension
Expand Down Expand Up @@ -142,6 +152,17 @@ func Projection2DValue(tsr Tensor, oddRow bool, row, col int) float64 {
return tsr.Float1D(idx)
}

// Projection2DString returns the string value at given row, col coords for a 2D projection
// of the given tensor, collapsing higher dimensions down to 2D (and 1D up to 2D).
// For any odd number of dimensions, the remaining outer-most dimension
// can either be multipliexed across the row or column, given the oddRow arg.
// Even multiples of inner-most dimensions are assumed to be row, then column.
// RowMajor and ColMajor layouts are handled appropriately.
func Projection2DString(tsr Tensor, oddRow bool, row, col int) string {
idx := Projection2DIndex(tsr.Shape(), oddRow, row, col)
return tsr.String1D(idx)
}

// Projection2DSet sets a float64 value at given row, col coords for a 2D projection
// of the given tensor, collapsing higher dimensions down to 2D (and 1D up to 2D).
// For any odd number of dimensions, the remaining outer-most dimension
Expand All @@ -152,3 +173,14 @@ func Projection2DSet(tsr Tensor, oddRow bool, row, col int, val float64) {
idx := Projection2DIndex(tsr.Shape(), oddRow, row, col)
tsr.SetFloat1D(idx, val)
}

// Projection2DSetString sets a string value at given row, col coords for a 2D projection
// of the given tensor, collapsing higher dimensions down to 2D (and 1D up to 2D).
// For any odd number of dimensions, the remaining outer-most dimension
// can either be multipliexed across the row or column, given the oddRow arg.
// Even multiples of inner-most dimensions are assumed to be row, then column.
// RowMajor and ColMajor layouts are handled appropriately.
func Projection2DSetString(tsr Tensor, oddRow bool, row, col int, val string) {
idx := Projection2DIndex(tsr.Shape(), oddRow, row, col)
tsr.SetString1D(idx, val)
}
Loading
Loading