tile.https.any.js (4832B)
1 // META: title=test WebNN API tile operation 2 // META: global=window 3 // META: variant=?cpu 4 // META: variant=?gpu 5 // META: variant=?npu 6 // META: script=../resources/utils.js 7 // META: timeout=long 8 9 'use strict'; 10 11 // https://github.com/webmachinelearning/webnn/issues/375 12 // Represents the tile operation that repeats a tensor the given number of 13 // times along each axis. 14 // 15 // MLOperand tile( 16 // MLOperand input, sequence<unsigned long> repetitions, optional 17 // MLOperatorOptions options = {}); 18 19 const tileTests = [ 20 { 21 'name': 'tile float32 0D scalar tensor by repetitions=[]', 22 'graph': { 23 'inputs': { 24 'tileInput': { 25 'data': [0.5], 26 'descriptor': {shape: [], dataType: 'float32'} 27 } 28 }, 29 'operators': [{ 30 'name': 'tile', 31 'arguments': [{'input': 'tileInput'}, {'repetitions': []}], 32 'outputs': 'tileOutput' 33 }], 34 'expectedOutputs': { 35 'tileOutput': { 36 'data': [0.5], 37 'descriptor': {shape: [], dataType: 'float32'} 38 } 39 } 40 } 41 }, 42 { 43 'name': 'tile float32 1D constant tensor', 44 'graph': { 45 'inputs': { 46 'tileInput': { 47 'data': [1, 2, 3, 4], 48 'descriptor': {shape: [4], dataType: 'float32'}, 49 'constant': true 50 } 51 }, 52 'operators': [{ 53 'name': 'tile', 54 'arguments': [{'input': 'tileInput'}, {'repetitions': [2]}], 55 'outputs': 'tileOutput' 56 }], 57 'expectedOutputs': { 58 'tileOutput': { 59 'data': [1, 2, 3, 4, 1, 2, 3, 4], 60 'descriptor': {shape: [8], dataType: 'float32'} 61 } 62 } 63 } 64 }, 65 { 66 'name': 'tile float32 1D tensor', 67 'graph': { 68 'inputs': { 69 'tileInput': { 70 'data': [1, 2, 3, 4], 71 'descriptor': {shape: [4], dataType: 'float32'}, 72 'constant': false 73 } 74 }, 75 'operators': [{ 76 'name': 'tile', 77 'arguments': [{'input': 'tileInput'}, {'repetitions': [2]}], 78 'outputs': 'tileOutput' 79 }], 80 'expectedOutputs': { 81 'tileOutput': { 82 'data': [1, 2, 3, 4, 1, 2, 3, 4], 83 'descriptor': {shape: [8], dataType: 'float32'} 84 } 85 } 86 } 87 }, 88 { 89 'name': 'tile float16 1D tensor', 90 'graph': { 91 'inputs': { 92 'tileInput': { 93 'data': [1, 2, 3, 4], 94 'descriptor': {shape: [4], dataType: 'float16'}, 95 'constant': false 96 } 97 }, 98 'operators': [{ 99 'name': 'tile', 100 'arguments': [{'input': 'tileInput'}, {'repetitions': [2]}], 101 'outputs': 'tileOutput' 102 }], 103 'expectedOutputs': { 104 'tileOutput': { 105 'data': [1, 2, 3, 4, 1, 2, 3, 4], 106 'descriptor': {shape: [8], dataType: 'float16'} 107 } 108 } 109 } 110 }, 111 { 112 'name': 'tile float16 2D tensor', 113 'graph': { 114 'inputs': { 115 'tileInput': { 116 'data': [1, 2, 3, 4], 117 'descriptor': {shape: [2, 2], dataType: 'float16'}, 118 'constant': false 119 } 120 }, 121 'operators': [{ 122 'name': 'tile', 123 'arguments': [{'input': 'tileInput'}, {'repetitions': [2, 3]}], 124 'outputs': 'tileOutput' 125 }], 126 'expectedOutputs': { 127 'tileOutput': { 128 'data': [ 129 1, 2, 1, 2, 1, 2, 3, 4, 3, 4, 3, 4, 130 1, 2, 1, 2, 1, 2, 3, 4, 3, 4, 3, 4 131 ], 132 'descriptor': {shape: [4, 6], dataType: 'float16'} 133 } 134 } 135 } 136 }, 137 { 138 'name': 'tile uint32 2D tensor', 139 'graph': { 140 'inputs': { 141 'tileInput': { 142 'data': [1, 2, 3, 4], 143 'descriptor': {shape: [2, 2], dataType: 'uint32'}, 144 'constant': false 145 } 146 }, 147 'operators': [{ 148 'name': 'tile', 149 'arguments': [{'input': 'tileInput'}, {'repetitions': [2, 3]}], 150 'outputs': 'tileOutput' 151 }], 152 'expectedOutputs': { 153 'tileOutput': { 154 'data': [ 155 1, 2, 1, 2, 1, 2, 3, 4, 3, 4, 3, 4, 156 1, 2, 1, 2, 1, 2, 3, 4, 3, 4, 3, 4 157 ], 158 'descriptor': {shape: [4, 6], dataType: 'uint32'} 159 } 160 } 161 } 162 }, 163 { 164 'name': 'tile int32 4D tensor', 165 'graph': { 166 'inputs': { 167 'tileInput': { 168 'data': [1, 2, 3, 4], 169 'descriptor': {shape: [1, 1, 2, 2], dataType: 'int32'}, 170 'constant': false 171 } 172 }, 173 'operators': [{ 174 'name': 'tile', 175 'arguments': [{'input': 'tileInput'}, {'repetitions': [1, 1, 2, 2]}], 176 'outputs': 'tileOutput' 177 }], 178 'expectedOutputs': { 179 'tileOutput': { 180 'data': [1, 2, 1, 2, 3, 4, 3, 4, 1, 2, 1, 2, 3, 4, 3, 4], 181 'descriptor': {shape: [1, 1, 4, 4], dataType: 'int32'} 182 } 183 } 184 } 185 }, 186 ]; 187 188 webnn_conformance_test(tileTests, buildAndExecuteGraph, getZeroULPTolerance);