Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArrayTile.{cols | rows} calls boxing fix #3441

Merged
merged 1 commit into from
Dec 3, 2021
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Specialize Grid for Int and Long [#3428](https://github.com/locationtech/geotrellis/pull/3428)
- Move GeoWave and GeoMesa subproject to their own repositories [#3439](https://github.com/locationtech/geotrellis/pull/3439)
- Use JTS 1.18, GeoTools 25.0 [#3437](https://github.com/locationtech/geotrellis/pull/3437)
- ArrayTile.{cols | rows} calls boxing fix [#3441](https://github.com/locationtech/geotrellis/pull/3441)

## [3.6.0] - 2021-04-30

Expand Down
65 changes: 65 additions & 0 deletions bench/src/main/scala/geotrellis/raster/GridBoxingBench.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright 2021 Azavea & Astraea, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package geotrellis.raster

import org.openjdk.jmh.annotations._

import java.util.concurrent.TimeUnit
import scala.util.Random

/** See issue https://github.com/locationtech/geotrellis/issues/3427 */
@BenchmarkMode(Array(Mode.AverageTime))
@State(Scope.Thread)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
class GridBoxingBench {
val size = 1024

@Param(Array("short", "int"))
var cellType: String = _

var tile: MutableArrayTile = _

@Setup(Level.Trial)
def setup(): Unit = {
tile = cellType match {
case "short" =>
ShortArrayTile(
1 to size * size map (_.toShort) toArray, size, size
)
case "int" =>
IntArrayTile(
1 to size * size toArray, size, size
)
}
}

var row: Int = _
var col: Int = _
var value: Int = _
@Setup(Level.Invocation)
def selectCell(): Unit = {
row = Random.nextInt(size)
col = Random.nextInt(size)
value = Random.nextInt()
}

@Benchmark
def setCell(): Tile = {
tile.set(row, col, value)
tile
}
}
7 changes: 7 additions & 0 deletions raster/src/main/scala/geotrellis/raster/ArrayTile.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ import spire.syntax.cfor._
* cases.
*/
abstract class ArrayTile extends Tile with Serializable {
/**
* cols and rows are explicitly defined to help with the Grid[N].{cols | rows} specialized functions dispatch.
* See https://github.com/locationtech/geotrellis/issues/3427
*/
def cols: Int

def rows: Int

/**
* Return the [[ArrayTile]] equivalent of this ArrayTile.
Expand Down
8 changes: 8 additions & 0 deletions raster/src/main/scala/geotrellis/raster/ConstantTile.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ import spire.syntax.cfor._
*/
abstract class ConstantTile extends Tile {

/**
* cols and rows are explicitly defined to help with the Grid[N].{cols | rows} specialized functions dispatch.
* See https://github.com/locationtech/geotrellis/issues/3427
*/
def cols: Int

def rows: Int

/** Precomputed view of tile cells as seen by [[get]] method */
protected val iVal: Int

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ import spire.syntax.cfor._
abstract class MutableArrayTile extends ArrayTile {
def mutable = this

/**
* cols and rows are explicitly defined to help with the Grid[N].{cols | rows} specialized functions dispatch.
* See https://github.com/locationtech/geotrellis/issues/3427
*/
def cols: Int

def rows: Int

/**
* Update the datum at the specified index.
*
Expand Down
8 changes: 8 additions & 0 deletions raster/src/main/scala/geotrellis/raster/Tile.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ package geotrellis.raster
* Base trait for a Tile.
*/
abstract class Tile extends CellGrid[Int] with IterableTile with MappableTile[Tile] {
/**
* cols and rows are explicitly defined to help with the Grid[N].{cols | rows} specialized functions dispatch.
* See https://github.com/locationtech/geotrellis/issues/3427
*/
def cols: Int

def rows: Int

/**
* Execute a function at each pixel of a [[Tile]]. Two functions
* are given: an integer version which is used if the tile is an
Expand Down