Skip to content

Commit 1a34b8d

Browse files
[Andrew Polyakov] Change max shape value to reduce memory consumption
1 parent e8d7317 commit 1a34b8d

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

utbot-python/src/main/kotlin/org/utbot/python/fuzzing/provider/NDArrayValueProvider.kt

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@ import kotlin.math.abs
1515

1616

1717
private val logger = KotlinLogging.logger {}
18+
private const val SHAPE_SIZE = 3
19+
private const val MAX_SHAPE_DIGITS = 2
1820

1921
class NDArrayValueProvider(
2022
private val typeStorage: PythonTypeHintsStorage
2123
) : PythonValueProvider {
24+
2225
override fun accept(type: FuzzedUtType): Boolean {
2326
return type.pythonTypeName() == pythonNdarrayClassId.canonicalName
2427
}
@@ -41,20 +44,25 @@ class NDArrayValueProvider(
4144
) {
4245
PythonFuzzedValue(
4346
PythonTree.NDArrayNode(
44-
emptyMap<Int, PythonTree.PythonTreeNode>().toMutableMap(), // Generate new Python IntNode
47+
emptyMap<Int, PythonTree.PythonTreeNode>().toMutableMap(),
4548
((it.first().tree as PythonTree.ListNode).items as Map<Int, PythonTree.PrimitiveNode>).values.map { node ->
46-
abs(node.repr.take(2).toInt())
47-
}
49+
abs(node.repr.take(MAX_SHAPE_DIGITS).toInt()) % 10
50+
}.take(SHAPE_SIZE).let { self ->
51+
if (self.fold(1, Int::times) == 0){
52+
listOf(0)
53+
} else {
54+
self
55+
}
56+
} // TODO: Rethink logic
4857
), "%var% = ${type.pythonTypeRepresentation()}"
4958
)
5059
},
5160
modify = sequence {
52-
yield(Routine.Call((0 until 10000).map { param[1] }.toFuzzed()) { instance, arguments ->
61+
yield(Routine.Call((0 until 1000000).map { param[1] }.toFuzzed()) { instance, arguments ->
5362
val obj = instance.tree as PythonTree.NDArrayNode
5463
(0 until obj.dimensions.fold(1, Int::times)).map {
55-
obj.items[it] = arguments.get(it).tree
64+
obj.items[it] = arguments[it].tree
5665
}
57-
5866
})
5967
},
6068
empty = Routine.Empty { PythonFuzzedValue(PythonTree.FakeNode) }

0 commit comments

Comments
 (0)