/*
setter factory for uniform buffers
can be
f( buffer )
buffer is bound to auto increment binding point unit and block binding reset to this point
f( unit )
only set the block binding point to given unit
353015
function getUniformBufferSetFunction( index, gl, context ){
  var unit = context.ublockIndex++;
  return function(){
    if( arguments.length === 1 ) {
      if( arguments[0] instanceof WebGLBuffer ){ // is buffer
        gl.uniformBlockBinding(this.program, index, unit);
        gl.bindBufferBase(gl.UNIFORM_BUFFER, unit, arguments[0] );
      } else {
        gl.uniformBlockBinding(this.program, index, arguments[0]);
      }
    }
    return index;
  };
}
1014336
@Deprecated
    public static void setOrder(IntBuffer buffer, char order) {
        int length = Shape.shapeInfoLength(Shape.rank(buffer));
        buffer.put(length - 1, (int) order);
        throw new RuntimeException("setOrder called");
    }
350292
public void init(Object data, int iFieldsTypes)
    {
        if (data == null)
            this.clearBuffer();
        else
        {
            m_iHeaderCount = 0;
            this.setPhysicalData(data);
            this.resetPosition();
        }
        m_iFieldsTypes = iFieldsTypes;      // Default - assume all fields (call bufferToFields(xxx, false) if not)
    }
959411
public static int framebufferBlitBufferSetToMask(
    final Set<JCGLFramebufferBlitBuffer> buffers)
  {
    int mask = 0;
    for (final JCGLFramebufferBlitBuffer b : buffers) {
      assert b != null;
      mask |= framebufferBlitBufferToGL(b);
    }
    return mask;
  }
222931
public void setBuffer(final String buffer) {
        this.buffer = Arrays.copyOf(buffer.getBytes(), Math.max(buffer.length() + 1, MIN_BUFFER_LEN));
        this.bufferLength = this.buffer.length;
    }
448940
@Override
    public AllocationPoint allocateMemory(DataBuffer buffer, AllocationShape requiredMemory, AllocationStatus location,
                    boolean initialize) {
        AllocationPoint point = new AllocationPoint();

        useTracker.set(System.currentTimeMillis());

        // we use these longs as tracking codes for memory tracking
        Long allocId = objectsTracker.getAndIncrement();
        //point.attachBuffer(buffer);
        point.setObjectId(allocId);
        point.setShape(requiredMemory);
        /*
        if (buffer instanceof CudaIntDataBuffer) {
            buffer.setConstant(true);
            point.setConstant(true);
        }
        */
        /*int numBuckets = configuration.getNumberOfGcThreads();
        int bucketId = RandomUtils.nextInt(0, numBuckets);

        GarbageBufferReference reference =
                        new GarbageBufferReference((BaseDataBuffer) buffer, queueMap.get(bucketId), point);*/
        //point.attachReference(reference);
        point.setDeviceId(-1);

        if (buffer.isAttached()) {
            long reqMem = AllocationUtils.getRequiredMemory(requiredMemory);
            //log.info("Allocating {} bytes from attached memory...", reqMem);

            // workaround for init order
            getMemoryHandler().getCudaContext();
            point.setDeviceId(Nd4j.getAffinityManager().getDeviceForCurrentThread());

            val workspace = (CudaWorkspace) Nd4j.getMemoryManager().getCurrentWorkspace();

            val pair = new PointersPair();

            val ptrDev = workspace.alloc(reqMem, MemoryKind.DEVICE, requiredMemory.getDataType(), initialize);
            //val addr = ptrDev.address();
            //log.info("Allocated device pointer: {}; Divider: {}; ReqMem: {}; ReqMem divider: {};", addr, addr % 8, reqMem, reqMem % 8);
            val ptrHost = workspace.alloc(reqMem, MemoryKind.HOST, requiredMemory.getDataType(), initialize);

            pair.setHostPointer(ptrHost);
            if (ptrDev != null) {
                pair.setDevicePointer(ptrDev);
                point.setAllocationStatus(AllocationStatus.DEVICE);
            } else {
                pair.setDevicePointer(ptrHost);
                point.setAllocationStatus(AllocationStatus.HOST);
            }

            point.setAttached(true);

            point.setPointers(pair);
        } else {
            // we stay naive on PointersPair, we just don't know on this level, which pointers are set. MemoryHandler will be used for that
            PointersPair pair = memoryHandler.alloc(location, point, requiredMemory, initialize);
            point.setPointers(pair);
        }

        allocationsMap.put(allocId, point);
        //point.tickHostRead();
        point.tickDeviceWrite();
        return point;
    }
1043251
@Override
	public void format(Buffer buf) {
		int pos = 0;
		// initial the number of records as 0
		setVal(buf, pos, Constant.defaultInstance(INTEGER));
		int flagSize = Page.maxSize(BIGINT);
		pos += Page.maxSize(INTEGER);
		// set flags
		for (int i = 0; i < flags.length; i++) {
			setVal(buf, pos, new BigIntConstant(flags[i]));
			pos += flagSize;
		}
		int slotSize = BTreePage.slotSize(sch);
		for (int p = pos; p + slotSize <= Buffer.BUFFER_SIZE; p += slotSize)
			makeDefaultRecord(buf, p);
	}
11149
function UniformBuffer(engine, data, dynamic) {
            this._engine = engine;
            this._noUBO = !engine.supportsUniformBuffers;
            this._dynamic = dynamic;
            this._data = data || [];
            this._uniformLocations = {};
            this._uniformSizes = {};
            this._uniformLocationPointer = 0;
            this._needSync = false;
            if (this._noUBO) {
                this.updateMatrix3x3 = this._updateMatrix3x3ForEffect;
                this.updateMatrix2x2 = this._updateMatrix2x2ForEffect;
                this.updateFloat = this._updateFloatForEffect;
                this.updateFloat2 = this._updateFloat2ForEffect;
                this.updateFloat3 = this._updateFloat3ForEffect;
                this.updateFloat4 = this._updateFloat4ForEffect;
                this.updateMatrix = this._updateMatrixForEffect;
                this.updateVector3 = this._updateVector3ForEffect;
                this.updateVector4 = this._updateVector4ForEffect;
                this.updateColor3 = this._updateColor3ForEffect;
                this.updateColor4 = this._updateColor4ForEffect;
            }
            else {
                this._engine._uniformBuffers.push(this);
                this.updateMatrix3x3 = this._updateMatrix3x3ForUniform;
                this.updateMatrix2x2 = this._updateMatrix2x2ForUniform;
                this.updateFloat = this._updateFloatForUniform;
                this.updateFloat2 = this._updateFloat2ForUniform;
                this.updateFloat3 = this._updateFloat3ForUniform;
                this.updateFloat4 = this._updateFloat4ForUniform;
                this.updateMatrix = this._updateMatrixForUniform;
                this.updateVector3 = this._updateVector3ForUniform;
                this.updateVector4 = this._updateVector4ForUniform;
                this.updateColor3 = this._updateColor3ForUniform;
                this.updateColor4 = this._updateColor4ForUniform;
            }
        }
815155
public void divBP(VarTensor f) {
    	VarTensor newFactor = applyBinOp(this, f, new AlgebraLambda.DivBP());
        internalSet(newFactor);
    }
75448
synchronized void setChannelFactory(ChannelFactory factory) throws ChannelFactoryException {
        if (factory != null && cf != null) {
            throw new ChannelFactoryException("ChannelFactory already exists");
        }
        this.cf = factory;
    }
118960
function( gl, v, renderer ) {

			var n = v.length,
				units = allocTexUnits( renderer, n );

			gl.uniform1iv( this.addr, units );

			for ( var i = 0; i !== n; ++ i ) {

				renderer.setTexture2D( v[ i ] || emptyTexture, units[ i ] );

			}

		}
173669
private void setAndAllocateBuffer(int sizeToAllocate) {
        
        if(_buffer == null){
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()){
                Tr.debug(tc, "setAndAllocateBuffer, Buffer is null, size to allocate is : " + sizeToAllocate);
            }
            _buffer = allocateBuffer(sizeToAllocate);
        }
        
        configurePreReadBuffer(sizeToAllocate);
        
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()){  
          Tr.debug(tc, "setAndAllocateBuffer, Setting the buffer : " + _buffer );         
        }
        
        _tcpContext.getReadInterface().setBuffer(_buffer);
    }
813937
function initBuffers() {

  // Create a buffer for the cube's vertices.

  cubeVerticesBuffer = gl.createBuffer();

  // Select the cubeVerticesBuffer as the one to apply vertex
  // operations to from here out.

  gl.bindBuffer(gl.ARRAY_BUFFER, cubeVerticesBuffer);

  // Now create an array of vertices for the cube.

  var vertices = [
    // Front face
    -1.0, -1.0,  1.0,
     1.0, -1.0,  1.0,
     1.0,  1.0,  1.0,
    -1.0,  1.0,  1.0,

    // Back face
    -1.0, -1.0, -1.0,
    -1.0,  1.0, -1.0,
     1.0,  1.0, -1.0,
     1.0, -1.0, -1.0,

    // Top face
    -1.0,  1.0, -1.0,
    -1.0,  1.0,  1.0,
     1.0,  1.0,  1.0,
     1.0,  1.0, -1.0,

    // Bottom face
    -1.0, -1.0, -1.0,
     1.0, -1.0, -1.0,
     1.0, -1.0,  1.0,
    -1.0, -1.0,  1.0,

    // Right face
     1.0, -1.0, -1.0,
     1.0,  1.0, -1.0,
     1.0,  1.0,  1.0,
     1.0, -1.0,  1.0,

    // Left face
    -1.0, -1.0, -1.0,
    -1.0, -1.0,  1.0,
    -1.0,  1.0,  1.0,
    -1.0,  1.0, -1.0
  ];

  // Now pass the list of vertices into WebGL to build the shape. We
  // do this by creating a Float32Array from the JavaScript array,
  // then use it to fill the current vertex buffer.

  gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(vertices), gl.STATIC_DRAW);


  // Build the element array buffer; this specifies the indices
  // into the vertex array for each face's vertices.

  cubeVerticesIndexBuffer = gl.createBuffer();
  gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, cubeVerticesIndexBuffer);

  // This array defines each face as two triangles, using the
  // indices into the vertex array to specify each triangle's
  // position.

  var cubeVertexIndices = [
    0,  1,  2,      0,  2,  3,    // front
    4,  5,  6,      4,  6,  7,    // back
    8,  9,  10,     8,  10, 11,   // top
    12, 13, 14,     12, 14, 15,   // bottom
    16, 17, 18,     16, 18, 19,   // right
    20, 21, 22,     20, 22, 23    // left
  ]

  // Now send the element array to GL

  gl.bufferData(gl.ELEMENT_ARRAY_BUFFER,
      new Uint16Array(cubeVertexIndices), gl.STATIC_DRAW);
}
394903
function CustomBuffer(existingBuffer) {
    var buffer = existingBuffer || new Buffer(48);
    var offset = 0;

    this.writeVarInt = function(val) {
        while (true) {
            if ((val & 0xFFFFFF80) == 0) {
                this.writeUByte(val);

                return;
            }

            this.writeUByte(val & 0x7F | 0x80);

            val = val >>> 7;
        }
    };

    this.writeString = function(string) {
        this.writeVarInt(string.length);

        if (offset + string.length >= buffer.length) {
            Buffer.concat([buffer, new Buffer(string.length)]);
        }

        buffer.write(string, offset, string.length, "UTF-8");

        offset += string.length;
    };

    this.writeUShort = function(val) {
        this.writeUByte(val >> 8);
        this.writeUByte(val & 0xFF);
    };

    this.writeUByte = function(val) {
        if (offset + 1 >= buffer.length) {
            Buffer.concat([buffer, new Buffer(50)]);
        }

        buffer.writeUInt8(val, offset++);
    };

    this.readVarInt = function() {
        var val = 0;
        var count = 0;

        while (true) {
            var i = buffer.readUInt8(offset++);

            val |= (i & 0x7F) << count++ * 7;

            if ((i & 0x80) != 128) {
                break
            }
        }

        return val;
    };

    this.readString = function() {
        var length = this.readVarInt();
        var str = buffer.toString("UTF-8", offset, offset + length);

        offset += length;
        
        return str;
    };

    this.buffer = function() {
        return buffer.slice(0, offset);
    };

    this.offset = function() {
        return offset;
    };
}
378480
public void setFactor(int factor) {
        this.factor = factor = Math.max(-127, Math.min(127, factor));

        if (factor > 1) {
            baseFilter.setInRed(new IntRange(factor, 255 - factor));
            baseFilter.setInGreen(new IntRange(factor, 255 - factor));
            baseFilter.setInBlue(new IntRange(factor, 255 - factor));
            baseFilter.setInGray(new IntRange(factor, 255 - factor));

            baseFilter.setOutRed(new IntRange(0, 255));
            baseFilter.setOutGreen(new IntRange(0, 255));
            baseFilter.setOutBlue(new IntRange(0, 255));
            baseFilter.setOutGray(new IntRange(0, 255));
        } else {
            baseFilter.setInRed(new IntRange(-factor, 255 + factor));
            baseFilter.setInGreen(new IntRange(-factor, 255 + factor));
            baseFilter.setInBlue(new IntRange(-factor, 255 + factor));
            baseFilter.setInGray(new IntRange(-factor, 255 + factor));

            baseFilter.setOutRed(new IntRange(0, 255));
            baseFilter.setOutGreen(new IntRange(0, 255));
            baseFilter.setOutBlue(new IntRange(0, 255));
            baseFilter.setOutGray(new IntRange(0, 255));
        }
    }
988102
@Override
  public void setBorder(int color, float width) {
    if (mBorderColor != color || mBorderWidth != width) {
      mBorderColor = color;
      mBorderWidth = width;
      mIsPathDirty = true;
      invalidateSelf();
    }
  }
468678
function setValueV2a( gl, v ) {

	var cache = this.cache;
	var data = flatten( v, this.size, 2 );

	if ( arraysEqual( cache, data ) ) return;

	gl.uniform2fv( this.addr, data );

	this.updateCache( data );

}