GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — arrayfire-python/arrayfire/bcast.py at master · arrayfire/arrayfire-python Expand file tree/ Copy pathbcast.pyMore file actions 96 lines (77 loc) · 2.24 KB / Copy pathbcast.pyFile metadata and controls96 lines (77 loc) · 2.24 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 ####################################################### # Copyright (c) 2015, ArrayFire # All rights reserved. # # This file is distributed under 3-clause BSD license. # The complete license agreement can be obtained at: # http://arrayfire.com/licenses/BSD-3-Clause ######################################################## """ Function to perform broadcasting operations. """ class _bcast(object): _flag = False def get(self): return _bcast._flag def set(self, flag): _bcast._flag = flag def toggle(self): _bcast._flag ^= True _bcast_var = _bcast() def broadcast(func, *args): """ Function to perform broadcast operations. This function can be used directly or as an annotation in the following manner. Example ------- Using broadcast as an annotation >>> import arrayfire as af >>> @af.broadcast ... def add(a, b): ... return a + b ... >>> a = af.randu(2,3) >>> b = af.randu(2,1) # b is a different size >>> # Trying to add arrays of different sizes raises an exceptions >>> c = add(a, b) # This call does not raise an exception because of the annotation >>> af.display(a) [2 3 1 1] 0.4107 0.9518 0.4198 0.8224 0.1794 0.0081 >>> af.display(b) [2 1 1 1] 0.7269 0.7104 >>> af.display(c) [2 3 1 1] 1.1377 1.6787 1.1467 1.5328 0.8898 0.7185 Using broadcast as function >>> import arrayfire as af >>> add = lambda a,b: a + b >>> a = af.randu(2,3) >>> b = af.randu(2,1) # b is a different size >>> # Trying to add arrays of different sizes raises an exceptions >>> c = af.broadcast(add, a, b) # This call does not raise an exception >>> af.display(a) [2 3 1 1] 0.4107 0.9518 0.4198 0.8224 0.1794 0.0081 >>> af.display(b) [2 1 1 1] 0.7269 0.7104 >>> af.display(c) [2 3 1 1] 1.1377 1.6787 1.1467 1.5328 0.8898 0.7185 """ def wrapper(*func_args): _bcast_var.toggle() res = func(*func_args) _bcast_var.toggle() return res if len(args) == 0: return wrapper else: return wrapper(*args) |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |