repo_id
stringlengths
21
96
file_path
stringlengths
31
155
content
stringlengths
1
92.9M
__index_level_0__
int64
0
0
rapidsai_public_repos/node/modules/cudf/test/series
rapidsai_public_repos/node/modules/cudf/test/series/binaryop/int16-tests.ts
// Copyright (c) 2021, NVIDIA CORPORATION. // // 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. import {setDefaultAllocator} from '@rapidsai/cuda'; import {DeviceBuffer} from '@rapidsai/rmm'; import * as arrow from 'apache-arrow'; import {makeTestNumbers, makeTestSeries, toBigInt} from '../utils'; setDefaultAllocator((byteLength: number) => new DeviceBuffer(byteLength)); const makeTestData = (values?: (number|null)[]) => makeTestSeries(new arrow.Int16, makeTestNumbers(values)); describe('Series binaryops (Int16)', () => { describe('Series.add', () => { test('adds a Series', () => { const {lhs, rhs} = makeTestData(); // lhs + lhs == [0 + 0, 1 + 1, 2 + 2] expect([...lhs.add(lhs)].map(Number)).toEqual([0, 2, 4]); // lhs + rhs == [0 + 1, 1 + 2, 2 + 3] expect([...lhs.add(rhs)].map(Number)).toEqual([1, 3, 5]); }); test('adds a number', () => { const {lhs} = makeTestData(); expect([...lhs.add(-1)].map(Number)).toEqual([-1, 0, 1]); expect([...lhs.add(0)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.add(1)].map(Number)).toEqual([1, 2, 3]); expect([...lhs.add(2)].map(Number)).toEqual([2, 3, 4]); }); test('adds a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.add(-1n)].map(toBigInt)).toEqual([-1n, 0n, 1n]); expect([...lhs.add(0n)].map(toBigInt)).toEqual([0n, 1n, 2n]); expect([...lhs.add(1n)].map(toBigInt)).toEqual([1n, 2n, 3n]); expect([...lhs.add(2n)].map(toBigInt)).toEqual([2n, 3n, 4n]); }); }); describe('Series.sub', () => { test('subtracts a Series', () => { const {lhs, rhs} = makeTestData(); // lhs - lhs == [0 - 0, 1 - 1, 2 - 2] expect([...lhs.sub(lhs)].map(Number)).toEqual([0, 0, 0]); // lhs - rhs == [0 - 1, 1 - 2, 2 - 3] expect([...lhs.sub(rhs)].map(Number)).toEqual([-1, -1, -1]); // rhs - lhs == [1 - 0, 2 - 1, 3 - 2] expect([...rhs.sub(lhs)].map(Number)).toEqual([1, 1, 1]); }); test('subtracts a number', () => { const {lhs} = makeTestData(); expect([...lhs.sub(-1)].map(Number)).toEqual([1, 2, 3]); expect([...lhs.sub(0)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.sub(1)].map(Number)).toEqual([-1, 0, 1]); expect([...lhs.sub(2)].map(Number)).toEqual([-2, -1, 0]); }); test('subtracts a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.sub(-1n)].map(toBigInt)).toEqual([1n, 2n, 3n]); expect([...lhs.sub(0n)].map(toBigInt)).toEqual([0n, 1n, 2n]); expect([...lhs.sub(1n)].map(toBigInt)).toEqual([-1n, 0n, 1n]); expect([...lhs.sub(2n)].map(toBigInt)).toEqual([-2n, -1n, 0n]); }); }); describe('Series.mul', () => { test('multiplies against a Series', () => { const {lhs, rhs} = makeTestData(); // lhs * lhs == [0 * 0, 1 * 1, 2 * 2] expect([...lhs.mul(lhs)].map(Number)).toEqual([0, 1, 4]); // lhs * rhs == [0 * 1, 1 * 2, 2 * 3] expect([...lhs.mul(rhs)].map(Number)).toEqual([0, 2, 6]); }); test('multiplies against a number', () => { const {lhs} = makeTestData(); expect([...lhs.mul(-1)].map(Number)).toEqual([-0, -1, -2]); expect([...lhs.mul(0)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.mul(1)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.mul(2)].map(Number)).toEqual([0, 2, 4]); }); test('multiplies against a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.mul(-1n)].map(toBigInt)).toEqual([0n, -1n, -2n]); expect([...lhs.mul(0n)].map(toBigInt)).toEqual([0n, 0n, 0n]); expect([...lhs.mul(1n)].map(toBigInt)).toEqual([0n, 1n, 2n]); expect([...lhs.mul(2n)].map(toBigInt)).toEqual([0n, 2n, 4n]); }); }); describe('Series.div', () => { test('divides by a Series', () => { const {lhs, rhs} = makeTestData(); // lhs / lhs == [0/0, 1/1, 2/2] expect([...lhs.div(lhs)].map(Number)).toEqual([-1, 1, 1]); // lhs / rhs == [0/1, 1/2, 2/3] expect([...lhs.div(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('divides by a number', () => { const {lhs} = makeTestData(); expect([...lhs.div(-1)].map(Number)).toEqual([-0, -1, -2]); expect([...lhs.div(0)].map(Number)).toEqual([NaN, Infinity, Infinity]); expect([...lhs.div(1)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.div(2)].map(Number)).toEqual([0, 0.5, 1]); }); test('divides by a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.div(-1n)].map(toBigInt)).toEqual([0n, -1n, -2n]); expect([...lhs.div(0n)].map(toBigInt)).toEqual([4294967295n, 4294967295n, 4294967295n]); expect([...lhs.div(1n)].map(toBigInt)).toEqual([0n, 1n, 2n]); expect([...lhs.div(2n)].map(toBigInt)).toEqual([0n, 0n, 1n]); }); }); describe('Series.trueDiv', () => { test('trueDivides by a Series', () => { const {lhs, rhs} = makeTestData(); // lhs / lhs == [0/0, 1/1, 2/2] expect([...lhs.trueDiv(lhs)].map(Number)).toEqual([0, 1, 1]); // lhs / rhs == [0/1, 1/2, 2/3] expect([...lhs.trueDiv(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('trueDivides by a number', () => { const {lhs} = makeTestData(); expect([...lhs.trueDiv(-1)].map(Number)).toEqual([-0, -1, -2]); expect([...lhs.trueDiv(0)].map(Number)).toEqual([NaN, Infinity, Infinity]); expect([...lhs.trueDiv(1)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.trueDiv(2)].map(Number)).toEqual([0, 0.5, 1]); }); test('trueDivides by a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.trueDiv(-1n)].map(toBigInt)).toEqual([0n, -1n, -2n]); expect([...lhs.trueDiv(0n)].map(toBigInt)) .toEqual([-9223372036854775808n, 9223372036854775807n, 9223372036854775807n]); expect([...lhs.trueDiv(1n)].map(toBigInt)).toEqual([0n, 1n, 2n]); expect([...lhs.trueDiv(2n)].map(toBigInt)).toEqual([0n, 0n, 1n]); }); }); describe('Series.floorDiv', () => { test('floorDivides by a Series', () => { const {lhs, rhs} = makeTestData(); // lhs / lhs == floor([0/0, 1/1, 2/2]) expect([...lhs.floorDiv(lhs)].map(Number)).toEqual([0, 1, 1]); // lhs / rhs == floor([0/1, 1/2, 2/3]) expect([...lhs.floorDiv(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('floorDivides by a number', () => { const {lhs} = makeTestData(); expect([...lhs.floorDiv(-1)].map(Number)).toEqual([-0, -1, -2]); expect([...lhs.floorDiv(0)].map(Number)).toEqual([NaN, Infinity, Infinity]); expect([...lhs.floorDiv(1)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.floorDiv(2)].map(Number)).toEqual([0, 0, 1]); }); test('floorDivides by a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.floorDiv(-1n)].map(toBigInt)).toEqual([0n, -1n, -2n]); expect([...lhs.floorDiv(0n)].map(toBigInt)) .toEqual([-9223372036854775808n, 9223372036854775807n, 9223372036854775807n]); expect([...lhs.floorDiv(1n)].map(toBigInt)).toEqual([0n, 1n, 2n]); expect([...lhs.floorDiv(2n)].map(toBigInt)).toEqual([0n, 0n, 1n]); }); }); describe('Series.mod', () => { test('modulo by a Series', () => { const {lhs, rhs} = makeTestData(); // lhs % lhs == [0 % 0, 1 % 1, 2 % 2]) expect([...lhs.mod(lhs)].map(Number)).toEqual([-1, 0, 0]); // lhs % rhs == [0 % 1, 1 % 2, 2 % 3]) expect([...lhs.mod(rhs)].map(Number)).toEqual([0, 1, 2]); }); test('modulo by a number', () => { const {lhs} = makeTestData(); expect([...lhs.mod(-1)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.mod(0)].map(Number)).toEqual([NaN, NaN, NaN]); expect([...lhs.mod(1)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.mod(2)].map(Number)).toEqual([0, 1, 0]); }); test('modulo by a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.mod(-1n)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.mod(0n)].map(Number)).toEqual([4294967295, 4294967295, 4294967295]); expect([...lhs.mod(1n)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.mod(2n)].map(Number)).toEqual([0, 1, 0]); }); }); describe('Series.pow', () => { test('computes to the power of a Series', () => { const {lhs, rhs} = makeTestData(); // lhs ** lhs == [0 ** 0, 1 ** 1, 2 ** 2]) expect([...lhs.pow(lhs)].map(Number)).toEqual([1, 1, 4]); // lhs ** rhs == [0 ** 1, 1 ** 2, 2 ** 3]) expect([...lhs.pow(rhs)].map(Number)).toEqual([0, 1, 8]); }); test('computes to the power of a number', () => { const {lhs} = makeTestData(); expect([...lhs.pow(-1)].map(Number)).toEqual([Infinity, 1, 0.5]); expect([...lhs.pow(0)].map(Number)).toEqual([1, 1, 1]); expect([...lhs.pow(1)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.pow(2)].map(Number)).toEqual([0, 1, 4]); }); test('computes to the power of a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.pow(-1n)].map(Number)).toEqual([9223372036854776000, 1, 0]); expect([...lhs.pow(0n)].map(Number)).toEqual([1, 1, 1]); expect([...lhs.pow(1n)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.pow(2n)].map(Number)).toEqual([0, 1, 4]); }); }); describe('Series.eq', () => { test('compares against Series', () => { const {lhs, rhs} = makeTestData(); // lhs == lhs == true expect([...lhs.eq(lhs)].map(Number)).toEqual([1, 1, 1]); // lhs == rhs == false expect([...lhs.eq(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('compares against numbers', () => { const {lhs} = makeTestData(); expect([...lhs.eq(0)].map(Number)).toEqual([1, 0, 0]); expect([...lhs.eq(1)].map(Number)).toEqual([0, 1, 0]); expect([...lhs.eq(2)].map(Number)).toEqual([0, 0, 1]); }); test('compares against bigints', () => { const {lhs} = makeTestData(); expect([...lhs.eq(0n)].map(toBigInt)).toEqual([1n, 0n, 0n]); expect([...lhs.eq(1n)].map(toBigInt)).toEqual([0n, 1n, 0n]); expect([...lhs.eq(2n)].map(toBigInt)).toEqual([0n, 0n, 1n]); }); }); describe('Series.ne', () => { test('compares against Series', () => { const {lhs, rhs} = makeTestData(); // lhs != rhs == true expect([...lhs.ne(rhs)].map(Number)).toEqual([1, 1, 1]); // lhs != lhs == false expect([...lhs.ne(lhs)].map(Number)).toEqual([0, 0, 0]); }); test('compares against numbers', () => { const {lhs} = makeTestData(); expect([...lhs.ne(0)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.ne(1)].map(Number)).toEqual([1, 0, 1]); expect([...lhs.ne(2)].map(Number)).toEqual([1, 1, 0]); }); test('compares against bigints', () => { const {lhs} = makeTestData(); expect([...lhs.ne(0n)].map(toBigInt)).toEqual([0n, 1n, 1n]); expect([...lhs.ne(1n)].map(toBigInt)).toEqual([1n, 0n, 1n]); expect([...lhs.ne(2n)].map(toBigInt)).toEqual([1n, 1n, 0n]); }); }); describe('Series.lt', () => { test('compares against Series', () => { const {lhs, rhs} = makeTestData(); // lhs < rhs == true expect([...lhs.lt(rhs)].map(Number)).toEqual([1, 1, 1]); // lhs < lhs == false expect([...lhs.lt(lhs)].map(Number)).toEqual([0, 0, 0]); // rhs < lhs == false expect([...rhs.lt(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('compares against numbers', () => { const {lhs} = makeTestData(); expect([...lhs.lt(3)].map(Number)).toEqual([1, 1, 1]); expect([...lhs.lt(2)].map(Number)).toEqual([1, 1, 0]); expect([...lhs.lt(1)].map(Number)).toEqual([1, 0, 0]); expect([...lhs.lt(0)].map(Number)).toEqual([0, 0, 0]); }); test('compares against bigints', () => { const {lhs} = makeTestData(); expect([...lhs.lt(3n)].map(toBigInt)).toEqual([1n, 1n, 1n]); expect([...lhs.lt(2n)].map(toBigInt)).toEqual([1n, 1n, 0n]); expect([...lhs.lt(1n)].map(toBigInt)).toEqual([1n, 0n, 0n]); expect([...lhs.lt(0n)].map(toBigInt)).toEqual([0n, 0n, 0n]); }); }); describe('Series.le', () => { test('compares against Series', () => { const {lhs, rhs} = makeTestData(); // lhs <= lhs == true expect([...lhs.le(lhs)].map(Number)).toEqual([1, 1, 1]); // lhs <= rhs == true expect([...lhs.le(rhs)].map(Number)).toEqual([1, 1, 1]); // rhs <= lhs == false expect([...rhs.le(lhs)].map(Number)).toEqual([0, 0, 0]); }); test('compares against numbers', () => { const {lhs} = makeTestData(); expect([...lhs.le(2)].map(Number)).toEqual([1, 1, 1]); expect([...lhs.le(1)].map(Number)).toEqual([1, 1, 0]); expect([...lhs.le(0)].map(Number)).toEqual([1, 0, 0]); }); test('compares against bigints', () => { const {lhs} = makeTestData(); expect([...lhs.le(2n)].map(toBigInt)).toEqual([1n, 1n, 1n]); expect([...lhs.le(1n)].map(toBigInt)).toEqual([1n, 1n, 0n]); expect([...lhs.le(0n)].map(toBigInt)).toEqual([1n, 0n, 0n]); }); }); describe('Series.gt', () => { test('compares against Series', () => { const {lhs, rhs} = makeTestData(); // rhs > lhs == true expect([...rhs.gt(lhs)].map(Number)).toEqual([1, 1, 1]); // lhs > rhs == false expect([...lhs.gt(rhs)].map(Number)).toEqual([0, 0, 0]); // lhs > lhs == false expect([...lhs.gt(lhs)].map(Number)).toEqual([0, 0, 0]); }); test('compares against numbers', () => { const {lhs} = makeTestData(); expect([...lhs.gt(2)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.gt(1)].map(Number)).toEqual([0, 0, 1]); expect([...lhs.gt(0)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.gt(-1)].map(Number)).toEqual([1, 1, 1]); }); test('compares against bigints', () => { const {lhs} = makeTestData(); expect([...lhs.gt(2n)].map(toBigInt)).toEqual([0n, 0n, 0n]); expect([...lhs.gt(1n)].map(toBigInt)).toEqual([0n, 0n, 1n]); expect([...lhs.gt(0n)].map(toBigInt)).toEqual([0n, 1n, 1n]); expect([...lhs.gt(-1n)].map(toBigInt)).toEqual([1n, 1n, 1n]); }); }); describe('Series.ge', () => { test('compares against Series', () => { const {lhs, rhs} = makeTestData(); // lhs >= lhs == true expect([...lhs.ge(lhs)].map(Number)).toEqual([1, 1, 1]); // lhs >= rhs == false expect([...lhs.ge(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('compares against numbers', () => { const {lhs} = makeTestData(); expect([...lhs.ge(3)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.ge(2)].map(Number)).toEqual([0, 0, 1]); expect([...lhs.ge(1)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.ge(0)].map(Number)).toEqual([1, 1, 1]); }); test('compares against bigints', () => { const {lhs} = makeTestData(); expect([...lhs.ge(3n)].map(toBigInt)).toEqual([0n, 0n, 0n]); expect([...lhs.ge(2n)].map(toBigInt)).toEqual([0n, 0n, 1n]); expect([...lhs.ge(1n)].map(toBigInt)).toEqual([0n, 1n, 1n]); expect([...lhs.ge(0n)].map(toBigInt)).toEqual([1n, 1n, 1n]); }); }); describe('Series.bitwiseAnd', () => { test('bitwiseAnd with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs ** lhs == [0 & 0, 1 & 1, 2 & 2]) expect([...lhs.bitwiseAnd(lhs)].map(Number)).toEqual([0, 1, 2]); // lhs ** rhs == [0 & 1, 1 & 2, 2 & 3]) expect([...lhs.bitwiseAnd(rhs)].map(Number)).toEqual([0, 0, 2]); }); test('bitwiseAnd with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.bitwiseAnd(-1)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.bitwiseAnd(0)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.bitwiseAnd(1)].map(Number)).toEqual([0, 1, 0]); expect([...lhs.bitwiseAnd(2)].map(Number)).toEqual([0, 0, 2]); }); test('bitwiseAnd with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.bitwiseAnd(-1n)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.bitwiseAnd(0n)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.bitwiseAnd(1n)].map(Number)).toEqual([0, 1, 0]); expect([...lhs.bitwiseAnd(2n)].map(Number)).toEqual([0, 0, 2]); }); }); describe('Series.bitwiseOr', () => { test('bitwiseOr with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs | lhs == [0 | 0, 1 | 1, 2 | 2]) expect([...lhs.bitwiseOr(lhs)].map(Number)).toEqual([0, 1, 2]); // lhs | rhs == [0 | 1, 1 | 2, 2 | 3]) expect([...lhs.bitwiseOr(rhs)].map(Number)).toEqual([1, 3, 3]); }); test('bitwiseOr with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.bitwiseOr(-1)].map(Number)).toEqual([-1, -1, -1]); expect([...lhs.bitwiseOr(0)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.bitwiseOr(1)].map(Number)).toEqual([1, 1, 3]); expect([...lhs.bitwiseOr(2)].map(Number)).toEqual([2, 3, 2]); }); test('bitwiseOr with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.bitwiseOr(-1n)].map(Number)).toEqual([-1, -1, -1]); expect([...lhs.bitwiseOr(0n)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.bitwiseOr(1n)].map(Number)).toEqual([1, 1, 3]); expect([...lhs.bitwiseOr(2n)].map(Number)).toEqual([2, 3, 2]); }); }); describe('Series.bitwiseXor', () => { test('bitwiseXor with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs ^ lhs == [0 ^ 0, 1 ^ 1, 2 ^ 2]) expect([...lhs.bitwiseXor(lhs)].map(Number)).toEqual([0, 0, 0]); // lhs ^ rhs == [0 ^ 1, 1 ^ 2, 2 ^ 3]) expect([...lhs.bitwiseXor(rhs)].map(Number)).toEqual([1, 3, 1]); }); test('bitwiseXor with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.bitwiseXor(-1)].map(Number)).toEqual([-1, -2, -3]); expect([...lhs.bitwiseXor(0)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.bitwiseXor(1)].map(Number)).toEqual([1, 0, 3]); expect([...lhs.bitwiseXor(2)].map(Number)).toEqual([2, 3, 0]); }); test('bitwiseXor with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.bitwiseXor(-1n)].map(Number)).toEqual([-1, -2, -3]); expect([...lhs.bitwiseXor(0n)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.bitwiseXor(1n)].map(Number)).toEqual([1, 0, 3]); expect([...lhs.bitwiseXor(2n)].map(Number)).toEqual([2, 3, 0]); }); }); describe('Series.logicalAnd', () => { test('logicalAnd with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs && lhs == [0 && 0, 1 && 1, 2 && 2]) expect([...lhs.logicalAnd(lhs)].map(Number)).toEqual([0, 1, 1]); // lhs && rhs == [0 && 1, 1 && 2, 2 && 3]) expect([...lhs.logicalAnd(rhs)].map(Number)).toEqual([0, 1, 1]); }); test('logicalAnd with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.logicalAnd(-1)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.logicalAnd(0)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.logicalAnd(1)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.logicalAnd(2)].map(Number)).toEqual([0, 1, 1]); }); test('logicalAnd with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.logicalAnd(-1n)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.logicalAnd(0n)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.logicalAnd(1n)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.logicalAnd(2n)].map(Number)).toEqual([0, 1, 1]); }); }); describe('Series.logicalOr', () => { test('logicalOr with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs || lhs == [0 || 0, 1 || 1, 2 || 2]) expect([...lhs.logicalOr(lhs)].map(Number)).toEqual([0, 1, 1]); // lhs || rhs == [0 || 1, 1 || 2, 2 || 3]) expect([...lhs.logicalOr(rhs)].map(Number)).toEqual([1, 1, 1]); }); test('logicalOr with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.logicalOr(-1)].map(Number)).toEqual([1, 1, 1]); expect([...lhs.logicalOr(0)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.logicalOr(1)].map(Number)).toEqual([1, 1, 1]); expect([...lhs.logicalOr(2)].map(Number)).toEqual([1, 1, 1]); }); test('logicalOr with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.logicalOr(-1n)].map(Number)).toEqual([1, 1, 1]); expect([...lhs.logicalOr(0n)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.logicalOr(1n)].map(Number)).toEqual([1, 1, 1]); expect([...lhs.logicalOr(2n)].map(Number)).toEqual([1, 1, 1]); }); }); describe('Series.shiftLeft', () => { test('shiftLeft with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs || lhs == [0 || 0, 1 || 1, 2 || 2]) expect([...lhs.shiftLeft(lhs)].map(Number)).toEqual([0, 2, 8]); // lhs || rhs == [0 || 1, 1 || 2, 2 || 3]) expect([...lhs.shiftLeft(rhs)].map(Number)).toEqual([0, 4, 16]); }); test('shiftLeft with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.shiftLeft(-1)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.shiftLeft(0)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.shiftLeft(1)].map(Number)).toEqual([0, 2, 4]); expect([...lhs.shiftLeft(2)].map(Number)).toEqual([0, 4, 8]); }); test('shiftLeft with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.shiftLeft(-1n)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.shiftLeft(0n)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.shiftLeft(1n)].map(Number)).toEqual([0, 2, 4]); expect([...lhs.shiftLeft(2n)].map(Number)).toEqual([0, 4, 8]); }); }); describe('Series.shiftRight', () => { test('shiftRight with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs || lhs == [0 || 0, 1 || 1, 2 || 2]) expect([...lhs.shiftRight(lhs)].map(Number)).toEqual([0, 0, 0]); // lhs || rhs == [0 || 1, 1 || 2, 2 || 3]) expect([...lhs.shiftRight(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('shiftRight with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.shiftRight(-1)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.shiftRight(0)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.shiftRight(1)].map(Number)).toEqual([0, 0, 1]); expect([...lhs.shiftRight(2)].map(Number)).toEqual([0, 0, 0]); }); test('shiftRight with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.shiftRight(-1n)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.shiftRight(0n)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.shiftRight(1n)].map(Number)).toEqual([0, 0, 1]); expect([...lhs.shiftRight(2n)].map(Number)).toEqual([0, 0, 0]); }); }); describe('Series.shiftRightUnsigned', () => { test('shiftRightUnsigned with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs || lhs == [0 || 0, 1 || 1, 2 || 2]) expect([...lhs.shiftRightUnsigned(lhs)].map(Number)).toEqual([0, 0, 0]); // lhs || rhs == [0 || 1, 1 || 2, 2 || 3]) expect([...lhs.shiftRightUnsigned(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('shiftRightUnsigned with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.shiftRightUnsigned(-1)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.shiftRightUnsigned(0)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.shiftRightUnsigned(1)].map(Number)).toEqual([0, 0, 1]); expect([...lhs.shiftRightUnsigned(2)].map(Number)).toEqual([0, 0, 0]); }); test('shiftRightUnsigned with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.shiftRightUnsigned(-1n)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.shiftRightUnsigned(0n)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.shiftRightUnsigned(1n)].map(Number)).toEqual([0, 0, 1]); expect([...lhs.shiftRightUnsigned(2n)].map(Number)).toEqual([0, 0, 0]); }); }); describe('Series.logBase', () => { test('logBase with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs || lhs == [0 || 0, 1 || 1, 2 || 2]) expect([...lhs.logBase(lhs)].map(Number)).toEqual([0, 0, 1]); // lhs || rhs == [0 || 1, 1 || 2, 2 || 3]) expect([...lhs.logBase(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('logBase with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.logBase(-1)].map(Number)).toEqual([NaN, NaN, NaN]); expect([...lhs.logBase(0)].map(Number)).toEqual([NaN, -0, -0]); expect([...lhs.logBase(1)].map(Number)).toEqual([-Infinity, NaN, Infinity]); expect([...lhs.logBase(2)].map(Number)).toEqual([-Infinity, 0, 1]); }); test('logBase with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.logBase(-1n)].map(Number)) .toEqual([-9223372036854776000, -9223372036854776000, -9223372036854776000]); expect([...lhs.logBase(0n)].map(Number)).toEqual([-9223372036854776000, 0, 0]); expect([...lhs.logBase(1n)].map(Number)) .toEqual([-9223372036854776000, -9223372036854776000, 9223372036854776000]); expect([...lhs.logBase(2n)].map(Number)).toEqual([-9223372036854776000, 0, 1]); }); }); describe('Series.atan2', () => { test('atan2 with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs || lhs == [0 || 0, 1 || 1, 2 || 2]) expect([...lhs.atan2(lhs)].map(Number)).toEqual([0, 0, 0]); // lhs || rhs == [0 || 1, 1 || 2, 2 || 3]) expect([...lhs.atan2(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('atan2 with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.atan2(-1)].map(Number)) .toEqual([3.141592653589793, 2.356194490192345, 2.0344439357957027]); expect([...lhs.atan2(0)].map(Number)).toEqual([0, 1.5707963267948966, 1.5707963267948966]); expect([...lhs.atan2(1)].map(Number)).toEqual([0, 0.7853981633974483, 1.1071487177940904]); expect([...lhs.atan2(2)].map(Number)).toEqual([0, 0.46364760900080615, 0.7853981633974483]); }); test('atan2 with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.atan2(-1n)].map(Number)).toEqual([3, 2, 2]); expect([...lhs.atan2(0n)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.atan2(1n)].map(Number)).toEqual([0, 0, 1]); expect([...lhs.atan2(2n)].map(Number)).toEqual([0, 0, 0]); }); }); describe('Series.nullEquals', () => { test('nullEquals with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs || lhs == [0 || 0, 1 || 1, 2 || 2]) expect([...lhs.nullEquals(lhs)].map(Number)).toEqual([1, 1, 1]); // lhs || rhs == [0 || 1, 1 || 2, 2 || 3]) expect([...lhs.nullEquals(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('nullEquals with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.nullEquals(-1)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.nullEquals(0)].map(Number)).toEqual([1, 0, 0]); expect([...lhs.nullEquals(1)].map(Number)).toEqual([0, 1, 0]); expect([...lhs.nullEquals(2)].map(Number)).toEqual([0, 0, 1]); }); test('nullEquals with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.nullEquals(-1n)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.nullEquals(0n)].map(Number)).toEqual([1, 0, 0]); expect([...lhs.nullEquals(1n)].map(Number)).toEqual([0, 1, 0]); expect([...lhs.nullEquals(2n)].map(Number)).toEqual([0, 0, 1]); }); }); describe('Series.nullMax', () => { test('nullMax with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs || lhs == [0 || 0, 1 || 1, 2 || 2]) expect([...lhs.nullMax(lhs)].map(Number)).toEqual([0, 1, 2]); // lhs || rhs == [0 || 1, 1 || 2, 2 || 3]) expect([...lhs.nullMax(rhs)].map(Number)).toEqual([1, 2, 3]); }); test('nullMax with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.nullMax(-1)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.nullMax(0)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.nullMax(1)].map(Number)).toEqual([1, 1, 2]); expect([...lhs.nullMax(2)].map(Number)).toEqual([2, 2, 2]); }); test('nullMax with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.nullMax(-1n)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.nullMax(0n)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.nullMax(1n)].map(Number)).toEqual([1, 1, 2]); expect([...lhs.nullMax(2n)].map(Number)).toEqual([2, 2, 2]); }); }); describe('Series.nullMin', () => { test('nullMin with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs || lhs == [0 || 0, 1 || 1, 2 || 2]) expect([...lhs.nullMin(lhs)].map(Number)).toEqual([0, 1, 2]); // lhs || rhs == [0 || 1, 1 || 2, 2 || 3]) expect([...lhs.nullMin(rhs)].map(Number)).toEqual([0, 1, 2]); }); test('nullMin with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.nullMin(-1)].map(Number)).toEqual([-1, -1, -1]); expect([...lhs.nullMin(0)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.nullMin(1)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.nullMin(2)].map(Number)).toEqual([0, 1, 2]); }); test('nullMin with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.nullMin(-1n)].map(Number)).toEqual([-1, -1, -1]); expect([...lhs.nullMin(0n)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.nullMin(1n)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.nullMin(2n)].map(Number)).toEqual([0, 1, 2]); }); }); });
0
rapidsai_public_repos/node/modules/cudf/test/series
rapidsai_public_repos/node/modules/cudf/test/series/binaryop/int32-tests.ts
// Copyright (c) 2021, NVIDIA CORPORATION. // // 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. import {setDefaultAllocator} from '@rapidsai/cuda'; import {DeviceBuffer} from '@rapidsai/rmm'; import * as arrow from 'apache-arrow'; import {makeTestNumbers, makeTestSeries, toBigInt} from '../utils'; setDefaultAllocator((byteLength: number) => new DeviceBuffer(byteLength)); const makeTestData = (values?: (number|null)[]) => makeTestSeries(new arrow.Int32, makeTestNumbers(values)); describe('Series binaryops (Int32)', () => { describe('Series.add', () => { test('adds a Series', () => { const {lhs, rhs} = makeTestData(); // lhs + lhs == [0 + 0, 1 + 1, 2 + 2] expect([...lhs.add(lhs)].map(Number)).toEqual([0, 2, 4]); // lhs + rhs == [0 + 1, 1 + 2, 2 + 3] expect([...lhs.add(rhs)].map(Number)).toEqual([1, 3, 5]); }); test('adds a number', () => { const {lhs} = makeTestData(); expect([...lhs.add(-1)].map(Number)).toEqual([-1, 0, 1]); expect([...lhs.add(0)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.add(1)].map(Number)).toEqual([1, 2, 3]); expect([...lhs.add(2)].map(Number)).toEqual([2, 3, 4]); }); test('adds a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.add(-1n)].map(toBigInt)).toEqual([-1n, 0n, 1n]); expect([...lhs.add(0n)].map(toBigInt)).toEqual([0n, 1n, 2n]); expect([...lhs.add(1n)].map(toBigInt)).toEqual([1n, 2n, 3n]); expect([...lhs.add(2n)].map(toBigInt)).toEqual([2n, 3n, 4n]); }); }); describe('Series.sub', () => { test('subtracts a Series', () => { const {lhs, rhs} = makeTestData(); // lhs - lhs == [0 - 0, 1 - 1, 2 - 2] expect([...lhs.sub(lhs)].map(Number)).toEqual([0, 0, 0]); // lhs - rhs == [0 - 1, 1 - 2, 2 - 3] expect([...lhs.sub(rhs)].map(Number)).toEqual([-1, -1, -1]); // rhs - lhs == [1 - 0, 2 - 1, 3 - 2] expect([...rhs.sub(lhs)].map(Number)).toEqual([1, 1, 1]); }); test('subtracts a number', () => { const {lhs} = makeTestData(); expect([...lhs.sub(-1)].map(Number)).toEqual([1, 2, 3]); expect([...lhs.sub(0)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.sub(1)].map(Number)).toEqual([-1, 0, 1]); expect([...lhs.sub(2)].map(Number)).toEqual([-2, -1, 0]); }); test('subtracts a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.sub(-1n)].map(toBigInt)).toEqual([1n, 2n, 3n]); expect([...lhs.sub(0n)].map(toBigInt)).toEqual([0n, 1n, 2n]); expect([...lhs.sub(1n)].map(toBigInt)).toEqual([-1n, 0n, 1n]); expect([...lhs.sub(2n)].map(toBigInt)).toEqual([-2n, -1n, 0n]); }); }); describe('Series.mul', () => { test('multiplies against a Series', () => { const {lhs, rhs} = makeTestData(); // lhs * lhs == [0 * 0, 1 * 1, 2 * 2] expect([...lhs.mul(lhs)].map(Number)).toEqual([0, 1, 4]); // lhs * rhs == [0 * 1, 1 * 2, 2 * 3] expect([...lhs.mul(rhs)].map(Number)).toEqual([0, 2, 6]); }); test('multiplies against a number', () => { const {lhs} = makeTestData(); expect([...lhs.mul(-1)].map(Number)).toEqual([-0, -1, -2]); expect([...lhs.mul(0)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.mul(1)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.mul(2)].map(Number)).toEqual([0, 2, 4]); }); test('multiplies against a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.mul(-1n)].map(toBigInt)).toEqual([0n, -1n, -2n]); expect([...lhs.mul(0n)].map(toBigInt)).toEqual([0n, 0n, 0n]); expect([...lhs.mul(1n)].map(toBigInt)).toEqual([0n, 1n, 2n]); expect([...lhs.mul(2n)].map(toBigInt)).toEqual([0n, 2n, 4n]); }); }); describe('Series.div', () => { test('divides by a Series', () => { const {lhs, rhs} = makeTestData(); // lhs / lhs == [0/0, 1/1, 2/2] expect([...lhs.div(lhs)].map(Number)).toEqual([-1, 1, 1]); // lhs / rhs == [0/1, 1/2, 2/3] expect([...lhs.div(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('divides by a number', () => { const {lhs} = makeTestData(); expect([...lhs.div(-1)].map(Number)).toEqual([-0, -1, -2]); expect([...lhs.div(0)].map(Number)).toEqual([NaN, Infinity, Infinity]); expect([...lhs.div(1)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.div(2)].map(Number)).toEqual([0, 0.5, 1]); }); test('divides by a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.div(-1n)].map(toBigInt)).toEqual([0n, -1n, -2n]); expect([...lhs.div(0n)].map(toBigInt)).toEqual([4294967295n, 4294967295n, 4294967295n]); expect([...lhs.div(1n)].map(toBigInt)).toEqual([0n, 1n, 2n]); expect([...lhs.div(2n)].map(toBigInt)).toEqual([0n, 0n, 1n]); }); }); describe('Series.trueDiv', () => { test('trueDivides by a Series', () => { const {lhs, rhs} = makeTestData(); // lhs / lhs == [0/0, 1/1, 2/2] expect([...lhs.trueDiv(lhs)].map(Number)).toEqual([-2147483648, 1, 1]); // lhs / rhs == [0/1, 1/2, 2/3] expect([...lhs.trueDiv(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('trueDivides by a number', () => { const {lhs} = makeTestData(); expect([...lhs.trueDiv(-1)].map(Number)).toEqual([-0, -1, -2]); expect([...lhs.trueDiv(0)].map(Number)).toEqual([NaN, Infinity, Infinity]); expect([...lhs.trueDiv(1)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.trueDiv(2)].map(Number)).toEqual([0, 0.5, 1]); }); test('trueDivides by a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.trueDiv(-1n)].map(toBigInt)).toEqual([0n, -1n, -2n]); expect([...lhs.trueDiv(0n)].map(toBigInt)) .toEqual([-9223372036854775808n, 9223372036854775807n, 9223372036854775807n]); expect([...lhs.trueDiv(1n)].map(toBigInt)).toEqual([0n, 1n, 2n]); expect([...lhs.trueDiv(2n)].map(toBigInt)).toEqual([0n, 0n, 1n]); }); }); describe('Series.floorDiv', () => { test('floorDivides by a Series', () => { const {lhs, rhs} = makeTestData(); // lhs / lhs == floor([0/0, 1/1, 2/2]) expect([...lhs.floorDiv(lhs)].map(Number)).toEqual([-2147483648, 1, 1]); // lhs / rhs == floor([0/1, 1/2, 2/3]) expect([...lhs.floorDiv(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('floorDivides by a number', () => { const {lhs} = makeTestData(); expect([...lhs.floorDiv(-1)].map(Number)).toEqual([-0, -1, -2]); expect([...lhs.floorDiv(0)].map(Number)).toEqual([NaN, Infinity, Infinity]); expect([...lhs.floorDiv(1)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.floorDiv(2)].map(Number)).toEqual([0, 0, 1]); }); test('floorDivides by a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.floorDiv(-1n)].map(toBigInt)).toEqual([0n, -1n, -2n]); expect([...lhs.floorDiv(0n)].map(toBigInt)) .toEqual([-9223372036854775808n, 9223372036854775807n, 9223372036854775807n]); expect([...lhs.floorDiv(1n)].map(toBigInt)).toEqual([0n, 1n, 2n]); expect([...lhs.floorDiv(2n)].map(toBigInt)).toEqual([0n, 0n, 1n]); }); }); describe('Series.mod', () => { test('modulo by a Series', () => { const {lhs, rhs} = makeTestData(); // lhs % lhs == [0 % 0, 1 % 1, 2 % 2]) expect([...lhs.mod(lhs)].map(Number)).toEqual([-1, 0, 0]); // lhs % rhs == [0 % 1, 1 % 2, 2 % 3]) expect([...lhs.mod(rhs)].map(Number)).toEqual([0, 1, 2]); }); test('modulo by a number', () => { const {lhs} = makeTestData(); expect([...lhs.mod(-1)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.mod(0)].map(Number)).toEqual([NaN, NaN, NaN]); expect([...lhs.mod(1)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.mod(2)].map(Number)).toEqual([0, 1, 0]); }); test('modulo by a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.mod(-1n)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.mod(0n)].map(Number)).toEqual([4294967295, 4294967295, 4294967295]); expect([...lhs.mod(1n)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.mod(2n)].map(Number)).toEqual([0, 1, 0]); }); }); describe('Series.pow', () => { test('computes to the power of a Series', () => { const {lhs, rhs} = makeTestData(); // lhs ** lhs == [0 ** 0, 1 ** 1, 2 ** 2]) expect([...lhs.pow(lhs)].map(Number)).toEqual([1, 1, 4]); // lhs ** rhs == [0 ** 1, 1 ** 2, 2 ** 3]) expect([...lhs.pow(rhs)].map(Number)).toEqual([0, 1, 8]); }); test('computes to the power of a number', () => { const {lhs} = makeTestData(); expect([...lhs.pow(-1)].map(Number)).toEqual([Infinity, 1, 0.5]); expect([...lhs.pow(0)].map(Number)).toEqual([1, 1, 1]); expect([...lhs.pow(1)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.pow(2)].map(Number)).toEqual([0, 1, 4]); }); test('computes to the power of a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.pow(-1n)].map(Number)).toEqual([9223372036854776000, 1, 0]); expect([...lhs.pow(0n)].map(Number)).toEqual([1, 1, 1]); expect([...lhs.pow(1n)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.pow(2n)].map(Number)).toEqual([0, 1, 4]); }); }); describe('Series.eq', () => { test('compares against Series', () => { const {lhs, rhs} = makeTestData(); // lhs == lhs == true expect([...lhs.eq(lhs)].map(Number)).toEqual([1, 1, 1]); // lhs == rhs == false expect([...lhs.eq(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('compares against numbers', () => { const {lhs} = makeTestData(); expect([...lhs.eq(0)].map(Number)).toEqual([1, 0, 0]); expect([...lhs.eq(1)].map(Number)).toEqual([0, 1, 0]); expect([...lhs.eq(2)].map(Number)).toEqual([0, 0, 1]); }); test('compares against bigints', () => { const {lhs} = makeTestData(); expect([...lhs.eq(0n)].map(toBigInt)).toEqual([1n, 0n, 0n]); expect([...lhs.eq(1n)].map(toBigInt)).toEqual([0n, 1n, 0n]); expect([...lhs.eq(2n)].map(toBigInt)).toEqual([0n, 0n, 1n]); }); }); describe('Series.ne', () => { test('compares against Series', () => { const {lhs, rhs} = makeTestData(); // lhs != rhs == true expect([...lhs.ne(rhs)].map(Number)).toEqual([1, 1, 1]); // lhs != lhs == false expect([...lhs.ne(lhs)].map(Number)).toEqual([0, 0, 0]); }); test('compares against numbers', () => { const {lhs} = makeTestData(); expect([...lhs.ne(0)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.ne(1)].map(Number)).toEqual([1, 0, 1]); expect([...lhs.ne(2)].map(Number)).toEqual([1, 1, 0]); }); test('compares against bigints', () => { const {lhs} = makeTestData(); expect([...lhs.ne(0n)].map(toBigInt)).toEqual([0n, 1n, 1n]); expect([...lhs.ne(1n)].map(toBigInt)).toEqual([1n, 0n, 1n]); expect([...lhs.ne(2n)].map(toBigInt)).toEqual([1n, 1n, 0n]); }); }); describe('Series.lt', () => { test('compares against Series', () => { const {lhs, rhs} = makeTestData(); // lhs < rhs == true expect([...lhs.lt(rhs)].map(Number)).toEqual([1, 1, 1]); // lhs < lhs == false expect([...lhs.lt(lhs)].map(Number)).toEqual([0, 0, 0]); // rhs < lhs == false expect([...rhs.lt(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('compares against numbers', () => { const {lhs} = makeTestData(); expect([...lhs.lt(3)].map(Number)).toEqual([1, 1, 1]); expect([...lhs.lt(2)].map(Number)).toEqual([1, 1, 0]); expect([...lhs.lt(1)].map(Number)).toEqual([1, 0, 0]); expect([...lhs.lt(0)].map(Number)).toEqual([0, 0, 0]); }); test('compares against bigints', () => { const {lhs} = makeTestData(); expect([...lhs.lt(3n)].map(toBigInt)).toEqual([1n, 1n, 1n]); expect([...lhs.lt(2n)].map(toBigInt)).toEqual([1n, 1n, 0n]); expect([...lhs.lt(1n)].map(toBigInt)).toEqual([1n, 0n, 0n]); expect([...lhs.lt(0n)].map(toBigInt)).toEqual([0n, 0n, 0n]); }); }); describe('Series.le', () => { test('compares against Series', () => { const {lhs, rhs} = makeTestData(); // lhs <= lhs == true expect([...lhs.le(lhs)].map(Number)).toEqual([1, 1, 1]); // lhs <= rhs == true expect([...lhs.le(rhs)].map(Number)).toEqual([1, 1, 1]); // rhs <= lhs == false expect([...rhs.le(lhs)].map(Number)).toEqual([0, 0, 0]); }); test('compares against numbers', () => { const {lhs} = makeTestData(); expect([...lhs.le(2)].map(Number)).toEqual([1, 1, 1]); expect([...lhs.le(1)].map(Number)).toEqual([1, 1, 0]); expect([...lhs.le(0)].map(Number)).toEqual([1, 0, 0]); }); test('compares against bigints', () => { const {lhs} = makeTestData(); expect([...lhs.le(2n)].map(toBigInt)).toEqual([1n, 1n, 1n]); expect([...lhs.le(1n)].map(toBigInt)).toEqual([1n, 1n, 0n]); expect([...lhs.le(0n)].map(toBigInt)).toEqual([1n, 0n, 0n]); }); }); describe('Series.gt', () => { test('compares against Series', () => { const {lhs, rhs} = makeTestData(); // rhs > lhs == true expect([...rhs.gt(lhs)].map(Number)).toEqual([1, 1, 1]); // lhs > rhs == false expect([...lhs.gt(rhs)].map(Number)).toEqual([0, 0, 0]); // lhs > lhs == false expect([...lhs.gt(lhs)].map(Number)).toEqual([0, 0, 0]); }); test('compares against numbers', () => { const {lhs} = makeTestData(); expect([...lhs.gt(2)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.gt(1)].map(Number)).toEqual([0, 0, 1]); expect([...lhs.gt(0)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.gt(-1)].map(Number)).toEqual([1, 1, 1]); }); test('compares against bigints', () => { const {lhs} = makeTestData(); expect([...lhs.gt(2n)].map(toBigInt)).toEqual([0n, 0n, 0n]); expect([...lhs.gt(1n)].map(toBigInt)).toEqual([0n, 0n, 1n]); expect([...lhs.gt(0n)].map(toBigInt)).toEqual([0n, 1n, 1n]); expect([...lhs.gt(-1n)].map(toBigInt)).toEqual([1n, 1n, 1n]); }); }); describe('Series.ge', () => { test('compares against Series', () => { const {lhs, rhs} = makeTestData(); // lhs >= lhs == true expect([...lhs.ge(lhs)].map(Number)).toEqual([1, 1, 1]); // lhs >= rhs == false expect([...lhs.ge(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('compares against numbers', () => { const {lhs} = makeTestData(); expect([...lhs.ge(3)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.ge(2)].map(Number)).toEqual([0, 0, 1]); expect([...lhs.ge(1)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.ge(0)].map(Number)).toEqual([1, 1, 1]); }); test('compares against bigints', () => { const {lhs} = makeTestData(); expect([...lhs.ge(3n)].map(toBigInt)).toEqual([0n, 0n, 0n]); expect([...lhs.ge(2n)].map(toBigInt)).toEqual([0n, 0n, 1n]); expect([...lhs.ge(1n)].map(toBigInt)).toEqual([0n, 1n, 1n]); expect([...lhs.ge(0n)].map(toBigInt)).toEqual([1n, 1n, 1n]); }); }); describe('Series.bitwiseAnd', () => { test('bitwiseAnd with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs ** lhs == [0 & 0, 1 & 1, 2 & 2]) expect([...lhs.bitwiseAnd(lhs)].map(Number)).toEqual([0, 1, 2]); // lhs ** rhs == [0 & 1, 1 & 2, 2 & 3]) expect([...lhs.bitwiseAnd(rhs)].map(Number)).toEqual([0, 0, 2]); }); test('bitwiseAnd with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.bitwiseAnd(-1)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.bitwiseAnd(0)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.bitwiseAnd(1)].map(Number)).toEqual([0, 1, 0]); expect([...lhs.bitwiseAnd(2)].map(Number)).toEqual([0, 0, 2]); }); test('bitwiseAnd with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.bitwiseAnd(-1n)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.bitwiseAnd(0n)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.bitwiseAnd(1n)].map(Number)).toEqual([0, 1, 0]); expect([...lhs.bitwiseAnd(2n)].map(Number)).toEqual([0, 0, 2]); }); }); describe('Series.bitwiseOr', () => { test('bitwiseOr with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs | lhs == [0 | 0, 1 | 1, 2 | 2]) expect([...lhs.bitwiseOr(lhs)].map(Number)).toEqual([0, 1, 2]); // lhs | rhs == [0 | 1, 1 | 2, 2 | 3]) expect([...lhs.bitwiseOr(rhs)].map(Number)).toEqual([1, 3, 3]); }); test('bitwiseOr with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.bitwiseOr(-1)].map(Number)).toEqual([-1, -1, -1]); expect([...lhs.bitwiseOr(0)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.bitwiseOr(1)].map(Number)).toEqual([1, 1, 3]); expect([...lhs.bitwiseOr(2)].map(Number)).toEqual([2, 3, 2]); }); test('bitwiseOr with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.bitwiseOr(-1n)].map(Number)).toEqual([-1, -1, -1]); expect([...lhs.bitwiseOr(0n)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.bitwiseOr(1n)].map(Number)).toEqual([1, 1, 3]); expect([...lhs.bitwiseOr(2n)].map(Number)).toEqual([2, 3, 2]); }); }); describe('Series.bitwiseXor', () => { test('bitwiseXor with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs ^ lhs == [0 ^ 0, 1 ^ 1, 2 ^ 2]) expect([...lhs.bitwiseXor(lhs)].map(Number)).toEqual([0, 0, 0]); // lhs ^ rhs == [0 ^ 1, 1 ^ 2, 2 ^ 3]) expect([...lhs.bitwiseXor(rhs)].map(Number)).toEqual([1, 3, 1]); }); test('bitwiseXor with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.bitwiseXor(-1)].map(Number)).toEqual([-1, -2, -3]); expect([...lhs.bitwiseXor(0)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.bitwiseXor(1)].map(Number)).toEqual([1, 0, 3]); expect([...lhs.bitwiseXor(2)].map(Number)).toEqual([2, 3, 0]); }); test('bitwiseXor with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.bitwiseXor(-1n)].map(Number)).toEqual([-1, -2, -3]); expect([...lhs.bitwiseXor(0n)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.bitwiseXor(1n)].map(Number)).toEqual([1, 0, 3]); expect([...lhs.bitwiseXor(2n)].map(Number)).toEqual([2, 3, 0]); }); }); describe('Series.logicalAnd', () => { test('logicalAnd with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs && lhs == [0 && 0, 1 && 1, 2 && 2]) expect([...lhs.logicalAnd(lhs)].map(Number)).toEqual([0, 1, 1]); // lhs && rhs == [0 && 1, 1 && 2, 2 && 3]) expect([...lhs.logicalAnd(rhs)].map(Number)).toEqual([0, 1, 1]); }); test('logicalAnd with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.logicalAnd(-1)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.logicalAnd(0)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.logicalAnd(1)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.logicalAnd(2)].map(Number)).toEqual([0, 1, 1]); }); test('logicalAnd with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.logicalAnd(-1n)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.logicalAnd(0n)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.logicalAnd(1n)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.logicalAnd(2n)].map(Number)).toEqual([0, 1, 1]); }); }); describe('Series.logicalOr', () => { test('logicalOr with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs || lhs == [0 || 0, 1 || 1, 2 || 2]) expect([...lhs.logicalOr(lhs)].map(Number)).toEqual([0, 1, 1]); // lhs || rhs == [0 || 1, 1 || 2, 2 || 3]) expect([...lhs.logicalOr(rhs)].map(Number)).toEqual([1, 1, 1]); }); test('logicalOr with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.logicalOr(-1)].map(Number)).toEqual([1, 1, 1]); expect([...lhs.logicalOr(0)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.logicalOr(1)].map(Number)).toEqual([1, 1, 1]); expect([...lhs.logicalOr(2)].map(Number)).toEqual([1, 1, 1]); }); test('logicalOr with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.logicalOr(-1n)].map(Number)).toEqual([1, 1, 1]); expect([...lhs.logicalOr(0n)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.logicalOr(1n)].map(Number)).toEqual([1, 1, 1]); expect([...lhs.logicalOr(2n)].map(Number)).toEqual([1, 1, 1]); }); }); describe('Series.shiftLeft', () => { test('shiftLeft with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs || lhs == [0 || 0, 1 || 1, 2 || 2]) expect([...lhs.shiftLeft(lhs)].map(Number)).toEqual([0, 2, 8]); // lhs || rhs == [0 || 1, 1 || 2, 2 || 3]) expect([...lhs.shiftLeft(rhs)].map(Number)).toEqual([0, 4, 16]); }); test('shiftLeft with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.shiftLeft(-1)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.shiftLeft(0)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.shiftLeft(1)].map(Number)).toEqual([0, 2, 4]); expect([...lhs.shiftLeft(2)].map(Number)).toEqual([0, 4, 8]); }); test('shiftLeft with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.shiftLeft(-1n)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.shiftLeft(0n)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.shiftLeft(1n)].map(Number)).toEqual([0, 2, 4]); expect([...lhs.shiftLeft(2n)].map(Number)).toEqual([0, 4, 8]); }); }); describe('Series.shiftRight', () => { test('shiftRight with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs || lhs == [0 || 0, 1 || 1, 2 || 2]) expect([...lhs.shiftRight(lhs)].map(Number)).toEqual([0, 0, 0]); // lhs || rhs == [0 || 1, 1 || 2, 2 || 3]) expect([...lhs.shiftRight(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('shiftRight with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.shiftRight(-1)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.shiftRight(0)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.shiftRight(1)].map(Number)).toEqual([0, 0, 1]); expect([...lhs.shiftRight(2)].map(Number)).toEqual([0, 0, 0]); }); test('shiftRight with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.shiftRight(-1n)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.shiftRight(0n)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.shiftRight(1n)].map(Number)).toEqual([0, 0, 1]); expect([...lhs.shiftRight(2n)].map(Number)).toEqual([0, 0, 0]); }); }); describe('Series.shiftRightUnsigned', () => { test('shiftRightUnsigned with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs || lhs == [0 || 0, 1 || 1, 2 || 2]) expect([...lhs.shiftRightUnsigned(lhs)].map(Number)).toEqual([0, 0, 0]); // lhs || rhs == [0 || 1, 1 || 2, 2 || 3]) expect([...lhs.shiftRightUnsigned(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('shiftRightUnsigned with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.shiftRightUnsigned(-1)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.shiftRightUnsigned(0)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.shiftRightUnsigned(1)].map(Number)).toEqual([0, 0, 1]); expect([...lhs.shiftRightUnsigned(2)].map(Number)).toEqual([0, 0, 0]); }); test('shiftRightUnsigned with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.shiftRightUnsigned(-1n)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.shiftRightUnsigned(0n)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.shiftRightUnsigned(1n)].map(Number)).toEqual([0, 0, 1]); expect([...lhs.shiftRightUnsigned(2n)].map(Number)).toEqual([0, 0, 0]); }); }); describe('Series.logBase', () => { test('logBase with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs || lhs == [0 || 0, 1 || 1, 2 || 2]) expect([...lhs.logBase(lhs)].map(Number)).toEqual([-2147483648, -2147483648, 1]); // lhs || rhs == [0 || 1, 1 || 2, 2 || 3]) expect([...lhs.logBase(rhs)].map(Number)).toEqual([-2147483648, 0, 0]); }); test('logBase with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.logBase(-1)].map(Number)).toEqual([NaN, NaN, NaN]); expect([...lhs.logBase(0)].map(Number)).toEqual([NaN, -0, -0]); expect([...lhs.logBase(1)].map(Number)).toEqual([-Infinity, NaN, Infinity]); expect([...lhs.logBase(2)].map(Number)).toEqual([-Infinity, 0, 1]); }); test('logBase with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.logBase(-1n)].map(Number)) .toEqual([-9223372036854776000, -9223372036854776000, -9223372036854776000]); expect([...lhs.logBase(0n)].map(Number)).toEqual([-9223372036854776000, 0, 0]); expect([...lhs.logBase(1n)].map(Number)) .toEqual([-9223372036854776000, -9223372036854776000, 9223372036854776000]); expect([...lhs.logBase(2n)].map(Number)).toEqual([-9223372036854776000, 0, 1]); }); }); describe('Series.atan2', () => { test('atan2 with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs || lhs == [0 || 0, 1 || 1, 2 || 2]) expect([...lhs.atan2(lhs)].map(Number)).toEqual([0, 0, 0]); // lhs || rhs == [0 || 1, 1 || 2, 2 || 3]) expect([...lhs.atan2(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('atan2 with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.atan2(-1)].map(Number)) .toEqual([3.141592653589793, 2.356194490192345, 2.0344439357957027]); expect([...lhs.atan2(0)].map(Number)).toEqual([0, 1.5707963267948966, 1.5707963267948966]); expect([...lhs.atan2(1)].map(Number)).toEqual([0, 0.7853981633974483, 1.1071487177940904]); expect([...lhs.atan2(2)].map(Number)).toEqual([0, 0.46364760900080615, 0.7853981633974483]); }); test('atan2 with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.atan2(-1n)].map(Number)).toEqual([3, 2, 2]); expect([...lhs.atan2(0n)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.atan2(1n)].map(Number)).toEqual([0, 0, 1]); expect([...lhs.atan2(2n)].map(Number)).toEqual([0, 0, 0]); }); }); describe('Series.nullEquals', () => { test('nullEquals with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs || lhs == [0 || 0, 1 || 1, 2 || 2]) expect([...lhs.nullEquals(lhs)].map(Number)).toEqual([1, 1, 1]); // lhs || rhs == [0 || 1, 1 || 2, 2 || 3]) expect([...lhs.nullEquals(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('nullEquals with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.nullEquals(-1)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.nullEquals(0)].map(Number)).toEqual([1, 0, 0]); expect([...lhs.nullEquals(1)].map(Number)).toEqual([0, 1, 0]); expect([...lhs.nullEquals(2)].map(Number)).toEqual([0, 0, 1]); }); test('nullEquals with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.nullEquals(-1n)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.nullEquals(0n)].map(Number)).toEqual([1, 0, 0]); expect([...lhs.nullEquals(1n)].map(Number)).toEqual([0, 1, 0]); expect([...lhs.nullEquals(2n)].map(Number)).toEqual([0, 0, 1]); }); }); describe('Series.nullMax', () => { test('nullMax with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs || lhs == [0 || 0, 1 || 1, 2 || 2]) expect([...lhs.nullMax(lhs)].map(Number)).toEqual([0, 1, 2]); // lhs || rhs == [0 || 1, 1 || 2, 2 || 3]) expect([...lhs.nullMax(rhs)].map(Number)).toEqual([1, 2, 3]); }); test('nullMax with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.nullMax(-1)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.nullMax(0)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.nullMax(1)].map(Number)).toEqual([1, 1, 2]); expect([...lhs.nullMax(2)].map(Number)).toEqual([2, 2, 2]); }); test('nullMax with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.nullMax(-1n)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.nullMax(0n)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.nullMax(1n)].map(Number)).toEqual([1, 1, 2]); expect([...lhs.nullMax(2n)].map(Number)).toEqual([2, 2, 2]); }); }); describe('Series.nullMin', () => { test('nullMin with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs || lhs == [0 || 0, 1 || 1, 2 || 2]) expect([...lhs.nullMin(lhs)].map(Number)).toEqual([0, 1, 2]); // lhs || rhs == [0 || 1, 1 || 2, 2 || 3]) expect([...lhs.nullMin(rhs)].map(Number)).toEqual([0, 1, 2]); }); test('nullMin with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.nullMin(-1)].map(Number)).toEqual([-1, -1, -1]); expect([...lhs.nullMin(0)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.nullMin(1)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.nullMin(2)].map(Number)).toEqual([0, 1, 2]); }); test('nullMin with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.nullMin(-1n)].map(Number)).toEqual([-1, -1, -1]); expect([...lhs.nullMin(0n)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.nullMin(1n)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.nullMin(2n)].map(Number)).toEqual([0, 1, 2]); }); }); });
0
rapidsai_public_repos/node/modules/cudf/test/series
rapidsai_public_repos/node/modules/cudf/test/series/binaryop/int8-tests.ts
// Copyright (c) 2021, NVIDIA CORPORATION. // // 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. import {setDefaultAllocator} from '@rapidsai/cuda'; import {DeviceBuffer} from '@rapidsai/rmm'; import * as arrow from 'apache-arrow'; import {makeTestNumbers, makeTestSeries, toBigInt} from '../utils'; setDefaultAllocator((byteLength: number) => new DeviceBuffer(byteLength)); const makeTestData = (values?: (number|null)[]) => makeTestSeries(new arrow.Int8, makeTestNumbers(values)); describe('Series binaryops (Int8)', () => { describe('Series.add', () => { test('adds a Series', () => { const {lhs, rhs} = makeTestData(); // lhs + lhs == [0 + 0, 1 + 1, 2 + 2] expect([...lhs.add(lhs)].map(Number)).toEqual([0, 2, 4]); // lhs + rhs == [0 + 1, 1 + 2, 2 + 3] expect([...lhs.add(rhs)].map(Number)).toEqual([1, 3, 5]); }); test('adds a number', () => { const {lhs} = makeTestData(); expect([...lhs.add(-1)].map(Number)).toEqual([-1, 0, 1]); expect([...lhs.add(0)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.add(1)].map(Number)).toEqual([1, 2, 3]); expect([...lhs.add(2)].map(Number)).toEqual([2, 3, 4]); }); test('adds a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.add(-1n)].map(toBigInt)).toEqual([-1n, 0n, 1n]); expect([...lhs.add(0n)].map(toBigInt)).toEqual([0n, 1n, 2n]); expect([...lhs.add(1n)].map(toBigInt)).toEqual([1n, 2n, 3n]); expect([...lhs.add(2n)].map(toBigInt)).toEqual([2n, 3n, 4n]); }); }); describe('Series.sub', () => { test('subtracts a Series', () => { const {lhs, rhs} = makeTestData(); // lhs - lhs == [0 - 0, 1 - 1, 2 - 2] expect([...lhs.sub(lhs)].map(Number)).toEqual([0, 0, 0]); // lhs - rhs == [0 - 1, 1 - 2, 2 - 3] expect([...lhs.sub(rhs)].map(Number)).toEqual([-1, -1, -1]); // rhs - lhs == [1 - 0, 2 - 1, 3 - 2] expect([...rhs.sub(lhs)].map(Number)).toEqual([1, 1, 1]); }); test('subtracts a number', () => { const {lhs} = makeTestData(); expect([...lhs.sub(-1)].map(Number)).toEqual([1, 2, 3]); expect([...lhs.sub(0)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.sub(1)].map(Number)).toEqual([-1, 0, 1]); expect([...lhs.sub(2)].map(Number)).toEqual([-2, -1, 0]); }); test('subtracts a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.sub(-1n)].map(toBigInt)).toEqual([1n, 2n, 3n]); expect([...lhs.sub(0n)].map(toBigInt)).toEqual([0n, 1n, 2n]); expect([...lhs.sub(1n)].map(toBigInt)).toEqual([-1n, 0n, 1n]); expect([...lhs.sub(2n)].map(toBigInt)).toEqual([-2n, -1n, 0n]); }); }); describe('Series.mul', () => { test('multiplies against a Series', () => { const {lhs, rhs} = makeTestData(); // lhs * lhs == [0 * 0, 1 * 1, 2 * 2] expect([...lhs.mul(lhs)].map(Number)).toEqual([0, 1, 4]); // lhs * rhs == [0 * 1, 1 * 2, 2 * 3] expect([...lhs.mul(rhs)].map(Number)).toEqual([0, 2, 6]); }); test('multiplies against a number', () => { const {lhs} = makeTestData(); expect([...lhs.mul(-1)].map(Number)).toEqual([-0, -1, -2]); expect([...lhs.mul(0)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.mul(1)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.mul(2)].map(Number)).toEqual([0, 2, 4]); }); test('multiplies against a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.mul(-1n)].map(toBigInt)).toEqual([0n, -1n, -2n]); expect([...lhs.mul(0n)].map(toBigInt)).toEqual([0n, 0n, 0n]); expect([...lhs.mul(1n)].map(toBigInt)).toEqual([0n, 1n, 2n]); expect([...lhs.mul(2n)].map(toBigInt)).toEqual([0n, 2n, 4n]); }); }); describe('Series.div', () => { test('divides by a Series', () => { const {lhs, rhs} = makeTestData(); // lhs / lhs == [0/0, 1/1, 2/2] expect([...lhs.div(lhs)].map(Number)).toEqual([-1, 1, 1]); // lhs / rhs == [0/1, 1/2, 2/3] expect([...lhs.div(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('divides by a number', () => { const {lhs} = makeTestData(); expect([...lhs.div(-1)].map(Number)).toEqual([-0, -1, -2]); expect([...lhs.div(0)].map(Number)).toEqual([NaN, Infinity, Infinity]); expect([...lhs.div(1)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.div(2)].map(Number)).toEqual([0, 0.5, 1]); }); test('divides by a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.div(-1n)].map(toBigInt)).toEqual([0n, -1n, -2n]); expect([...lhs.div(0n)].map(toBigInt)).toEqual([4294967295n, 4294967295n, 4294967295n]); expect([...lhs.div(1n)].map(toBigInt)).toEqual([0n, 1n, 2n]); expect([...lhs.div(2n)].map(toBigInt)).toEqual([0n, 0n, 1n]); }); }); describe('Series.trueDiv', () => { test('trueDivides by a Series', () => { const {lhs, rhs} = makeTestData(); // lhs / lhs == [0/0, 1/1, 2/2] expect([...lhs.trueDiv(lhs)].map(Number)).toEqual([0, 1, 1]); // lhs / rhs == [0/1, 1/2, 2/3] expect([...lhs.trueDiv(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('trueDivides by a number', () => { const {lhs} = makeTestData(); expect([...lhs.trueDiv(-1)].map(Number)).toEqual([-0, -1, -2]); expect([...lhs.trueDiv(0)].map(Number)).toEqual([NaN, Infinity, Infinity]); expect([...lhs.trueDiv(1)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.trueDiv(2)].map(Number)).toEqual([0, 0.5, 1]); }); test('trueDivides by a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.trueDiv(-1n)].map(toBigInt)).toEqual([0n, -1n, -2n]); expect([...lhs.trueDiv(0n)].map(toBigInt)) .toEqual([-9223372036854775808n, 9223372036854775807n, 9223372036854775807n]); expect([...lhs.trueDiv(1n)].map(toBigInt)).toEqual([0n, 1n, 2n]); expect([...lhs.trueDiv(2n)].map(toBigInt)).toEqual([0n, 0n, 1n]); }); }); describe('Series.floorDiv', () => { test('floorDivides by a Series', () => { const {lhs, rhs} = makeTestData(); // lhs / lhs == floor([0/0, 1/1, 2/2]) expect([...lhs.floorDiv(lhs)].map(Number)).toEqual([0, 1, 1]); // lhs / rhs == floor([0/1, 1/2, 2/3]) expect([...lhs.floorDiv(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('floorDivides by a number', () => { const {lhs} = makeTestData(); expect([...lhs.floorDiv(-1)].map(Number)).toEqual([-0, -1, -2]); expect([...lhs.floorDiv(0)].map(Number)).toEqual([NaN, Infinity, Infinity]); expect([...lhs.floorDiv(1)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.floorDiv(2)].map(Number)).toEqual([0, 0, 1]); }); test('floorDivides by a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.floorDiv(-1n)].map(toBigInt)).toEqual([0n, -1n, -2n]); expect([...lhs.floorDiv(0n)].map(toBigInt)) .toEqual([-9223372036854775808n, 9223372036854775807n, 9223372036854775807n]); expect([...lhs.floorDiv(1n)].map(toBigInt)).toEqual([0n, 1n, 2n]); expect([...lhs.floorDiv(2n)].map(toBigInt)).toEqual([0n, 0n, 1n]); }); }); describe('Series.mod', () => { test('modulo by a Series', () => { const {lhs, rhs} = makeTestData(); // lhs % lhs == [0 % 0, 1 % 1, 2 % 2]) expect([...lhs.mod(lhs)].map(Number)).toEqual([-1, 0, 0]); // lhs % rhs == [0 % 1, 1 % 2, 2 % 3]) expect([...lhs.mod(rhs)].map(Number)).toEqual([0, 1, 2]); }); test('modulo by a number', () => { const {lhs} = makeTestData(); expect([...lhs.mod(-1)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.mod(0)].map(Number)).toEqual([NaN, NaN, NaN]); expect([...lhs.mod(1)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.mod(2)].map(Number)).toEqual([0, 1, 0]); }); test('modulo by a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.mod(-1n)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.mod(0n)].map(Number)).toEqual([4294967295, 4294967295, 4294967295]); expect([...lhs.mod(1n)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.mod(2n)].map(Number)).toEqual([0, 1, 0]); }); }); describe('Series.pow', () => { test('computes to the power of a Series', () => { const {lhs, rhs} = makeTestData(); // lhs ** lhs == [0 ** 0, 1 ** 1, 2 ** 2]) expect([...lhs.pow(lhs)].map(Number)).toEqual([1, 1, 4]); // lhs ** rhs == [0 ** 1, 1 ** 2, 2 ** 3]) expect([...lhs.pow(rhs)].map(Number)).toEqual([0, 1, 8]); }); test('computes to the power of a number', () => { const {lhs} = makeTestData(); expect([...lhs.pow(-1)].map(Number)).toEqual([Infinity, 1, 0.5]); expect([...lhs.pow(0)].map(Number)).toEqual([1, 1, 1]); expect([...lhs.pow(1)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.pow(2)].map(Number)).toEqual([0, 1, 4]); }); test('computes to the power of a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.pow(-1n)].map(Number)).toEqual([9223372036854776000, 1, 0]); expect([...lhs.pow(0n)].map(Number)).toEqual([1, 1, 1]); expect([...lhs.pow(1n)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.pow(2n)].map(Number)).toEqual([0, 1, 4]); }); }); describe('Series.eq', () => { test('compares against Series', () => { const {lhs, rhs} = makeTestData(); // lhs == lhs == true expect([...lhs.eq(lhs)].map(Number)).toEqual([1, 1, 1]); // lhs == rhs == false expect([...lhs.eq(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('compares against numbers', () => { const {lhs} = makeTestData(); expect([...lhs.eq(0)].map(Number)).toEqual([1, 0, 0]); expect([...lhs.eq(1)].map(Number)).toEqual([0, 1, 0]); expect([...lhs.eq(2)].map(Number)).toEqual([0, 0, 1]); }); test('compares against bigints', () => { const {lhs} = makeTestData(); expect([...lhs.eq(0n)].map(toBigInt)).toEqual([1n, 0n, 0n]); expect([...lhs.eq(1n)].map(toBigInt)).toEqual([0n, 1n, 0n]); expect([...lhs.eq(2n)].map(toBigInt)).toEqual([0n, 0n, 1n]); }); }); describe('Series.ne', () => { test('compares against Series', () => { const {lhs, rhs} = makeTestData(); // lhs != rhs == true expect([...lhs.ne(rhs)].map(Number)).toEqual([1, 1, 1]); // lhs != lhs == false expect([...lhs.ne(lhs)].map(Number)).toEqual([0, 0, 0]); }); test('compares against numbers', () => { const {lhs} = makeTestData(); expect([...lhs.ne(0)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.ne(1)].map(Number)).toEqual([1, 0, 1]); expect([...lhs.ne(2)].map(Number)).toEqual([1, 1, 0]); }); test('compares against bigints', () => { const {lhs} = makeTestData(); expect([...lhs.ne(0n)].map(toBigInt)).toEqual([0n, 1n, 1n]); expect([...lhs.ne(1n)].map(toBigInt)).toEqual([1n, 0n, 1n]); expect([...lhs.ne(2n)].map(toBigInt)).toEqual([1n, 1n, 0n]); }); }); describe('Series.lt', () => { test('compares against Series', () => { const {lhs, rhs} = makeTestData(); // lhs < rhs == true expect([...lhs.lt(rhs)].map(Number)).toEqual([1, 1, 1]); // lhs < lhs == false expect([...lhs.lt(lhs)].map(Number)).toEqual([0, 0, 0]); // rhs < lhs == false expect([...rhs.lt(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('compares against numbers', () => { const {lhs} = makeTestData(); expect([...lhs.lt(3)].map(Number)).toEqual([1, 1, 1]); expect([...lhs.lt(2)].map(Number)).toEqual([1, 1, 0]); expect([...lhs.lt(1)].map(Number)).toEqual([1, 0, 0]); expect([...lhs.lt(0)].map(Number)).toEqual([0, 0, 0]); }); test('compares against bigints', () => { const {lhs} = makeTestData(); expect([...lhs.lt(3n)].map(toBigInt)).toEqual([1n, 1n, 1n]); expect([...lhs.lt(2n)].map(toBigInt)).toEqual([1n, 1n, 0n]); expect([...lhs.lt(1n)].map(toBigInt)).toEqual([1n, 0n, 0n]); expect([...lhs.lt(0n)].map(toBigInt)).toEqual([0n, 0n, 0n]); }); }); describe('Series.le', () => { test('compares against Series', () => { const {lhs, rhs} = makeTestData(); // lhs <= lhs == true expect([...lhs.le(lhs)].map(Number)).toEqual([1, 1, 1]); // lhs <= rhs == true expect([...lhs.le(rhs)].map(Number)).toEqual([1, 1, 1]); // rhs <= lhs == false expect([...rhs.le(lhs)].map(Number)).toEqual([0, 0, 0]); }); test('compares against numbers', () => { const {lhs} = makeTestData(); expect([...lhs.le(2)].map(Number)).toEqual([1, 1, 1]); expect([...lhs.le(1)].map(Number)).toEqual([1, 1, 0]); expect([...lhs.le(0)].map(Number)).toEqual([1, 0, 0]); }); test('compares against bigints', () => { const {lhs} = makeTestData(); expect([...lhs.le(2n)].map(toBigInt)).toEqual([1n, 1n, 1n]); expect([...lhs.le(1n)].map(toBigInt)).toEqual([1n, 1n, 0n]); expect([...lhs.le(0n)].map(toBigInt)).toEqual([1n, 0n, 0n]); }); }); describe('Series.gt', () => { test('compares against Series', () => { const {lhs, rhs} = makeTestData(); // rhs > lhs == true expect([...rhs.gt(lhs)].map(Number)).toEqual([1, 1, 1]); // lhs > rhs == false expect([...lhs.gt(rhs)].map(Number)).toEqual([0, 0, 0]); // lhs > lhs == false expect([...lhs.gt(lhs)].map(Number)).toEqual([0, 0, 0]); }); test('compares against numbers', () => { const {lhs} = makeTestData(); expect([...lhs.gt(2)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.gt(1)].map(Number)).toEqual([0, 0, 1]); expect([...lhs.gt(0)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.gt(-1)].map(Number)).toEqual([1, 1, 1]); }); test('compares against bigints', () => { const {lhs} = makeTestData(); expect([...lhs.gt(2n)].map(toBigInt)).toEqual([0n, 0n, 0n]); expect([...lhs.gt(1n)].map(toBigInt)).toEqual([0n, 0n, 1n]); expect([...lhs.gt(0n)].map(toBigInt)).toEqual([0n, 1n, 1n]); expect([...lhs.gt(-1n)].map(toBigInt)).toEqual([1n, 1n, 1n]); }); }); describe('Series.ge', () => { test('compares against Series', () => { const {lhs, rhs} = makeTestData(); // lhs >= lhs == true expect([...lhs.ge(lhs)].map(Number)).toEqual([1, 1, 1]); // lhs >= rhs == false expect([...lhs.ge(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('compares against numbers', () => { const {lhs} = makeTestData(); expect([...lhs.ge(3)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.ge(2)].map(Number)).toEqual([0, 0, 1]); expect([...lhs.ge(1)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.ge(0)].map(Number)).toEqual([1, 1, 1]); }); test('compares against bigints', () => { const {lhs} = makeTestData(); expect([...lhs.ge(3n)].map(toBigInt)).toEqual([0n, 0n, 0n]); expect([...lhs.ge(2n)].map(toBigInt)).toEqual([0n, 0n, 1n]); expect([...lhs.ge(1n)].map(toBigInt)).toEqual([0n, 1n, 1n]); expect([...lhs.ge(0n)].map(toBigInt)).toEqual([1n, 1n, 1n]); }); }); describe('Series.bitwiseAnd', () => { test('bitwiseAnd with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs ** lhs == [0 & 0, 1 & 1, 2 & 2]) expect([...lhs.bitwiseAnd(lhs)].map(Number)).toEqual([0, 1, 2]); // lhs ** rhs == [0 & 1, 1 & 2, 2 & 3]) expect([...lhs.bitwiseAnd(rhs)].map(Number)).toEqual([0, 0, 2]); }); test('bitwiseAnd with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.bitwiseAnd(-1)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.bitwiseAnd(0)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.bitwiseAnd(1)].map(Number)).toEqual([0, 1, 0]); expect([...lhs.bitwiseAnd(2)].map(Number)).toEqual([0, 0, 2]); }); test('bitwiseAnd with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.bitwiseAnd(-1n)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.bitwiseAnd(0n)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.bitwiseAnd(1n)].map(Number)).toEqual([0, 1, 0]); expect([...lhs.bitwiseAnd(2n)].map(Number)).toEqual([0, 0, 2]); }); }); describe('Series.bitwiseOr', () => { test('bitwiseOr with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs | lhs == [0 | 0, 1 | 1, 2 | 2]) expect([...lhs.bitwiseOr(lhs)].map(Number)).toEqual([0, 1, 2]); // lhs | rhs == [0 | 1, 1 | 2, 2 | 3]) expect([...lhs.bitwiseOr(rhs)].map(Number)).toEqual([1, 3, 3]); }); test('bitwiseOr with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.bitwiseOr(-1)].map(Number)).toEqual([-1, -1, -1]); expect([...lhs.bitwiseOr(0)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.bitwiseOr(1)].map(Number)).toEqual([1, 1, 3]); expect([...lhs.bitwiseOr(2)].map(Number)).toEqual([2, 3, 2]); }); test('bitwiseOr with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.bitwiseOr(-1n)].map(Number)).toEqual([-1, -1, -1]); expect([...lhs.bitwiseOr(0n)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.bitwiseOr(1n)].map(Number)).toEqual([1, 1, 3]); expect([...lhs.bitwiseOr(2n)].map(Number)).toEqual([2, 3, 2]); }); }); describe('Series.bitwiseXor', () => { test('bitwiseXor with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs ^ lhs == [0 ^ 0, 1 ^ 1, 2 ^ 2]) expect([...lhs.bitwiseXor(lhs)].map(Number)).toEqual([0, 0, 0]); // lhs ^ rhs == [0 ^ 1, 1 ^ 2, 2 ^ 3]) expect([...lhs.bitwiseXor(rhs)].map(Number)).toEqual([1, 3, 1]); }); test('bitwiseXor with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.bitwiseXor(-1)].map(Number)).toEqual([-1, -2, -3]); expect([...lhs.bitwiseXor(0)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.bitwiseXor(1)].map(Number)).toEqual([1, 0, 3]); expect([...lhs.bitwiseXor(2)].map(Number)).toEqual([2, 3, 0]); }); test('bitwiseXor with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.bitwiseXor(-1n)].map(Number)).toEqual([-1, -2, -3]); expect([...lhs.bitwiseXor(0n)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.bitwiseXor(1n)].map(Number)).toEqual([1, 0, 3]); expect([...lhs.bitwiseXor(2n)].map(Number)).toEqual([2, 3, 0]); }); }); describe('Series.logicalAnd', () => { test('logicalAnd with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs && lhs == [0 && 0, 1 && 1, 2 && 2]) expect([...lhs.logicalAnd(lhs)].map(Number)).toEqual([0, 1, 1]); // lhs && rhs == [0 && 1, 1 && 2, 2 && 3]) expect([...lhs.logicalAnd(rhs)].map(Number)).toEqual([0, 1, 1]); }); test('logicalAnd with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.logicalAnd(-1)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.logicalAnd(0)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.logicalAnd(1)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.logicalAnd(2)].map(Number)).toEqual([0, 1, 1]); }); test('logicalAnd with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.logicalAnd(-1n)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.logicalAnd(0n)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.logicalAnd(1n)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.logicalAnd(2n)].map(Number)).toEqual([0, 1, 1]); }); }); describe('Series.logicalOr', () => { test('logicalOr with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs || lhs == [0 || 0, 1 || 1, 2 || 2]) expect([...lhs.logicalOr(lhs)].map(Number)).toEqual([0, 1, 1]); // lhs || rhs == [0 || 1, 1 || 2, 2 || 3]) expect([...lhs.logicalOr(rhs)].map(Number)).toEqual([1, 1, 1]); }); test('logicalOr with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.logicalOr(-1)].map(Number)).toEqual([1, 1, 1]); expect([...lhs.logicalOr(0)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.logicalOr(1)].map(Number)).toEqual([1, 1, 1]); expect([...lhs.logicalOr(2)].map(Number)).toEqual([1, 1, 1]); }); test('logicalOr with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.logicalOr(-1n)].map(Number)).toEqual([1, 1, 1]); expect([...lhs.logicalOr(0n)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.logicalOr(1n)].map(Number)).toEqual([1, 1, 1]); expect([...lhs.logicalOr(2n)].map(Number)).toEqual([1, 1, 1]); }); }); describe('Series.shiftLeft', () => { test('shiftLeft with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs || lhs == [0 || 0, 1 || 1, 2 || 2]) expect([...lhs.shiftLeft(lhs)].map(Number)).toEqual([0, 2, 8]); // lhs || rhs == [0 || 1, 1 || 2, 2 || 3]) expect([...lhs.shiftLeft(rhs)].map(Number)).toEqual([0, 4, 16]); }); test('shiftLeft with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.shiftLeft(-1)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.shiftLeft(0)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.shiftLeft(1)].map(Number)).toEqual([0, 2, 4]); expect([...lhs.shiftLeft(2)].map(Number)).toEqual([0, 4, 8]); }); test('shiftLeft with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.shiftLeft(-1n)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.shiftLeft(0n)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.shiftLeft(1n)].map(Number)).toEqual([0, 2, 4]); expect([...lhs.shiftLeft(2n)].map(Number)).toEqual([0, 4, 8]); }); }); describe('Series.shiftRight', () => { test('shiftRight with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs || lhs == [0 || 0, 1 || 1, 2 || 2]) expect([...lhs.shiftRight(lhs)].map(Number)).toEqual([0, 0, 0]); // lhs || rhs == [0 || 1, 1 || 2, 2 || 3]) expect([...lhs.shiftRight(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('shiftRight with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.shiftRight(-1)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.shiftRight(0)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.shiftRight(1)].map(Number)).toEqual([0, 0, 1]); expect([...lhs.shiftRight(2)].map(Number)).toEqual([0, 0, 0]); }); }); describe('Series.shiftRightUnsigned', () => { test('shiftRightUnsigned with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs || lhs == [0 || 0, 1 || 1, 2 || 2]) expect([...lhs.shiftRightUnsigned(lhs)].map(Number)).toEqual([0, 0, 0]); // lhs || rhs == [0 || 1, 1 || 2, 2 || 3]) expect([...lhs.shiftRightUnsigned(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('shiftRightUnsigned with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.shiftRightUnsigned(-1)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.shiftRightUnsigned(0)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.shiftRightUnsigned(1)].map(Number)).toEqual([0, 0, 1]); expect([...lhs.shiftRightUnsigned(2)].map(Number)).toEqual([0, 0, 0]); }); test('shiftRightUnsigned with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.shiftRightUnsigned(-1n)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.shiftRightUnsigned(0n)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.shiftRightUnsigned(1n)].map(Number)).toEqual([0, 0, 1]); expect([...lhs.shiftRightUnsigned(2n)].map(Number)).toEqual([0, 0, 0]); }); }); describe('Series.logBase', () => { test('logBase with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs || lhs == [0 || 0, 1 || 1, 2 || 2]) expect([...lhs.logBase(lhs)].map(Number)).toEqual([0, 0, 1]); // lhs || rhs == [0 || 1, 1 || 2, 2 || 3]) expect([...lhs.logBase(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('logBase with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.logBase(-1)].map(Number)).toEqual([NaN, NaN, NaN]); expect([...lhs.logBase(0)].map(Number)).toEqual([NaN, -0, -0]); expect([...lhs.logBase(1)].map(Number)).toEqual([-Infinity, NaN, Infinity]); expect([...lhs.logBase(2)].map(Number)).toEqual([-Infinity, 0, 1]); }); test('logBase with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.logBase(-1n)].map(Number)) .toEqual([-9223372036854776000, -9223372036854776000, -9223372036854776000]); expect([...lhs.logBase(0n)].map(Number)).toEqual([-9223372036854776000, 0, 0]); expect([...lhs.logBase(1n)].map(Number)) .toEqual([-9223372036854776000, -9223372036854776000, 9223372036854776000]); expect([...lhs.logBase(2n)].map(Number)).toEqual([-9223372036854776000, 0, 1]); }); }); describe('Series.atan2', () => { test('atan2 with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs || lhs == [0 || 0, 1 || 1, 2 || 2]) expect([...lhs.atan2(lhs)].map(Number)).toEqual([0, 0, 0]); // lhs || rhs == [0 || 1, 1 || 2, 2 || 3]) expect([...lhs.atan2(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('atan2 with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.atan2(-1)].map(Number)) .toEqual([3.141592653589793, 2.356194490192345, 2.0344439357957027]); expect([...lhs.atan2(0)].map(Number)).toEqual([0, 1.5707963267948966, 1.5707963267948966]); expect([...lhs.atan2(1)].map(Number)).toEqual([0, 0.7853981633974483, 1.1071487177940904]); expect([...lhs.atan2(2)].map(Number)).toEqual([0, 0.46364760900080615, 0.7853981633974483]); }); test('atan2 with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.atan2(-1n)].map(Number)).toEqual([3, 2, 2]); expect([...lhs.atan2(0n)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.atan2(1n)].map(Number)).toEqual([0, 0, 1]); expect([...lhs.atan2(2n)].map(Number)).toEqual([0, 0, 0]); }); }); describe('Series.nullEquals', () => { test('nullEquals with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs || lhs == [0 || 0, 1 || 1, 2 || 2]) expect([...lhs.nullEquals(lhs)].map(Number)).toEqual([1, 1, 1]); // lhs || rhs == [0 || 1, 1 || 2, 2 || 3]) expect([...lhs.nullEquals(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('nullEquals with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.nullEquals(-1)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.nullEquals(0)].map(Number)).toEqual([1, 0, 0]); expect([...lhs.nullEquals(1)].map(Number)).toEqual([0, 1, 0]); expect([...lhs.nullEquals(2)].map(Number)).toEqual([0, 0, 1]); }); test('nullEquals with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.nullEquals(-1n)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.nullEquals(0n)].map(Number)).toEqual([1, 0, 0]); expect([...lhs.nullEquals(1n)].map(Number)).toEqual([0, 1, 0]); expect([...lhs.nullEquals(2n)].map(Number)).toEqual([0, 0, 1]); }); }); describe('Series.nullMax', () => { test('nullMax with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs || lhs == [0 || 0, 1 || 1, 2 || 2]) expect([...lhs.nullMax(lhs)].map(Number)).toEqual([0, 1, 2]); // lhs || rhs == [0 || 1, 1 || 2, 2 || 3]) expect([...lhs.nullMax(rhs)].map(Number)).toEqual([1, 2, 3]); }); test('nullMax with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.nullMax(-1)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.nullMax(0)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.nullMax(1)].map(Number)).toEqual([1, 1, 2]); expect([...lhs.nullMax(2)].map(Number)).toEqual([2, 2, 2]); }); test('nullMax with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.nullMax(-1n)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.nullMax(0n)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.nullMax(1n)].map(Number)).toEqual([1, 1, 2]); expect([...lhs.nullMax(2n)].map(Number)).toEqual([2, 2, 2]); }); }); describe('Series.nullMin', () => { test('nullMin with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs || lhs == [0 || 0, 1 || 1, 2 || 2]) expect([...lhs.nullMin(lhs)].map(Number)).toEqual([0, 1, 2]); // lhs || rhs == [0 || 1, 1 || 2, 2 || 3]) expect([...lhs.nullMin(rhs)].map(Number)).toEqual([0, 1, 2]); }); test('nullMin with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.nullMin(-1)].map(Number)).toEqual([-1, -1, -1]); expect([...lhs.nullMin(0)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.nullMin(1)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.nullMin(2)].map(Number)).toEqual([0, 1, 2]); }); test('nullMin with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.nullMin(-1n)].map(Number)).toEqual([-1, -1, -1]); expect([...lhs.nullMin(0n)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.nullMin(1n)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.nullMin(2n)].map(Number)).toEqual([0, 1, 2]); }); }); });
0
rapidsai_public_repos/node/modules/cudf/test/series
rapidsai_public_repos/node/modules/cudf/test/series/binaryop/uint8-tests.ts
// Copyright (c) 2021, NVIDIA CORPORATION. // // 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. import {setDefaultAllocator} from '@rapidsai/cuda'; import {DeviceBuffer} from '@rapidsai/rmm'; import * as arrow from 'apache-arrow'; import {makeTestNumbers, makeTestSeries, toBigInt} from '../utils'; setDefaultAllocator((byteLength: number) => new DeviceBuffer(byteLength)); const makeTestData = (values?: (number|null)[]) => makeTestSeries(new arrow.Uint8, makeTestNumbers(values)); describe('Series binaryops (Uint8)', () => { describe('Series.add', () => { test('adds a Series', () => { const {lhs, rhs} = makeTestData(); // lhs + lhs == [0 + 0, 1 + 1, 2 + 2] expect([...lhs.add(lhs)].map(Number)).toEqual([0, 2, 4]); // lhs + rhs == [0 + 1, 1 + 2, 2 + 3] expect([...lhs.add(rhs)].map(Number)).toEqual([1, 3, 5]); }); test('adds a number', () => { const {lhs} = makeTestData(); expect([...lhs.add(-1)].map(Number)).toEqual([-1, 0, 1]); expect([...lhs.add(0)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.add(1)].map(Number)).toEqual([1, 2, 3]); expect([...lhs.add(2)].map(Number)).toEqual([2, 3, 4]); }); test('adds a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.add(-1n)].map(toBigInt)).toEqual([-1n, 0n, 1n]); expect([...lhs.add(0n)].map(toBigInt)).toEqual([0n, 1n, 2n]); expect([...lhs.add(1n)].map(toBigInt)).toEqual([1n, 2n, 3n]); expect([...lhs.add(2n)].map(toBigInt)).toEqual([2n, 3n, 4n]); }); }); describe('Series.sub', () => { test('subtracts a Series', () => { const {lhs, rhs} = makeTestData(); // lhs - lhs == [0 - 0, 1 - 1, 2 - 2] expect([...lhs.sub(lhs)].map(Number)).toEqual([0, 0, 0]); // lhs - rhs == [0 - 1, 1 - 2, 2 - 3] expect([...lhs.sub(rhs)].map(Number)).toEqual([255, 255, 255]); // rhs - lhs == [1 - 0, 2 - 1, 3 - 2] expect([...rhs.sub(lhs)].map(Number)).toEqual([1, 1, 1]); }); test('subtracts a number', () => { const {lhs} = makeTestData(); expect([...lhs.sub(-1)].map(Number)).toEqual([1, 2, 3]); expect([...lhs.sub(0)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.sub(1)].map(Number)).toEqual([-1, 0, 1]); expect([...lhs.sub(2)].map(Number)).toEqual([-2, -1, 0]); }); test('subtracts a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.sub(-1n)].map(toBigInt)).toEqual([1n, 2n, 3n]); expect([...lhs.sub(0n)].map(toBigInt)).toEqual([0n, 1n, 2n]); expect([...lhs.sub(1n)].map(toBigInt)).toEqual([-1n, 0n, 1n]); expect([...lhs.sub(2n)].map(toBigInt)).toEqual([-2n, -1n, 0n]); }); }); describe('Series.mul', () => { test('multiplies against a Series', () => { const {lhs, rhs} = makeTestData(); // lhs * lhs == [0 * 0, 1 * 1, 2 * 2] expect([...lhs.mul(lhs)].map(Number)).toEqual([0, 1, 4]); // lhs * rhs == [0 * 1, 1 * 2, 2 * 3] expect([...lhs.mul(rhs)].map(Number)).toEqual([0, 2, 6]); }); test('multiplies against a number', () => { const {lhs} = makeTestData(); expect([...lhs.mul(-1)].map(Number)).toEqual([-0, -1, -2]); expect([...lhs.mul(0)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.mul(1)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.mul(2)].map(Number)).toEqual([0, 2, 4]); }); test('multiplies against a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.mul(-1n)].map(toBigInt)).toEqual([0n, -1n, -2n]); expect([...lhs.mul(0n)].map(toBigInt)).toEqual([0n, 0n, 0n]); expect([...lhs.mul(1n)].map(toBigInt)).toEqual([0n, 1n, 2n]); expect([...lhs.mul(2n)].map(toBigInt)).toEqual([0n, 2n, 4n]); }); }); describe('Series.div', () => { test('divides by a Series', () => { const {lhs, rhs} = makeTestData(); // lhs / lhs == [0/0, 1/1, 2/2] expect([...lhs.div(lhs)].map(Number)).toEqual([255, 1, 1]); // lhs / rhs == [0/1, 1/2, 2/3] expect([...lhs.div(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('divides by a number', () => { const {lhs} = makeTestData(); expect([...lhs.div(-1)].map(Number)).toEqual([-0, -1, -2]); expect([...lhs.div(0)].map(Number)).toEqual([NaN, Infinity, Infinity]); expect([...lhs.div(1)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.div(2)].map(Number)).toEqual([0, 0.5, 1]); }); test('divides by a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.div(-1n)].map(toBigInt)).toEqual([0n, -1n, -2n]); expect([...lhs.div(0n)].map(toBigInt)).toEqual([4294967295n, 4294967295n, 4294967295n]); expect([...lhs.div(1n)].map(toBigInt)).toEqual([0n, 1n, 2n]); expect([...lhs.div(2n)].map(toBigInt)).toEqual([0n, 0n, 1n]); }); }); describe('Series.trueDiv', () => { test('trueDivides by a Series', () => { const {lhs, rhs} = makeTestData(); // lhs / lhs == [0/0, 1/1, 2/2] expect([...lhs.trueDiv(lhs)].map(Number)).toEqual([0, 1, 1]); // lhs / rhs == [0/1, 1/2, 2/3] expect([...lhs.trueDiv(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('trueDivides by a number', () => { const {lhs} = makeTestData(); expect([...lhs.trueDiv(-1)].map(Number)).toEqual([-0, -1, -2]); expect([...lhs.trueDiv(0)].map(Number)).toEqual([NaN, Infinity, Infinity]); expect([...lhs.trueDiv(1)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.trueDiv(2)].map(Number)).toEqual([0, 0.5, 1]); }); test('trueDivides by a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.trueDiv(-1n)].map(toBigInt)).toEqual([0n, -1n, -2n]); expect([...lhs.trueDiv(0n)].map(toBigInt)) .toEqual([-9223372036854775808n, 9223372036854775807n, 9223372036854775807n]); expect([...lhs.trueDiv(1n)].map(toBigInt)).toEqual([0n, 1n, 2n]); expect([...lhs.trueDiv(2n)].map(toBigInt)).toEqual([0n, 0n, 1n]); }); }); describe('Series.floorDiv', () => { test('floorDivides by a Series', () => { const {lhs, rhs} = makeTestData(); // lhs / lhs == floor([0/0, 1/1, 2/2]) expect([...lhs.floorDiv(lhs)].map(Number)).toEqual([0, 1, 1]); // lhs / rhs == floor([0/1, 1/2, 2/3]) expect([...lhs.floorDiv(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('floorDivides by a number', () => { const {lhs} = makeTestData(); expect([...lhs.floorDiv(-1)].map(Number)).toEqual([-0, -1, -2]); expect([...lhs.floorDiv(0)].map(Number)).toEqual([NaN, Infinity, Infinity]); expect([...lhs.floorDiv(1)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.floorDiv(2)].map(Number)).toEqual([0, 0, 1]); }); test('floorDivides by a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.floorDiv(-1n)].map(toBigInt)).toEqual([0n, -1n, -2n]); expect([...lhs.floorDiv(0n)].map(toBigInt)) .toEqual([-9223372036854775808n, 9223372036854775807n, 9223372036854775807n]); expect([...lhs.floorDiv(1n)].map(toBigInt)).toEqual([0n, 1n, 2n]); expect([...lhs.floorDiv(2n)].map(toBigInt)).toEqual([0n, 0n, 1n]); }); }); describe('Series.mod', () => { test('modulo by a Series', () => { const {lhs, rhs} = makeTestData(); // lhs % lhs == [0 % 0, 1 % 1, 2 % 2]) expect([...lhs.mod(lhs)].map(Number)).toEqual([255, 0, 0]); // lhs % rhs == [0 % 1, 1 % 2, 2 % 3]) expect([...lhs.mod(rhs)].map(Number)).toEqual([0, 1, 2]); }); test('modulo by a number', () => { const {lhs} = makeTestData(); expect([...lhs.mod(-1)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.mod(0)].map(Number)).toEqual([NaN, NaN, NaN]); expect([...lhs.mod(1)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.mod(2)].map(Number)).toEqual([0, 1, 0]); }); test('modulo by a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.mod(-1n)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.mod(0n)].map(Number)).toEqual([4294967295, 4294967295, 4294967295]); expect([...lhs.mod(1n)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.mod(2n)].map(Number)).toEqual([0, 1, 0]); }); }); describe('Series.pow', () => { test('computes to the power of a Series', () => { const {lhs, rhs} = makeTestData(); // lhs ** lhs == [0 ** 0, 1 ** 1, 2 ** 2]) expect([...lhs.pow(lhs)].map(Number)).toEqual([1, 1, 4]); // lhs ** rhs == [0 ** 1, 1 ** 2, 2 ** 3]) expect([...lhs.pow(rhs)].map(Number)).toEqual([0, 1, 8]); }); test('computes to the power of a number', () => { const {lhs} = makeTestData(); expect([...lhs.pow(-1)].map(Number)).toEqual([Infinity, 1, 0.5]); expect([...lhs.pow(0)].map(Number)).toEqual([1, 1, 1]); expect([...lhs.pow(1)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.pow(2)].map(Number)).toEqual([0, 1, 4]); }); test('computes to the power of a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.pow(-1n)].map(Number)).toEqual([9223372036854776000, 1, 0]); expect([...lhs.pow(0n)].map(Number)).toEqual([1, 1, 1]); expect([...lhs.pow(1n)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.pow(2n)].map(Number)).toEqual([0, 1, 4]); }); }); describe('Series.eq', () => { test('compares against Series', () => { const {lhs, rhs} = makeTestData(); // lhs == lhs == true expect([...lhs.eq(lhs)].map(Number)).toEqual([1, 1, 1]); // lhs == rhs == false expect([...lhs.eq(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('compares against numbers', () => { const {lhs} = makeTestData(); expect([...lhs.eq(0)].map(Number)).toEqual([1, 0, 0]); expect([...lhs.eq(1)].map(Number)).toEqual([0, 1, 0]); expect([...lhs.eq(2)].map(Number)).toEqual([0, 0, 1]); }); test('compares against bigints', () => { const {lhs} = makeTestData(); expect([...lhs.eq(0n)].map(toBigInt)).toEqual([1n, 0n, 0n]); expect([...lhs.eq(1n)].map(toBigInt)).toEqual([0n, 1n, 0n]); expect([...lhs.eq(2n)].map(toBigInt)).toEqual([0n, 0n, 1n]); }); }); describe('Series.ne', () => { test('compares against Series', () => { const {lhs, rhs} = makeTestData(); // lhs != rhs == true expect([...lhs.ne(rhs)].map(Number)).toEqual([1, 1, 1]); // lhs != lhs == false expect([...lhs.ne(lhs)].map(Number)).toEqual([0, 0, 0]); }); test('compares against numbers', () => { const {lhs} = makeTestData(); expect([...lhs.ne(0)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.ne(1)].map(Number)).toEqual([1, 0, 1]); expect([...lhs.ne(2)].map(Number)).toEqual([1, 1, 0]); }); test('compares against bigints', () => { const {lhs} = makeTestData(); expect([...lhs.ne(0n)].map(toBigInt)).toEqual([0n, 1n, 1n]); expect([...lhs.ne(1n)].map(toBigInt)).toEqual([1n, 0n, 1n]); expect([...lhs.ne(2n)].map(toBigInt)).toEqual([1n, 1n, 0n]); }); }); describe('Series.lt', () => { test('compares against Series', () => { const {lhs, rhs} = makeTestData(); // lhs < rhs == true expect([...lhs.lt(rhs)].map(Number)).toEqual([1, 1, 1]); // lhs < lhs == false expect([...lhs.lt(lhs)].map(Number)).toEqual([0, 0, 0]); // rhs < lhs == false expect([...rhs.lt(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('compares against numbers', () => { const {lhs} = makeTestData(); expect([...lhs.lt(3)].map(Number)).toEqual([1, 1, 1]); expect([...lhs.lt(2)].map(Number)).toEqual([1, 1, 0]); expect([...lhs.lt(1)].map(Number)).toEqual([1, 0, 0]); expect([...lhs.lt(0)].map(Number)).toEqual([0, 0, 0]); }); test('compares against bigints', () => { const {lhs} = makeTestData(); expect([...lhs.lt(3n)].map(toBigInt)).toEqual([1n, 1n, 1n]); expect([...lhs.lt(2n)].map(toBigInt)).toEqual([1n, 1n, 0n]); expect([...lhs.lt(1n)].map(toBigInt)).toEqual([1n, 0n, 0n]); expect([...lhs.lt(0n)].map(toBigInt)).toEqual([0n, 0n, 0n]); }); }); describe('Series.le', () => { test('compares against Series', () => { const {lhs, rhs} = makeTestData(); // lhs <= lhs == true expect([...lhs.le(lhs)].map(Number)).toEqual([1, 1, 1]); // lhs <= rhs == true expect([...lhs.le(rhs)].map(Number)).toEqual([1, 1, 1]); // rhs <= lhs == false expect([...rhs.le(lhs)].map(Number)).toEqual([0, 0, 0]); }); test('compares against numbers', () => { const {lhs} = makeTestData(); expect([...lhs.le(2)].map(Number)).toEqual([1, 1, 1]); expect([...lhs.le(1)].map(Number)).toEqual([1, 1, 0]); expect([...lhs.le(0)].map(Number)).toEqual([1, 0, 0]); }); test('compares against bigints', () => { const {lhs} = makeTestData(); expect([...lhs.le(2n)].map(toBigInt)).toEqual([1n, 1n, 1n]); expect([...lhs.le(1n)].map(toBigInt)).toEqual([1n, 1n, 0n]); expect([...lhs.le(0n)].map(toBigInt)).toEqual([1n, 0n, 0n]); }); }); describe('Series.gt', () => { test('compares against Series', () => { const {lhs, rhs} = makeTestData(); // rhs > lhs == true expect([...rhs.gt(lhs)].map(Number)).toEqual([1, 1, 1]); // lhs > rhs == false expect([...lhs.gt(rhs)].map(Number)).toEqual([0, 0, 0]); // lhs > lhs == false expect([...lhs.gt(lhs)].map(Number)).toEqual([0, 0, 0]); }); test('compares against numbers', () => { const {lhs} = makeTestData(); expect([...lhs.gt(2)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.gt(1)].map(Number)).toEqual([0, 0, 1]); expect([...lhs.gt(0)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.gt(-1)].map(Number)).toEqual([1, 1, 1]); }); test('compares against bigints', () => { const {lhs} = makeTestData(); expect([...lhs.gt(2n)].map(toBigInt)).toEqual([0n, 0n, 0n]); expect([...lhs.gt(1n)].map(toBigInt)).toEqual([0n, 0n, 1n]); expect([...lhs.gt(0n)].map(toBigInt)).toEqual([0n, 1n, 1n]); expect([...lhs.gt(-1n)].map(toBigInt)).toEqual([1n, 1n, 1n]); }); }); describe('Series.ge', () => { test('compares against Series', () => { const {lhs, rhs} = makeTestData(); // lhs >= lhs == true expect([...lhs.ge(lhs)].map(Number)).toEqual([1, 1, 1]); // lhs >= rhs == false expect([...lhs.ge(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('compares against numbers', () => { const {lhs} = makeTestData(); expect([...lhs.ge(3)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.ge(2)].map(Number)).toEqual([0, 0, 1]); expect([...lhs.ge(1)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.ge(0)].map(Number)).toEqual([1, 1, 1]); }); test('compares against bigints', () => { const {lhs} = makeTestData(); expect([...lhs.ge(3n)].map(toBigInt)).toEqual([0n, 0n, 0n]); expect([...lhs.ge(2n)].map(toBigInt)).toEqual([0n, 0n, 1n]); expect([...lhs.ge(1n)].map(toBigInt)).toEqual([0n, 1n, 1n]); expect([...lhs.ge(0n)].map(toBigInt)).toEqual([1n, 1n, 1n]); }); }); describe('Series.bitwiseAnd', () => { test('bitwiseAnd with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs ** lhs == [0 & 0, 1 & 1, 2 & 2]) expect([...lhs.bitwiseAnd(lhs)].map(Number)).toEqual([0, 1, 2]); // lhs ** rhs == [0 & 1, 1 & 2, 2 & 3]) expect([...lhs.bitwiseAnd(rhs)].map(Number)).toEqual([0, 0, 2]); }); test('bitwiseAnd with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.bitwiseAnd(-1)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.bitwiseAnd(0)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.bitwiseAnd(1)].map(Number)).toEqual([0, 1, 0]); expect([...lhs.bitwiseAnd(2)].map(Number)).toEqual([0, 0, 2]); }); test('bitwiseAnd with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.bitwiseAnd(-1n)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.bitwiseAnd(0n)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.bitwiseAnd(1n)].map(Number)).toEqual([0, 1, 0]); expect([...lhs.bitwiseAnd(2n)].map(Number)).toEqual([0, 0, 2]); }); }); describe('Series.bitwiseOr', () => { test('bitwiseOr with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs | lhs == [0 | 0, 1 | 1, 2 | 2]) expect([...lhs.bitwiseOr(lhs)].map(Number)).toEqual([0, 1, 2]); // lhs | rhs == [0 | 1, 1 | 2, 2 | 3]) expect([...lhs.bitwiseOr(rhs)].map(Number)).toEqual([1, 3, 3]); }); test('bitwiseOr with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.bitwiseOr(-1)].map(Number)).toEqual([255, 255, 255]); expect([...lhs.bitwiseOr(0)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.bitwiseOr(1)].map(Number)).toEqual([1, 1, 3]); expect([...lhs.bitwiseOr(2)].map(Number)).toEqual([2, 3, 2]); }); test('bitwiseOr with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.bitwiseOr(-1n)].map(Number)).toEqual([255, 255, 255]); expect([...lhs.bitwiseOr(0n)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.bitwiseOr(1n)].map(Number)).toEqual([1, 1, 3]); expect([...lhs.bitwiseOr(2n)].map(Number)).toEqual([2, 3, 2]); }); }); describe('Series.bitwiseXor', () => { test('bitwiseXor with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs ^ lhs == [0 ^ 0, 1 ^ 1, 2 ^ 2]) expect([...lhs.bitwiseXor(lhs)].map(Number)).toEqual([0, 0, 0]); // lhs ^ rhs == [0 ^ 1, 1 ^ 2, 2 ^ 3]) expect([...lhs.bitwiseXor(rhs)].map(Number)).toEqual([1, 3, 1]); }); test('bitwiseXor with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.bitwiseXor(-1)].map(Number)).toEqual([255, 254, 253]); expect([...lhs.bitwiseXor(0)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.bitwiseXor(1)].map(Number)).toEqual([1, 0, 3]); expect([...lhs.bitwiseXor(2)].map(Number)).toEqual([2, 3, 0]); }); test('bitwiseXor with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.bitwiseXor(-1n)].map(Number)).toEqual([255, 254, 253]); expect([...lhs.bitwiseXor(0n)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.bitwiseXor(1n)].map(Number)).toEqual([1, 0, 3]); expect([...lhs.bitwiseXor(2n)].map(Number)).toEqual([2, 3, 0]); }); }); describe('Series.logicalAnd', () => { test('logicalAnd with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs && lhs == [0 && 0, 1 && 1, 2 && 2]) expect([...lhs.logicalAnd(lhs)].map(Number)).toEqual([0, 1, 1]); // lhs && rhs == [0 && 1, 1 && 2, 2 && 3]) expect([...lhs.logicalAnd(rhs)].map(Number)).toEqual([0, 1, 1]); }); test('logicalAnd with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.logicalAnd(-1)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.logicalAnd(0)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.logicalAnd(1)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.logicalAnd(2)].map(Number)).toEqual([0, 1, 1]); }); test('logicalAnd with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.logicalAnd(-1n)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.logicalAnd(0n)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.logicalAnd(1n)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.logicalAnd(2n)].map(Number)).toEqual([0, 1, 1]); }); }); describe('Series.logicalOr', () => { test('logicalOr with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs || lhs == [0 || 0, 1 || 1, 2 || 2]) expect([...lhs.logicalOr(lhs)].map(Number)).toEqual([0, 1, 1]); // lhs || rhs == [0 || 1, 1 || 2, 2 || 3]) expect([...lhs.logicalOr(rhs)].map(Number)).toEqual([1, 1, 1]); }); test('logicalOr with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.logicalOr(-1)].map(Number)).toEqual([1, 1, 1]); expect([...lhs.logicalOr(0)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.logicalOr(1)].map(Number)).toEqual([1, 1, 1]); expect([...lhs.logicalOr(2)].map(Number)).toEqual([1, 1, 1]); }); test('logicalOr with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.logicalOr(-1n)].map(Number)).toEqual([1, 1, 1]); expect([...lhs.logicalOr(0n)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.logicalOr(1n)].map(Number)).toEqual([1, 1, 1]); expect([...lhs.logicalOr(2n)].map(Number)).toEqual([1, 1, 1]); }); }); describe('Series.shiftLeft', () => { test('shiftLeft with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs || lhs == [0 || 0, 1 || 1, 2 || 2]) expect([...lhs.shiftLeft(lhs)].map(Number)).toEqual([0, 2, 8]); // lhs || rhs == [0 || 1, 1 || 2, 2 || 3]) expect([...lhs.shiftLeft(rhs)].map(Number)).toEqual([0, 4, 16]); }); test('shiftLeft with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.shiftLeft(-1)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.shiftLeft(0)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.shiftLeft(1)].map(Number)).toEqual([0, 2, 4]); expect([...lhs.shiftLeft(2)].map(Number)).toEqual([0, 4, 8]); }); test('shiftLeft with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.shiftLeft(-1n)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.shiftLeft(0n)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.shiftLeft(1n)].map(Number)).toEqual([0, 2, 4]); expect([...lhs.shiftLeft(2n)].map(Number)).toEqual([0, 4, 8]); }); }); describe('Series.shiftRight', () => { test('shiftRight with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs || lhs == [0 || 0, 1 || 1, 2 || 2]) expect([...lhs.shiftRight(lhs)].map(Number)).toEqual([0, 0, 0]); // lhs || rhs == [0 || 1, 1 || 2, 2 || 3]) expect([...lhs.shiftRight(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('shiftRight with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.shiftRight(-1)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.shiftRight(0)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.shiftRight(1)].map(Number)).toEqual([0, 0, 1]); expect([...lhs.shiftRight(2)].map(Number)).toEqual([0, 0, 0]); }); test('shiftRight with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.shiftRight(-1n)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.shiftRight(0n)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.shiftRight(1n)].map(Number)).toEqual([0, 0, 1]); expect([...lhs.shiftRight(2n)].map(Number)).toEqual([0, 0, 0]); }); }); describe('Series.shiftRightUnsigned', () => { test('shiftRightUnsigned with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs || lhs == [0 || 0, 1 || 1, 2 || 2]) expect([...lhs.shiftRightUnsigned(lhs)].map(Number)).toEqual([0, 0, 0]); // lhs || rhs == [0 || 1, 1 || 2, 2 || 3]) expect([...lhs.shiftRightUnsigned(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('shiftRightUnsigned with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.shiftRightUnsigned(-1)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.shiftRightUnsigned(0)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.shiftRightUnsigned(1)].map(Number)).toEqual([0, 0, 1]); expect([...lhs.shiftRightUnsigned(2)].map(Number)).toEqual([0, 0, 0]); }); test('shiftRightUnsigned with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.shiftRightUnsigned(-1n)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.shiftRightUnsigned(0n)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.shiftRightUnsigned(1n)].map(Number)).toEqual([0, 0, 1]); expect([...lhs.shiftRightUnsigned(2n)].map(Number)).toEqual([0, 0, 0]); }); }); describe('Series.logBase', () => { test('logBase with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs || lhs == [0 || 0, 1 || 1, 2 || 2]) expect([...lhs.logBase(lhs)].map(Number)).toEqual([0, 0, 1]); // lhs || rhs == [0 || 1, 1 || 2, 2 || 3]) expect([...lhs.logBase(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('logBase with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.logBase(-1)].map(Number)).toEqual([NaN, NaN, NaN]); expect([...lhs.logBase(0)].map(Number)).toEqual([NaN, -0, -0]); expect([...lhs.logBase(1)].map(Number)).toEqual([-Infinity, NaN, Infinity]); expect([...lhs.logBase(2)].map(Number)).toEqual([-Infinity, 0, 1]); }); test('logBase with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.logBase(-1n)].map(Number)) .toEqual([-9223372036854776000, -9223372036854776000, -9223372036854776000]); expect([...lhs.logBase(0n)].map(Number)).toEqual([-9223372036854776000, 0, 0]); expect([...lhs.logBase(1n)].map(Number)) .toEqual([-9223372036854776000, -9223372036854776000, 9223372036854776000]); expect([...lhs.logBase(2n)].map(Number)).toEqual([-9223372036854776000, 0, 1]); }); }); describe('Series.atan2', () => { test('atan2 with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs || lhs == [0 || 0, 1 || 1, 2 || 2]) expect([...lhs.atan2(lhs)].map(Number)).toEqual([0, 0, 0]); // lhs || rhs == [0 || 1, 1 || 2, 2 || 3]) expect([...lhs.atan2(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('atan2 with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.atan2(-1)].map(Number)) .toEqual([3.141592653589793, 2.356194490192345, 2.0344439357957027]); expect([...lhs.atan2(0)].map(Number)).toEqual([0, 1.5707963267948966, 1.5707963267948966]); expect([...lhs.atan2(1)].map(Number)).toEqual([0, 0.7853981633974483, 1.1071487177940904]); expect([...lhs.atan2(2)].map(Number)).toEqual([0, 0.46364760900080615, 0.7853981633974483]); }); test('atan2 with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.atan2(-1n)].map(Number)).toEqual([3, 2, 2]); expect([...lhs.atan2(0n)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.atan2(1n)].map(Number)).toEqual([0, 0, 1]); expect([...lhs.atan2(2n)].map(Number)).toEqual([0, 0, 0]); }); }); describe('Series.nullEquals', () => { test('nullEquals with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs || lhs == [0 || 0, 1 || 1, 2 || 2]) expect([...lhs.nullEquals(lhs)].map(Number)).toEqual([1, 1, 1]); // lhs || rhs == [0 || 1, 1 || 2, 2 || 3]) expect([...lhs.nullEquals(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('nullEquals with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.nullEquals(-1)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.nullEquals(0)].map(Number)).toEqual([1, 0, 0]); expect([...lhs.nullEquals(1)].map(Number)).toEqual([0, 1, 0]); expect([...lhs.nullEquals(2)].map(Number)).toEqual([0, 0, 1]); }); test('nullEquals with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.nullEquals(-1n)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.nullEquals(0n)].map(Number)).toEqual([1, 0, 0]); expect([...lhs.nullEquals(1n)].map(Number)).toEqual([0, 1, 0]); expect([...lhs.nullEquals(2n)].map(Number)).toEqual([0, 0, 1]); }); }); describe('Series.nullMax', () => { test('nullMax with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs || lhs == [0 || 0, 1 || 1, 2 || 2]) expect([...lhs.nullMax(lhs)].map(Number)).toEqual([0, 1, 2]); // lhs || rhs == [0 || 1, 1 || 2, 2 || 3]) expect([...lhs.nullMax(rhs)].map(Number)).toEqual([1, 2, 3]); }); test('nullMax with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.nullMax(-1)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.nullMax(0)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.nullMax(1)].map(Number)).toEqual([1, 1, 2]); expect([...lhs.nullMax(2)].map(Number)).toEqual([2, 2, 2]); }); test('nullMax with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.nullMax(-1n)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.nullMax(0n)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.nullMax(1n)].map(Number)).toEqual([1, 1, 2]); expect([...lhs.nullMax(2n)].map(Number)).toEqual([2, 2, 2]); }); }); describe('Series.nullMin', () => { test('nullMin with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs || lhs == [0 || 0, 1 || 1, 2 || 2]) expect([...lhs.nullMin(lhs)].map(Number)).toEqual([0, 1, 2]); // lhs || rhs == [0 || 1, 1 || 2, 2 || 3]) expect([...lhs.nullMin(rhs)].map(Number)).toEqual([0, 1, 2]); }); test('nullMin with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.nullMin(-1)].map(Number)).toEqual([-1, -1, -1]); expect([...lhs.nullMin(0)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.nullMin(1)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.nullMin(2)].map(Number)).toEqual([0, 1, 2]); }); test('nullMin with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.nullMin(-1n)].map(Number)).toEqual([-1, -1, -1]); expect([...lhs.nullMin(0n)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.nullMin(1n)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.nullMin(2n)].map(Number)).toEqual([0, 1, 2]); }); }); });
0
rapidsai_public_repos/node/modules/cudf/test/series
rapidsai_public_repos/node/modules/cudf/test/series/binaryop/int64-tests.ts
// Copyright (c) 2021, NVIDIA CORPORATION. // // 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. import {setDefaultAllocator} from '@rapidsai/cuda'; import {DeviceBuffer} from '@rapidsai/rmm'; import * as arrow from 'apache-arrow'; import {makeTestBigInts, makeTestSeries, toBigInt} from '../utils'; setDefaultAllocator((byteLength: number) => new DeviceBuffer(byteLength)); const makeTestData = (values?: (number|null)[]) => makeTestSeries(new arrow.Int64, makeTestBigInts(values)); describe('Series binaryops (Int64)', () => { describe('Series.add', () => { test('adds a Series', () => { const {lhs, rhs} = makeTestData(); // lhs + lhs == [0 + 0, 1 + 1, 2 + 2] expect([...lhs.add(lhs)].map(Number)).toEqual([0, 2, 4]); // lhs + rhs == [0 + 1, 1 + 2, 2 + 3] expect([...lhs.add(rhs)].map(Number)).toEqual([1, 3, 5]); }); test('adds a number', () => { const {lhs} = makeTestData(); expect([...lhs.add(-1)].map(Number)).toEqual([-1, 0, 1]); expect([...lhs.add(0)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.add(1)].map(Number)).toEqual([1, 2, 3]); expect([...lhs.add(2)].map(Number)).toEqual([2, 3, 4]); }); test('adds a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.add(-1n)].map(toBigInt)).toEqual([-1n, 0n, 1n]); expect([...lhs.add(0n)].map(toBigInt)).toEqual([0n, 1n, 2n]); expect([...lhs.add(1n)].map(toBigInt)).toEqual([1n, 2n, 3n]); expect([...lhs.add(2n)].map(toBigInt)).toEqual([2n, 3n, 4n]); }); }); describe('Series.sub', () => { test('subtracts a Series', () => { const {lhs, rhs} = makeTestData(); // lhs - lhs == [0 - 0, 1 - 1, 2 - 2] expect([...lhs.sub(lhs)].map(Number)).toEqual([0, 0, 0]); // lhs - rhs == [0 - 1, 1 - 2, 2 - 3] expect([...lhs.sub(rhs)].map(Number)).toEqual([-1, -1, -1]); // rhs - lhs == [1 - 0, 2 - 1, 3 - 2] expect([...rhs.sub(lhs)].map(Number)).toEqual([1, 1, 1]); }); test('subtracts a number', () => { const {lhs} = makeTestData(); expect([...lhs.sub(-1)].map(Number)).toEqual([1, 2, 3]); expect([...lhs.sub(0)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.sub(1)].map(Number)).toEqual([-1, 0, 1]); expect([...lhs.sub(2)].map(Number)).toEqual([-2, -1, 0]); }); test('subtracts a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.sub(-1n)].map(toBigInt)).toEqual([1n, 2n, 3n]); expect([...lhs.sub(0n)].map(toBigInt)).toEqual([0n, 1n, 2n]); expect([...lhs.sub(1n)].map(toBigInt)).toEqual([-1n, 0n, 1n]); expect([...lhs.sub(2n)].map(toBigInt)).toEqual([-2n, -1n, 0n]); }); }); describe('Series.mul', () => { test('multiplies against a Series', () => { const {lhs, rhs} = makeTestData(); // lhs * lhs == [0 * 0, 1 * 1, 2 * 2] expect([...lhs.mul(lhs)].map(Number)).toEqual([0, 1, 4]); // lhs * rhs == [0 * 1, 1 * 2, 2 * 3] expect([...lhs.mul(rhs)].map(Number)).toEqual([0, 2, 6]); }); test('multiplies against a number', () => { const {lhs} = makeTestData(); expect([...lhs.mul(-1)].map(Number)).toEqual([-0, -1, -2]); expect([...lhs.mul(0)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.mul(1)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.mul(2)].map(Number)).toEqual([0, 2, 4]); }); test('multiplies against a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.mul(-1n)].map(toBigInt)).toEqual([0n, -1n, -2n]); expect([...lhs.mul(0n)].map(toBigInt)).toEqual([0n, 0n, 0n]); expect([...lhs.mul(1n)].map(toBigInt)).toEqual([0n, 1n, 2n]); expect([...lhs.mul(2n)].map(toBigInt)).toEqual([0n, 2n, 4n]); }); }); describe('Series.div', () => { test('divides by a Series', () => { const {lhs, rhs} = makeTestData(); // lhs / lhs == [0/0, 1/1, 2/2] expect([...lhs.div(lhs)].map(Number)).toEqual([4294967295, 1, 1]); // lhs / rhs == [0/1, 1/2, 2/3] expect([...lhs.div(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('divides by a number', () => { const {lhs} = makeTestData(); expect([...lhs.div(-1)].map(Number)).toEqual([-0, -1, -2]); expect([...lhs.div(0)].map(Number)).toEqual([NaN, Infinity, Infinity]); expect([...lhs.div(1)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.div(2)].map(Number)).toEqual([0, 0.5, 1]); }); test('divides by a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.div(-1n)].map(toBigInt)).toEqual([0n, -1n, -2n]); expect([...lhs.div(0n)].map(toBigInt)).toEqual([4294967295n, 4294967295n, 4294967295n]); expect([...lhs.div(1n)].map(toBigInt)).toEqual([0n, 1n, 2n]); expect([...lhs.div(2n)].map(toBigInt)).toEqual([0n, 0n, 1n]); }); }); describe('Series.trueDiv', () => { test('trueDivides by a Series', () => { const {lhs, rhs} = makeTestData(); // lhs / lhs == [0/0, 1/1, 2/2] expect([...lhs.trueDiv(lhs)].map(Number)).toEqual([-9223372036854776000, 1, 1]); // lhs / rhs == [0/1, 1/2, 2/3] expect([...lhs.trueDiv(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('trueDivides by a number', () => { const {lhs} = makeTestData(); expect([...lhs.trueDiv(-1)].map(Number)).toEqual([-0, -1, -2]); expect([...lhs.trueDiv(0)].map(Number)).toEqual([NaN, Infinity, Infinity]); expect([...lhs.trueDiv(1)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.trueDiv(2)].map(Number)).toEqual([0, 0.5, 1]); }); test('trueDivides by a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.trueDiv(-1n)].map(toBigInt)).toEqual([0n, -1n, -2n]); expect([...lhs.trueDiv(0n)].map(toBigInt)) .toEqual([-9223372036854775808n, 9223372036854775807n, 9223372036854775807n]); expect([...lhs.trueDiv(1n)].map(toBigInt)).toEqual([0n, 1n, 2n]); expect([...lhs.trueDiv(2n)].map(toBigInt)).toEqual([0n, 0n, 1n]); }); }); describe('Series.floorDiv', () => { test('floorDivides by a Series', () => { const {lhs, rhs} = makeTestData(); // lhs / lhs == floor([0/0, 1/1, 2/2]) expect([...lhs.floorDiv(lhs)].map(Number)).toEqual([-9223372036854776000, 1, 1]); // lhs / rhs == floor([0/1, 1/2, 2/3]) expect([...lhs.floorDiv(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('floorDivides by a number', () => { const {lhs} = makeTestData(); expect([...lhs.floorDiv(-1)].map(Number)).toEqual([-0, -1, -2]); expect([...lhs.floorDiv(0)].map(Number)).toEqual([NaN, Infinity, Infinity]); expect([...lhs.floorDiv(1)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.floorDiv(2)].map(Number)).toEqual([0, 0, 1]); }); test('floorDivides by a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.floorDiv(-1n)].map(toBigInt)).toEqual([0n, -1n, -2n]); expect([...lhs.floorDiv(0n)].map(toBigInt)) .toEqual([-9223372036854775808n, 9223372036854775807n, 9223372036854775807n]); expect([...lhs.floorDiv(1n)].map(toBigInt)).toEqual([0n, 1n, 2n]); expect([...lhs.floorDiv(2n)].map(toBigInt)).toEqual([0n, 0n, 1n]); }); }); describe('Series.mod', () => { test('modulo by a Series', () => { const {lhs, rhs} = makeTestData(); // lhs % lhs == [0 % 0, 1 % 1, 2 % 2]) expect([...lhs.mod(lhs)].map(Number)).toEqual([4294967295, 0, 0]); // lhs % rhs == [0 % 1, 1 % 2, 2 % 3]) expect([...lhs.mod(rhs)].map(Number)).toEqual([0, 1, 2]); }); test('modulo by a number', () => { const {lhs} = makeTestData(); expect([...lhs.mod(-1)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.mod(0)].map(Number)).toEqual([NaN, NaN, NaN]); expect([...lhs.mod(1)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.mod(2)].map(Number)).toEqual([0, 1, 0]); }); test('modulo by a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.mod(-1n)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.mod(0n)].map(Number)).toEqual([4294967295, 4294967295, 4294967295]); expect([...lhs.mod(1n)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.mod(2n)].map(Number)).toEqual([0, 1, 0]); }); }); describe('Series.pow', () => { test('computes to the power of a Series', () => { const {lhs, rhs} = makeTestData(); // lhs ** lhs == [0 ** 0, 1 ** 1, 2 ** 2]) expect([...lhs.pow(lhs)].map(Number)).toEqual([1, 1, 4]); // lhs ** rhs == [0 ** 1, 1 ** 2, 2 ** 3]) expect([...lhs.pow(rhs)].map(Number)).toEqual([0, 1, 8]); }); test('computes to the power of a number', () => { const {lhs} = makeTestData(); expect([...lhs.pow(-1)].map(Number)).toEqual([Infinity, 1, 0.5]); expect([...lhs.pow(0)].map(Number)).toEqual([1, 1, 1]); expect([...lhs.pow(1)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.pow(2)].map(Number)).toEqual([0, 1, 4]); }); test('computes to the power of a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.pow(-1n)].map(Number)).toEqual([9223372036854776000, 1, 0]); expect([...lhs.pow(0n)].map(Number)).toEqual([1, 1, 1]); expect([...lhs.pow(1n)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.pow(2n)].map(Number)).toEqual([0, 1, 4]); }); }); describe('Series.eq', () => { test('compares against Series', () => { const {lhs, rhs} = makeTestData(); // lhs == lhs == true expect([...lhs.eq(lhs)].map(Number)).toEqual([1, 1, 1]); // lhs == rhs == false expect([...lhs.eq(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('compares against numbers', () => { const {lhs} = makeTestData(); expect([...lhs.eq(0)].map(Number)).toEqual([1, 0, 0]); expect([...lhs.eq(1)].map(Number)).toEqual([0, 1, 0]); expect([...lhs.eq(2)].map(Number)).toEqual([0, 0, 1]); }); test('compares against bigints', () => { const {lhs} = makeTestData(); expect([...lhs.eq(0n)].map(toBigInt)).toEqual([1n, 0n, 0n]); expect([...lhs.eq(1n)].map(toBigInt)).toEqual([0n, 1n, 0n]); expect([...lhs.eq(2n)].map(toBigInt)).toEqual([0n, 0n, 1n]); }); }); describe('Series.ne', () => { test('compares against Series', () => { const {lhs, rhs} = makeTestData(); // lhs != rhs == true expect([...lhs.ne(rhs)].map(Number)).toEqual([1, 1, 1]); // lhs != lhs == false expect([...lhs.ne(lhs)].map(Number)).toEqual([0, 0, 0]); }); test('compares against numbers', () => { const {lhs} = makeTestData(); expect([...lhs.ne(0)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.ne(1)].map(Number)).toEqual([1, 0, 1]); expect([...lhs.ne(2)].map(Number)).toEqual([1, 1, 0]); }); test('compares against bigints', () => { const {lhs} = makeTestData(); expect([...lhs.ne(0n)].map(toBigInt)).toEqual([0n, 1n, 1n]); expect([...lhs.ne(1n)].map(toBigInt)).toEqual([1n, 0n, 1n]); expect([...lhs.ne(2n)].map(toBigInt)).toEqual([1n, 1n, 0n]); }); }); describe('Series.lt', () => { test('compares against Series', () => { const {lhs, rhs} = makeTestData(); // lhs < rhs == true expect([...lhs.lt(rhs)].map(Number)).toEqual([1, 1, 1]); // lhs < lhs == false expect([...lhs.lt(lhs)].map(Number)).toEqual([0, 0, 0]); // rhs < lhs == false expect([...rhs.lt(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('compares against numbers', () => { const {lhs} = makeTestData(); expect([...lhs.lt(3)].map(Number)).toEqual([1, 1, 1]); expect([...lhs.lt(2)].map(Number)).toEqual([1, 1, 0]); expect([...lhs.lt(1)].map(Number)).toEqual([1, 0, 0]); expect([...lhs.lt(0)].map(Number)).toEqual([0, 0, 0]); }); test('compares against bigints', () => { const {lhs} = makeTestData(); expect([...lhs.lt(3n)].map(toBigInt)).toEqual([1n, 1n, 1n]); expect([...lhs.lt(2n)].map(toBigInt)).toEqual([1n, 1n, 0n]); expect([...lhs.lt(1n)].map(toBigInt)).toEqual([1n, 0n, 0n]); expect([...lhs.lt(0n)].map(toBigInt)).toEqual([0n, 0n, 0n]); }); }); describe('Series.le', () => { test('compares against Series', () => { const {lhs, rhs} = makeTestData(); // lhs <= lhs == true expect([...lhs.le(lhs)].map(Number)).toEqual([1, 1, 1]); // lhs <= rhs == true expect([...lhs.le(rhs)].map(Number)).toEqual([1, 1, 1]); // rhs <= lhs == false expect([...rhs.le(lhs)].map(Number)).toEqual([0, 0, 0]); }); test('compares against numbers', () => { const {lhs} = makeTestData(); expect([...lhs.le(2)].map(Number)).toEqual([1, 1, 1]); expect([...lhs.le(1)].map(Number)).toEqual([1, 1, 0]); expect([...lhs.le(0)].map(Number)).toEqual([1, 0, 0]); }); test('compares against bigints', () => { const {lhs} = makeTestData(); expect([...lhs.le(2n)].map(toBigInt)).toEqual([1n, 1n, 1n]); expect([...lhs.le(1n)].map(toBigInt)).toEqual([1n, 1n, 0n]); expect([...lhs.le(0n)].map(toBigInt)).toEqual([1n, 0n, 0n]); }); }); describe('Series.gt', () => { test('compares against Series', () => { const {lhs, rhs} = makeTestData(); // rhs > lhs == true expect([...rhs.gt(lhs)].map(Number)).toEqual([1, 1, 1]); // lhs > rhs == false expect([...lhs.gt(rhs)].map(Number)).toEqual([0, 0, 0]); // lhs > lhs == false expect([...lhs.gt(lhs)].map(Number)).toEqual([0, 0, 0]); }); test('compares against numbers', () => { const {lhs} = makeTestData(); expect([...lhs.gt(2)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.gt(1)].map(Number)).toEqual([0, 0, 1]); expect([...lhs.gt(0)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.gt(-1)].map(Number)).toEqual([1, 1, 1]); }); test('compares against bigints', () => { const {lhs} = makeTestData(); expect([...lhs.gt(2n)].map(toBigInt)).toEqual([0n, 0n, 0n]); expect([...lhs.gt(1n)].map(toBigInt)).toEqual([0n, 0n, 1n]); expect([...lhs.gt(0n)].map(toBigInt)).toEqual([0n, 1n, 1n]); expect([...lhs.gt(-1n)].map(toBigInt)).toEqual([1n, 1n, 1n]); }); }); describe('Series.ge', () => { test('compares against Series', () => { const {lhs, rhs} = makeTestData(); // lhs >= lhs == true expect([...lhs.ge(lhs)].map(Number)).toEqual([1, 1, 1]); // lhs >= rhs == false expect([...lhs.ge(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('compares against numbers', () => { const {lhs} = makeTestData(); expect([...lhs.ge(3)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.ge(2)].map(Number)).toEqual([0, 0, 1]); expect([...lhs.ge(1)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.ge(0)].map(Number)).toEqual([1, 1, 1]); }); test('compares against bigints', () => { const {lhs} = makeTestData(); expect([...lhs.ge(3n)].map(toBigInt)).toEqual([0n, 0n, 0n]); expect([...lhs.ge(2n)].map(toBigInt)).toEqual([0n, 0n, 1n]); expect([...lhs.ge(1n)].map(toBigInt)).toEqual([0n, 1n, 1n]); expect([...lhs.ge(0n)].map(toBigInt)).toEqual([1n, 1n, 1n]); }); }); describe('Series.bitwiseAnd', () => { test('bitwiseAnd with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs ** lhs == [0 & 0, 1 & 1, 2 & 2]) expect([...lhs.bitwiseAnd(lhs)].map(Number)).toEqual([0, 1, 2]); // lhs ** rhs == [0 & 1, 1 & 2, 2 & 3]) expect([...lhs.bitwiseAnd(rhs)].map(Number)).toEqual([0, 0, 2]); }); test('bitwiseAnd with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.bitwiseAnd(-1)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.bitwiseAnd(0)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.bitwiseAnd(1)].map(Number)).toEqual([0, 1, 0]); expect([...lhs.bitwiseAnd(2)].map(Number)).toEqual([0, 0, 2]); }); test('bitwiseAnd with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.bitwiseAnd(-1n)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.bitwiseAnd(0n)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.bitwiseAnd(1n)].map(Number)).toEqual([0, 1, 0]); expect([...lhs.bitwiseAnd(2n)].map(Number)).toEqual([0, 0, 2]); }); }); describe('Series.bitwiseOr', () => { test('bitwiseOr with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs | lhs == [0 | 0, 1 | 1, 2 | 2]) expect([...lhs.bitwiseOr(lhs)].map(Number)).toEqual([0, 1, 2]); // lhs | rhs == [0 | 1, 1 | 2, 2 | 3]) expect([...lhs.bitwiseOr(rhs)].map(Number)).toEqual([1, 3, 3]); }); test('bitwiseOr with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.bitwiseOr(-1)].map(Number)).toEqual([-1, -1, -1]); expect([...lhs.bitwiseOr(0)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.bitwiseOr(1)].map(Number)).toEqual([1, 1, 3]); expect([...lhs.bitwiseOr(2)].map(Number)).toEqual([2, 3, 2]); }); test('bitwiseOr with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.bitwiseOr(-1n)].map(Number)).toEqual([-1, -1, -1]); expect([...lhs.bitwiseOr(0n)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.bitwiseOr(1n)].map(Number)).toEqual([1, 1, 3]); expect([...lhs.bitwiseOr(2n)].map(Number)).toEqual([2, 3, 2]); }); }); describe('Series.bitwiseXor', () => { test('bitwiseXor with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs ^ lhs == [0 ^ 0, 1 ^ 1, 2 ^ 2]) expect([...lhs.bitwiseXor(lhs)].map(Number)).toEqual([0, 0, 0]); // lhs ^ rhs == [0 ^ 1, 1 ^ 2, 2 ^ 3]) expect([...lhs.bitwiseXor(rhs)].map(Number)).toEqual([1, 3, 1]); }); test('bitwiseXor with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.bitwiseXor(-1)].map(Number)).toEqual([-1, -2, -3]); expect([...lhs.bitwiseXor(0)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.bitwiseXor(1)].map(Number)).toEqual([1, 0, 3]); expect([...lhs.bitwiseXor(2)].map(Number)).toEqual([2, 3, 0]); }); test('bitwiseXor with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.bitwiseXor(-1n)].map(Number)).toEqual([-1, -2, -3]); expect([...lhs.bitwiseXor(0n)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.bitwiseXor(1n)].map(Number)).toEqual([1, 0, 3]); expect([...lhs.bitwiseXor(2n)].map(Number)).toEqual([2, 3, 0]); }); }); describe('Series.logicalAnd', () => { test('logicalAnd with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs && lhs == [0 && 0, 1 && 1, 2 && 2]) expect([...lhs.logicalAnd(lhs)].map(Number)).toEqual([0, 1, 1]); // lhs && rhs == [0 && 1, 1 && 2, 2 && 3]) expect([...lhs.logicalAnd(rhs)].map(Number)).toEqual([0, 1, 1]); }); test('logicalAnd with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.logicalAnd(-1)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.logicalAnd(0)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.logicalAnd(1)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.logicalAnd(2)].map(Number)).toEqual([0, 1, 1]); }); test('logicalAnd with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.logicalAnd(-1n)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.logicalAnd(0n)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.logicalAnd(1n)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.logicalAnd(2n)].map(Number)).toEqual([0, 1, 1]); }); }); describe('Series.logicalOr', () => { test('logicalOr with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs || lhs == [0 || 0, 1 || 1, 2 || 2]) expect([...lhs.logicalOr(lhs)].map(Number)).toEqual([0, 1, 1]); // lhs || rhs == [0 || 1, 1 || 2, 2 || 3]) expect([...lhs.logicalOr(rhs)].map(Number)).toEqual([1, 1, 1]); }); test('logicalOr with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.logicalOr(-1)].map(Number)).toEqual([1, 1, 1]); expect([...lhs.logicalOr(0)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.logicalOr(1)].map(Number)).toEqual([1, 1, 1]); expect([...lhs.logicalOr(2)].map(Number)).toEqual([1, 1, 1]); }); test('logicalOr with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.logicalOr(-1n)].map(Number)).toEqual([1, 1, 1]); expect([...lhs.logicalOr(0n)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.logicalOr(1n)].map(Number)).toEqual([1, 1, 1]); expect([...lhs.logicalOr(2n)].map(Number)).toEqual([1, 1, 1]); }); }); describe('Series.shiftLeft', () => { test('shiftLeft with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs || lhs == [0 || 0, 1 || 1, 2 || 2]) expect([...lhs.shiftLeft(lhs)].map(Number)).toEqual([0, 2, 8]); // lhs || rhs == [0 || 1, 1 || 2, 2 || 3]) expect([...lhs.shiftLeft(rhs)].map(Number)).toEqual([0, 4, 16]); }); test('shiftLeft with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.shiftLeft(-1)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.shiftLeft(0)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.shiftLeft(1)].map(Number)).toEqual([0, 2, 4]); expect([...lhs.shiftLeft(2)].map(Number)).toEqual([0, 4, 8]); }); test('shiftLeft with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.shiftLeft(-1n)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.shiftLeft(0n)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.shiftLeft(1n)].map(Number)).toEqual([0, 2, 4]); expect([...lhs.shiftLeft(2n)].map(Number)).toEqual([0, 4, 8]); }); }); describe('Series.shiftRight', () => { test('shiftRight with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs || lhs == [0 || 0, 1 || 1, 2 || 2]) expect([...lhs.shiftRight(lhs)].map(Number)).toEqual([0, 0, 0]); // lhs || rhs == [0 || 1, 1 || 2, 2 || 3]) expect([...lhs.shiftRight(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('shiftRight with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.shiftRight(-1)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.shiftRight(0)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.shiftRight(1)].map(Number)).toEqual([0, 0, 1]); expect([...lhs.shiftRight(2)].map(Number)).toEqual([0, 0, 0]); }); test('shiftRight with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.shiftRight(-1n)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.shiftRight(0n)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.shiftRight(1n)].map(Number)).toEqual([0, 0, 1]); expect([...lhs.shiftRight(2n)].map(Number)).toEqual([0, 0, 0]); }); }); describe('Series.shiftRightUnsigned', () => { test('shiftRightUnsigned with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs || lhs == [0 || 0, 1 || 1, 2 || 2]) expect([...lhs.shiftRightUnsigned(lhs)].map(Number)).toEqual([0, 0, 0]); // lhs || rhs == [0 || 1, 1 || 2, 2 || 3]) expect([...lhs.shiftRightUnsigned(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('shiftRightUnsigned with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.shiftRightUnsigned(-1)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.shiftRightUnsigned(0)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.shiftRightUnsigned(1)].map(Number)).toEqual([0, 0, 1]); expect([...lhs.shiftRightUnsigned(2)].map(Number)).toEqual([0, 0, 0]); }); test('shiftRightUnsigned with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.shiftRightUnsigned(-1n)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.shiftRightUnsigned(0n)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.shiftRightUnsigned(1n)].map(Number)).toEqual([0, 0, 1]); expect([...lhs.shiftRightUnsigned(2n)].map(Number)).toEqual([0, 0, 0]); }); }); describe('Series.logBase', () => { test('logBase with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs || lhs == [0 || 0, 1 || 1, 2 || 2]) expect([...lhs.logBase(lhs)].map(Number)) .toEqual([-9223372036854776000, -9223372036854776000, 1]); // lhs || rhs == [0 || 1, 1 || 2, 2 || 3]) expect([...lhs.logBase(rhs)].map(Number)).toEqual([-9223372036854776000, 0, 0]); }); test('logBase with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.logBase(-1)].map(Number)).toEqual([NaN, NaN, NaN]); expect([...lhs.logBase(0)].map(Number)).toEqual([NaN, -0, -0]); expect([...lhs.logBase(1)].map(Number)).toEqual([-Infinity, NaN, Infinity]); expect([...lhs.logBase(2)].map(Number)).toEqual([-Infinity, 0, 1]); }); test('logBase with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.logBase(-1n)].map(Number)) .toEqual([-9223372036854776000, -9223372036854776000, -9223372036854776000]); expect([...lhs.logBase(0n)].map(Number)).toEqual([-9223372036854776000, 0, 0]); expect([...lhs.logBase(1n)].map(Number)) .toEqual([-9223372036854776000, -9223372036854776000, 9223372036854776000]); expect([...lhs.logBase(2n)].map(Number)).toEqual([-9223372036854776000, 0, 1]); }); }); describe('Series.atan2', () => { test('atan2 with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs || lhs == [0 || 0, 1 || 1, 2 || 2]) expect([...lhs.atan2(lhs)].map(Number)).toEqual([0, 0, 0]); // lhs || rhs == [0 || 1, 1 || 2, 2 || 3]) expect([...lhs.atan2(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('atan2 with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.atan2(-1)].map(Number)) .toEqual([3.141592653589793, 2.356194490192345, 2.0344439357957027]); expect([...lhs.atan2(0)].map(Number)).toEqual([0, 1.5707963267948966, 1.5707963267948966]); expect([...lhs.atan2(1)].map(Number)).toEqual([0, 0.7853981633974483, 1.1071487177940904]); expect([...lhs.atan2(2)].map(Number)).toEqual([0, 0.46364760900080615, 0.7853981633974483]); }); test('atan2 with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.atan2(-1n)].map(Number)).toEqual([3, 2, 2]); expect([...lhs.atan2(0n)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.atan2(1n)].map(Number)).toEqual([0, 0, 1]); expect([...lhs.atan2(2n)].map(Number)).toEqual([0, 0, 0]); }); }); describe('Series.nullEquals', () => { test('nullEquals with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs || lhs == [0 || 0, 1 || 1, 2 || 2]) expect([...lhs.nullEquals(lhs)].map(Number)).toEqual([1, 1, 1]); // lhs || rhs == [0 || 1, 1 || 2, 2 || 3]) expect([...lhs.nullEquals(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('nullEquals with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.nullEquals(-1)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.nullEquals(0)].map(Number)).toEqual([1, 0, 0]); expect([...lhs.nullEquals(1)].map(Number)).toEqual([0, 1, 0]); expect([...lhs.nullEquals(2)].map(Number)).toEqual([0, 0, 1]); }); test('nullEquals with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.nullEquals(-1n)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.nullEquals(0n)].map(Number)).toEqual([1, 0, 0]); expect([...lhs.nullEquals(1n)].map(Number)).toEqual([0, 1, 0]); expect([...lhs.nullEquals(2n)].map(Number)).toEqual([0, 0, 1]); }); }); describe('Series.nullMax', () => { test('nullMax with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs || lhs == [0 || 0, 1 || 1, 2 || 2]) expect([...lhs.nullMax(lhs)].map(Number)).toEqual([0, 1, 2]); // lhs || rhs == [0 || 1, 1 || 2, 2 || 3]) expect([...lhs.nullMax(rhs)].map(Number)).toEqual([1, 2, 3]); }); test('nullMax with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.nullMax(-1)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.nullMax(0)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.nullMax(1)].map(Number)).toEqual([1, 1, 2]); expect([...lhs.nullMax(2)].map(Number)).toEqual([2, 2, 2]); }); test('nullMax with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.nullMax(-1n)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.nullMax(0n)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.nullMax(1n)].map(Number)).toEqual([1, 1, 2]); expect([...lhs.nullMax(2n)].map(Number)).toEqual([2, 2, 2]); }); }); describe('Series.nullMin', () => { test('nullMin with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs || lhs == [0 || 0, 1 || 1, 2 || 2]) expect([...lhs.nullMin(lhs)].map(Number)).toEqual([0, 1, 2]); // lhs || rhs == [0 || 1, 1 || 2, 2 || 3]) expect([...lhs.nullMin(rhs)].map(Number)).toEqual([0, 1, 2]); }); test('nullMin with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.nullMin(-1)].map(Number)).toEqual([-1, -1, -1]); expect([...lhs.nullMin(0)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.nullMin(1)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.nullMin(2)].map(Number)).toEqual([0, 1, 2]); }); test('nullMin with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.nullMin(-1n)].map(Number)).toEqual([-1, -1, -1]); expect([...lhs.nullMin(0n)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.nullMin(1n)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.nullMin(2n)].map(Number)).toEqual([0, 1, 2]); }); }); });
0
rapidsai_public_repos/node/modules/cudf/test/series
rapidsai_public_repos/node/modules/cudf/test/series/binaryop/uint16-tests.ts
// Copyright (c) 2021, NVIDIA CORPORATION. // // 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. import {setDefaultAllocator} from '@rapidsai/cuda'; import {DeviceBuffer} from '@rapidsai/rmm'; import * as arrow from 'apache-arrow'; import {makeTestNumbers, makeTestSeries, toBigInt} from '../utils'; setDefaultAllocator((byteLength: number) => new DeviceBuffer(byteLength)); const makeTestData = (values?: (number|null)[]) => makeTestSeries(new arrow.Uint16, makeTestNumbers(values)); describe('Series binaryops (Uint16)', () => { describe('Series.add', () => { test('adds a Series', () => { const {lhs, rhs} = makeTestData(); // lhs + lhs == [0 + 0, 1 + 1, 2 + 2] expect([...lhs.add(lhs)].map(Number)).toEqual([0, 2, 4]); // lhs + rhs == [0 + 1, 1 + 2, 2 + 3] expect([...lhs.add(rhs)].map(Number)).toEqual([1, 3, 5]); }); test('adds a number', () => { const {lhs} = makeTestData(); expect([...lhs.add(-1)].map(Number)).toEqual([-1, 0, 1]); expect([...lhs.add(0)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.add(1)].map(Number)).toEqual([1, 2, 3]); expect([...lhs.add(2)].map(Number)).toEqual([2, 3, 4]); }); test('adds a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.add(-1n)].map(toBigInt)).toEqual([-1n, 0n, 1n]); expect([...lhs.add(0n)].map(toBigInt)).toEqual([0n, 1n, 2n]); expect([...lhs.add(1n)].map(toBigInt)).toEqual([1n, 2n, 3n]); expect([...lhs.add(2n)].map(toBigInt)).toEqual([2n, 3n, 4n]); }); }); describe('Series.sub', () => { test('subtracts a Series', () => { const {lhs, rhs} = makeTestData(); // lhs - lhs == [0 - 0, 1 - 1, 2 - 2] expect([...lhs.sub(lhs)].map(Number)).toEqual([0, 0, 0]); // lhs - rhs == [0 - 1, 1 - 2, 2 - 3] expect([...lhs.sub(rhs)].map(Number)).toEqual([65535, 65535, 65535]); // rhs - lhs == [1 - 0, 2 - 1, 3 - 2] expect([...rhs.sub(lhs)].map(Number)).toEqual([1, 1, 1]); }); test('subtracts a number', () => { const {lhs} = makeTestData(); expect([...lhs.sub(-1)].map(Number)).toEqual([1, 2, 3]); expect([...lhs.sub(0)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.sub(1)].map(Number)).toEqual([-1, 0, 1]); expect([...lhs.sub(2)].map(Number)).toEqual([-2, -1, 0]); }); test('subtracts a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.sub(-1n)].map(toBigInt)).toEqual([1n, 2n, 3n]); expect([...lhs.sub(0n)].map(toBigInt)).toEqual([0n, 1n, 2n]); expect([...lhs.sub(1n)].map(toBigInt)).toEqual([-1n, 0n, 1n]); expect([...lhs.sub(2n)].map(toBigInt)).toEqual([-2n, -1n, 0n]); }); }); describe('Series.mul', () => { test('multiplies against a Series', () => { const {lhs, rhs} = makeTestData(); // lhs * lhs == [0 * 0, 1 * 1, 2 * 2] expect([...lhs.mul(lhs)].map(Number)).toEqual([0, 1, 4]); // lhs * rhs == [0 * 1, 1 * 2, 2 * 3] expect([...lhs.mul(rhs)].map(Number)).toEqual([0, 2, 6]); }); test('multiplies against a number', () => { const {lhs} = makeTestData(); expect([...lhs.mul(-1)].map(Number)).toEqual([-0, -1, -2]); expect([...lhs.mul(0)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.mul(1)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.mul(2)].map(Number)).toEqual([0, 2, 4]); }); test('multiplies against a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.mul(-1n)].map(toBigInt)).toEqual([0n, -1n, -2n]); expect([...lhs.mul(0n)].map(toBigInt)).toEqual([0n, 0n, 0n]); expect([...lhs.mul(1n)].map(toBigInt)).toEqual([0n, 1n, 2n]); expect([...lhs.mul(2n)].map(toBigInt)).toEqual([0n, 2n, 4n]); }); }); describe('Series.div', () => { test('divides by a Series', () => { const {lhs, rhs} = makeTestData(); // lhs / lhs == [0/0, 1/1, 2/2] expect([...lhs.div(lhs)].map(Number)).toEqual([65535, 1, 1]); // lhs / rhs == [0/1, 1/2, 2/3] expect([...lhs.div(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('divides by a number', () => { const {lhs} = makeTestData(); expect([...lhs.div(-1)].map(Number)).toEqual([-0, -1, -2]); expect([...lhs.div(0)].map(Number)).toEqual([NaN, Infinity, Infinity]); expect([...lhs.div(1)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.div(2)].map(Number)).toEqual([0, 0.5, 1]); }); test('divides by a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.div(-1n)].map(toBigInt)).toEqual([0n, -1n, -2n]); expect([...lhs.div(0n)].map(toBigInt)).toEqual([4294967295n, 4294967295n, 4294967295n]); expect([...lhs.div(1n)].map(toBigInt)).toEqual([0n, 1n, 2n]); expect([...lhs.div(2n)].map(toBigInt)).toEqual([0n, 0n, 1n]); }); }); describe('Series.trueDiv', () => { test('trueDivides by a Series', () => { const {lhs, rhs} = makeTestData(); // lhs / lhs == [0/0, 1/1, 2/2] expect([...lhs.trueDiv(lhs)].map(Number)).toEqual([0, 1, 1]); // lhs / rhs == [0/1, 1/2, 2/3] expect([...lhs.trueDiv(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('trueDivides by a number', () => { const {lhs} = makeTestData(); expect([...lhs.trueDiv(-1)].map(Number)).toEqual([-0, -1, -2]); expect([...lhs.trueDiv(0)].map(Number)).toEqual([NaN, Infinity, Infinity]); expect([...lhs.trueDiv(1)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.trueDiv(2)].map(Number)).toEqual([0, 0.5, 1]); }); test('trueDivides by a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.trueDiv(-1n)].map(toBigInt)).toEqual([0n, -1n, -2n]); expect([...lhs.trueDiv(0n)].map(toBigInt)) .toEqual([-9223372036854775808n, 9223372036854775807n, 9223372036854775807n]); expect([...lhs.trueDiv(1n)].map(toBigInt)).toEqual([0n, 1n, 2n]); expect([...lhs.trueDiv(2n)].map(toBigInt)).toEqual([0n, 0n, 1n]); }); }); describe('Series.floorDiv', () => { test('floorDivides by a Series', () => { const {lhs, rhs} = makeTestData(); // lhs / lhs == floor([0/0, 1/1, 2/2]) expect([...lhs.floorDiv(lhs)].map(Number)).toEqual([0, 1, 1]); // lhs / rhs == floor([0/1, 1/2, 2/3]) expect([...lhs.floorDiv(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('floorDivides by a number', () => { const {lhs} = makeTestData(); expect([...lhs.floorDiv(-1)].map(Number)).toEqual([-0, -1, -2]); expect([...lhs.floorDiv(0)].map(Number)).toEqual([NaN, Infinity, Infinity]); expect([...lhs.floorDiv(1)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.floorDiv(2)].map(Number)).toEqual([0, 0, 1]); }); test('floorDivides by a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.floorDiv(-1n)].map(toBigInt)).toEqual([0n, -1n, -2n]); expect([...lhs.floorDiv(0n)].map(toBigInt)) .toEqual([-9223372036854775808n, 9223372036854775807n, 9223372036854775807n]); expect([...lhs.floorDiv(1n)].map(toBigInt)).toEqual([0n, 1n, 2n]); expect([...lhs.floorDiv(2n)].map(toBigInt)).toEqual([0n, 0n, 1n]); }); }); describe('Series.mod', () => { test('modulo by a Series', () => { const {lhs, rhs} = makeTestData(); // lhs % lhs == [0 % 0, 1 % 1, 2 % 2]) expect([...lhs.mod(lhs)].map(Number)).toEqual([65535, 0, 0]); // lhs % rhs == [0 % 1, 1 % 2, 2 % 3]) expect([...lhs.mod(rhs)].map(Number)).toEqual([0, 1, 2]); }); test('modulo by a number', () => { const {lhs} = makeTestData(); expect([...lhs.mod(-1)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.mod(0)].map(Number)).toEqual([NaN, NaN, NaN]); expect([...lhs.mod(1)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.mod(2)].map(Number)).toEqual([0, 1, 0]); }); test('modulo by a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.mod(-1n)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.mod(0n)].map(Number)).toEqual([4294967295, 4294967295, 4294967295]); expect([...lhs.mod(1n)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.mod(2n)].map(Number)).toEqual([0, 1, 0]); }); }); describe('Series.pow', () => { test('computes to the power of a Series', () => { const {lhs, rhs} = makeTestData(); // lhs ** lhs == [0 ** 0, 1 ** 1, 2 ** 2]) expect([...lhs.pow(lhs)].map(Number)).toEqual([1, 1, 4]); // lhs ** rhs == [0 ** 1, 1 ** 2, 2 ** 3]) expect([...lhs.pow(rhs)].map(Number)).toEqual([0, 1, 8]); }); test('computes to the power of a number', () => { const {lhs} = makeTestData(); expect([...lhs.pow(-1)].map(Number)).toEqual([Infinity, 1, 0.5]); expect([...lhs.pow(0)].map(Number)).toEqual([1, 1, 1]); expect([...lhs.pow(1)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.pow(2)].map(Number)).toEqual([0, 1, 4]); }); test('computes to the power of a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.pow(-1n)].map(Number)).toEqual([9223372036854776000, 1, 0]); expect([...lhs.pow(0n)].map(Number)).toEqual([1, 1, 1]); expect([...lhs.pow(1n)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.pow(2n)].map(Number)).toEqual([0, 1, 4]); }); }); describe('Series.eq', () => { test('compares against Series', () => { const {lhs, rhs} = makeTestData(); // lhs == lhs == true expect([...lhs.eq(lhs)].map(Number)).toEqual([1, 1, 1]); // lhs == rhs == false expect([...lhs.eq(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('compares against numbers', () => { const {lhs} = makeTestData(); expect([...lhs.eq(0)].map(Number)).toEqual([1, 0, 0]); expect([...lhs.eq(1)].map(Number)).toEqual([0, 1, 0]); expect([...lhs.eq(2)].map(Number)).toEqual([0, 0, 1]); }); test('compares against bigints', () => { const {lhs} = makeTestData(); expect([...lhs.eq(0n)].map(toBigInt)).toEqual([1n, 0n, 0n]); expect([...lhs.eq(1n)].map(toBigInt)).toEqual([0n, 1n, 0n]); expect([...lhs.eq(2n)].map(toBigInt)).toEqual([0n, 0n, 1n]); }); }); describe('Series.ne', () => { test('compares against Series', () => { const {lhs, rhs} = makeTestData(); // lhs != rhs == true expect([...lhs.ne(rhs)].map(Number)).toEqual([1, 1, 1]); // lhs != lhs == false expect([...lhs.ne(lhs)].map(Number)).toEqual([0, 0, 0]); }); test('compares against numbers', () => { const {lhs} = makeTestData(); expect([...lhs.ne(0)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.ne(1)].map(Number)).toEqual([1, 0, 1]); expect([...lhs.ne(2)].map(Number)).toEqual([1, 1, 0]); }); test('compares against bigints', () => { const {lhs} = makeTestData(); expect([...lhs.ne(0n)].map(toBigInt)).toEqual([0n, 1n, 1n]); expect([...lhs.ne(1n)].map(toBigInt)).toEqual([1n, 0n, 1n]); expect([...lhs.ne(2n)].map(toBigInt)).toEqual([1n, 1n, 0n]); }); }); describe('Series.lt', () => { test('compares against Series', () => { const {lhs, rhs} = makeTestData(); // lhs < rhs == true expect([...lhs.lt(rhs)].map(Number)).toEqual([1, 1, 1]); // lhs < lhs == false expect([...lhs.lt(lhs)].map(Number)).toEqual([0, 0, 0]); // rhs < lhs == false expect([...rhs.lt(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('compares against numbers', () => { const {lhs} = makeTestData(); expect([...lhs.lt(3)].map(Number)).toEqual([1, 1, 1]); expect([...lhs.lt(2)].map(Number)).toEqual([1, 1, 0]); expect([...lhs.lt(1)].map(Number)).toEqual([1, 0, 0]); expect([...lhs.lt(0)].map(Number)).toEqual([0, 0, 0]); }); test('compares against bigints', () => { const {lhs} = makeTestData(); expect([...lhs.lt(3n)].map(toBigInt)).toEqual([1n, 1n, 1n]); expect([...lhs.lt(2n)].map(toBigInt)).toEqual([1n, 1n, 0n]); expect([...lhs.lt(1n)].map(toBigInt)).toEqual([1n, 0n, 0n]); expect([...lhs.lt(0n)].map(toBigInt)).toEqual([0n, 0n, 0n]); }); }); describe('Series.le', () => { test('compares against Series', () => { const {lhs, rhs} = makeTestData(); // lhs <= lhs == true expect([...lhs.le(lhs)].map(Number)).toEqual([1, 1, 1]); // lhs <= rhs == true expect([...lhs.le(rhs)].map(Number)).toEqual([1, 1, 1]); // rhs <= lhs == false expect([...rhs.le(lhs)].map(Number)).toEqual([0, 0, 0]); }); test('compares against numbers', () => { const {lhs} = makeTestData(); expect([...lhs.le(2)].map(Number)).toEqual([1, 1, 1]); expect([...lhs.le(1)].map(Number)).toEqual([1, 1, 0]); expect([...lhs.le(0)].map(Number)).toEqual([1, 0, 0]); }); test('compares against bigints', () => { const {lhs} = makeTestData(); expect([...lhs.le(2n)].map(toBigInt)).toEqual([1n, 1n, 1n]); expect([...lhs.le(1n)].map(toBigInt)).toEqual([1n, 1n, 0n]); expect([...lhs.le(0n)].map(toBigInt)).toEqual([1n, 0n, 0n]); }); }); describe('Series.gt', () => { test('compares against Series', () => { const {lhs, rhs} = makeTestData(); // rhs > lhs == true expect([...rhs.gt(lhs)].map(Number)).toEqual([1, 1, 1]); // lhs > rhs == false expect([...lhs.gt(rhs)].map(Number)).toEqual([0, 0, 0]); // lhs > lhs == false expect([...lhs.gt(lhs)].map(Number)).toEqual([0, 0, 0]); }); test('compares against numbers', () => { const {lhs} = makeTestData(); expect([...lhs.gt(2)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.gt(1)].map(Number)).toEqual([0, 0, 1]); expect([...lhs.gt(0)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.gt(-1)].map(Number)).toEqual([1, 1, 1]); }); test('compares against bigints', () => { const {lhs} = makeTestData(); expect([...lhs.gt(2n)].map(toBigInt)).toEqual([0n, 0n, 0n]); expect([...lhs.gt(1n)].map(toBigInt)).toEqual([0n, 0n, 1n]); expect([...lhs.gt(0n)].map(toBigInt)).toEqual([0n, 1n, 1n]); expect([...lhs.gt(-1n)].map(toBigInt)).toEqual([1n, 1n, 1n]); }); }); describe('Series.ge', () => { test('compares against Series', () => { const {lhs, rhs} = makeTestData(); // lhs >= lhs == true expect([...lhs.ge(lhs)].map(Number)).toEqual([1, 1, 1]); // lhs >= rhs == false expect([...lhs.ge(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('compares against numbers', () => { const {lhs} = makeTestData(); expect([...lhs.ge(3)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.ge(2)].map(Number)).toEqual([0, 0, 1]); expect([...lhs.ge(1)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.ge(0)].map(Number)).toEqual([1, 1, 1]); }); test('compares against bigints', () => { const {lhs} = makeTestData(); expect([...lhs.ge(3n)].map(toBigInt)).toEqual([0n, 0n, 0n]); expect([...lhs.ge(2n)].map(toBigInt)).toEqual([0n, 0n, 1n]); expect([...lhs.ge(1n)].map(toBigInt)).toEqual([0n, 1n, 1n]); expect([...lhs.ge(0n)].map(toBigInt)).toEqual([1n, 1n, 1n]); }); }); describe('Series.bitwiseAnd', () => { test('bitwiseAnd with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs ** lhs == [0 & 0, 1 & 1, 2 & 2]) expect([...lhs.bitwiseAnd(lhs)].map(Number)).toEqual([0, 1, 2]); // lhs ** rhs == [0 & 1, 1 & 2, 2 & 3]) expect([...lhs.bitwiseAnd(rhs)].map(Number)).toEqual([0, 0, 2]); }); test('bitwiseAnd with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.bitwiseAnd(-1)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.bitwiseAnd(0)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.bitwiseAnd(1)].map(Number)).toEqual([0, 1, 0]); expect([...lhs.bitwiseAnd(2)].map(Number)).toEqual([0, 0, 2]); }); test('bitwiseAnd with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.bitwiseAnd(-1n)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.bitwiseAnd(0n)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.bitwiseAnd(1n)].map(Number)).toEqual([0, 1, 0]); expect([...lhs.bitwiseAnd(2n)].map(Number)).toEqual([0, 0, 2]); }); }); describe('Series.bitwiseOr', () => { test('bitwiseOr with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs | lhs == [0 | 0, 1 | 1, 2 | 2]) expect([...lhs.bitwiseOr(lhs)].map(Number)).toEqual([0, 1, 2]); // lhs | rhs == [0 | 1, 1 | 2, 2 | 3]) expect([...lhs.bitwiseOr(rhs)].map(Number)).toEqual([1, 3, 3]); }); test('bitwiseOr with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.bitwiseOr(-1)].map(Number)).toEqual([65535, 65535, 65535]); expect([...lhs.bitwiseOr(0)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.bitwiseOr(1)].map(Number)).toEqual([1, 1, 3]); expect([...lhs.bitwiseOr(2)].map(Number)).toEqual([2, 3, 2]); }); test('bitwiseOr with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.bitwiseOr(-1n)].map(Number)).toEqual([65535, 65535, 65535]); expect([...lhs.bitwiseOr(0n)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.bitwiseOr(1n)].map(Number)).toEqual([1, 1, 3]); expect([...lhs.bitwiseOr(2n)].map(Number)).toEqual([2, 3, 2]); }); }); describe('Series.bitwiseXor', () => { test('bitwiseXor with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs ^ lhs == [0 ^ 0, 1 ^ 1, 2 ^ 2]) expect([...lhs.bitwiseXor(lhs)].map(Number)).toEqual([0, 0, 0]); // lhs ^ rhs == [0 ^ 1, 1 ^ 2, 2 ^ 3]) expect([...lhs.bitwiseXor(rhs)].map(Number)).toEqual([1, 3, 1]); }); test('bitwiseXor with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.bitwiseXor(-1)].map(Number)).toEqual([65535, 65534, 65533]); expect([...lhs.bitwiseXor(0)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.bitwiseXor(1)].map(Number)).toEqual([1, 0, 3]); expect([...lhs.bitwiseXor(2)].map(Number)).toEqual([2, 3, 0]); }); test('bitwiseXor with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.bitwiseXor(-1n)].map(Number)).toEqual([65535, 65534, 65533]); expect([...lhs.bitwiseXor(0n)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.bitwiseXor(1n)].map(Number)).toEqual([1, 0, 3]); expect([...lhs.bitwiseXor(2n)].map(Number)).toEqual([2, 3, 0]); }); }); describe('Series.logicalAnd', () => { test('logicalAnd with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs && lhs == [0 && 0, 1 && 1, 2 && 2]) expect([...lhs.logicalAnd(lhs)].map(Number)).toEqual([0, 1, 1]); // lhs && rhs == [0 && 1, 1 && 2, 2 && 3]) expect([...lhs.logicalAnd(rhs)].map(Number)).toEqual([0, 1, 1]); }); test('logicalAnd with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.logicalAnd(-1)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.logicalAnd(0)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.logicalAnd(1)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.logicalAnd(2)].map(Number)).toEqual([0, 1, 1]); }); test('logicalAnd with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.logicalAnd(-1n)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.logicalAnd(0n)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.logicalAnd(1n)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.logicalAnd(2n)].map(Number)).toEqual([0, 1, 1]); }); }); describe('Series.logicalOr', () => { test('logicalOr with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs || lhs == [0 || 0, 1 || 1, 2 || 2]) expect([...lhs.logicalOr(lhs)].map(Number)).toEqual([0, 1, 1]); // lhs || rhs == [0 || 1, 1 || 2, 2 || 3]) expect([...lhs.logicalOr(rhs)].map(Number)).toEqual([1, 1, 1]); }); test('logicalOr with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.logicalOr(-1)].map(Number)).toEqual([1, 1, 1]); expect([...lhs.logicalOr(0)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.logicalOr(1)].map(Number)).toEqual([1, 1, 1]); expect([...lhs.logicalOr(2)].map(Number)).toEqual([1, 1, 1]); }); test('logicalOr with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.logicalOr(-1n)].map(Number)).toEqual([1, 1, 1]); expect([...lhs.logicalOr(0n)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.logicalOr(1n)].map(Number)).toEqual([1, 1, 1]); expect([...lhs.logicalOr(2n)].map(Number)).toEqual([1, 1, 1]); }); }); describe('Series.shiftLeft', () => { test('shiftLeft with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs || lhs == [0 || 0, 1 || 1, 2 || 2]) expect([...lhs.shiftLeft(lhs)].map(Number)).toEqual([0, 2, 8]); // lhs || rhs == [0 || 1, 1 || 2, 2 || 3]) expect([...lhs.shiftLeft(rhs)].map(Number)).toEqual([0, 4, 16]); }); test('shiftLeft with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.shiftLeft(-1)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.shiftLeft(0)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.shiftLeft(1)].map(Number)).toEqual([0, 2, 4]); expect([...lhs.shiftLeft(2)].map(Number)).toEqual([0, 4, 8]); }); test('shiftLeft with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.shiftLeft(-1n)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.shiftLeft(0n)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.shiftLeft(1n)].map(Number)).toEqual([0, 2, 4]); expect([...lhs.shiftLeft(2n)].map(Number)).toEqual([0, 4, 8]); }); }); describe('Series.shiftRight', () => { test('shiftRight with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs || lhs == [0 || 0, 1 || 1, 2 || 2]) expect([...lhs.shiftRight(lhs)].map(Number)).toEqual([0, 0, 0]); // lhs || rhs == [0 || 1, 1 || 2, 2 || 3]) expect([...lhs.shiftRight(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('shiftRight with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.shiftRight(-1)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.shiftRight(0)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.shiftRight(1)].map(Number)).toEqual([0, 0, 1]); expect([...lhs.shiftRight(2)].map(Number)).toEqual([0, 0, 0]); }); test('shiftRight with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.shiftRight(-1n)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.shiftRight(0n)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.shiftRight(1n)].map(Number)).toEqual([0, 0, 1]); expect([...lhs.shiftRight(2n)].map(Number)).toEqual([0, 0, 0]); }); }); describe('Series.shiftRightUnsigned', () => { test('shiftRightUnsigned with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs || lhs == [0 || 0, 1 || 1, 2 || 2]) expect([...lhs.shiftRightUnsigned(lhs)].map(Number)).toEqual([0, 0, 0]); // lhs || rhs == [0 || 1, 1 || 2, 2 || 3]) expect([...lhs.shiftRightUnsigned(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('shiftRightUnsigned with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.shiftRightUnsigned(-1)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.shiftRightUnsigned(0)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.shiftRightUnsigned(1)].map(Number)).toEqual([0, 0, 1]); expect([...lhs.shiftRightUnsigned(2)].map(Number)).toEqual([0, 0, 0]); }); test('shiftRightUnsigned with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.shiftRightUnsigned(-1n)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.shiftRightUnsigned(0n)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.shiftRightUnsigned(1n)].map(Number)).toEqual([0, 0, 1]); expect([...lhs.shiftRightUnsigned(2n)].map(Number)).toEqual([0, 0, 0]); }); }); describe('Series.logBase', () => { test('logBase with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs || lhs == [0 || 0, 1 || 1, 2 || 2]) expect([...lhs.logBase(lhs)].map(Number)).toEqual([0, 0, 1]); // lhs || rhs == [0 || 1, 1 || 2, 2 || 3]) expect([...lhs.logBase(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('logBase with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.logBase(-1)].map(Number)).toEqual([NaN, NaN, NaN]); expect([...lhs.logBase(0)].map(Number)).toEqual([NaN, -0, -0]); expect([...lhs.logBase(1)].map(Number)).toEqual([-Infinity, NaN, Infinity]); expect([...lhs.logBase(2)].map(Number)).toEqual([-Infinity, 0, 1]); }); test('logBase with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.logBase(-1n)].map(Number)) .toEqual([-9223372036854776000, -9223372036854776000, -9223372036854776000]); expect([...lhs.logBase(0n)].map(Number)).toEqual([-9223372036854776000, 0, 0]); expect([...lhs.logBase(1n)].map(Number)) .toEqual([-9223372036854776000, -9223372036854776000, 9223372036854776000]); expect([...lhs.logBase(2n)].map(Number)).toEqual([-9223372036854776000, 0, 1]); }); }); describe('Series.atan2', () => { test('atan2 with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs || lhs == [0 || 0, 1 || 1, 2 || 2]) expect([...lhs.atan2(lhs)].map(Number)).toEqual([0, 0, 0]); // lhs || rhs == [0 || 1, 1 || 2, 2 || 3]) expect([...lhs.atan2(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('atan2 with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.atan2(-1)].map(Number)) .toEqual([3.141592653589793, 2.356194490192345, 2.0344439357957027]); expect([...lhs.atan2(0)].map(Number)).toEqual([0, 1.5707963267948966, 1.5707963267948966]); expect([...lhs.atan2(1)].map(Number)).toEqual([0, 0.7853981633974483, 1.1071487177940904]); expect([...lhs.atan2(2)].map(Number)).toEqual([0, 0.46364760900080615, 0.7853981633974483]); }); test('atan2 with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.atan2(-1n)].map(Number)).toEqual([3, 2, 2]); expect([...lhs.atan2(0n)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.atan2(1n)].map(Number)).toEqual([0, 0, 1]); expect([...lhs.atan2(2n)].map(Number)).toEqual([0, 0, 0]); }); }); describe('Series.nullEquals', () => { test('nullEquals with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs || lhs == [0 || 0, 1 || 1, 2 || 2]) expect([...lhs.nullEquals(lhs)].map(Number)).toEqual([1, 1, 1]); // lhs || rhs == [0 || 1, 1 || 2, 2 || 3]) expect([...lhs.nullEquals(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('nullEquals with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.nullEquals(-1)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.nullEquals(0)].map(Number)).toEqual([1, 0, 0]); expect([...lhs.nullEquals(1)].map(Number)).toEqual([0, 1, 0]); expect([...lhs.nullEquals(2)].map(Number)).toEqual([0, 0, 1]); }); test('nullEquals with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.nullEquals(-1n)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.nullEquals(0n)].map(Number)).toEqual([1, 0, 0]); expect([...lhs.nullEquals(1n)].map(Number)).toEqual([0, 1, 0]); expect([...lhs.nullEquals(2n)].map(Number)).toEqual([0, 0, 1]); }); }); describe('Series.nullMax', () => { test('nullMax with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs || lhs == [0 || 0, 1 || 1, 2 || 2]) expect([...lhs.nullMax(lhs)].map(Number)).toEqual([0, 1, 2]); // lhs || rhs == [0 || 1, 1 || 2, 2 || 3]) expect([...lhs.nullMax(rhs)].map(Number)).toEqual([1, 2, 3]); }); test('nullMax with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.nullMax(-1)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.nullMax(0)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.nullMax(1)].map(Number)).toEqual([1, 1, 2]); expect([...lhs.nullMax(2)].map(Number)).toEqual([2, 2, 2]); }); test('nullMax with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.nullMax(-1n)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.nullMax(0n)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.nullMax(1n)].map(Number)).toEqual([1, 1, 2]); expect([...lhs.nullMax(2n)].map(Number)).toEqual([2, 2, 2]); }); }); describe('Series.nullMin', () => { test('nullMin with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs || lhs == [0 || 0, 1 || 1, 2 || 2]) expect([...lhs.nullMin(lhs)].map(Number)).toEqual([0, 1, 2]); // lhs || rhs == [0 || 1, 1 || 2, 2 || 3]) expect([...lhs.nullMin(rhs)].map(Number)).toEqual([0, 1, 2]); }); test('nullMin with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.nullMin(-1)].map(Number)).toEqual([-1, -1, -1]); expect([...lhs.nullMin(0)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.nullMin(1)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.nullMin(2)].map(Number)).toEqual([0, 1, 2]); }); test('nullMin with a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.nullMin(-1n)].map(Number)).toEqual([-1, -1, -1]); expect([...lhs.nullMin(0n)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.nullMin(1n)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.nullMin(2n)].map(Number)).toEqual([0, 1, 2]); }); }); });
0
rapidsai_public_repos/node/modules/cudf/test/series
rapidsai_public_repos/node/modules/cudf/test/series/binaryop/float64-tests.ts
// Copyright (c) 2021, NVIDIA CORPORATION. // // 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. import {setDefaultAllocator} from '@rapidsai/cuda'; import {DeviceBuffer} from '@rapidsai/rmm'; import * as arrow from 'apache-arrow'; import {makeTestNumbers, makeTestSeries} from '../utils'; setDefaultAllocator((byteLength: number) => new DeviceBuffer(byteLength)); const makeTestData = (values?: (number|null)[]) => makeTestSeries(new arrow.Float64, makeTestNumbers(values)); describe('Series binaryops (Float64)', () => { describe('Series.add', () => { test('adds a Series', () => { const {lhs, rhs} = makeTestData(); // lhs + lhs == [0 + 0, 1 + 1, 2 + 2] expect([...lhs.add(lhs)].map(Number)).toEqual([0, 2, 4]); // lhs + rhs == [0 + 1, 1 + 2, 2 + 3] expect([...lhs.add(rhs)].map(Number)).toEqual([1, 3, 5]); }); test('adds a number', () => { const {lhs} = makeTestData(); expect([...lhs.add(-1)].map(Number)).toEqual([-1, 0, 1]); expect([...lhs.add(0)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.add(1)].map(Number)).toEqual([1, 2, 3]); expect([...lhs.add(2)].map(Number)).toEqual([2, 3, 4]); }); test('adds a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.add(-1n)].map(Number)).toEqual([-1, 0, 1]); expect([...lhs.add(0n)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.add(1n)].map(Number)).toEqual([1, 2, 3]); expect([...lhs.add(2n)].map(Number)).toEqual([2, 3, 4]); }); }); describe('Series.sub', () => { test('subtracts a Series', () => { const {lhs, rhs} = makeTestData(); // lhs - lhs == [0 - 0, 1 - 1, 2 - 2] expect([...lhs.sub(lhs)].map(Number)).toEqual([0, 0, 0]); // lhs - rhs == [0 - 1, 1 - 2, 2 - 3] expect([...lhs.sub(rhs)].map(Number)).toEqual([-1, -1, -1]); // rhs - lhs == [1 - 0, 2 - 1, 3 - 2] expect([...rhs.sub(lhs)].map(Number)).toEqual([1, 1, 1]); }); test('subtracts a number', () => { const {lhs} = makeTestData(); expect([...lhs.sub(-1)].map(Number)).toEqual([1, 2, 3]); expect([...lhs.sub(0)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.sub(1)].map(Number)).toEqual([-1, 0, 1]); expect([...lhs.sub(2)].map(Number)).toEqual([-2, -1, 0]); }); test('subtracts a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.sub(-1n)].map(Number)).toEqual([1, 2, 3]); expect([...lhs.sub(0n)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.sub(1n)].map(Number)).toEqual([-1, 0, 1]); expect([...lhs.sub(2n)].map(Number)).toEqual([-2, -1, 0]); }); }); describe('Series.mul', () => { test('multiplies against a Series', () => { const {lhs, rhs} = makeTestData(); // lhs * lhs == [0 * 0, 1 * 1, 2 * 2] expect([...lhs.mul(lhs)].map(Number)).toEqual([0, 1, 4]); // lhs * rhs == [0 * 1, 1 * 2, 2 * 3] expect([...lhs.mul(rhs)].map(Number)).toEqual([0, 2, 6]); }); test('multiplies against a number', () => { const {lhs} = makeTestData(); expect([...lhs.mul(-1)].map(Number)).toEqual([-0, -1, -2]); expect([...lhs.mul(0)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.mul(1)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.mul(2)].map(Number)).toEqual([0, 2, 4]); }); test('multiplies against a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.mul(-1n)].map(Number)).toEqual([-0, -1, -2]); expect([...lhs.mul(0n)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.mul(1n)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.mul(2n)].map(Number)).toEqual([0, 2, 4]); }); }); describe('Series.div', () => { test('divides by a Series', () => { const {lhs, rhs} = makeTestData(); // lhs / lhs == [0/0, 1/1, 2/2] expect([...lhs.div(lhs)].map(Number)).toEqual([NaN, 1, 1]); // lhs / rhs == [0/1, 1/2, 2/3] expect([...lhs.div(rhs)].map(Number)).toEqual([0, 0.5, 0.6666666666666666]); }); test('divides by a number', () => { const {lhs} = makeTestData(); expect([...lhs.div(-1)].map(Number)).toEqual([-0, -1, -2]); expect([...lhs.div(0)].map(Number)).toEqual([NaN, Infinity, Infinity]); expect([...lhs.div(1)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.div(2)].map(Number)).toEqual([0, 0.5, 1]); }); test('divides by a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.div(-1n)].map(Number)).toEqual([-0, -1, -2]); expect([...lhs.div(0n)].map(Number)).toEqual([NaN, Infinity, Infinity]); expect([...lhs.div(1n)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.div(2n)].map(Number)).toEqual([0, 0.5, 1]); }); }); describe('Series.trueDiv', () => { test('trueDivides by a Series', () => { const {lhs, rhs} = makeTestData(); // lhs / lhs == [0/0, 1/1, 2/2] expect([...lhs.trueDiv(lhs)].map(Number)).toEqual([NaN, 1, 1]); // lhs / rhs == [0/1, 1/2, 2/3] expect([...lhs.trueDiv(rhs)].map(Number)).toEqual([0, 0.5, 0.6666666666666666]); }); test('trueDivides by a number', () => { const {lhs} = makeTestData(); expect([...lhs.trueDiv(-1)].map(Number)).toEqual([-0, -1, -2]); expect([...lhs.trueDiv(0)].map(Number)).toEqual([NaN, Infinity, Infinity]); expect([...lhs.trueDiv(1)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.trueDiv(2)].map(Number)).toEqual([0, 0.5, 1]); }); test('trueDivides by a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.trueDiv(-1n)].map(Number)).toEqual([-0, -1, -2]); expect([...lhs.trueDiv(0n)].map(Number)).toEqual([NaN, Infinity, Infinity]); expect([...lhs.trueDiv(1n)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.trueDiv(2n)].map(Number)).toEqual([0, 0.5, 1]); }); }); describe('Series.floorDiv', () => { test('floorDivides by a Series', () => { const {lhs, rhs} = makeTestData(); // lhs / lhs == floor([0/0, 1/1, 2/2]) expect([...lhs.floorDiv(lhs)].map(Number)).toEqual([NaN, 1, 1]); // lhs / rhs == floor([0/1, 1/2, 2/3]) expect([...lhs.floorDiv(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('floorDivides by a number', () => { const {lhs} = makeTestData(); expect([...lhs.floorDiv(-1)].map(Number)).toEqual([-0, -1, -2]); expect([...lhs.floorDiv(0)].map(Number)).toEqual([NaN, Infinity, Infinity]); expect([...lhs.floorDiv(1)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.floorDiv(2)].map(Number)).toEqual([0, 0, 1]); }); test('floorDivides by a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.floorDiv(-1n)].map(Number)).toEqual([-0, -1, -2]); expect([...lhs.floorDiv(0n)].map(Number)).toEqual([NaN, Infinity, Infinity]); expect([...lhs.floorDiv(1n)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.floorDiv(2n)].map(Number)).toEqual([0, 0, 1]); }); }); describe('Series.mod', () => { test('modulo by a Series', () => { const {lhs, rhs} = makeTestData(); // lhs % lhs == [0 % 0, 1 % 1, 2 % 2]) expect([...lhs.mod(lhs)].map(Number)).toEqual([NaN, 0, 0]); // lhs % rhs == [0 % 1, 1 % 2, 2 % 3]) expect([...lhs.mod(rhs)].map(Number)).toEqual([0, 1, 2]); }); test('modulo by a number', () => { const {lhs} = makeTestData(); expect([...lhs.mod(-1)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.mod(0)].map(Number)).toEqual([NaN, NaN, NaN]); expect([...lhs.mod(1)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.mod(2)].map(Number)).toEqual([0, 1, 0]); }); test('modulo by a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.mod(-1n)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.mod(0n)].map(Number)).toEqual([NaN, NaN, NaN]); expect([...lhs.mod(1n)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.mod(2n)].map(Number)).toEqual([0, 1, 0]); }); }); describe('Series.pow', () => { test('computes to the power of a Series', () => { const {lhs, rhs} = makeTestData(); // lhs ** lhs == [0 ** 0, 1 ** 1, 2 ** 2]) expect([...lhs.pow(lhs)].map(Number)).toEqual([1, 1, 4]); // lhs ** rhs == [0 ** 1, 1 ** 2, 2 ** 3]) expect([...lhs.pow(rhs)].map(Number)).toEqual([0, 1, 8]); }); test('computes to the power of a number', () => { const {lhs} = makeTestData(); expect([...lhs.pow(-1)].map(Number)).toEqual([Infinity, 1, 0.5]); expect([...lhs.pow(0)].map(Number)).toEqual([1, 1, 1]); expect([...lhs.pow(1)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.pow(2)].map(Number)).toEqual([0, 1, 4]); }); test('computes to the power of a bigint', () => { const {lhs} = makeTestData(); expect([...lhs.pow(-1n)].map(Number)).toEqual([Infinity, 1, 0.5]); expect([...lhs.pow(0n)].map(Number)).toEqual([1, 1, 1]); expect([...lhs.pow(1n)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.pow(2n)].map(Number)).toEqual([0, 1, 4]); }); }); describe('Series.eq', () => { test('compares against Series', () => { const {lhs, rhs} = makeTestData(); // lhs == lhs == true expect([...lhs.eq(lhs)].map(Number)).toEqual([1, 1, 1]); // lhs == rhs == false expect([...lhs.eq(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('compares against numbers', () => { const {lhs} = makeTestData(); expect([...lhs.eq(0)].map(Number)).toEqual([1, 0, 0]); expect([...lhs.eq(1)].map(Number)).toEqual([0, 1, 0]); expect([...lhs.eq(2)].map(Number)).toEqual([0, 0, 1]); }); test('compares against bigints', () => { const {lhs} = makeTestData(); expect([...lhs.eq(0n)].map(Number)).toEqual([1, 0, 0]); expect([...lhs.eq(1n)].map(Number)).toEqual([0, 1, 0]); expect([...lhs.eq(2n)].map(Number)).toEqual([0, 0, 1]); }); }); describe('Series.ne', () => { test('compares against Series', () => { const {lhs, rhs} = makeTestData(); // lhs != rhs == true expect([...lhs.ne(rhs)].map(Number)).toEqual([1, 1, 1]); // lhs != lhs == false expect([...lhs.ne(lhs)].map(Number)).toEqual([0, 0, 0]); }); test('compares against numbers', () => { const {lhs} = makeTestData(); expect([...lhs.ne(0)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.ne(1)].map(Number)).toEqual([1, 0, 1]); expect([...lhs.ne(2)].map(Number)).toEqual([1, 1, 0]); }); test('compares against bigints', () => { const {lhs} = makeTestData(); expect([...lhs.ne(0n)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.ne(1n)].map(Number)).toEqual([1, 0, 1]); expect([...lhs.ne(2n)].map(Number)).toEqual([1, 1, 0]); }); }); describe('Series.lt', () => { test('compares against Series', () => { const {lhs, rhs} = makeTestData(); // lhs < rhs == true expect([...lhs.lt(rhs)].map(Number)).toEqual([1, 1, 1]); // lhs < lhs == false expect([...lhs.lt(lhs)].map(Number)).toEqual([0, 0, 0]); // rhs < lhs == false expect([...rhs.lt(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('compares against numbers', () => { const {lhs} = makeTestData(); expect([...lhs.lt(3)].map(Number)).toEqual([1, 1, 1]); expect([...lhs.lt(2)].map(Number)).toEqual([1, 1, 0]); expect([...lhs.lt(1)].map(Number)).toEqual([1, 0, 0]); expect([...lhs.lt(0)].map(Number)).toEqual([0, 0, 0]); }); test('compares against bigints', () => { const {lhs} = makeTestData(); expect([...lhs.lt(3n)].map(Number)).toEqual([1, 1, 1]); expect([...lhs.lt(2n)].map(Number)).toEqual([1, 1, 0]); expect([...lhs.lt(1n)].map(Number)).toEqual([1, 0, 0]); expect([...lhs.lt(0n)].map(Number)).toEqual([0, 0, 0]); }); }); describe('Series.le', () => { test('compares against Series', () => { const {lhs, rhs} = makeTestData(); // lhs <= lhs == true expect([...lhs.le(lhs)].map(Number)).toEqual([1, 1, 1]); // lhs <= rhs == true expect([...lhs.le(rhs)].map(Number)).toEqual([1, 1, 1]); // rhs <= lhs == false expect([...rhs.le(lhs)].map(Number)).toEqual([0, 0, 0]); }); test('compares against numbers', () => { const {lhs} = makeTestData(); expect([...lhs.le(2)].map(Number)).toEqual([1, 1, 1]); expect([...lhs.le(1)].map(Number)).toEqual([1, 1, 0]); expect([...lhs.le(0)].map(Number)).toEqual([1, 0, 0]); }); test('compares against bigints', () => { const {lhs} = makeTestData(); expect([...lhs.le(2n)].map(Number)).toEqual([1, 1, 1]); expect([...lhs.le(1n)].map(Number)).toEqual([1, 1, 0]); expect([...lhs.le(0n)].map(Number)).toEqual([1, 0, 0]); }); }); describe('Series.gt', () => { test('compares against Series', () => { const {lhs, rhs} = makeTestData(); // rhs > lhs == true expect([...rhs.gt(lhs)].map(Number)).toEqual([1, 1, 1]); // lhs > rhs == false expect([...lhs.gt(rhs)].map(Number)).toEqual([0, 0, 0]); // lhs > lhs == false expect([...lhs.gt(lhs)].map(Number)).toEqual([0, 0, 0]); }); test('compares against numbers', () => { const {lhs} = makeTestData(); expect([...lhs.gt(2)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.gt(1)].map(Number)).toEqual([0, 0, 1]); expect([...lhs.gt(0)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.gt(-1)].map(Number)).toEqual([1, 1, 1]); }); test('compares against bigints', () => { const {lhs} = makeTestData(); expect([...lhs.gt(2n)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.gt(1n)].map(Number)).toEqual([0, 0, 1]); expect([...lhs.gt(0n)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.gt(-1n)].map(Number)).toEqual([1, 1, 1]); }); }); describe('Series.ge', () => { test('compares against Series', () => { const {lhs, rhs} = makeTestData(); // lhs >= lhs == true expect([...lhs.ge(lhs)].map(Number)).toEqual([1, 1, 1]); // lhs >= rhs == false expect([...lhs.ge(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('compares against numbers', () => { const {lhs} = makeTestData(); expect([...lhs.ge(3)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.ge(2)].map(Number)).toEqual([0, 0, 1]); expect([...lhs.ge(1)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.ge(0)].map(Number)).toEqual([1, 1, 1]); }); test('compares against bigints', () => { const {lhs} = makeTestData(); expect([...lhs.ge(3n)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.ge(2n)].map(Number)).toEqual([0, 0, 1]); expect([...lhs.ge(1n)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.ge(0n)].map(Number)).toEqual([1, 1, 1]); }); }); describe('Series.logicalAnd', () => { test('logicalAnd with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs && lhs == [0 && 0, 1 && 1, 2 && 2]) expect([...lhs.logicalAnd(lhs)].map(Number)).toEqual([0, 1, 1]); // lhs && rhs == [0 && 1, 1 && 2, 2 && 3]) expect([...lhs.logicalAnd(rhs)].map(Number)).toEqual([0, 1, 1]); }); test('logicalAnd with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.logicalAnd(-1)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.logicalAnd(0)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.logicalAnd(1)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.logicalAnd(2)].map(Number)).toEqual([0, 1, 1]); }); }); describe('Series.logicalOr', () => { test('logicalOr with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs || lhs == [0 || 0, 1 || 1, 2 || 2]) expect([...lhs.logicalOr(lhs)].map(Number)).toEqual([0, 1, 1]); // lhs || rhs == [0 || 1, 1 || 2, 2 || 3]) expect([...lhs.logicalOr(rhs)].map(Number)).toEqual([1, 1, 1]); }); test('logicalOr with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.logicalOr(-1)].map(Number)).toEqual([1, 1, 1]); expect([...lhs.logicalOr(0)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.logicalOr(1)].map(Number)).toEqual([1, 1, 1]); expect([...lhs.logicalOr(2)].map(Number)).toEqual([1, 1, 1]); }); }); describe('Series.logBase', () => { test('logBase with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs || lhs == [0 || 0, 1 || 1, 2 || 2]) expect([...lhs.logBase(lhs)].map(Number)).toEqual([NaN, NaN, 1]); // lhs || rhs == [0 || 1, 1 || 2, 2 || 3]) expect([...lhs.logBase(rhs)].map(Number)).toEqual([-Infinity, 0, 0.6309297535714574]); }); test('logBase with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.logBase(-1)].map(Number)).toEqual([NaN, NaN, NaN]); expect([...lhs.logBase(0)].map(Number)).toEqual([NaN, -0, -0]); expect([...lhs.logBase(1)].map(Number)).toEqual([-Infinity, NaN, Infinity]); expect([...lhs.logBase(2)].map(Number)).toEqual([-Infinity, 0, 1]); }); }); describe('Series.atan2', () => { test('atan2 with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs || lhs == [0 || 0, 1 || 1, 2 || 2]) expect([...lhs.atan2(lhs)].map(Number)).toEqual([0, 0.7853981633974483, 0.7853981633974483]); // lhs || rhs == [0 || 1, 1 || 2, 2 || 3]) expect([...lhs.atan2(rhs)].map(Number)).toEqual([0, 0.46364760900080615, 0.5880026035475675]); }); test('atan2 with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.atan2(-1)].map(Number)) .toEqual([3.141592653589793, 2.356194490192345, 2.0344439357957027]); expect([...lhs.atan2(0)].map(Number)).toEqual([0, 1.5707963267948966, 1.5707963267948966]); expect([...lhs.atan2(1)].map(Number)).toEqual([0, 0.7853981633974483, 1.1071487177940904]); expect([...lhs.atan2(2)].map(Number)).toEqual([0, 0.46364760900080615, 0.7853981633974483]); }); }); describe('Series.nullEquals', () => { test('nullEquals with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs || lhs == [0 || 0, 1 || 1, 2 || 2]) expect([...lhs.nullEquals(lhs)].map(Number)).toEqual([1, 1, 1]); // lhs || rhs == [0 || 1, 1 || 2, 2 || 3]) expect([...lhs.nullEquals(rhs)].map(Number)).toEqual([0, 0, 0]); }); test('nullEquals with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.nullEquals(-1)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.nullEquals(0)].map(Number)).toEqual([1, 0, 0]); expect([...lhs.nullEquals(1)].map(Number)).toEqual([0, 1, 0]); expect([...lhs.nullEquals(2)].map(Number)).toEqual([0, 0, 1]); }); }); describe('Series.nullMax', () => { test('nullMax with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs || lhs == [0 || 0, 1 || 1, 2 || 2]) expect([...lhs.nullMax(lhs)].map(Number)).toEqual([0, 1, 2]); // lhs || rhs == [0 || 1, 1 || 2, 2 || 3]) expect([...lhs.nullMax(rhs)].map(Number)).toEqual([1, 2, 3]); }); test('nullMax with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.nullMax(-1)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.nullMax(0)].map(Number)).toEqual([0, 1, 2]); expect([...lhs.nullMax(1)].map(Number)).toEqual([1, 1, 2]); expect([...lhs.nullMax(2)].map(Number)).toEqual([2, 2, 2]); }); }); describe('Series.nullMin', () => { test('nullMin with a Series', () => { const {lhs, rhs} = makeTestData(); // lhs || lhs == [0 || 0, 1 || 1, 2 || 2]) expect([...lhs.nullMin(lhs)].map(Number)).toEqual([0, 1, 2]); // lhs || rhs == [0 || 1, 1 || 2, 2 || 3]) expect([...lhs.nullMin(rhs)].map(Number)).toEqual([0, 1, 2]); }); test('nullMin with a scalar', () => { const {lhs} = makeTestData(); expect([...lhs.nullMin(-1)].map(Number)).toEqual([-1, -1, -1]); expect([...lhs.nullMin(0)].map(Number)).toEqual([0, 0, 0]); expect([...lhs.nullMin(1)].map(Number)).toEqual([0, 1, 1]); expect([...lhs.nullMin(2)].map(Number)).toEqual([0, 1, 2]); }); }); });
0
rapidsai_public_repos/node/modules/cudf/test/series
rapidsai_public_repos/node/modules/cudf/test/series/unaryop/float32-tests.ts
// Copyright (c) 2021, NVIDIA CORPORATION. // // 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. import '../../jest-extensions'; import {BigIntArray, setDefaultAllocator, TypedArray, TypedArrayConstructor} from '@rapidsai/cuda'; import {Numeric, Utf8String} from '@rapidsai/cudf'; import {DeviceBuffer} from '@rapidsai/rmm'; import * as arrow from 'apache-arrow'; import { clampFloatValuesLikeUnaryCast, makeTestNumbers, makeTestSeries, MathematicalUnaryOp, mathematicalUnaryOps, testForEachNumericType } from '../utils'; setDefaultAllocator((byteLength: number) => new DeviceBuffer(byteLength)); const makeTestData = (values?: (number|null)[]) => makeTestSeries(new arrow.Float32, makeTestNumbers(values)).lhs; describe('Series unaryops (Float32)', () => { const testMathematicalOp = <P extends MathematicalUnaryOp>(unaryMathOp: P) => { test(`Series.${unaryMathOp}`, () => { const values = [-2.5, 0, 2.5]; const actual = makeTestData(values)[unaryMathOp]().data.toArray(); const expected = new Float32Array(values).map(x => Math[unaryMathOp](x)); expect(actual).toEqualTypedArray(expected); }); }; for (const op of mathematicalUnaryOps) { testMathematicalOp(op); } test('Series.not', () => { const actual = makeTestData([-2.5, 0, 2.5]).not(); expect([...actual]).toEqual([-2.5, 0, 2.5].map((x) => !x)); }); test('Series.isNull', () => { const actual = makeTestData([null, 2.5, 5]).isNull(); expect([...actual]).toEqual([true, false, false]); }); test('Series.isNotNull', () => { const actual = makeTestData([null, 2.5, 5]).isNotNull(); expect([...actual]).toEqual([false, true, true]); }); test('Series.isNaN', () => { const actual = makeTestData([NaN, 2.5, 5]).isNaN(); expect([...actual]).toEqual([true, false, false]); }); test('Series.isNotNaN', () => { const actual = makeTestData([NaN, 2.5, 5]).isNotNaN(); expect([...actual]).toEqual([false, true, true]); }); test('Series.nansToNulls', () => { const actual = makeTestData([NaN, 2.5, 5]).nansToNulls(); expect([...actual]).toEqual([null, 2.5, 5]); }); test('Series.rint', () => { const actual = makeTestData([NaN, 2.5, 5]).rint(); expect([...actual]).toEqual([NaN, 2, 5]); }); test('Series.cast Utf8String', () => { const actual = makeTestData([NaN, 2, 2.5]); expect([...actual.cast(new Utf8String)]).toEqual(['NaN', '2.0', '2.5']); }); testForEachNumericType( 'Series.cast %p', function testSeriesCast<T extends TypedArray|BigIntArray, R extends Numeric>( TypedArrayCtor: TypedArrayConstructor<T>, type: R) { const input = Array.from({length: 16}, () => 16 * (Math.random() - 0.5)); const actual = makeTestData(input).cast(type).data.toArray(); const expected = new TypedArrayCtor(clampFloatValuesLikeUnaryCast(type, input)); expect(actual).toEqualTypedArray(expected); }); testForEachNumericType( 'Series.view %p', function testSeriesView<T extends TypedArray|BigIntArray, R extends Numeric>( TypedArrayCtor: TypedArrayConstructor<T>, type: R) { const input = Array.from({length: 16}, () => 16 * (Math.random() - 0.5)); const actual = makeTestData(input).view(type).data.toArray(); const expected = new TypedArrayCtor(new Float32Array(input).buffer); expect(actual).toEqualTypedArray(expected); }); });
0
rapidsai_public_repos/node/modules/cudf/test/series
rapidsai_public_repos/node/modules/cudf/test/series/unaryop/uint32-tests.ts
// Copyright (c) 2021, NVIDIA CORPORATION. // // 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. import '../../jest-extensions'; import {BigIntArray, setDefaultAllocator, TypedArray, TypedArrayConstructor} from '@rapidsai/cuda'; import {Numeric, Utf8String} from '@rapidsai/cudf'; import {DeviceBuffer} from '@rapidsai/rmm'; import * as arrow from 'apache-arrow'; import { clampIntValuesLikeUnaryCast, makeTestNumbers, makeTestSeries, MathematicalUnaryOp, testForEachNumericType } from '../utils'; setDefaultAllocator((byteLength: number) => new DeviceBuffer(byteLength)); const makeTestData = (values?: (number|null)[]) => makeTestSeries(new arrow.Uint32, makeTestNumbers(values)).lhs; describe('Series unaryops (Uint32)', () => { const runMathOp = (op: MathematicalUnaryOp) => [...makeTestData([-3, 0, 3])[op]()]; test('Series.sin', () => { expect(runMathOp('sin')).toEqual([0, 0, 0]); }); test('Series.cos', () => { expect(runMathOp('cos')).toEqual([0, 1, 0]); }); test('Series.tan', () => { expect(runMathOp('tan')).toEqual([0, 0, 0]); }); test('Series.asin', () => { expect(runMathOp('asin')).toEqual([2147483648, 0, 2147483648]); }); test('Series.acos', () => { expect(runMathOp('acos')).toEqual([2147483648, 1, 2147483648]); }); test('Series.atan', () => { expect(runMathOp('atan')).toEqual([1, 0, 1]); }); test('Series.sinh', () => { expect(runMathOp('sinh')).toEqual([4294967295, 0, 10]); }); test('Series.cosh', () => { expect(runMathOp('cosh')).toEqual([4294967295, 1, 10]); }); test('Series.tanh', () => { expect(runMathOp('tanh')).toEqual([1, 0, 0]); }); test('Series.asinh', () => { expect(runMathOp('asinh')).toEqual([22, 0, 1]); }); test('Series.acosh', () => { expect(runMathOp('acosh')).toEqual([22, 2147483648, 1]); }); test('Series.atanh', () => { expect(runMathOp('atanh')).toEqual([2147483648, 0, 2147483648]); }); test('Series.exp', () => { expect(runMathOp('exp')).toEqual([4294967295, 1, 20]); }); test('Series.log', () => { expect(runMathOp('log')).toEqual([22, 0, 1]); }); test('Series.sqrt', () => { expect(runMathOp('sqrt')).toEqual([65535, 0, 1]); }); test('Series.cbrt', () => { expect(runMathOp('cbrt')).toEqual([1625, 0, 1]); }); test('Series.ceil', () => { expect(runMathOp('ceil')).toEqual([4294967293, 0, 3]); }); test('Series.floor', () => { expect(runMathOp('floor')).toEqual([4294967293, 0, 3]); }); test('Series.abs', () => { expect(runMathOp('abs')).toEqual([4294967293, 0, 3]); }); test('Series.not', () => { const actual = makeTestData([-3, 0, 3]).not(); expect([...actual]).toEqual([-3, 0, 3].map((x) => !x)); }); test('Series.isNull', () => { const actual = makeTestData([null, 3, 6]).isNull(); expect([...actual]).toEqual([true, false, false]); }); test('Series.isNotNull', () => { const actual = makeTestData([null, 3, 6]).isNotNull(); expect([...actual]).toEqual([false, true, true]); }); test('Series.bitInvert', () => { const actual = makeTestData([null, 0, 3, 6]).bitInvert(); expect([...actual]).toEqual([null, 4294967295, 4294967292, 4294967289]); }); test('Series.cast Utf8String', () => { const actual = makeTestData([null, 0, 3, 6]); expect([...actual.cast(new Utf8String)]).toEqual([null, '0', '3', '6']); }); test('Series.toHexString', () => { const actual = makeTestData([1234, 0, 27, null]); expect([...actual.toHexString()]).toEqual(['04D2', '00', '1B', null]); }); const clampValuesLikeUnaryCast = clampIntValuesLikeUnaryCast(new Uint32Array([0])); testForEachNumericType( 'Series.cast %p', function testSeriesCast<T extends TypedArray|BigIntArray, R extends Numeric>( TypedArrayCtor: TypedArrayConstructor<T>, type: R) { const input = Array.from({length: 16}, () => 16 * (Math.random() - 0.5) | 0); const actual = makeTestData(input).cast(type).data.toArray(); const expected = new TypedArrayCtor(clampValuesLikeUnaryCast(type, input)); expect(actual).toEqualTypedArray(expected); }); testForEachNumericType( 'Series.view %p', function testSeriesView<T extends TypedArray|BigIntArray, R extends Numeric>( TypedArrayCtor: TypedArrayConstructor<T>, type: R) { const input = Array.from({length: 16}, () => 16 * (Math.random() - 0.5) | 0); const actual = makeTestData(input).view(type).data.toArray(); const expected = new TypedArrayCtor(new Uint32Array(input).buffer); expect(actual).toEqualTypedArray(expected); }); });
0
rapidsai_public_repos/node/modules/cudf/test/series
rapidsai_public_repos/node/modules/cudf/test/series/unaryop/bool8-test.ts
// Copyright (c) 2021, NVIDIA CORPORATION. // // 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. import '../../jest-extensions'; import {setDefaultAllocator} from '@rapidsai/cuda'; import {Series, Utf8String} from '@rapidsai/cudf'; import {DeviceBuffer} from '@rapidsai/rmm'; setDefaultAllocator((byteLength: number) => new DeviceBuffer(byteLength)); describe('Series unaryops (Bool8)', () => { test('Series.cast Utf8String', () => { const actual = Series.new([null, true, false, true]); expect([...actual.cast(new Utf8String)]).toEqual([null, 'true', 'false', 'true']); }); });
0
rapidsai_public_repos/node/modules/cudf/test/series
rapidsai_public_repos/node/modules/cudf/test/series/unaryop/uint64-tests.ts
// Copyright (c) 2021, NVIDIA CORPORATION. // // 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. import '../../jest-extensions'; import {BigIntArray, setDefaultAllocator, TypedArray, TypedArrayConstructor} from '@rapidsai/cuda'; import {Bool8, Float32, Float64, Int64, Numeric, Uint64, Utf8String} from '@rapidsai/cudf'; import {DeviceBuffer} from '@rapidsai/rmm'; import * as arrow from 'apache-arrow'; import { makeTestBigInts, makeTestSeries, MathematicalUnaryOp, testForEachNumericType } from '../utils'; setDefaultAllocator((byteLength: number) => new DeviceBuffer(byteLength)); const makeTestData = (values?: (number|bigint|null)[]) => makeTestSeries(new arrow.Uint64, makeTestBigInts(values)).lhs; const toBigInt = (x: bigint|null) => x == null ? null : BigInt.asUintN(64, 0n + x); describe('Series unaryops (Uint64)', () => { const BIG_INT53 = 9223372036854775808n; const BIG_INT64 = 18446744073709551615n; const runMathOp = (op: MathematicalUnaryOp) => [...makeTestData([-3n, 0n, 3n])[op]()].map(toBigInt); test('Series.sin', () => { expect(runMathOp('sin')).toEqual([0n, 0n, 0n]); }); test('Series.cos', () => { expect(runMathOp('cos')).toEqual([0n, 1n, 0n]); }); test('Series.tan', () => { expect(runMathOp('tan')).toEqual([0n, 0n, 0n]); }); test('Series.asin', () => { expect(runMathOp('asin')).toEqual([BIG_INT53, 0n, BIG_INT53]); }); test('Series.acos', () => { expect(runMathOp('acos')).toEqual([BIG_INT53, 1n, BIG_INT53]); }); test('Series.atan', () => { expect(runMathOp('atan')).toEqual([1n, 0n, 1n]); }); test('Series.sinh', () => { expect(runMathOp('sinh')).toEqual([BIG_INT64, 0n, 10n]); }); test('Series.cosh', () => { expect(runMathOp('cosh')).toEqual([BIG_INT64, 1n, 10n]); }); test('Series.tanh', () => { expect(runMathOp('tanh')).toEqual([1n, 0n, 0n]); }); test('Series.asinh', () => { expect(runMathOp('asinh')).toEqual([45n, 0n, 1n]); }); test('Series.acosh', () => { expect(runMathOp('acosh')).toEqual([45n, BIG_INT53, 1n]); }); test('Series.atanh', () => { expect(runMathOp('atanh')).toEqual([BIG_INT53, 0n, BIG_INT53]); }); test('Series.exp', () => { expect(runMathOp('exp')).toEqual([BIG_INT64, 1n, 20n]); }); test('Series.log', () => { expect(runMathOp('log')).toEqual([44n, 0n, 1n]); }); test('Series.sqrt', () => { expect(runMathOp('sqrt')).toEqual([4294967296n, 0n, 1n]); }); test('Series.cbrt', () => { expect(runMathOp('cbrt')).toEqual([2642245n, 0n, 1n]); }); test('Series.ceil', () => { expect(runMathOp('ceil')).toEqual([BIG_INT64, 0n, 3n]); }); test('Series.floor', () => { expect(runMathOp('floor')).toEqual([BIG_INT64, 0n, 3n]); }); test('Series.abs', () => { expect(runMathOp('abs')).toEqual([18446744073709551613n, 0n, 3n]); }); test('Series.not', () => { const actual = makeTestData([-3n, 0n, 3n]).not(); expect([...actual]).toEqual([-3n, 0n, 3n].map((x) => !x)); }); test('Series.isNull', () => { const actual = makeTestData([null, 3n, 6n]).isNull(); expect([...actual]).toEqual([true, false, false]); }); test('Series.isNotNull', () => { const actual = makeTestData([null, 3n, 6n]).isNotNull(); expect([...actual]).toEqual([false, true, true]); }); test('Series.bitInvert', () => { const actual = makeTestData([null, 0n, 3n, 6n]).bitInvert(); expect([...actual].map(toBigInt)).toEqual([null, ~0n, ~3n, ~6n].map(toBigInt)); }); test('Series.cast Utf8String', () => { const actual = makeTestData([null, 0n, 3n, 6n]); expect([...actual.cast(new Utf8String)]).toEqual([null, '0', '3', '6']); }); test('Series.toHexString', () => { const actual = makeTestData([1234n, 0n, 27n, null]); expect([...actual.toHexString()]).toEqual(['04D2', '00', '1B', null]); }); testForEachNumericType( 'Series.cast %p', function testSeriesCast<T extends TypedArray|BigIntArray, R extends Numeric>( TypedArrayCtor: TypedArrayConstructor<T>, type: R) { const input = Array.from({length: 16}, () => 16 * (Math.random() - 0.5) | 0); const actual = makeTestData(input).cast(type).data.toArray(); const expected = new TypedArrayCtor(input.map((x) => { if (type instanceof Bool8) { return x | 0 ? 1 : 0; } if (type instanceof Int64) { return BigInt.asIntN(64, BigInt(x | 0)); } if (type instanceof Uint64) { return BigInt.asUintN(64, BigInt(x | 0)); } if (type instanceof Float32) { return Number(BigInt.asUintN(64, BigInt(x | 0))); } if (type instanceof Float64) { return Number(BigInt.asUintN(64, BigInt(x | 0))); } return x | 0; })); expect(actual).toEqualTypedArray(expected); }); testForEachNumericType( 'Series.view %p', function testSeriesView<T extends TypedArray|BigIntArray, R extends Numeric>( TypedArrayCtor: TypedArrayConstructor<T>, type: R) { const input = Array.from({length: 16}, () => 16 * (Math.random() - 0.5) | 0); const actual = makeTestData(input).view(type).data.toArray(); const expected = new TypedArrayCtor(new BigUint64Array(input.map(BigInt)).buffer); expect(actual).toEqualTypedArray(expected); }); });
0
rapidsai_public_repos/node/modules/cudf/test/series
rapidsai_public_repos/node/modules/cudf/test/series/unaryop/int16-tests.ts
// Copyright (c) 2021, NVIDIA CORPORATION. // // 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. import '../../jest-extensions'; import {BigIntArray, setDefaultAllocator, TypedArray, TypedArrayConstructor} from '@rapidsai/cuda'; import {Numeric, Utf8String} from '@rapidsai/cudf'; import {DeviceBuffer} from '@rapidsai/rmm'; import * as arrow from 'apache-arrow'; import { clampIntValuesLikeUnaryCast, makeTestNumbers, makeTestSeries, MathematicalUnaryOp, testForEachNumericType } from '../utils'; setDefaultAllocator((byteLength: number) => new DeviceBuffer(byteLength)); const makeTestData = (values?: (number|null)[]) => makeTestSeries(new arrow.Int16, makeTestNumbers(values)).lhs; describe('Series unaryops (Int16)', () => { const runMathOp = (op: MathematicalUnaryOp) => [...makeTestData([-3, 0, 3])[op]()]; test('Series.sin', () => { expect(runMathOp('sin')).toEqual([0, 0, 0]); }); test('Series.cos', () => { expect(runMathOp('cos')).toEqual([0, 1, 0]); }); test('Series.tan', () => { expect(runMathOp('tan')).toEqual([0, 0, 0]); }); test('Series.asin', () => { expect(runMathOp('asin')).toEqual([0, 0, 0]); }); test('Series.acos', () => { expect(runMathOp('acos')).toEqual([0, 1, 0]); }); test('Series.atan', () => { expect(runMathOp('atan')).toEqual([-1, 0, 1]); }); test('Series.sinh', () => { expect(runMathOp('sinh')).toEqual([-10, 0, 10]); }); test('Series.cosh', () => { expect(runMathOp('cosh')).toEqual([10, 1, 10]); }); test('Series.tanh', () => { expect(runMathOp('tanh')).toEqual([0, 0, 0]); }); test('Series.asinh', () => { expect(runMathOp('asinh')).toEqual([-1, 0, 1]); }); test('Series.acosh', () => { expect(runMathOp('acosh')).toEqual([0, 0, 1]); }); test('Series.atanh', () => { expect(runMathOp('atanh')).toEqual([0, 0, 0]); }); test('Series.exp', () => { expect(runMathOp('exp')).toEqual([0, 1, 20]); }); test('Series.log', () => { expect(runMathOp('log')).toEqual([0, 0, 1]); }); test('Series.sqrt', () => { expect(runMathOp('sqrt')).toEqual([0, 0, 1]); }); test('Series.cbrt', () => { expect(runMathOp('cbrt')).toEqual([-1, 0, 1]); }); test('Series.ceil', () => { expect(runMathOp('ceil')).toEqual([-3, 0, 3]); }); test('Series.floor', () => { expect(runMathOp('floor')).toEqual([-3, 0, 3]); }); test('Series.abs', () => { expect(runMathOp('abs')).toEqual([3, 0, 3]); }); test('Series.not', () => { const actual = makeTestData([-3, 0, 3]).not(); expect([...actual]).toEqual([-3, 0, 3].map((x) => !x)); }); test('Series.isNull', () => { const actual = makeTestData([null, 3, 6]).isNull(); expect([...actual]).toEqual([true, false, false]); }); test('Series.isNotNull', () => { const actual = makeTestData([null, 3, 6]).isNotNull(); expect([...actual]).toEqual([false, true, true]); }); test('Series.bitInvert', () => { const actual = makeTestData([null, 0, 3, 6]).bitInvert(); expect([...actual]).toEqual([null, ~0, ~3, ~6]); }); test('Series.cast Utf8String', () => { const actual = makeTestData([null, 0, 3, 6]); expect([...actual.cast(new Utf8String)]).toEqual([null, '0', '3', '6']); }); test('Series.toHexString', () => { const actual = makeTestData([1234, 0, 27, null]); expect([...actual.toHexString()]).toEqual(['04D2', '00', '1B', null]); }); const clampValuesLikeUnaryCast = clampIntValuesLikeUnaryCast(new Int32Array([0])); testForEachNumericType( 'Series.cast %p', function testSeriesCast<T extends TypedArray|BigIntArray, R extends Numeric>( TypedArrayCtor: TypedArrayConstructor<T>, type: R) { const input = Array.from({length: 16}, () => 16 * (Math.random() - 0.5) | 0); const actual = makeTestData(input).cast(type).data.toArray(); const expected = new TypedArrayCtor(clampValuesLikeUnaryCast(type, input)); expect(actual).toEqualTypedArray(expected); }); testForEachNumericType( 'Series.view %p', function testSeriesView<T extends TypedArray|BigIntArray, R extends Numeric>( TypedArrayCtor: TypedArrayConstructor<T>, type: R) { const input = Array.from({length: 16}, () => 16 * (Math.random() - 0.5) | 0); const actual = makeTestData(input).view(type).data.toArray(); const expected = new TypedArrayCtor(new Int16Array(input).buffer); expect(actual).toEqualTypedArray(expected); }); });
0
rapidsai_public_repos/node/modules/cudf/test/series
rapidsai_public_repos/node/modules/cudf/test/series/unaryop/int32-tests.ts
// Copyright (c) 2021, NVIDIA CORPORATION. // // 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. import '../../jest-extensions'; import {BigIntArray, setDefaultAllocator, TypedArray, TypedArrayConstructor} from '@rapidsai/cuda'; import {Numeric, Utf8String} from '@rapidsai/cudf'; import {DeviceBuffer} from '@rapidsai/rmm'; import * as arrow from 'apache-arrow'; import { clampIntValuesLikeUnaryCast, makeTestNumbers, makeTestSeries, MathematicalUnaryOp, testForEachNumericType } from '../utils'; setDefaultAllocator((byteLength: number) => new DeviceBuffer(byteLength)); const makeTestData = (values?: (number|null)[]) => makeTestSeries(new arrow.Int32, makeTestNumbers(values)).lhs; describe('Series unaryops (Int32)', () => { const runMathOp = (op: MathematicalUnaryOp) => [...makeTestData([-3, 0, 3])[op]()]; test('Series.sin', () => { expect(runMathOp('sin')).toEqual([0, 0, 0]); }); test('Series.cos', () => { expect(runMathOp('cos')).toEqual([0, 1, 0]); }); test('Series.tan', () => { expect(runMathOp('tan')).toEqual([0, 0, 0]); }); test('Series.asin', () => { expect(runMathOp('asin')).toEqual([-2147483648, 0, -2147483648]); }); test('Series.acos', () => { expect(runMathOp('acos')).toEqual([-2147483648, 1, -2147483648]); }); test('Series.atan', () => { expect(runMathOp('atan')).toEqual([-1, 0, 1]); }); test('Series.sinh', () => { expect(runMathOp('sinh')).toEqual([-10, 0, 10]); }); test('Series.cosh', () => { expect(runMathOp('cosh')).toEqual([10, 1, 10]); }); test('Series.tanh', () => { expect(runMathOp('tanh')).toEqual([0, 0, 0]); }); test('Series.asinh', () => { expect(runMathOp('asinh')).toEqual([-1, 0, 1]); }); test('Series.acosh', () => { expect(runMathOp('acosh')).toEqual([-2147483648, -2147483648, 1]); }); test('Series.atanh', () => { expect(runMathOp('atanh')).toEqual([-2147483648, 0, -2147483648]); }); test('Series.exp', () => { expect(runMathOp('exp')).toEqual([0, 1, 20]); }); test('Series.log', () => { expect(runMathOp('log')).toEqual([-2147483648, -2147483648, 1]); }); test('Series.sqrt', () => { expect(runMathOp('sqrt')).toEqual([-2147483648, 0, 1]); }); test('Series.cbrt', () => { expect(runMathOp('cbrt')).toEqual([-1, 0, 1]); }); test('Series.ceil', () => { expect(runMathOp('ceil')).toEqual([-3, 0, 3]); }); test('Series.floor', () => { expect(runMathOp('floor')).toEqual([-3, 0, 3]); }); test('Series.abs', () => { expect(runMathOp('abs')).toEqual([3, 0, 3]); }); test('Series.not', () => { const actual = makeTestData([-3, 0, 3]).not(); expect([...actual]).toEqual([-3, 0, 3].map((x) => !x)); }); test('Series.isNull', () => { const actual = makeTestData([null, 3, 6]).isNull(); expect([...actual]).toEqual([true, false, false]); }); test('Series.isNotNull', () => { const actual = makeTestData([null, 3, 6]).isNotNull(); expect([...actual]).toEqual([false, true, true]); }); test('Series.bitInvert', () => { const actual = makeTestData([null, 0, 3, 6]).bitInvert(); expect([...actual]).toEqual([null, ~0, ~3, ~6]); }); test('Series.cast Utf8String', () => { const actual = makeTestData([null, 0, 3, 6]); expect([...actual.cast(new Utf8String)]).toEqual([null, '0', '3', '6']); }); test('Series.toHexString', () => { const actual = makeTestData([1234, 0, 27, null]); expect([...actual.toHexString()]).toEqual(['04D2', '00', '1B', null]); }); const clampValuesLikeUnaryCast = clampIntValuesLikeUnaryCast(new Int32Array([0])); testForEachNumericType( 'Series.cast %p', function testSeriesCast<T extends TypedArray|BigIntArray, R extends Numeric>( TypedArrayCtor: TypedArrayConstructor<T>, type: R) { const input = Array.from({length: 16}, () => 16 * (Math.random() - 0.5) | 0); const actual = makeTestData(input).cast(type).data.toArray(); const expected = new TypedArrayCtor(clampValuesLikeUnaryCast(type, input)); expect(actual).toEqualTypedArray(expected); }); testForEachNumericType( 'Series.view %p', function testSeriesView<T extends TypedArray|BigIntArray, R extends Numeric>( TypedArrayCtor: TypedArrayConstructor<T>, type: R) { const input = Array.from({length: 16}, () => 16 * (Math.random() - 0.5) | 0); const actual = makeTestData(input).view(type).data.toArray(); const expected = new TypedArrayCtor(new Int32Array(input).buffer); expect(actual).toEqualTypedArray(expected); }); });
0
rapidsai_public_repos/node/modules/cudf/test/series
rapidsai_public_repos/node/modules/cudf/test/series/unaryop/int8-tests.ts
// Copyright (c) 2021, NVIDIA CORPORATION. // // 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. import '../../jest-extensions'; import {BigIntArray, setDefaultAllocator, TypedArray, TypedArrayConstructor} from '@rapidsai/cuda'; import {Numeric, Utf8String} from '@rapidsai/cudf'; import {DeviceBuffer} from '@rapidsai/rmm'; import * as arrow from 'apache-arrow'; import { clampIntValuesLikeUnaryCast, makeTestNumbers, makeTestSeries, MathematicalUnaryOp, testForEachNumericType } from '../utils'; setDefaultAllocator((byteLength: number) => new DeviceBuffer(byteLength)); const makeTestData = (values?: (number|null)[]) => makeTestSeries(new arrow.Int8, makeTestNumbers(values)).lhs; describe('Series unaryops (Int8)', () => { const runMathOp = (op: MathematicalUnaryOp) => [...makeTestData([-3, 0, 3])[op]()]; test('Series.sin', () => { expect(runMathOp('sin')).toEqual([0, 0, 0]); }); test('Series.cos', () => { expect(runMathOp('cos')).toEqual([0, 1, 0]); }); test('Series.tan', () => { expect(runMathOp('tan')).toEqual([0, 0, 0]); }); test('Series.asin', () => { expect(runMathOp('asin')).toEqual([0, 0, 0]); }); test('Series.acos', () => { expect(runMathOp('acos')).toEqual([0, 1, 0]); }); test('Series.atan', () => { expect(runMathOp('atan')).toEqual([-1, 0, 1]); }); test('Series.sinh', () => { expect(runMathOp('sinh')).toEqual([-10, 0, 10]); }); test('Series.cosh', () => { expect(runMathOp('cosh')).toEqual([10, 1, 10]); }); test('Series.tanh', () => { expect(runMathOp('tanh')).toEqual([0, 0, 0]); }); test('Series.asinh', () => { expect(runMathOp('asinh')).toEqual([-1, 0, 1]); }); test('Series.acosh', () => { expect(runMathOp('acosh')).toEqual([0, 0, 1]); }); test('Series.atanh', () => { expect(runMathOp('atanh')).toEqual([0, 0, 0]); }); test('Series.exp', () => { expect(runMathOp('exp')).toEqual([0, 1, 20]); }); test('Series.log', () => { expect(runMathOp('log')).toEqual([0, 0, 1]); }); test('Series.sqrt', () => { expect(runMathOp('sqrt')).toEqual([0, 0, 1]); }); test('Series.cbrt', () => { expect(runMathOp('cbrt')).toEqual([-1, 0, 1]); }); test('Series.ceil', () => { expect(runMathOp('ceil')).toEqual([-3, 0, 3]); }); test('Series.floor', () => { expect(runMathOp('floor')).toEqual([-3, 0, 3]); }); test('Series.abs', () => { expect(runMathOp('abs')).toEqual([3, 0, 3]); }); test('Series.not', () => { const actual = makeTestData([-3, 0, 3]).not(); expect([...actual]).toEqual([-3, 0, 3].map((x) => !x)); }); test('Series.isNull', () => { const actual = makeTestData([null, 3, 6]).isNull(); expect([...actual]).toEqual([true, false, false]); }); test('Series.isNotNull', () => { const actual = makeTestData([null, 3, 6]).isNotNull(); expect([...actual]).toEqual([false, true, true]); }); test('Series.bitInvert', () => { const actual = makeTestData([null, 0, 3, 6]).bitInvert(); expect([...actual]).toEqual([null, ~0, ~3, ~6]); }); test('Series.cast Utf8String', () => { const actual = makeTestData([null, 0, 3, 6]); expect([...actual.cast(new Utf8String)]).toEqual([null, '0', '3', '6']); }); test('Series.toHexString', () => { const actual = makeTestData([0, 27, null]); expect([...actual.toHexString()]).toEqual(['00', '1B', null]); }); const clampValuesLikeUnaryCast = clampIntValuesLikeUnaryCast(new Int32Array([0])); testForEachNumericType( 'Series.cast %p', function testSeriesCast<T extends TypedArray|BigIntArray, R extends Numeric>( TypedArrayCtor: TypedArrayConstructor<T>, type: R) { const input = Array.from({length: 16}, () => 16 * (Math.random() - 0.5) | 0); const actual = makeTestData(input).cast(type).data.toArray(); const expected = new TypedArrayCtor(clampValuesLikeUnaryCast(type, input)); expect(actual).toEqualTypedArray(expected); }); testForEachNumericType( 'Series.view %p', function testSeriesView<T extends TypedArray|BigIntArray, R extends Numeric>( TypedArrayCtor: TypedArrayConstructor<T>, type: R) { const input = Array.from({length: 16}, () => 16 * (Math.random() - 0.5) | 0); const actual = makeTestData(input).view(type).data.toArray(); const expected = new TypedArrayCtor(new Int8Array(input).buffer); expect(actual).toEqualTypedArray(expected); }); });
0
rapidsai_public_repos/node/modules/cudf/test/series
rapidsai_public_repos/node/modules/cudf/test/series/unaryop/uint8-tests.ts
// Copyright (c) 2021, NVIDIA CORPORATION. // // 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. import '../../jest-extensions'; import {BigIntArray, setDefaultAllocator, TypedArray, TypedArrayConstructor} from '@rapidsai/cuda'; import {Numeric, Utf8String} from '@rapidsai/cudf'; import {DeviceBuffer} from '@rapidsai/rmm'; import * as arrow from 'apache-arrow'; import { clampIntValuesLikeUnaryCast, makeTestNumbers, makeTestSeries, MathematicalUnaryOp, testForEachNumericType } from '../utils'; setDefaultAllocator((byteLength: number) => new DeviceBuffer(byteLength)); const makeTestData = (values?: (number|null)[]) => makeTestSeries(new arrow.Uint8, makeTestNumbers(values)).lhs; describe('Series unaryops (Uint8)', () => { const runMathOp = (op: MathematicalUnaryOp) => [...makeTestData([-3, 0, 3])[op]()]; test('Series.sin', () => { expect(runMathOp('sin')).toEqual([0, 0, 0]); }); test('Series.cos', () => { expect(runMathOp('cos')).toEqual([0, 1, 0]); }); test('Series.tan', () => { expect(runMathOp('tan')).toEqual([0, 0, 0]); }); test('Series.asin', () => { expect(runMathOp('asin')).toEqual([0, 0, 0]); }); test('Series.acos', () => { expect(runMathOp('acos')).toEqual([0, 1, 0]); }); test('Series.atan', () => { expect(runMathOp('atan')).toEqual([1, 0, 1]); }); test('Series.sinh', () => { expect(runMathOp('sinh')).toEqual([255, 0, 10]); }); test('Series.cosh', () => { expect(runMathOp('cosh')).toEqual([255, 1, 10]); }); test('Series.tanh', () => { expect(runMathOp('tanh')).toEqual([1, 0, 0]); }); test('Series.asinh', () => { expect(runMathOp('asinh')).toEqual([6, 0, 1]); }); test('Series.acosh', () => { expect(runMathOp('acosh')).toEqual([6, 0, 1]); }); test('Series.atanh', () => { expect(runMathOp('atanh')).toEqual([0, 0, 0]); }); test('Series.exp', () => { expect(runMathOp('exp')).toEqual([255, 1, 20]); }); test('Series.log', () => { expect(runMathOp('log')).toEqual([5, 0, 1]); }); test('Series.sqrt', () => { expect(runMathOp('sqrt')).toEqual([15, 0, 1]); }); test('Series.cbrt', () => { expect(runMathOp('cbrt')).toEqual([6, 0, 1]); }); test('Series.ceil', () => { expect(runMathOp('ceil')).toEqual([253, 0, 3]); }); test('Series.floor', () => { expect(runMathOp('floor')).toEqual([253, 0, 3]); }); test('Series.abs', () => { expect(runMathOp('abs')).toEqual([253, 0, 3]); }); test('Series.not', () => { const actual = makeTestData([-3, 0, 3]).not(); expect([...actual]).toEqual([-3, 0, 3].map((x) => !x)); }); test('Series.isNull', () => { const actual = makeTestData([null, 3, 6]).isNull(); expect([...actual]).toEqual([true, false, false]); }); test('Series.isNotNull', () => { const actual = makeTestData([null, 3, 6]).isNotNull(); expect([...actual]).toEqual([false, true, true]); }); test('Series.bitInvert', () => { const actual = makeTestData([null, 0, 3, 6]).bitInvert(); expect([...actual]).toEqual([null, 255, 252, 249]); }); test('Series.cast Utf8String', () => { const actual = makeTestData([null, 0, 3, 6]); expect([...actual.cast(new Utf8String)]).toEqual([null, '0', '3', '6']); }); test('Series.toHexString', () => { const actual = makeTestData([0, 27, null]); expect([...actual.toHexString()]).toEqual(['00', '1B', null]); }); const clampValuesLikeUnaryCast = clampIntValuesLikeUnaryCast(new Uint8Array([0])); testForEachNumericType( 'Series.cast %p', function testSeriesCast<T extends TypedArray|BigIntArray, R extends Numeric>( TypedArrayCtor: TypedArrayConstructor<T>, type: R) { const input = Array.from({length: 16}, () => 16 * (Math.random() - 0.5) | 0); const actual = makeTestData(input).cast(type).data.toArray(); const expected = new TypedArrayCtor(clampValuesLikeUnaryCast(type, input)); expect(actual).toEqualTypedArray(expected); }); testForEachNumericType( 'Series.view %p', function testSeriesView<T extends TypedArray|BigIntArray, R extends Numeric>( TypedArrayCtor: TypedArrayConstructor<T>, type: R) { const input = Array.from({length: 16}, () => 16 * (Math.random() - 0.5) | 0); const actual = makeTestData(input).view(type).data.toArray(); const expected = new TypedArrayCtor(new Uint8Array(input).buffer); expect(actual).toEqualTypedArray(expected); }); });
0
rapidsai_public_repos/node/modules/cudf/test/series
rapidsai_public_repos/node/modules/cudf/test/series/unaryop/int64-tests.ts
// Copyright (c) 2021, NVIDIA CORPORATION. // // 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. import '../../jest-extensions'; import {BigIntArray, setDefaultAllocator, TypedArray, TypedArrayConstructor} from '@rapidsai/cuda'; import {Numeric, Utf8String} from '@rapidsai/cudf'; import {DeviceBuffer} from '@rapidsai/rmm'; import * as arrow from 'apache-arrow'; import { clampIntValuesLikeUnaryCast, makeTestBigInts, makeTestSeries, MathematicalUnaryOp, testForEachNumericType } from '../utils'; setDefaultAllocator((byteLength: number) => new DeviceBuffer(byteLength)); const makeTestData = (values?: (number|bigint|null)[]) => makeTestSeries(new arrow.Int64, makeTestBigInts(values)).lhs; const toBigInt = (x: bigint|null) => x == null ? null : BigInt.asIntN(64, 0n + x); describe('Series unaryops (Int64)', () => { const LIL_INT53 = -9223372036854775808n; const runMathOp = (op: MathematicalUnaryOp) => [...makeTestData([-3n, 0n, 3n])[op]()].map(toBigInt); test('Series.sin', () => { expect(runMathOp('sin')).toEqual([0n, 0n, 0n]); }); test('Series.cos', () => { expect(runMathOp('cos')).toEqual([0n, 1n, 0n]); }); test('Series.tan', () => { expect(runMathOp('tan')).toEqual([0n, 0n, 0n]); }); test('Series.asin', () => { expect(runMathOp('asin')).toEqual([LIL_INT53, 0n, LIL_INT53]); }); test('Series.acos', () => { expect(runMathOp('acos')).toEqual([LIL_INT53, 1n, LIL_INT53]); }); test('Series.atan', () => { expect(runMathOp('atan')).toEqual([-1n, 0n, 1n]); }); test('Series.sinh', () => { expect(runMathOp('sinh')).toEqual([-10n, 0n, 10n]); }); test('Series.cosh', () => { expect(runMathOp('cosh')).toEqual([10n, 1n, 10n]); }); test('Series.tanh', () => { expect(runMathOp('tanh')).toEqual([0n, 0n, 0n]); }); test('Series.asinh', () => { expect(runMathOp('asinh')).toEqual([-1n, 0n, 1n]); }); test('Series.acosh', () => { expect(runMathOp('acosh')).toEqual([LIL_INT53, LIL_INT53, 1n]); }); test('Series.atanh', () => { expect(runMathOp('atanh')).toEqual([LIL_INT53, 0n, LIL_INT53]); }); test('Series.exp', () => { expect(runMathOp('exp')).toEqual([0n, 1n, 20n]); }); test('Series.log', () => { expect(runMathOp('log')).toEqual([LIL_INT53, LIL_INT53, 1n]); }); test('Series.sqrt', () => { expect(runMathOp('sqrt')).toEqual([LIL_INT53, 0n, 1n]); }); test('Series.cbrt', () => { expect(runMathOp('cbrt')).toEqual([-1n, 0n, 1n]); }); test('Series.ceil', () => { expect(runMathOp('ceil')).toEqual([-3n, 0n, 3n]); }); test('Series.floor', () => { expect(runMathOp('floor')).toEqual([-3n, 0n, 3n]); }); test('Series.abs', () => { expect(runMathOp('abs')).toEqual([3n, 0n, 3n]); }); test('Series.not', () => { const actual = makeTestData([-3n, 0n, 3n]).not(); expect([...actual]).toEqual([-3n, 0n, 3n].map((x) => !x)); }); test('Series.isNull', () => { const actual = makeTestData([null, 3n, 6n]).isNull(); expect([...actual]).toEqual([true, false, false]); }); test('Series.isNotNull', () => { const actual = makeTestData([null, 3n, 6n]).isNotNull(); expect([...actual]).toEqual([false, true, true]); }); test('Series.bitInvert', () => { const actual = makeTestData([null, 0n, 3n, 6n]).bitInvert(); expect([...actual].map(toBigInt)).toEqual([null, ~0n, ~3n, ~6n].map(toBigInt)); }); test('Series.cast Utf8String', () => { const actual = makeTestData([null, 0n, 3n, 6n]); expect([...actual.cast(new Utf8String)]).toEqual([null, '0', '3', '6']); }); test('Series.toHexString', () => { const actual = makeTestData([1234n, 0n, 27n, null]); expect([...actual.toHexString()]).toEqual(['04D2', '00', '1B', null]); }); test('Series.toIpv4String', () => { const actual = makeTestData([2080309255n, 2130706433n, null]); expect([...actual.toIpv4String()]).toEqual(['123.255.0.7', '127.0.0.1', null]); }); const clampValuesLikeUnaryCast = clampIntValuesLikeUnaryCast(new Int32Array([0])); testForEachNumericType( 'Series.cast %p', function testSeriesCast<T extends TypedArray|BigIntArray, R extends Numeric>( TypedArrayCtor: TypedArrayConstructor<T>, type: R) { const input = Array.from({length: 16}, () => 16 * (Math.random() - 0.5) | 0); const actual = makeTestData(input).cast(type).data.toArray(); const expected = new TypedArrayCtor(clampValuesLikeUnaryCast(type, input)); expect(actual).toEqualTypedArray(expected); }); testForEachNumericType( 'Series.view %p', function testSeriesView<T extends TypedArray|BigIntArray, R extends Numeric>( TypedArrayCtor: TypedArrayConstructor<T>, type: R) { const input = Array.from({length: 16}, () => 16 * (Math.random() - 0.5) | 0); const actual = makeTestData(input).view(type).data.toArray(); const expected = new TypedArrayCtor(new BigInt64Array(input.map(BigInt)).buffer); expect(actual).toEqualTypedArray(expected); }); });
0
rapidsai_public_repos/node/modules/cudf/test/series
rapidsai_public_repos/node/modules/cudf/test/series/unaryop/uint16-tests.ts
// Copyright (c) 2021, NVIDIA CORPORATION. // // 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. import '../../jest-extensions'; import {BigIntArray, setDefaultAllocator, TypedArray, TypedArrayConstructor} from '@rapidsai/cuda'; import {Numeric, Utf8String} from '@rapidsai/cudf'; import {DeviceBuffer} from '@rapidsai/rmm'; import * as arrow from 'apache-arrow'; import { clampIntValuesLikeUnaryCast, makeTestNumbers, makeTestSeries, MathematicalUnaryOp, testForEachNumericType } from '../utils'; setDefaultAllocator((byteLength: number) => new DeviceBuffer(byteLength)); const makeTestData = (values?: (number|null)[]) => makeTestSeries(new arrow.Uint16, makeTestNumbers(values)).lhs; describe('Series unaryops (Uint16)', () => { const runMathOp = (op: MathematicalUnaryOp) => [...makeTestData([-3, 0, 3])[op]()]; test('Series.sin', () => { expect(runMathOp('sin')).toEqual([0, 0, 0]); }); test('Series.cos', () => { expect(runMathOp('cos')).toEqual([0, 1, 0]); }); test('Series.tan', () => { expect(runMathOp('tan')).toEqual([0, 0, 0]); }); test('Series.asin', () => { expect(runMathOp('asin')).toEqual([0, 0, 0]); }); test('Series.acos', () => { expect(runMathOp('acos')).toEqual([0, 1, 0]); }); test('Series.atan', () => { expect(runMathOp('atan')).toEqual([1, 0, 1]); }); test('Series.sinh', () => { expect(runMathOp('sinh')).toEqual([65535, 0, 10]); }); test('Series.cosh', () => { expect(runMathOp('cosh')).toEqual([65535, 1, 10]); }); test('Series.tanh', () => { expect(runMathOp('tanh')).toEqual([1, 0, 0]); }); test('Series.asinh', () => { expect(runMathOp('asinh')).toEqual([11, 0, 1]); }); test('Series.acosh', () => { expect(runMathOp('acosh')).toEqual([11, 0, 1]); }); test('Series.atanh', () => { expect(runMathOp('atanh')).toEqual([0, 0, 0]); }); test('Series.exp', () => { expect(runMathOp('exp')).toEqual([65535, 1, 20]); }); test('Series.log', () => { expect(runMathOp('log')).toEqual([11, 0, 1]); }); test('Series.sqrt', () => { expect(runMathOp('sqrt')).toEqual([255, 0, 1]); }); test('Series.cbrt', () => { expect(runMathOp('cbrt')).toEqual([40, 0, 1]); }); test('Series.ceil', () => { expect(runMathOp('ceil')).toEqual([65533, 0, 3]); }); test('Series.floor', () => { expect(runMathOp('floor')).toEqual([65533, 0, 3]); }); test('Series.abs', () => { expect(runMathOp('abs')).toEqual([65533, 0, 3]); }); test('Series.not', () => { const actual = makeTestData([-3, 0, 3]).not(); expect([...actual]).toEqual([-3, 0, 3].map((x) => !x)); }); test('Series.isNull', () => { const actual = makeTestData([null, 3, 6]).isNull(); expect([...actual]).toEqual([true, false, false]); }); test('Series.isNotNull', () => { const actual = makeTestData([null, 3, 6]).isNotNull(); expect([...actual]).toEqual([false, true, true]); }); test('Series.bitInvert', () => { const actual = makeTestData([null, 0, 3, 6]).bitInvert(); expect([...actual]).toEqual([null, 65535, 65532, 65529]); }); test('Series.cast Utf8String', () => { const actual = makeTestData([null, 0, 3, 6]); expect([...actual.cast(new Utf8String)]).toEqual([null, '0', '3', '6']); }); test('Series.toHexString', () => { const actual = makeTestData([1234, 0, 27, null]); expect([...actual.toHexString()]).toEqual(['04D2', '00', '1B', null]); }); const clampValuesLikeUnaryCast = clampIntValuesLikeUnaryCast(new Uint16Array([0])); testForEachNumericType( 'Series.cast %p', function testSeriesCast<T extends TypedArray|BigIntArray, R extends Numeric>( TypedArrayCtor: TypedArrayConstructor<T>, type: R) { const input = Array.from({length: 16}, () => 16 * (Math.random() - 0.5) | 0); const actual = makeTestData(input).cast(type).data.toArray(); const expected = new TypedArrayCtor(clampValuesLikeUnaryCast(type, input)); expect(actual).toEqualTypedArray(expected); }); testForEachNumericType( 'Series.view %p', function testSeriesView<T extends TypedArray|BigIntArray, R extends Numeric>( TypedArrayCtor: TypedArrayConstructor<T>, type: R) { const input = Array.from({length: 16}, () => 16 * (Math.random() - 0.5) | 0); const actual = makeTestData(input).view(type).data.toArray(); const expected = new TypedArrayCtor(new Uint16Array(input).buffer); expect(actual).toEqualTypedArray(expected); }); });
0
rapidsai_public_repos/node/modules/cudf/test/series
rapidsai_public_repos/node/modules/cudf/test/series/unaryop/float64-tests.ts
// Copyright (c) 2021, NVIDIA CORPORATION. // // 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. import '../../jest-extensions'; import {BigIntArray, setDefaultAllocator, TypedArray, TypedArrayConstructor} from '@rapidsai/cuda'; import {Numeric, Utf8String} from '@rapidsai/cudf'; import {DeviceBuffer} from '@rapidsai/rmm'; import * as arrow from 'apache-arrow'; import { clampFloatValuesLikeUnaryCast, makeTestNumbers, makeTestSeries, MathematicalUnaryOp, mathematicalUnaryOps, testForEachNumericType } from '../utils'; setDefaultAllocator((byteLength: number) => new DeviceBuffer(byteLength)); const makeTestData = (values?: (number|null)[]) => makeTestSeries(new arrow.Float64, makeTestNumbers(values)).lhs; describe('Series unaryops (Float64)', () => { const testMathematicalOp = <P extends MathematicalUnaryOp>(unaryMathOp: P) => { test(`Series.${unaryMathOp}`, () => { const values = [-2.5, 0, 2.5]; const actual = makeTestData(values)[unaryMathOp]().data.toArray(); const expected = new Float64Array(values).map(x => Math[unaryMathOp](x)); expect(actual).toEqualTypedArray(expected); }); }; for (const op of mathematicalUnaryOps) { testMathematicalOp(op); } test('Series.not', () => { const actual = makeTestData([-2.5, 0, 2.5]).not(); expect([...actual]).toEqual([-2.5, 0, 2.5].map((x) => !x)); }); test('Series.isNull', () => { const actual = makeTestData([null, 2.5, 5]).isNull(); expect([...actual]).toEqual([true, false, false]); }); test('Series.isNotNull', () => { const actual = makeTestData([null, 2.5, 5]).isNotNull(); expect([...actual]).toEqual([false, true, true]); }); test('Series.isNaN', () => { const actual = makeTestData([NaN, 2.5, 5]).isNaN(); expect([...actual]).toEqual([true, false, false]); }); test('Series.isNotNaN', () => { const actual = makeTestData([NaN, 2.5, 5]).isNotNaN(); expect([...actual]).toEqual([false, true, true]); }); test('Series.nansToNulls', () => { const actual = makeTestData([NaN, 2.5, 5]).nansToNulls(); expect([...actual]).toEqual([null, 2.5, 5]); }); test('Series.rint', () => { const actual = makeTestData([NaN, 2.5, 5]).rint(); expect([...actual]).toEqual([NaN, 2, 5]); }); test('Series.cast Utf8String', () => { const actual = makeTestData([NaN, 2, 2.5]); expect([...actual.cast(new Utf8String)]).toEqual(['NaN', '2.0', '2.5']); }); testForEachNumericType( 'Series.cast %p', function testSeriesCast<T extends TypedArray|BigIntArray, R extends Numeric>( TypedArrayCtor: TypedArrayConstructor<T>, type: R) { const input = Array.from({length: 16}, () => 16 * (Math.random() - 0.5)); const actual = makeTestData(input).cast(type).data.toArray(); const expected = new TypedArrayCtor(clampFloatValuesLikeUnaryCast(type, input)); expect(actual).toEqualTypedArray(expected); }); testForEachNumericType( 'Series.view %p', function testSeriesView<T extends TypedArray|BigIntArray, R extends Numeric>( TypedArrayCtor: TypedArrayConstructor<T>, type: R) { const input = Array.from({length: 16}, () => 16 * (Math.random() - 0.5)); const actual = makeTestData(input).view(type).data.toArray(); const expected = new TypedArrayCtor(new Float64Array(input).buffer); expect(actual).toEqualTypedArray(expected); }); });
0
rapidsai_public_repos/node/modules/cudf/test/series
rapidsai_public_repos/node/modules/cudf/test/series/reduce/nunique-tests.ts
// Copyright (c) 2021, NVIDIA CORPORATION. // // 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. import '../../jest-extensions'; import {setDefaultAllocator} from '@rapidsai/cuda'; import { Bool8, Float32, Float64, Int16, Int32, Int64, Int8, Series, Uint16, Uint32, Uint64, Uint8 } from '@rapidsai/cudf'; import {DeviceBuffer} from '@rapidsai/rmm'; setDefaultAllocator((byteLength: number) => new DeviceBuffer(byteLength)); const numbers = [null, 0, 1, 1, null, 2, 3, 3, 4, 4]; const bigints = [null, 0n, 1n, 1n, null, 2n, 3n, 3n, 4n, 4n]; const bools = [null, false, true, true, null, true, false, true, false, true]; const float_with_NaN = [NaN, 1, 2, 3, 4, 3, 7, 7, 2, NaN]; function testNumberNunique<T extends Int8|Int16|Int32|Uint8|Uint16|Uint32|Float32|Float64>( type: T, data: (T['scalarType']|null)[], expected: number, dropna = true) { expect(Series.new({type, data}).nunique(dropna)).toEqual(expected + (dropna ? 0 : 1)); } function testBigIntNunique<T extends Int64|Uint64>( type: T, data: (T['scalarType']|null)[], expected: number, dropna = true) { expect(Series.new({type, data}).nunique(dropna)).toEqual(expected + (dropna ? 0 : 1)); } function testBooleanNunique<T extends Bool8>( type: T, data: (T['scalarType']|null)[], expected: number, dropna = true) { expect(Series.new({type, data}).nunique(dropna)).toEqual(expected + (dropna ? 0 : 1)); } describe.each([[true], [false]])('Series.any(dropna=%p)', (dropna) => { test('Int8', () => { testNumberNunique(new Int8, numbers, 5, dropna); }); test('Int16', () => { testNumberNunique(new Int16, numbers, 5, dropna); }); test('Int32', () => { testNumberNunique(new Int32, numbers, 5, dropna); }); test('Int64', () => { testBigIntNunique(new Int64, bigints, 5, dropna); }); test('Uint8', () => { testNumberNunique(new Uint8, numbers, 5, dropna); }); test('Uint16', () => { testNumberNunique(new Uint16, numbers, 5, dropna); }); test('Uint32', () => { testNumberNunique(new Uint32, numbers, 5, dropna); }); test('Uint64', () => { testBigIntNunique(new Uint64, bigints, 5, dropna); }); test('Float32', () => { testNumberNunique(new Float32, numbers, 5, dropna); }); test('Float64', () => { testNumberNunique(new Float64, numbers, 5, dropna); }); test('Bool8', () => { testBooleanNunique(new Bool8, bools, 2, dropna); }); test('Float32', () => { testNumberNunique(new Float32, float_with_NaN, 5, dropna); }); test('Float64', () => { testNumberNunique(new Float64, float_with_NaN, 5, dropna); }); });
0
rapidsai_public_repos/node/modules/cudf/test/series
rapidsai_public_repos/node/modules/cudf/test/series/reduce/mean-tests.ts
// Copyright (c) 2021, NVIDIA CORPORATION. // // 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. import '../../jest-extensions'; import {setDefaultAllocator} from '@rapidsai/cuda'; import { Bool8, Float32, Float64, Int16, Int32, Int64, Int8, Series, Uint16, Uint32, Uint64, Uint8 } from '@rapidsai/cudf'; import {DeviceBuffer} from '@rapidsai/rmm'; setDefaultAllocator((byteLength: number) => new DeviceBuffer(byteLength)); const numbers = [null, 0, 1, 1, null, 2, 3, 3, 4, 4]; const bigints = [null, 0n, 1n, 1n, null, 2n, 3n, 3n, 4n, 4n]; const bools = [null, false, true, true, null, true, false, true, false, true]; const float_with_NaN = [NaN, 1, 2, 3, 4, 3, 7, 7, 2, NaN]; function jsMean(values: number[]) { if (values.length === 0) return NaN; return values.reduce((x: number, y: number) => x + y) / values.length; } function jsMeanBigInt(values: bigint[]) { if (values.length === 0) return NaN; return Number(values.reduce((x: bigint, y: bigint) => x + y)) / values.length; } function jsMeanBoolean(values: boolean[]) { if (values.length === 0) return NaN; let sum = 0; values.forEach((x) => sum += (x ? 1 : 0)); return sum / values.length; } function testNumberMean<T extends Int8|Int16|Int32|Uint8|Uint16|Uint32|Float32|Float64>( type: T, data: (T['scalarType']|null)[], skipNulls = true) { if (skipNulls) { const expected = jsMean(data.filter((x) => x !== null && !isNaN(x)) as number[]); expect(Series.new({type, data}).mean(skipNulls)).toEqual(expected); } else { const expected = data.some((x) => x === null || isNaN(x)) ? NaN : jsMean(data as number[]); expect(Series.new({type, data}).mean(skipNulls)).toEqual(expected); } } function testBigIntMean<T extends Int64|Uint64>( type: T, data: (T['scalarType']|null)[], skipNulls = true) { if (skipNulls) { const expected = jsMeanBigInt(data.filter((x) => x !== null) as bigint[]); expect(Series.new({type, data}).mean(skipNulls)).toEqual(expected); } else { const expected = data.some((x) => x === null) ? NaN : jsMeanBigInt(data as bigint[]); expect(Series.new({type, data}).mean(skipNulls)).toEqual(expected); } } function testBooleanMean<T extends Bool8>( type: T, data: (T['scalarType']|null)[], skipNulls = true) { if (skipNulls) { const expected = jsMeanBoolean(data.filter((x) => x !== null) as boolean[]); expect(Series.new({type, data}).mean(skipNulls)).toEqual(expected); } else { const expected = data.some((x) => x === null) ? NaN : jsMeanBoolean(data as boolean[]); expect(Series.new({type, data}).mean(skipNulls)).toEqual(expected); } } describe.each([[true], [false]])('Series.mean(skipNulls=%p)', (skipNulls) => { test('Int8', () => { testNumberMean(new Int8, numbers, skipNulls); }); test('Int16', () => { testNumberMean(new Int16, numbers, skipNulls); }); test('Int32', () => { testNumberMean(new Int32, numbers, skipNulls); }); test('Int64', () => { testBigIntMean(new Int64, bigints, skipNulls); }); test('Uint8', () => { testNumberMean(new Uint8, numbers, skipNulls); }); test('Uint16', () => { testNumberMean(new Uint16, numbers, skipNulls); }); test('Uint32', () => { testNumberMean(new Uint32, numbers, skipNulls); }); test('Uint64', () => { testBigIntMean(new Uint64, bigints, skipNulls); }); test('Float32', () => { testNumberMean(new Float32, numbers, skipNulls); }); test('Float64', () => { testNumberMean(new Float64, numbers, skipNulls); }); test('Bool8', () => { testBooleanMean(new Bool8, bools, skipNulls); }); test('Float32', () => { testNumberMean(new Float32, float_with_NaN, skipNulls); }); test('Float64', () => { testNumberMean(new Float64, float_with_NaN, skipNulls); }); });
0
rapidsai_public_repos/node/modules/cudf/test/series
rapidsai_public_repos/node/modules/cudf/test/series/reduce/cummax-tests.ts
// Copyright (c) 2021, NVIDIA CORPORATION. // // 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. import '../../jest-extensions'; import {setDefaultAllocator} from '@rapidsai/cuda'; import { Bool8, Float32, Float64, Int16, Int32, Int64, Int8, Series, Uint16, Uint32, Uint64, Uint8 } from '@rapidsai/cudf'; import {DeviceBuffer} from '@rapidsai/rmm'; setDefaultAllocator((byteLength: number) => new DeviceBuffer(byteLength)); const numbers = [4, 2, null, 5, 1, 1]; const float_with_NaN = [4, 2, NaN, 5, 1, 1]; const bools = [true, false, null, false, true]; const bigints = [4n, 2n, null, 5n, 1n, 1n]; function testNumberAny<T extends Int8|Int16|Int32|Uint8|Uint16|Uint32|Float32|Float64>( type: T, data: (T['scalarType']|null)[], skipNulls = true) { const expected = skipNulls ? [4, 4, null, 5, 5, 5] // : [4, 4, null, null, null, null]; expect([...Series.new({type, data}).cumulativeMax(skipNulls)]).toEqual(expected); } function testBigIntAny<T extends Int64|Uint64>( type: T, data: (T['scalarType']|null)[], skipNulls = true) { const expected = skipNulls ? [4n, 4n, null, 5n, 5n, 5n] // : [4n, 4n, null, null, null, null]; expect([...Series.new({type, data}).cumulativeMax(skipNulls)]).toEqual(expected); } function testBooleanAny<T extends Bool8>( type: T, data: (T['scalarType']|null)[], skipNulls = true) { const expected = skipNulls ? [true, true, null, true, true] // : [true, true, null, null, null]; expect([...Series.new({type, data}).cumulativeMax(skipNulls)]).toEqual(expected); } describe.each([[true], [false]])('Series.cumulativeMax(skipNulls=%p)', (skipNulls) => { test('Int8', () => { testNumberAny(new Int8, numbers, skipNulls); }); test('Int16', () => { testNumberAny(new Int16, numbers, skipNulls); }); test('Int32', () => { testNumberAny(new Int32, numbers, skipNulls); }); test('Int64', () => { testBigIntAny(new Int64, bigints, skipNulls); }); test('Uint8', () => { testNumberAny(new Uint8, numbers, skipNulls); }); test('Uint16', () => { testNumberAny(new Uint16, numbers, skipNulls); }); test('Uint32', () => { testNumberAny(new Uint32, numbers, skipNulls); }); test('Uint64', () => { testBigIntAny(new Uint64, bigints, skipNulls); }); test('Float32', () => { testNumberAny(new Float32, numbers, skipNulls); }); test('Float64', () => { testNumberAny(new Float64, numbers, skipNulls); }); test('Bool8', () => { testBooleanAny(new Bool8, bools, skipNulls); }); test('Float32-nan', () => { testNumberAny(new Float32, float_with_NaN, skipNulls); }); test('Float64-nan', () => { testNumberAny(new Float64, float_with_NaN, skipNulls); }); });
0
rapidsai_public_repos/node/modules/cudf/test/series
rapidsai_public_repos/node/modules/cudf/test/series/reduce/median-tests.ts
// Copyright (c) 2021, NVIDIA CORPORATION. // // 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. import '../../jest-extensions'; import {setDefaultAllocator} from '@rapidsai/cuda'; import { Bool8, Float32, Float64, Int16, Int32, Int64, Int8, Series, Uint16, Uint32, Uint64, Uint8 } from '@rapidsai/cudf'; import {DeviceBuffer} from '@rapidsai/rmm'; setDefaultAllocator((byteLength: number) => new DeviceBuffer(byteLength)); const numbers = [null, 0, 1, 1, null, 2, 3, 3, 4, 4]; const bigints = [null, 0n, 1n, 1n, null, 2n, 3n, 3n, 4n, 4n]; const bools = [null, false, true, true, null, true, false, true, false, true]; const float_with_NaN = [NaN, 1, 2, 3, 4, 3, 7, 7, 2, NaN]; function jsMedian(values: any) { if (values.length === 0) return NaN; values.sort(function(a: any, b: any) { return Number(a) - Number(b); }); const half = Math.floor(values.length / 2); if (values.length % 2) return Number(values[half]); return (Number(values[half - 1]) + Number(values[half])) / 2.0; } function testNumberMedian<T extends Int8|Int16|Int32|Uint8|Uint16|Uint32|Float32|Float64>( type: T, data: (T['scalarType']|null)[], skipNulls = true) { if (skipNulls) { const expected = jsMedian(data.filter((x) => x !== null && !isNaN(x))); expect(Series.new({type, data}).median(skipNulls)).toEqual(expected); } else { const expected = data.some((x) => x === null || isNaN(x)) ? NaN : jsMedian(data); expect(Series.new({type, data}).median(skipNulls)).toEqual(expected); } } function testBigIntMedian<T extends Int64|Uint64>( type: T, data: (T['scalarType']|null)[], skipNulls = true) { if (skipNulls) { const expected = jsMedian(data.filter((x) => x !== null)); expect(Series.new({type, data}).median(skipNulls)).toEqual(expected); } else { const expected = data.some((x) => x === null) ? NaN : jsMedian(data); expect(Series.new({type, data}).median(skipNulls)).toEqual(expected); } } function testBooleanMedian<T extends Bool8>( type: T, data: (T['scalarType']|null)[], skipNulls = true) { if (skipNulls) { const expected = jsMedian(data.filter((x) => x !== null)); expect(Series.new({type, data}).median(skipNulls)).toEqual(expected); } else { const expected = data.some((x) => x === null) ? NaN : jsMedian(data); expect(Series.new({type, data}).median(skipNulls)).toEqual(expected); } } describe.each([[true], [false]])('Series.any(skipNulls=%p)', (skipNulls) => { test('Int8', () => { testNumberMedian(new Int8, numbers, skipNulls); }); test('Int16', () => { testNumberMedian(new Int16, numbers, skipNulls); }); test('Int32', () => { testNumberMedian(new Int32, numbers, skipNulls); }); test('Int64', () => { testBigIntMedian(new Int64, bigints, skipNulls); }); test('Uint8', () => { testNumberMedian(new Uint8, numbers, skipNulls); }); test('Uint16', () => { testNumberMedian(new Uint16, numbers, skipNulls); }); test('Uint32', () => { testNumberMedian(new Uint32, numbers, skipNulls); }); test('Uint64', () => { testBigIntMedian(new Uint64, bigints, skipNulls); }); test('Float32', () => { testNumberMedian(new Float32, numbers, skipNulls); }); test('Float64', () => { testNumberMedian(new Float64, numbers, skipNulls); }); test('Bool8', () => { testBooleanMedian(new Bool8, bools, skipNulls); }); test('Float32', () => { testNumberMedian(new Float32, float_with_NaN, skipNulls); }); test('Float64', () => { testNumberMedian(new Float64, float_with_NaN, skipNulls); }); });
0
rapidsai_public_repos/node/modules/cudf/test/series
rapidsai_public_repos/node/modules/cudf/test/series/reduce/product-tests.ts
// Copyright (c) 2021, NVIDIA CORPORATION. // // 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. import '../../jest-extensions'; import {BigIntArray, setDefaultAllocator, TypedArray} from '@rapidsai/cuda'; import { Bool8, Float32, Float64, Int16, Int32, Int64, Int8, Numeric, Series, Uint16, Uint32, Uint64, Uint8 } from '@rapidsai/cudf'; import {DeviceBuffer} from '@rapidsai/rmm'; import * as arrow from 'apache-arrow'; setDefaultAllocator((byteLength: number) => new DeviceBuffer(byteLength)); const makeNumbers = (length = 10) => Array.from({length}, (_, i) => Number(i)); const makeBigInts = (length = 10) => Array.from({length}, (_, i) => BigInt(i)); const makeBooleans = (length = 10) => Array.from({length}, (_, i) => Number(i % 2 == 0)); const float_with_NaN = Array.from([NaN, 1, 2, 3, 4, 5, 6, 7, 8, NaN]); function test_values<T extends Numeric>(lhs: number|bigint|undefined, rhs: number, type: T) { if (['Float32', 'Float64', 'Bool'].includes(type.toString())) { expect(lhs).toEqual(rhs); } else { expect(lhs).toEqual(BigInt(rhs)); } } function testNumberProduct<T extends Numeric, R extends TypedArray>(type: T, data: R) { const result = [...data].reduce((x, y) => { if (isNaN(y)) { y = 1; } if (isNaN(x)) { x = 1; } return x * y; }); test_values(Series.new({type, data}).product(), result, type); } function testNumberProductskipNulls<T extends Numeric, R extends TypedArray>( type: T, data: R, mask_array: Array<number>) { const mask = arrow.vectorFromArray(mask_array, new arrow.Bool).data[0].values; if (!data.includes(NaN)) { const result = [...data].reduce((x, y, i) => { if (mask_array[i] == 1) { return x * y; } return x; }); // skipNulls=false test_values(Series.new({type, data, nullMask: mask}).product(false), result, type); } else { // skipNulls=false expect(Series.new({type, data, nullMask: mask}).product(false)).toEqual(NaN); } } function testBigIntProduct<T extends Numeric, R extends BigIntArray>(type: T, data: R) { expect(Series.new({type, data}).product()).toEqual([...data].reduce((x, y) => x * y)); } function testBigIntProductskipNulls<T extends Numeric, R extends BigIntArray>( type: T, data: R, mask_array: Array<number>) { const mask = arrow.vectorFromArray(mask_array, new arrow.Bool).data[0].values; // skipNulls=false expect(Series.new({type, data, nullMask: mask}).product(false)).toEqual([ ...data ].reduce((x, y, i) => { if (mask_array[i] == 1) { return x * y; } return x; })); } describe('Series.product(skipNulls=true)', () => { test('Int8', () => { testNumberProduct(new Int8, new Int8Array(makeNumbers())); }); test('Int16', () => { testNumberProduct(new Int16, new Int16Array(makeNumbers())); }); test('Int32', () => { testNumberProduct(new Int32, new Int32Array(makeNumbers())); }); test('Int64', () => { testBigIntProduct(new Int64, new BigInt64Array(makeBigInts())); }); test('Uint8', () => { testNumberProduct(new Uint8, new Uint8Array(makeNumbers())); }); test('Uint16', () => { testNumberProduct(new Uint16, new Uint16Array(makeNumbers())); }); test('Uint32', () => { testNumberProduct(new Uint32, new Uint32Array(makeNumbers())); }); test('Uint64', () => { testBigIntProduct(new Uint64, new BigUint64Array(makeBigInts())); }); test('Float32', () => { testNumberProduct(new Float32, new Float32Array(makeNumbers())); }); test('Float64', () => { testNumberProduct(new Float64, new Float64Array(makeNumbers())); }); test('Bool8', () => { testNumberProduct(new Bool8, new Uint8ClampedArray(makeBooleans())); }); }); describe('Series.product(skipNulls=false)', () => { test( 'Int8', () => { testNumberProductskipNulls(new Int8, new Int8Array(makeNumbers()), makeBooleans()); }); test('Int16', () => { testNumberProductskipNulls(new Int16, new Int16Array(makeNumbers()), makeBooleans()); }); test('Int32', () => { testNumberProductskipNulls(new Int32, new Int32Array(makeNumbers()), makeBooleans()); }); test('Int64', () => { testBigIntProductskipNulls(new Int64, new BigInt64Array(makeBigInts()), makeBooleans()); }); test('Uint8', () => { testNumberProductskipNulls(new Uint8, new Uint8Array(makeNumbers()), makeBooleans()); }); test('Uint16', () => { testNumberProductskipNulls(new Uint16, new Uint16Array(makeNumbers()), makeBooleans()); }); test('Uint32', () => { testNumberProductskipNulls(new Uint32, new Uint32Array(makeNumbers()), makeBooleans()); }); test('Uint64', () => { testBigIntProductskipNulls(new Uint64, new BigUint64Array(makeBigInts()), makeBooleans()); }); test('Float32', () => { testNumberProductskipNulls(new Float32, new Float32Array(makeNumbers()), makeBooleans()); }); test('Float64', () => { testNumberProductskipNulls(new Float64, new Float64Array(makeNumbers()), makeBooleans()); }); test('Bool8', () => { testNumberProductskipNulls(new Bool8, new Uint8ClampedArray(makeBooleans()), makeBooleans()); }); }); describe('Float type Series with NaN => Series.product(skipNulls=true)', () => { test('Float32', () => { testNumberProduct(new Float32, new Float32Array(float_with_NaN)); }); test('Float64', () => { testNumberProduct(new Float64, new Float64Array(float_with_NaN)); }); }); describe('Float type Series with NaN => Series.product(skipNulls=false)', () => { test('Float32', () => { testNumberProductskipNulls(new Float32, new Float32Array(float_with_NaN), makeBooleans()); }); test('Float64', () => { testNumberProductskipNulls(new Float64, new Float64Array(float_with_NaN), makeBooleans()); }); });
0
rapidsai_public_repos/node/modules/cudf/test/series
rapidsai_public_repos/node/modules/cudf/test/series/reduce/any-tests.ts
// Copyright (c) 2021, NVIDIA CORPORATION. // // 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. import '../../jest-extensions'; import {setDefaultAllocator} from '@rapidsai/cuda'; import { Bool8, Float32, Float64, Int16, Int32, Int64, Int8, Series, Uint16, Uint32, Uint64, Uint8 } from '@rapidsai/cudf'; import {DeviceBuffer} from '@rapidsai/rmm'; setDefaultAllocator((byteLength: number) => new DeviceBuffer(byteLength)); const numbers = [null, 0, 1, 1, null, 2, 3, 3, 4, 4]; const bigints = [null, 0n, 1n, 1n, null, 2n, 3n, 3n, 4n, 4n]; const bools = [null, false, true, true, null, true, false, true, false, true]; const float_with_NaN = [NaN, 1, 2, 3, 4, 3, 7, 7, 2, NaN]; function testNumberAny<T extends Int8|Int16|Int32|Uint8|Uint16|Uint32|Float32|Float64>( type: T, data: (T['scalarType']|null)[], skipNulls = true) { const expected = skipNulls ? data.some((x) => x === null || x !== 0) // : data.some((x) => x !== null); expect(Series.new({type, data}).any(skipNulls)).toEqual(expected); } function testBigIntAny<T extends Int64|Uint64>( type: T, data: (T['scalarType']|null)[], skipNulls = true) { const expected = skipNulls ? data.some((x) => x === null || x !== 0n) // : data.some((x) => x !== null); expect(Boolean(Series.new({type, data}).any(skipNulls))).toEqual(expected); } function testBooleanAny<T extends Bool8>( type: T, data: (T['scalarType']|null)[], skipNulls = true) { const expected = skipNulls ? data.some((x) => x === null || x !== false) // : data.some((x) => x !== null); expect(Series.new({type, data}).any(skipNulls)).toEqual(expected); } describe.each([[true], [false]])('Series.any(skipNulls=%p)', (skipNulls) => { test('Int8', () => { testNumberAny(new Int8, numbers, skipNulls); }); test('Int16', () => { testNumberAny(new Int16, numbers, skipNulls); }); test('Int32', () => { testNumberAny(new Int32, numbers, skipNulls); }); test('Int64', () => { testBigIntAny(new Int64, bigints, skipNulls); }); test('Uint8', () => { testNumberAny(new Uint8, numbers, skipNulls); }); test('Uint16', () => { testNumberAny(new Uint16, numbers, skipNulls); }); test('Uint32', () => { testNumberAny(new Uint32, numbers, skipNulls); }); test('Uint64', () => { testBigIntAny(new Uint64, bigints, skipNulls); }); test('Float32', () => { testNumberAny(new Float32, numbers, skipNulls); }); test('Float64', () => { testNumberAny(new Float64, numbers, skipNulls); }); test('Bool8', () => { testBooleanAny(new Bool8, bools, skipNulls); }); test('Float32', () => { testNumberAny(new Float32, float_with_NaN, skipNulls); }); test('Float64', () => { testNumberAny(new Float64, float_with_NaN, skipNulls); }); });
0
rapidsai_public_repos/node/modules/cudf/test/series
rapidsai_public_repos/node/modules/cudf/test/series/reduce/minmax-tests.ts
// Copyright (c) 2022, NVIDIA CORPORATION. // // 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. import '../../jest-extensions'; import {setDefaultAllocator} from '@rapidsai/cuda'; import { Bool8, Float32, Float64, Int16, Int32, Int64, Int8, Series, Uint16, Uint32, Uint64, Uint8 } from '@rapidsai/cudf'; import {DeviceBuffer} from '@rapidsai/rmm'; setDefaultAllocator((byteLength: number) => new DeviceBuffer(byteLength)); const numbers = [4, 2, null, 5, 1, 1]; const float_with_NaN = [4, 2, NaN, 5, 1, 1]; const bools = [true, false, null, false, true]; const bigints = [4n, 2n, null, 5n, 1n, 1n]; function testNumberAny<T extends Int8|Int16|Int32|Uint8|Uint16|Uint32|Float32|Float64>( type: T, data: (T['scalarType']|null)[], skipNulls = true) { expect(Series.new({type, data}).minmax(skipNulls)).toEqual([1, 5]); } function testBigIntAny<T extends Int64|Uint64>( type: T, data: (T['scalarType']|null)[], skipNulls = true) { expect(Series.new({type, data}).minmax(skipNulls)).toEqual([1n, 5n]); } function testBooleanAny<T extends Bool8>( type: T, data: (T['scalarType']|null)[], skipNulls = true) { expect(Series.new({type, data}).minmax(skipNulls)).toEqual([false, true]); } describe.each([[true], [false]])('Series.minmax(skipNulls=%p)', (skipNulls) => { test('Int8', () => { testNumberAny(new Int8, numbers, skipNulls); }); test('Int16', () => { testNumberAny(new Int16, numbers, skipNulls); }); test('Int32', () => { testNumberAny(new Int32, numbers, skipNulls); }); test('Int64', () => { testBigIntAny(new Int64, bigints, skipNulls); }); test('Uint8', () => { testNumberAny(new Uint8, numbers, skipNulls); }); test('Uint16', () => { testNumberAny(new Uint16, numbers, skipNulls); }); test('Uint32', () => { testNumberAny(new Uint32, numbers, skipNulls); }); test('Uint64', () => { testBigIntAny(new Uint64, bigints, skipNulls); }); test('Float32', () => { testNumberAny(new Float32, numbers, skipNulls); }); test('Float64', () => { testNumberAny(new Float64, numbers, skipNulls); }); test('Bool8', () => { testBooleanAny(new Bool8, bools, skipNulls); }); test('Float32-nan', () => { testNumberAny(new Float32, float_with_NaN, skipNulls); }); test('Float64-nan', () => { testNumberAny(new Float64, float_with_NaN, skipNulls); }); });
0
rapidsai_public_repos/node/modules/cudf/test/series
rapidsai_public_repos/node/modules/cudf/test/series/reduce/cumprod-tests.ts
// Copyright (c) 2021, NVIDIA CORPORATION. // // 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. import '../../jest-extensions'; import {setDefaultAllocator} from '@rapidsai/cuda'; import { Bool8, Float32, Float64, Int16, Int32, Int64, Int8, Series, Uint16, Uint32, Uint64, Uint8 } from '@rapidsai/cudf'; import {DeviceBuffer} from '@rapidsai/rmm'; setDefaultAllocator((byteLength: number) => new DeviceBuffer(byteLength)); const numbers = [4, 2, null, 5, 1, 1]; const float_with_NaN = [4, 2, NaN, 5, 1, 1]; const bools = [true, false, null, false, true]; const bigints = [4n, 2n, null, 5n, 1n, 1n]; function testNumberAny<T extends Int8|Int16|Int32|Uint8|Uint16|Uint32|Float32|Float64>( type: T, data: (T['scalarType']|null)[], skipNulls = true) { const expected = skipNulls ? [4, 8, null, 40, 40, 40] // : [4, 8, null, null, null, null]; expect([...Series.new({type, data}).cumulativeProduct(skipNulls)]).toEqual(expected); } function testBigIntAny<T extends Int64|Uint64>( type: T, data: (T['scalarType']|null)[], skipNulls = true) { const expected = skipNulls ? [4n, 8n, null, 40n, 40n, 40n] // : [4n, 8n, null, null, null, null]; expect([...Series.new({type, data}).cumulativeProduct(skipNulls)]).toEqual(expected); } function testBooleanAny<T extends Bool8>( type: T, data: (T['scalarType']|null)[], skipNulls = true) { const expected = skipNulls ? [1, 0, null, 0, 0] // : [1, 0, null, null, null]; expect([...Series.new({type, data}).cumulativeProduct(skipNulls)]).toEqual(expected); } describe.each([[true], [false]])('Series.cumulativeProduct(skipNulls=%p)', (skipNulls) => { test('Int8', () => { testNumberAny(new Int8, numbers, skipNulls); }); test('Int16', () => { testNumberAny(new Int16, numbers, skipNulls); }); test('Int32', () => { testNumberAny(new Int32, numbers, skipNulls); }); test('Int64', () => { testBigIntAny(new Int64, bigints, skipNulls); }); test('Uint8', () => { testNumberAny(new Uint8, numbers, skipNulls); }); test('Uint16', () => { testNumberAny(new Uint16, numbers, skipNulls); }); test('Uint32', () => { testNumberAny(new Uint32, numbers, skipNulls); }); test('Uint64', () => { testBigIntAny(new Uint64, bigints, skipNulls); }); test('Float32', () => { testNumberAny(new Float32, numbers, skipNulls); }); test('Float64', () => { testNumberAny(new Float64, numbers, skipNulls); }); test('Bool8', () => { testBooleanAny(new Bool8, bools, skipNulls); }); test('Float32-nan', () => { testNumberAny(new Float32, float_with_NaN, skipNulls); }); test('Float64-nan', () => { testNumberAny(new Float64, float_with_NaN, skipNulls); }); });
0
rapidsai_public_repos/node/modules/cudf/test/series
rapidsai_public_repos/node/modules/cudf/test/series/reduce/variance-tests.ts
// Copyright (c) 2021, NVIDIA CORPORATION. // // 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. import '../../jest-extensions'; import {BigIntArray, setDefaultAllocator, TypedArray} from '@rapidsai/cuda'; import { Bool8, Float32, Float64, Int16, Int32, Int64, Int8, Numeric, Series, Uint16, Uint32, Uint64, Uint8 } from '@rapidsai/cudf'; import {DeviceBuffer} from '@rapidsai/rmm'; setDefaultAllocator((byteLength: number) => new DeviceBuffer(byteLength)); const makeNumbers = (length = 10) => Array.from({length}, (_, i) => Number(i)); const makeBigInts = (length = 10) => Array.from({length}, (_, i) => BigInt(i)); const makeBooleans = (length = 10) => Array.from({length}, (_, i) => Number(i % 2 == 0)); const param_ddof = [1, 3, 5]; const var_number_results = new Map([[1, 9.166666666666668], [3, 11.785714285714288], [5, 16.5]]); const var_bool_results = new Map([[1, 0.2777777777777778], [3, 0.35714285714285715], [5, 0.5]]); function testNumberVar<T extends Numeric, R extends TypedArray|BigIntArray>( skipNulls: boolean, ddof: number, type: T, data: R) { expect(Series.new({type, data}).var(skipNulls, ddof)) .toEqual((data.includes(<never>NaN) && skipNulls == false) ? NaN : var_number_results.get(ddof)); } function testBooleanVar<T extends Numeric, R extends TypedArray|BigIntArray>( skipNulls: boolean, ddof: number, type: T, data: R) { expect(Series.new({type, data}).var(skipNulls, ddof)) .toEqual((data.includes(<never>NaN) && skipNulls == false) ? NaN : var_bool_results.get(ddof)); } param_ddof.forEach(ddof => { describe('Series.var (skipNulls=True)', () => { const skipNulls = true; test('Int8', () => { testNumberVar(skipNulls, ddof, new Int8, new Int8Array(makeNumbers())); }); test('Int16', () => { testNumberVar(skipNulls, ddof, new Int16, new Int16Array(makeNumbers())); }); test('Int32', () => { testNumberVar(skipNulls, ddof, new Int32, new Int32Array(makeNumbers())); }); test('Int64', () => { testNumberVar(skipNulls, ddof, new Int64, new BigInt64Array(makeBigInts())); }); test('Uint8', () => { testNumberVar(skipNulls, ddof, new Uint8, new Uint8Array(makeNumbers())); }); test('Uint16', () => { testNumberVar(skipNulls, ddof, new Uint16, new Uint16Array(makeNumbers())); }); test('Uint32', () => { testNumberVar(skipNulls, ddof, new Uint32, new Uint32Array(makeNumbers())); }); test('Uint64', () => { testNumberVar(skipNulls, ddof, new Uint64, new BigUint64Array(makeBigInts())); }); test('Float32', () => { testNumberVar(skipNulls, ddof, new Float32, new Float32Array(makeNumbers())); }); test('Float64', () => { testNumberVar(skipNulls, ddof, new Float64, new Float64Array(makeNumbers())); }); test( 'Bool8', () => { testBooleanVar(skipNulls, ddof, new Bool8, new Uint8ClampedArray(makeBooleans())); }); }); describe('Float type Series with NaN => Series.var (skipNulls=True)', () => { const skipNulls = true; test('Float32', () => { testNumberVar( skipNulls, ddof, new Float32, new Float32Array([NaN].concat(makeNumbers().concat([NaN])))); }); test('Float64', () => { testNumberVar( skipNulls, ddof, new Float64, new Float64Array([NaN].concat(makeNumbers().concat([NaN])))); }); }); describe('Series.var (skipNulls=false)', () => { const skipNulls = false; test('Int8', () => { testNumberVar(skipNulls, ddof, new Int8, new Int8Array(makeNumbers())); }); test('Int16', () => { testNumberVar(skipNulls, ddof, new Int16, new Int16Array(makeNumbers())); }); test('Int32', () => { testNumberVar(skipNulls, ddof, new Int32, new Int32Array(makeNumbers())); }); test('Int64', () => { testNumberVar(skipNulls, ddof, new Int64, new BigInt64Array(makeBigInts())); }); test('Uint8', () => { testNumberVar(skipNulls, ddof, new Uint8, new Uint8Array(makeNumbers())); }); test('Uint16', () => { testNumberVar(skipNulls, ddof, new Uint16, new Uint16Array(makeNumbers())); }); test('Uint32', () => { testNumberVar(skipNulls, ddof, new Uint32, new Uint32Array(makeNumbers())); }); test('Uint64', () => { testNumberVar(skipNulls, ddof, new Uint64, new BigUint64Array(makeBigInts())); }); test('Float32', () => { testNumberVar(skipNulls, ddof, new Float32, new Float32Array(makeNumbers())); }); test('Float64', () => { testNumberVar(skipNulls, ddof, new Float64, new Float64Array(makeNumbers())); }); test( 'Bool8', () => { testBooleanVar(skipNulls, ddof, new Bool8, new Uint8ClampedArray(makeBooleans())); }); }); describe('Float type Series with NaN => Series.var (skipNulls=false)', () => { const skipNulls = false; test('Float32', () => { testNumberVar( skipNulls, ddof, new Float32, new Float32Array([NaN].concat(makeNumbers().concat([NaN])))); }); test('Float64', () => { testNumberVar( skipNulls, ddof, new Float64, new Float64Array([NaN].concat(makeNumbers().concat([NaN])))); }); }); });
0
rapidsai_public_repos/node/modules/cudf/test/series
rapidsai_public_repos/node/modules/cudf/test/series/reduce/min-tests.ts
// Copyright (c) 2022, NVIDIA CORPORATION. // // 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. import '../../jest-extensions'; import {setDefaultAllocator} from '@rapidsai/cuda'; import { Bool8, Float32, Float64, Int16, Int32, Int64, Int8, Series, Uint16, Uint32, Uint64, Uint8 } from '@rapidsai/cudf'; import {DeviceBuffer} from '@rapidsai/rmm'; setDefaultAllocator((byteLength: number) => new DeviceBuffer(byteLength)); const numbers = [4, 2, null, 5, 1, 1]; const float_with_NaN = [4, 2, NaN, 5, 1, 1]; const bools = [true, false, null, false, true]; const bigints = [4n, 2n, null, 5n, 1n, 1n]; function testNumberAny<T extends Int8|Int16|Int32|Uint8|Uint16|Uint32|Float32|Float64>( type: T, data: (T['scalarType']|null)[], skipNulls = true) { expect(Series.new({type, data}).min(skipNulls)).toEqual(1); } function testBigIntAny<T extends Int64|Uint64>( type: T, data: (T['scalarType']|null)[], skipNulls = true) { expect(Series.new({type, data}).min(skipNulls)).toEqual(1n); } function testBooleanAny<T extends Bool8>( type: T, data: (T['scalarType']|null)[], skipNulls = true) { expect(Series.new({type, data}).min(skipNulls)).toEqual(false); } describe.each([[true], [false]])('Series.min(skipNulls=%p)', (skipNulls) => { test('Int8', () => { testNumberAny(new Int8, numbers, skipNulls); }); test('Int16', () => { testNumberAny(new Int16, numbers, skipNulls); }); test('Int32', () => { testNumberAny(new Int32, numbers, skipNulls); }); test('Int64', () => { testBigIntAny(new Int64, bigints, skipNulls); }); test('Uint8', () => { testNumberAny(new Uint8, numbers, skipNulls); }); test('Uint16', () => { testNumberAny(new Uint16, numbers, skipNulls); }); test('Uint32', () => { testNumberAny(new Uint32, numbers, skipNulls); }); test('Uint64', () => { testBigIntAny(new Uint64, bigints, skipNulls); }); test('Float32', () => { testNumberAny(new Float32, numbers, skipNulls); }); test('Float64', () => { testNumberAny(new Float64, numbers, skipNulls); }); test('Bool8', () => { testBooleanAny(new Bool8, bools, skipNulls); }); test('Float32-nan', () => { testNumberAny(new Float32, float_with_NaN, skipNulls); }); test('Float64-nan', () => { testNumberAny(new Float64, float_with_NaN, skipNulls); }); });
0
rapidsai_public_repos/node/modules/cudf/test/series
rapidsai_public_repos/node/modules/cudf/test/series/reduce/quantile-tests.ts
// Copyright (c) 2021, NVIDIA CORPORATION. // // 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. import '../../jest-extensions'; import {BigIntArray, setDefaultAllocator, TypedArray} from '@rapidsai/cuda'; import { Bool8, Float32, Float64, Int16, Int32, Int64, Int8, Interpolation, Numeric, Series, Uint16, Uint32, Uint64, Uint8 } from '@rapidsai/cudf'; import {DeviceBuffer} from '@rapidsai/rmm'; setDefaultAllocator((byteLength: number) => new DeviceBuffer(byteLength)); const makeNumbers = (length = 10) => Array.from({length}, (_, i) => Number(i)); const makeBigInts = (length = 10) => Array.from({length}, (_, i) => BigInt(i)); const makeBooleans = (length = 10) => Array.from({length}, (_, i) => Number(i % 2 == 0)); const param_q = [0.3, 0.7]; const param_interpolation = ['linear', 'lower', 'higher', 'midpoint', 'nearest'] as (keyof typeof Interpolation)[]; const quantile_number_results = new Map([[0.3, [2.6999999999999997, 2, 3, 2.5, 3]], [0.7, [6.3, 6, 7, 6.5, 6]]]); const quantile_bool_results = new Map([[0.3, [0, 0, 0, 0, 0]], [0.7, [1, 1, 1, 1, 1]]]); function testNumberQuantile<T extends Numeric, R extends TypedArray|BigIntArray>( q: number, type: T, data: R) { param_interpolation.forEach((interop, idx) => { expect(Series.new({type, data}).quantile(q, interop)) .toEqual(quantile_number_results.get(q)?.[idx]); }); } function testBooleanQuantile<T extends Numeric, R extends TypedArray|BigIntArray>( q: number, type: T, data: R) { param_interpolation.forEach((interop, idx) => { expect(Series.new({type, data}).quantile(q, interop)) .toEqual(quantile_bool_results.get(q)?.[idx]); }); } param_q.forEach(q => { describe('Series.quantile', () => { test('Int8', () => { testNumberQuantile(q, new Int8, new Int8Array(makeNumbers())); }); test('Int16', () => { testNumberQuantile(q, new Int16, new Int16Array(makeNumbers())); }); test('Int32', () => { testNumberQuantile(q, new Int32, new Int32Array(makeNumbers())); }); test('Int64', () => { testNumberQuantile(q, new Int64, new BigInt64Array(makeBigInts())); }); test('Uint8', () => { testNumberQuantile(q, new Uint8, new Uint8Array(makeNumbers())); }); test('Uint16', () => { testNumberQuantile(q, new Uint16, new Uint16Array(makeNumbers())); }); test('Uint32', () => { testNumberQuantile(q, new Uint32, new Uint32Array(makeNumbers())); }); test('Uint64', () => { testNumberQuantile(q, new Uint64, new BigUint64Array(makeBigInts())); }); test('Float32', () => { testNumberQuantile(q, new Float32, new Float32Array(makeNumbers())); }); test('Float64', () => { testNumberQuantile(q, new Float64, new Float64Array(makeNumbers())); }); test('Bool8', () => { testBooleanQuantile(q, new Bool8, new Uint8ClampedArray(makeBooleans())); }); }); describe('Float type Series with NaN => Series.quantile', () => { test('Float32', () => { testNumberQuantile( q, new Float32, new Float32Array([NaN].concat(makeNumbers().concat([NaN])))); }); test('Float64', () => { testNumberQuantile( q, new Float64, new Float64Array([NaN].concat(makeNumbers().concat([NaN])))); }); }); });
0
rapidsai_public_repos/node/modules/cudf/test/series
rapidsai_public_repos/node/modules/cudf/test/series/reduce/sumOfSqaures-tests.ts
// Copyright (c) 2021, NVIDIA CORPORATION. // // 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. import '../../jest-extensions'; import {BigIntArray, setDefaultAllocator, TypedArray} from '@rapidsai/cuda'; import { Bool8, Float32, Float64, Int16, Int32, Int64, Int8, Numeric, Series, Uint16, Uint32, Uint64, Uint8 } from '@rapidsai/cudf'; import {DeviceBuffer} from '@rapidsai/rmm'; import * as arrow from 'apache-arrow'; setDefaultAllocator((byteLength: number) => new DeviceBuffer(byteLength)); const makeNumbers = (length = 10) => Array.from({length}, (_, i) => Number(i)); const makeBigInts = (length = 10) => Array.from({length}, (_, i) => BigInt(i)); const makeBooleans = (length = 10) => Array.from({length}, (_, i) => Number(i % 2 == 0)); const float_with_NaN = Array.from([NaN, 1, 2, 3, 4, 5, 6, 7, 8, NaN]); function test_values<T extends Numeric>(lhs: number|bigint|undefined, rhs: number, type: T) { if (['Float32', 'Float64', 'Bool'].includes(type.toString())) { expect(lhs).toEqual(rhs); } else { expect(lhs).toEqual(BigInt(rhs)); } } function testNumberSumOfSquares<T extends Numeric, R extends TypedArray>(type: T, data: R) { const result = [...data].reduce((x, y) => { if (isNaN(y)) { y = 0; } if (isNaN(x)) { x = 0; } return x + Math.pow(y, 2); }); test_values(Series.new({type, data}).sumOfSquares(), result, type); } function testNumberSumOfSquaresskipNulls<T extends Numeric, R extends TypedArray>( type: T, data: R, mask_array: Array<number>) { const mask = arrow.vectorFromArray(mask_array, new arrow.Bool).data[0].values; if (!data.includes(NaN)) { const result = [...data].reduce((x, y, i) => { if (mask_array[i] == 1) { return x + Math.pow(y, 2); } return x; }); // skipNulls=false test_values(Series.new({type, data, nullMask: mask}).sumOfSquares(false), result, type); } else { // skipNulls=false expect(Series.new({type, data, nullMask: mask}).sumOfSquares(false)).toEqual(NaN); } } function testBigIntSumOfSquares<T extends Numeric, R extends BigIntArray>(type: T, data: R) { expect(Series.new({type, data}).sumOfSquares()).toEqual([...data].reduce((x, y) => x + (y * y))); } function testBigIntSumOfSquaresskipNulls<T extends Numeric, R extends BigIntArray>( type: T, data: R, mask_array: Array<number>) { const mask = arrow.vectorFromArray(mask_array, new arrow.Bool).data[0].values; // skipNulls=false expect(Series.new({type, data, nullMask: mask}).sumOfSquares(false)).toEqual([ ...data ].reduce((x, y, i) => { if (mask_array[i] == 1) { return x + (y * y); } return x; })); } describe('Series.sumOfSquares(skipNulls=true)', () => { test('Int8', () => { testNumberSumOfSquares(new Int8, new Int8Array(makeNumbers())); }); test('Int16', () => { testNumberSumOfSquares(new Int16, new Int16Array(makeNumbers())); }); test('Int32', () => { testNumberSumOfSquares(new Int32, new Int32Array(makeNumbers())); }); test('Int64', () => { testBigIntSumOfSquares(new Int64, new BigInt64Array(makeBigInts())); }); test('Uint8', () => { testNumberSumOfSquares(new Uint8, new Uint8Array(makeNumbers())); }); test('Uint16', () => { testNumberSumOfSquares(new Uint16, new Uint16Array(makeNumbers())); }); test('Uint32', () => { testNumberSumOfSquares(new Uint32, new Uint32Array(makeNumbers())); }); test('Uint64', () => { testBigIntSumOfSquares(new Uint64, new BigUint64Array(makeBigInts())); }); test('Float32', () => { testNumberSumOfSquares(new Float32, new Float32Array(makeNumbers())); }); test('Float64', () => { testNumberSumOfSquares(new Float64, new Float64Array(makeNumbers())); }); test('Bool8', () => { testNumberSumOfSquares(new Bool8, new Uint8ClampedArray(makeBooleans())); }); }); describe('Series.sumOfSquares(skipNulls=false)', () => { test('Int8', () => { testNumberSumOfSquaresskipNulls(new Int8, new Int8Array(makeNumbers()), makeBooleans()); }); test('Int16', () => { testNumberSumOfSquaresskipNulls(new Int16, new Int16Array(makeNumbers()), makeBooleans()); }); test('Int32', () => { testNumberSumOfSquaresskipNulls(new Int32, new Int32Array(makeNumbers()), makeBooleans()); }); test('Int64', () => { testBigIntSumOfSquaresskipNulls(new Int64, new BigInt64Array(makeBigInts()), makeBooleans()); }); test('Uint8', () => { testNumberSumOfSquaresskipNulls(new Uint8, new Uint8Array(makeNumbers()), makeBooleans()); }); test('Uint16', () => { testNumberSumOfSquaresskipNulls(new Uint16, new Uint16Array(makeNumbers()), makeBooleans()); }); test('Uint32', () => { testNumberSumOfSquaresskipNulls(new Uint32, new Uint32Array(makeNumbers()), makeBooleans()); }); test('Uint64', () => { testBigIntSumOfSquaresskipNulls(new Uint64, new BigUint64Array(makeBigInts()), makeBooleans()); }); test('Float32', () => { testNumberSumOfSquaresskipNulls(new Float32, new Float32Array(makeNumbers()), makeBooleans()); }); test('Float64', () => { testNumberSumOfSquaresskipNulls(new Float64, new Float64Array(makeNumbers()), makeBooleans()); }); test('Bool8', () => { testNumberSumOfSquaresskipNulls( new Bool8, new Uint8ClampedArray(makeBooleans()), makeBooleans()); }); }); describe('Float type Series with NaN => Series.sumOfSquares(skipNulls=true)', () => { test('Float32', () => { testNumberSumOfSquares(new Float32, new Float32Array(float_with_NaN)); }); test('Float64', () => { testNumberSumOfSquares(new Float64, new Float64Array(float_with_NaN)); }); }); describe('Float type Series with NaN => Series.sumOfSquares(skipNulls=false)', () => { test('Float32', () => { testNumberSumOfSquaresskipNulls(new Float32, new Float32Array(float_with_NaN), makeBooleans()); }); test('Float64', () => { testNumberSumOfSquaresskipNulls(new Float64, new Float64Array(float_with_NaN), makeBooleans()); }); });
0
rapidsai_public_repos/node/modules/cudf/test/series
rapidsai_public_repos/node/modules/cudf/test/series/reduce/cummin-tests.ts
// Copyright (c) 2021, NVIDIA CORPORATION. // // 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. import '../../jest-extensions'; import {setDefaultAllocator} from '@rapidsai/cuda'; import { Bool8, Float32, Float64, Int16, Int32, Int64, Int8, Series, Uint16, Uint32, Uint64, Uint8 } from '@rapidsai/cudf'; import {DeviceBuffer} from '@rapidsai/rmm'; setDefaultAllocator((byteLength: number) => new DeviceBuffer(byteLength)); const numbers = [4, 2, null, 5, 1, 1]; const float_with_NaN = [4, 2, NaN, 5, 1, 1]; const bools = [true, false, null, false, true]; const bigints = [4n, 2n, null, 5n, 1n, 1n]; function testNumberAny<T extends Int8|Int16|Int32|Uint8|Uint16|Uint32|Float32|Float64>( type: T, data: (T['scalarType']|null)[], skipNulls = true) { const expected = skipNulls ? [4, 2, null, 2, 1, 1] // : [4, 2, null, null, null, null]; expect([...Series.new({type, data}).cumulativeMin(skipNulls)]).toEqual(expected); } function testBigIntAny<T extends Int64|Uint64>( type: T, data: (T['scalarType']|null)[], skipNulls = true) { const expected = skipNulls ? [4n, 2n, null, 2n, 1n, 1n] // : [4n, 2n, null, null, null, null]; expect([...Series.new({type, data}).cumulativeMin(skipNulls)]).toEqual(expected); } function testBooleanAny<T extends Bool8>( type: T, data: (T['scalarType']|null)[], skipNulls = true) { const expected = skipNulls ? [true, false, null, false, false] // : [true, false, null, null, null]; expect([...Series.new({type, data}).cumulativeMin(skipNulls)]).toEqual(expected); } describe.each([[true], [false]])('Series.cumulativeMin(skipNulls=%p)', (skipNulls) => { test('Int8', () => { testNumberAny(new Int8, numbers, skipNulls); }); test('Int16', () => { testNumberAny(new Int16, numbers, skipNulls); }); test('Int32', () => { testNumberAny(new Int32, numbers, skipNulls); }); test('Int64', () => { testBigIntAny(new Int64, bigints, skipNulls); }); test('Uint8', () => { testNumberAny(new Uint8, numbers, skipNulls); }); test('Uint16', () => { testNumberAny(new Uint16, numbers, skipNulls); }); test('Uint32', () => { testNumberAny(new Uint32, numbers, skipNulls); }); test('Uint64', () => { testBigIntAny(new Uint64, bigints, skipNulls); }); test('Float32', () => { testNumberAny(new Float32, numbers, skipNulls); }); test('Float64', () => { testNumberAny(new Float64, numbers, skipNulls); }); test('Bool8', () => { testBooleanAny(new Bool8, bools, skipNulls); }); test('Float32-nan', () => { testNumberAny(new Float32, float_with_NaN, skipNulls); }); test('Float64-nan', () => { testNumberAny(new Float64, float_with_NaN, skipNulls); }); });
0
rapidsai_public_repos/node/modules/cudf/test/series
rapidsai_public_repos/node/modules/cudf/test/series/reduce/sum-tests.ts
// Copyright (c) 2021, NVIDIA CORPORATION. // // 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. import '../../jest-extensions'; import {BigIntArray, setDefaultAllocator, TypedArray} from '@rapidsai/cuda'; import { Bool8, Float32, Float64, Int16, Int32, Int64, Int8, Numeric, Series, Uint16, Uint32, Uint64, Uint8 } from '@rapidsai/cudf'; import {DeviceBuffer} from '@rapidsai/rmm'; import * as arrow from 'apache-arrow'; setDefaultAllocator((byteLength: number) => new DeviceBuffer(byteLength)); const makeNumbers = (length = 10) => Array.from({length}, (_, i) => Number(i)); const makeBigInts = (length = 10) => Array.from({length}, (_, i) => BigInt(i)); const makeBooleans = (length = 10) => Array.from({length}, (_, i) => Number(i % 2 == 0)); const float_with_NaN = Array.from([NaN, 1, 2, 3, 4, 5, 6, 7, 8, NaN]); function test_values<T extends Numeric>(lhs: number|bigint|undefined, rhs: number, type: T) { if (['Float32', 'Float64', 'Bool'].includes(type.toString())) { expect(lhs).toEqual(rhs); } else { expect(lhs).toEqual(BigInt(rhs)); } } function testNumberSum<T extends Numeric, R extends TypedArray>(type: T, data: R) { const result = [...data].reduce((x, y) => { if (isNaN(y)) { y = 0; } if (isNaN(x)) { x = 0; } return x + y; }); test_values(Series.new({type, data}).sum(), result, type); } function testNumberSumskipNulls<T extends Numeric, R extends TypedArray>( type: T, data: R, mask_array: Array<number>) { const mask = arrow.vectorFromArray(mask_array, new arrow.Bool).data[0].values; if (!data.includes(NaN)) { const result = [...data].reduce((x, y, i) => { if (mask_array[i] == 1) { return x + y; } return x; }); // skipNulls=false test_values(Series.new({type, data, nullMask: mask}).sum(false), result, type); } else { // skipNulls=false expect(Series.new({type, data, nullMask: mask}).sum(false)).toEqual(NaN); } } function testBigIntSum<T extends Numeric, R extends BigIntArray>(type: T, data: R) { expect(Series.new({type, data}).sum()).toEqual([...data].reduce((x, y) => x + y)); } function testBigIntSumskipNulls<T extends Numeric, R extends BigIntArray>( type: T, data: R, mask_array: Array<number>) { const mask = arrow.vectorFromArray(mask_array, new arrow.Bool).data[0].values; // skipNulls=false expect(Series.new({type, data, nullMask: mask}).sum(false)).toEqual([ ...data ].reduce((x, y, i) => { if (mask_array[i] == 1) { return x + y; } return x; })); } describe('Series.sum(skipNulls=true)', () => { test('Int8', () => { testNumberSum(new Int8, new Int8Array(makeNumbers())); }); test('Int16', () => { testNumberSum(new Int16, new Int16Array(makeNumbers())); }); test('Int32', () => { testNumberSum(new Int32, new Int32Array(makeNumbers())); }); test('Int64', () => { testBigIntSum(new Int64, new BigInt64Array(makeBigInts())); }); test('Uint8', () => { testNumberSum(new Uint8, new Uint8Array(makeNumbers())); }); test('Uint16', () => { testNumberSum(new Uint16, new Uint16Array(makeNumbers())); }); test('Uint32', () => { testNumberSum(new Uint32, new Uint32Array(makeNumbers())); }); test('Uint64', () => { testBigIntSum(new Uint64, new BigUint64Array(makeBigInts())); }); test('Float32', () => { testNumberSum(new Float32, new Float32Array(makeNumbers())); }); test('Float64', () => { testNumberSum(new Float64, new Float64Array(makeNumbers())); }); test('Bool8', () => { testNumberSum(new Bool8, new Uint8ClampedArray(makeBooleans())); }); }); describe('Series.sum(skipNulls=false)', () => { test('Int8', () => { testNumberSumskipNulls(new Int8, new Int8Array(makeNumbers()), makeBooleans()); }); test('Int16', () => { testNumberSumskipNulls(new Int16, new Int16Array(makeNumbers()), makeBooleans()); }); test('Int32', () => { testNumberSumskipNulls(new Int32, new Int32Array(makeNumbers()), makeBooleans()); }); test( 'Int64', () => { testBigIntSumskipNulls(new Int64, new BigInt64Array(makeBigInts()), makeBooleans()); }); test('Uint8', () => { testNumberSumskipNulls(new Uint8, new Uint8Array(makeNumbers()), makeBooleans()); }); test( 'Uint16', () => { testNumberSumskipNulls(new Uint16, new Uint16Array(makeNumbers()), makeBooleans()); }); test( 'Uint32', () => { testNumberSumskipNulls(new Uint32, new Uint32Array(makeNumbers()), makeBooleans()); }); test('Uint64', () => { testBigIntSumskipNulls(new Uint64, new BigUint64Array(makeBigInts()), makeBooleans()); }); test('Float32', () => { testNumberSumskipNulls(new Float32, new Float32Array(makeNumbers()), makeBooleans()); }); test('Float64', () => { testNumberSumskipNulls(new Float64, new Float64Array(makeNumbers()), makeBooleans()); }); test('Bool8', () => { testNumberSumskipNulls(new Bool8, new Uint8ClampedArray(makeBooleans()), makeBooleans()); }); }); describe('Float type Series with NaN => Series.sum(skipNulls=true)', () => { test('Float32', () => { testNumberSum(new Float32, new Float32Array(float_with_NaN)); }); test('Float64', () => { testNumberSum(new Float64, new Float64Array(float_with_NaN)); }); }); describe('Float type Series with NaN => Series.sum(skipNulls=false)', () => { test('Float32', () => { testNumberSumskipNulls(new Float32, new Float32Array(float_with_NaN), makeBooleans()); }); test('Float64', () => { testNumberSumskipNulls(new Float64, new Float64Array(float_with_NaN), makeBooleans()); }); });
0
rapidsai_public_repos/node/modules/cudf/test/series
rapidsai_public_repos/node/modules/cudf/test/series/reduce/all-tests.ts
// Copyright (c) 2021, NVIDIA CORPORATION. // // 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. import '../../jest-extensions'; import {setDefaultAllocator} from '@rapidsai/cuda'; import { Bool8, Float32, Float64, Int16, Int32, Int64, Int8, Series, Uint16, Uint32, Uint64, Uint8 } from '@rapidsai/cudf'; import {DeviceBuffer} from '@rapidsai/rmm'; setDefaultAllocator((byteLength: number) => new DeviceBuffer(byteLength)); const numbers = [null, 0, 1, 1, null, 2, 3, 3, 4, 4]; const bigints = [null, 0n, 1n, 1n, null, 2n, 3n, 3n, 4n, 4n]; const bools = [null, false, true, true, null, true, false, true, false, true]; const float_with_NaN = [NaN, 1, 2, 3, 4, 3, 7, 7, 2, NaN]; function testNumberAll<T extends Int8|Int16|Int32|Uint8|Uint16|Uint32|Float32|Float64>( type: T, data: (T['scalarType']|null)[], skipNulls = true) { const expected = skipNulls ? data.every((x) => x === null || x !== 0) // : data.every((x) => x !== null); expect(Series.new({type, data}).all(skipNulls)).toEqual(expected); } function testBigIntAll<T extends Int64|Uint64>( type: T, data: (T['scalarType']|null)[], skipNulls = true) { const expected = skipNulls ? data.every((x) => x === null || x !== 0n) // : data.every((x) => x !== null); expect(Boolean(Series.new({type, data}).all(skipNulls))).toEqual(expected); } function testBooleanAll<T extends Bool8>( type: T, data: (T['scalarType']|null)[], skipNulls = true) { const expected = skipNulls ? data.every((x) => x === null || x !== false) // : data.every((x) => x !== null); expect(Series.new({type, data}).all(skipNulls)).toEqual(expected); } describe.each([[true], [false]])('Series.all(skipNulls=%p)', (skipNulls) => { test('Int8', () => { testNumberAll(new Int8, numbers, skipNulls); }); test('Int16', () => { testNumberAll(new Int16, numbers, skipNulls); }); test('Int32', () => { testNumberAll(new Int32, numbers, skipNulls); }); test('Int64', () => { testBigIntAll(new Int64, bigints, skipNulls); }); test('Uint8', () => { testNumberAll(new Uint8, numbers, skipNulls); }); test('Uint16', () => { testNumberAll(new Uint16, numbers, skipNulls); }); test('Uint32', () => { testNumberAll(new Uint32, numbers, skipNulls); }); test('Uint64', () => { testBigIntAll(new Uint64, bigints, skipNulls); }); test('Float32', () => { testNumberAll(new Float32, numbers, skipNulls); }); test('Float64', () => { testNumberAll(new Float64, numbers, skipNulls); }); test('Bool8', () => { testBooleanAll(new Bool8, bools, skipNulls); }); test('Float32', () => { testNumberAll(new Float32, float_with_NaN, skipNulls); }); test('Float64', () => { testNumberAll(new Float64, float_with_NaN, skipNulls); }); });
0
rapidsai_public_repos/node/modules/cudf/test/series
rapidsai_public_repos/node/modules/cudf/test/series/reduce/max-tests.ts
// Copyright (c) 2022, NVIDIA CORPORATION. // // 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. import '../../jest-extensions'; import {setDefaultAllocator} from '@rapidsai/cuda'; import { Bool8, Float32, Float64, Int16, Int32, Int64, Int8, Series, Uint16, Uint32, Uint64, Uint8 } from '@rapidsai/cudf'; import {DeviceBuffer} from '@rapidsai/rmm'; setDefaultAllocator((byteLength: number) => new DeviceBuffer(byteLength)); const numbers = [4, 2, null, 5, 1, 1]; const float_with_NaN = [4, 2, NaN, 5, 1, 1]; const bools = [true, false, null, false, true]; const bigints = [4n, 2n, null, 5n, 1n, 1n]; function testNumberAny<T extends Int8|Int16|Int32|Uint8|Uint16|Uint32|Float32|Float64>( type: T, data: (T['scalarType']|null)[], skipNulls = true) { expect(Series.new({type, data}).max(skipNulls)).toEqual(5); } function testBigIntAny<T extends Int64|Uint64>( type: T, data: (T['scalarType']|null)[], skipNulls = true) { expect(Series.new({type, data}).max(skipNulls)).toEqual(5n); } function testBooleanAny<T extends Bool8>( type: T, data: (T['scalarType']|null)[], skipNulls = true) { expect(Series.new({type, data}).max(skipNulls)).toEqual(true); } describe.each([[true], [false]])('Series.max(skipNulls=%p)', (skipNulls) => { test('Int8', () => { testNumberAny(new Int8, numbers, skipNulls); }); test('Int16', () => { testNumberAny(new Int16, numbers, skipNulls); }); test('Int32', () => { testNumberAny(new Int32, numbers, skipNulls); }); test('Int64', () => { testBigIntAny(new Int64, bigints, skipNulls); }); test('Uint8', () => { testNumberAny(new Uint8, numbers, skipNulls); }); test('Uint16', () => { testNumberAny(new Uint16, numbers, skipNulls); }); test('Uint32', () => { testNumberAny(new Uint32, numbers, skipNulls); }); test('Uint64', () => { testBigIntAny(new Uint64, bigints, skipNulls); }); test('Float32', () => { testNumberAny(new Float32, numbers, skipNulls); }); test('Float64', () => { testNumberAny(new Float64, numbers, skipNulls); }); test('Bool8', () => { testBooleanAny(new Bool8, bools, skipNulls); }); test('Float32-nan', () => { testNumberAny(new Float32, float_with_NaN, skipNulls); }); test('Float64-nan', () => { testNumberAny(new Float64, float_with_NaN, skipNulls); }); });
0
rapidsai_public_repos/node/modules/cudf/test/series
rapidsai_public_repos/node/modules/cudf/test/series/reduce/skew-tests.ts
// Copyright (c) 2021, NVIDIA CORPORATION. // // 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. import '../../jest-extensions'; import {setDefaultAllocator} from '@rapidsai/cuda'; import { Float32, Float64, Int16, Int32, Int64, Int8, Series, Uint16, Uint32, Uint64, Uint8 } from '@rapidsai/cudf'; import {DeviceBuffer} from '@rapidsai/rmm'; setDefaultAllocator((byteLength: number) => new DeviceBuffer(byteLength)); const numbers = [1, null, 2, 3, 4, 5, null, 10]; const bigints = [1n, null, 2n, 3n, 4n, 5n, null, 10n]; const float_with_NaN = [1.0, NaN, 2.0, 3.0, 4.0, 5.0, NaN, 10.0]; const result = 1.439590274527955; function testNumberSkew<T extends Int8|Int16|Int32|Int64|Uint8|Uint16|Uint32|Uint64|Float32| Float64>(type: T, data: (T['scalarType']|null)[], skipNulls = true) { const expected = skipNulls ? result : NaN; expect(Series.new({type, data}).skew(skipNulls)).toEqual(expected); } describe.each([[true], [false]])('Series.kurtosis(skipNulls=%p)', (skipNulls) => { test('Int8', () => { testNumberSkew(new Int8, numbers, skipNulls); }); test('Int16', () => { testNumberSkew(new Int16, numbers, skipNulls); }); test('Int32', () => { testNumberSkew(new Int32, numbers, skipNulls); }); test('Int64', () => { testNumberSkew(new Int64, bigints, skipNulls); }); test('Uint8', () => { testNumberSkew(new Uint8, numbers, skipNulls); }); test('Uint16', () => { testNumberSkew(new Uint16, numbers, skipNulls); }); test('Uint32', () => { testNumberSkew(new Uint32, numbers, skipNulls); }); test('Uint64', () => { testNumberSkew(new Uint64, bigints, skipNulls); }); test('Float32', () => { testNumberSkew(new Float32, numbers, skipNulls); }); test('Float64', () => { testNumberSkew(new Float64, numbers, skipNulls); }); test('Float32-nan', () => { testNumberSkew(new Float32, float_with_NaN, skipNulls); }); test('Float64-nan', () => { testNumberSkew(new Float64, float_with_NaN, skipNulls); }); }); describe.each([[[]], [[2]], [[2, 3]]])('Too short (data=%p)', (data) => { test('returns NaN', () => { expect(Series.new({type: new Float32, data: data}).skew()).toBe(NaN); }); }); describe('Zero variance', () => { test('returns 0', () => { expect(Series.new({type: new Float32, data: [1, 1, 1, 1, 1, 1]}).skew()).toBe(0); }); });
0
rapidsai_public_repos/node/modules/cudf/test/series
rapidsai_public_repos/node/modules/cudf/test/series/reduce/std-tests.ts
// Copyright (c) 2021, NVIDIA CORPORATION. // // 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. import '../../jest-extensions'; import {BigIntArray, setDefaultAllocator, TypedArray} from '@rapidsai/cuda'; import { Bool8, Float32, Float64, Int16, Int32, Int64, Int8, Numeric, Series, Uint16, Uint32, Uint64, Uint8 } from '@rapidsai/cudf'; import {DeviceBuffer} from '@rapidsai/rmm'; setDefaultAllocator((byteLength: number) => new DeviceBuffer(byteLength)); const makeNumbers = (length = 10) => Array.from({length}, (_, i) => Number(i)); const makeBigInts = (length = 10) => Array.from({length}, (_, i) => BigInt(i)); const makeBooleans = (length = 10) => Array.from({length}, (_, i) => Number(i % 2 == 0)); const param_ddof = [1, 3, 5]; const std_number_results = new Map([[1, 3.0276503540974917], [3, 3.4330328116279762], [5, 4.06201920231798]]); const std_bool_results = new Map([[1, 0.5270462766947299], [3, 0.5976143046671968], [5, 0.7071067811865476]]); function testNumberStd<T extends Numeric, R extends TypedArray|BigIntArray>( skipNulls: boolean, ddof: number, type: T, data: R) { expect(Series.new({type, data}).std(skipNulls, ddof)) .toEqual((data.includes(<never>NaN) && skipNulls == false) ? NaN : std_number_results.get(ddof)); } function testBooleanStd<T extends Numeric, R extends TypedArray|BigIntArray>( skipNulls: boolean, ddof: number, type: T, data: R) { expect(Series.new({type, data}).std(skipNulls, ddof)) .toEqual((data.includes(<never>NaN) && skipNulls == false) ? NaN : std_bool_results.get(ddof)); } param_ddof.forEach(ddof => { describe('Series.std (skipNulls=True)', () => { const skipNulls = true; test('Int8', () => { testNumberStd(skipNulls, ddof, new Int8, new Int8Array(makeNumbers())); }); test('Int16', () => { testNumberStd(skipNulls, ddof, new Int16, new Int16Array(makeNumbers())); }); test('Int32', () => { testNumberStd(skipNulls, ddof, new Int32, new Int32Array(makeNumbers())); }); test('Int64', () => { testNumberStd(skipNulls, ddof, new Int64, new BigInt64Array(makeBigInts())); }); test('Uint8', () => { testNumberStd(skipNulls, ddof, new Uint8, new Uint8Array(makeNumbers())); }); test('Uint16', () => { testNumberStd(skipNulls, ddof, new Uint16, new Uint16Array(makeNumbers())); }); test('Uint32', () => { testNumberStd(skipNulls, ddof, new Uint32, new Uint32Array(makeNumbers())); }); test('Uint64', () => { testNumberStd(skipNulls, ddof, new Uint64, new BigUint64Array(makeBigInts())); }); test('Float32', () => { testNumberStd(skipNulls, ddof, new Float32, new Float32Array(makeNumbers())); }); test('Float64', () => { testNumberStd(skipNulls, ddof, new Float64, new Float64Array(makeNumbers())); }); test( 'Bool8', () => { testBooleanStd(skipNulls, ddof, new Bool8, new Uint8ClampedArray(makeBooleans())); }); }); describe('Float type Series with NaN => Series.std (skipNulls=True)', () => { const skipNulls = true; test('Float32', () => { testNumberStd( skipNulls, ddof, new Float32, new Float32Array([NaN].concat(makeNumbers().concat([NaN])))); }); test('Float64', () => { testNumberStd( skipNulls, ddof, new Float64, new Float64Array([NaN].concat(makeNumbers().concat([NaN])))); }); }); describe('Series.std (skipNulls=false)', () => { const skipNulls = false; test('Int8', () => { testNumberStd(skipNulls, ddof, new Int8, new Int8Array(makeNumbers())); }); test('Int16', () => { testNumberStd(skipNulls, ddof, new Int16, new Int16Array(makeNumbers())); }); test('Int32', () => { testNumberStd(skipNulls, ddof, new Int32, new Int32Array(makeNumbers())); }); test('Int64', () => { testNumberStd(skipNulls, ddof, new Int64, new BigInt64Array(makeBigInts())); }); test('Uint8', () => { testNumberStd(skipNulls, ddof, new Uint8, new Uint8Array(makeNumbers())); }); test('Uint16', () => { testNumberStd(skipNulls, ddof, new Uint16, new Uint16Array(makeNumbers())); }); test('Uint32', () => { testNumberStd(skipNulls, ddof, new Uint32, new Uint32Array(makeNumbers())); }); test('Uint64', () => { testNumberStd(skipNulls, ddof, new Uint64, new BigUint64Array(makeBigInts())); }); test('Float32', () => { testNumberStd(skipNulls, ddof, new Float32, new Float32Array(makeNumbers())); }); test('Float64', () => { testNumberStd(skipNulls, ddof, new Float64, new Float64Array(makeNumbers())); }); test( 'Bool8', () => { testBooleanStd(skipNulls, ddof, new Bool8, new Uint8ClampedArray(makeBooleans())); }); }); describe('Float type Series with NaN => Series.std (skipNulls=false)', () => { const skipNulls = false; test('Float32', () => { testNumberStd( skipNulls, ddof, new Float32, new Float32Array([NaN].concat(makeNumbers().concat([NaN])))); }); test('Float64', () => { testNumberStd( skipNulls, ddof, new Float64, new Float64Array([NaN].concat(makeNumbers().concat([NaN])))); }); }); });
0
rapidsai_public_repos/node/modules/cudf/test/series
rapidsai_public_repos/node/modules/cudf/test/series/reduce/kurtosis-tests.ts
// Copyright (c) 2021, NVIDIA CORPORATION. // // 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. import '../../jest-extensions'; import {setDefaultAllocator} from '@rapidsai/cuda'; import { Float32, Float64, Int16, Int32, Int64, Int8, Series, Uint16, Uint32, Uint64, Uint8 } from '@rapidsai/cudf'; import {DeviceBuffer} from '@rapidsai/rmm'; setDefaultAllocator((byteLength: number) => new DeviceBuffer(byteLength)); const numbers = [1, null, 2, 3, 4, 5, null, 10]; const bigints = [1n, null, 2n, 3n, 4n, 5n, null, 10n]; const float_with_NaN = [1.0, NaN, 2.0, 3.0, 4.0, 5.0, NaN, 10.0]; const result = 2.4377317925288935; function testNumberKurtosis<T extends Int8|Int16|Int32|Int64|Uint8|Uint16|Uint32|Uint64|Float32| Float64>(type: T, data: (T['scalarType']|null)[], skipNulls = true) { const expected = skipNulls ? result : NaN; expect(Series.new({type, data}).kurtosis(skipNulls)).toEqual(expected); } describe.each([[true], [false]])('Series.kurtosis(skipNulls=%p)', (skipNulls) => { test('Int8', () => { testNumberKurtosis(new Int8, numbers, skipNulls); }); test('Int16', () => { testNumberKurtosis(new Int16, numbers, skipNulls); }); test('Int32', () => { testNumberKurtosis(new Int32, numbers, skipNulls); }); test('Int64', () => { testNumberKurtosis(new Int64, bigints, skipNulls); }); test('Uint8', () => { testNumberKurtosis(new Uint8, numbers, skipNulls); }); test('Uint16', () => { testNumberKurtosis(new Uint16, numbers, skipNulls); }); test('Uint32', () => { testNumberKurtosis(new Uint32, numbers, skipNulls); }); test('Uint64', () => { testNumberKurtosis(new Uint64, bigints, skipNulls); }); test('Float32', () => { testNumberKurtosis(new Float32, numbers, skipNulls); }); test('Float64', () => { testNumberKurtosis(new Float64, numbers, skipNulls); }); test('Float32-nan', () => { testNumberKurtosis(new Float32, float_with_NaN, skipNulls); }); test('Float64-nan', () => { testNumberKurtosis(new Float64, float_with_NaN, skipNulls); }); }); describe.each([[[]], [[2]], [[2, 3]], [[2, 3, -1]]])('Too short (data=%p)', (data) => { test('returns NaN', () => { expect(Series.new({type: new Float32, data: data}).kurtosis()).toBe(NaN); }); }); describe('Zero variance', () => { test('returns 0', () => { expect(Series.new({type: new Float32, data: [1, 1, 1, 1, 1, 1]}).kurtosis()).toBe(0); }); });
0
rapidsai_public_repos/node/modules/cudf/test/series
rapidsai_public_repos/node/modules/cudf/test/series/reduce/cumsum-tests.ts
// Copyright (c) 2021, NVIDIA CORPORATION. // // 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. import '../../jest-extensions'; import {setDefaultAllocator} from '@rapidsai/cuda'; import { Bool8, Float32, Float64, Int16, Int32, Int64, Int8, Series, Uint16, Uint32, Uint64, Uint8 } from '@rapidsai/cudf'; import {DeviceBuffer} from '@rapidsai/rmm'; setDefaultAllocator((byteLength: number) => new DeviceBuffer(byteLength)); const numbers = [4, 2, null, 5, 1, 1]; const float_with_NaN = [4, 2, NaN, 5, 1, 1]; const bools = [true, false, null, false, true]; const bigints = [4n, 2n, null, 5n, 1n, 1n]; function testNumberAny<T extends Int8|Int16|Int32|Uint8|Uint16|Uint32|Float32|Float64>( type: T, data: (T['scalarType']|null)[], skipNulls = true) { const expected = skipNulls ? [4, 6, null, 11, 12, 13] // : [4, 6, null, null, null, null]; expect([...Series.new({type, data}).cumulativeSum(skipNulls)]).toEqual(expected); } function testBigIntAny<T extends Int64|Uint64>( type: T, data: (T['scalarType']|null)[], skipNulls = true) { const expected = skipNulls ? [4n, 6n, null, 11n, 12n, 13n] // : [4n, 6n, null, null, null, null]; expect([...Series.new({type, data}).cumulativeSum(skipNulls)]).toEqual(expected); } function testBooleanAny<T extends Bool8>( type: T, data: (T['scalarType']|null)[], skipNulls = true) { const expected = skipNulls ? [1n, 1n, null, 1n, 2n] // : [1n, 1n, null, null, null]; expect([...Series.new({type, data}).cumulativeSum(skipNulls)]).toEqual(expected); } describe.each([[true], [false]])('Series.cumulativeSum(skipNulls=%p)', (skipNulls) => { test('Int8', () => { testNumberAny(new Int8, numbers, skipNulls); }); test('Int16', () => { testNumberAny(new Int16, numbers, skipNulls); }); test('Int32', () => { testNumberAny(new Int32, numbers, skipNulls); }); test('Int64', () => { testBigIntAny(new Int64, bigints, skipNulls); }); test('Uint8', () => { testNumberAny(new Uint8, numbers, skipNulls); }); test('Uint16', () => { testNumberAny(new Uint16, numbers, skipNulls); }); test('Uint32', () => { testNumberAny(new Uint32, numbers, skipNulls); }); test('Uint64', () => { testBigIntAny(new Uint64, bigints, skipNulls); }); test('Float32', () => { testNumberAny(new Float32, numbers, skipNulls); }); test('Float64', () => { testNumberAny(new Float64, numbers, skipNulls); }); test('Bool8', () => { testBooleanAny(new Bool8, bools, skipNulls); }); test('Float32-nan', () => { testNumberAny(new Float32, float_with_NaN, skipNulls); }); test('Float64-nan', () => { testNumberAny(new Float64, float_with_NaN, skipNulls); }); });
0
rapidsai_public_repos/node/modules
rapidsai_public_repos/node/modules/webgl/package.json
{ "name": "@rapidsai/webgl", "version": "22.12.2", "description": "NVIDIA RAPIDS OpenGL bindings exposed to node as WebGL2 APIs", "license": "Apache-2.0", "main": "index.js", "types": "build/js", "author": "NVIDIA, Inc. (https://nvidia.com/)", "maintainers": [ "Paul Taylor <[email protected]>" ], "homepage": "https://github.com/rapidsai/node/tree/main/modules/webgl#readme", "bugs": { "url": "https://github.com/rapidsai/node/issues" }, "repository": { "type": "git", "url": "git+https://github.com/rapidsai/node.git" }, "scripts": { "clean": "rimraf build doc compile_commands.json", "doc": "rimraf doc && typedoc --options typedoc.js", "test": "node -r dotenv/config node_modules/.bin/jest -c jest.config.js", "build": "yarn tsc:build && yarn cpp:build", "build:debug": "yarn tsc:build && yarn cpp:build:debug", "compile": "yarn tsc:build && yarn cpp:compile", "compile:debug": "yarn tsc:build && yarn cpp:compile:debug", "rebuild": "yarn tsc:build && yarn cpp:rebuild", "rebuild:debug": "yarn tsc:build && yarn cpp:rebuild:debug", "cpp:clean": "npx cmake-js clean -O build/Release", "cpp:clean:debug": "npx cmake-js clean -O build/Debug", "cpp:build": "npx cmake-js build -g -O build/Release", "cpp:build:debug": "npx cmake-js build -g -D -O build/Debug", "cpp:compile": "npx cmake-js compile -g -O build/Release", "postcpp:compile": "npx rapidsai-merge-compile-commands", "cpp:compile:debug": "npx cmake-js compile -g -D -O build/Debug", "postcpp:compile:debug": "npx rapidsai-merge-compile-commands", "cpp:configure": "npx cmake-js configure -g -O build/Release", "postcpp:configure": "npx rapidsai-merge-compile-commands", "cpp:configure:debug": "npx cmake-js configure -g -D -O build/Debug", "postcpp:configure:debug": "npx rapidsai-merge-compile-commands", "cpp:rebuild": "npx cmake-js rebuild -g -O build/Release", "postcpp:rebuild": "npx rapidsai-merge-compile-commands", "cpp:rebuild:debug": "npx cmake-js rebuild -g -D -O build/Debug", "postcpp:rebuild:debug": "npx rapidsai-merge-compile-commands", "cpp:reconfigure": "npx cmake-js reconfigure -g -O build/Release", "postcpp:reconfigure": "npx rapidsai-merge-compile-commands", "cpp:reconfigure:debug": "npx cmake-js reconfigure -g -D -O build/Debug", "postcpp:reconfigure:debug": "npx rapidsai-merge-compile-commands", "tsc:clean": "rimraf build/js", "tsc:build": "yarn tsc:clean && tsc -p ./tsconfig.json", "tsc:watch": "yarn tsc:clean && tsc -p ./tsconfig.json -w" }, "dependencies": { "@rapidsai/core": "~22.12.2" }, "files": [ "LICENSE", "README.md", "index.js", "package.json", "CMakeLists.txt", "build/js", "build/Release/*.so*", "build/Release/*.node" ] }
0
rapidsai_public_repos/node/modules
rapidsai_public_repos/node/modules/webgl/index.js
// Copyright (c) 2020, NVIDIA CORPORATION. // // 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. module.exports = require('./build/js/index');
0
rapidsai_public_repos/node/modules
rapidsai_public_repos/node/modules/webgl/jest.config.js
// Copyright (c) 2020-2021, NVIDIA CORPORATION. // // 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. try { require('dotenv').config(); } catch (e) {} module.exports = { 'verbose': true, 'testEnvironment': 'node', 'maxWorkers': process.env.PARALLEL_LEVEL || 1, 'globals': {'ts-jest': {'diagnostics': false, 'tsconfig': 'test/tsconfig.json'}}, 'rootDir': './', 'roots': ['<rootDir>/test/'], 'moduleFileExtensions': ['js', 'ts', 'tsx'], 'coverageReporters': ['lcov'], 'coveragePathIgnorePatterns': ['test\\/.*\\.(ts|tsx|js)$', '/node_modules/'], 'transform': {'^.+\\.jsx?$': 'ts-jest', '^.+\\.tsx?$': 'ts-jest'}, 'transformIgnorePatterns': ['/build/(js|Debug|Release)/*$', '/node_modules/(?!web-stream-tools).+\\.js$'], 'testRegex': '(.*(-|\\.)(test|spec)s?)\\.(ts|tsx|js)$', 'preset': 'ts-jest', 'testMatch': null, 'moduleNameMapper': { '^@rapidsai\/webgl(.*)': '<rootDir>/src/$1', '^\.\.\/(Debug|Release)\/(rapidsai_webgl.node)$': '<rootDir>/build/$1/$2', } };
0
rapidsai_public_repos/node/modules
rapidsai_public_repos/node/modules/webgl/CMakeLists.txt
#============================================================================= # Copyright (c) 2020-2022, NVIDIA CORPORATION. # # 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. #============================================================================= cmake_minimum_required(VERSION 3.24.1 FATAL_ERROR) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) unset(CMAKE_LIBRARY_OUTPUT_DIRECTORY) unset(CMAKE_LIBRARY_OUTPUT_DIRECTORY CACHE) option(NODE_RAPIDS_WEBGL_STATIC_LINK "Statically link GLEW libraries" ON) option(NODE_RAPIDS_USE_SCCACHE "Enable caching compilation results with sccache" ON) ################################################################################################### # - cmake modules --------------------------------------------------------------------------------- execute_process(COMMAND node -p "require('@rapidsai/core').cmake_modules_path" WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" OUTPUT_VARIABLE NODE_RAPIDS_CMAKE_MODULES_PATH OUTPUT_STRIP_TRAILING_WHITESPACE) include("${NODE_RAPIDS_CMAKE_MODULES_PATH}/cmake_policies.cmake") project(rapidsai_webgl VERSION $ENV{npm_package_version} LANGUAGES C CXX) execute_process(COMMAND node -p "require('path').dirname(require.resolve('@rapidsai/core'))" WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" OUTPUT_VARIABLE NODE_RAPIDS_CORE_MODULE_PATH OUTPUT_STRIP_TRAILING_WHITESPACE) include("${NODE_RAPIDS_CMAKE_MODULES_PATH}/ConfigureCXX.cmake") include("${NODE_RAPIDS_CMAKE_MODULES_PATH}/ConfigureNapi.cmake") include("${NODE_RAPIDS_CMAKE_MODULES_PATH}/ConfigureOpenGL.cmake") include("${NODE_RAPIDS_CMAKE_MODULES_PATH}/ConfigureOpenGLEW.cmake") include("${NODE_RAPIDS_CMAKE_MODULES_PATH}/install_utils.cmake") find_and_configure_glew( VERSION 2.1.0 USE_STATIC ${NODE_RAPIDS_WEBGL_STATIC_LINK} EXPORT_SET rapidsai_webgl-exports) ################################################################################################### # - rapidsai_webgl target ------------------------------------------------------------------------- file(GLOB_RECURSE NODE_WEBGL_SRC_FILES "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp") add_library(${PROJECT_NAME} SHARED ${NODE_WEBGL_SRC_FILES} ${CMAKE_JS_SRC}) set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" SUFFIX ".node" BUILD_RPATH "\$ORIGIN" INSTALL_RPATH "\$ORIGIN" CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON CUDA_STANDARD 17 CUDA_STANDARD_REQUIRED ON POSITION_INDEPENDENT_CODE ON INTERFACE_POSITION_INDEPENDENT_CODE ON ) target_compile_options(${PROJECT_NAME} PRIVATE "$<BUILD_INTERFACE:$<$<COMPILE_LANGUAGE:C>:${NODE_RAPIDS_CMAKE_C_FLAGS}>>" "$<BUILD_INTERFACE:$<$<COMPILE_LANGUAGE:CXX>:${NODE_RAPIDS_CMAKE_CXX_FLAGS}>>" ) target_include_directories(${PROJECT_NAME} PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>" "$<BUILD_INTERFACE:${RAPIDS_CORE_INCLUDE_DIR}>" "$<BUILD_INTERFACE:${NAPI_INCLUDE_DIRS}>" ) target_link_libraries(${PROJECT_NAME} PUBLIC ${CMAKE_JS_LIB} ${GLEW_LIBRARY} OpenGL::EGL OpenGL::OpenGL "${NODE_RAPIDS_CORE_MODULE_PATH}/build/${CMAKE_BUILD_TYPE}/rapidsai_core.node") generate_install_rules(NAME ${PROJECT_NAME}) # Create a symlink to compile_commands.json for the llvm-vs-code-extensions.vscode-clangd plugin execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_CURRENT_BINARY_DIR}/compile_commands.json ${CMAKE_CURRENT_SOURCE_DIR}/compile_commands.json)
0
rapidsai_public_repos/node/modules
rapidsai_public_repos/node/modules/webgl/README.md
### node-webgl (`npm install @rapidsai/webgl`) A node native addon that provides OpenGL bindings via GLEW (http://glew.sourceforge.net/). GLEW is a cross-platform OpenGL extension loader, providing runtime mechanisms for querying and loading only the OpenGL extensions available on the target platform and OpenGL version. These bindings provide an API that conforms to the DOM's WebGLContext and WebGL2Context APIs, but are rendered via OpenGL into a platform-native GLFW window. #### WebGL APIs - [`WebGLRenderingContext`](https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext) - [`WebGL2RenderingContext`](https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext) - [`WebGLProgram`](https://developer.mozilla.org/en-US/docs/Web/API/WebGLProgram) - [`WebGLShader`](https://developer.mozilla.org/en-US/docs/Web/API/WebGLShader) - [`WebGLBuffer`](https://developer.mozilla.org/en-US/docs/Web/API/WebGLBuffer) - [`WebGLVertexArrayObject`](https://developer.mozilla.org/en-US/docs/Web/API/WebGLVertexArrayObject) - [`WebGLFramebuffer`](https://developer.mozilla.org/en-US/docs/Web/API/WebGLFramebuffer) - [`WebGLRenderbuffer`](https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderbuffer) - [`WebGLTexture`](https://developer.mozilla.org/en-US/docs/Web/API/WebGLTexture) - [`WebGLUniformLocation`](https://developer.mozilla.org/en-US/docs/Web/API/WebGLUniformLocation) - [`WebGLActiveInfo`](https://developer.mozilla.org/en-US/docs/Web/API/WebGLActiveInfo) - [`WebGLTransformFeedback`](https://developer.mozilla.org/en-US/docs/Web/API/WebGLTransformFeedback) #### OpenGL APIs glInit, bindAttribLocation, disableVertexAttribArray, enableVertexAttribArray, getActiveAttrib, getAttribLocation, getVertexAttrib, getVertexAttribOffset, vertexAttrib1f, vertexAttrib1fv, vertexAttrib2f, vertexAttrib2fv, vertexAttrib3f, vertexAttrib3fv, vertexAttrib4f, vertexAttrib4fv, vertexAttribPointer, vertexAttribIPointer, blendColor, blendEquation, blendEquationSeparate, blendFunc, blendFuncSeparate, createBuffer, deleteBuffer, isBuffer, bindBuffer, bindBufferBase, bindBufferRange, bufferData, bufferSubData, copyBufferSubData, getBufferSubData, getBufferParameter, createFramebuffer, deleteFramebuffer, isFramebuffer, bindFramebuffer, bindFrameBuffer, blitFrameBuffer, checkFramebufferStatus, framebufferRenderbuffer, framebufferTexture2D, getFramebufferAttachmentParameter, createProgram, deleteProgram, isProgram, getProgramInfoLog, getProgramParameter, linkProgram, useProgram, validateProgram, createRenderbuffer, deleteRenderbuffer, isRenderbuffer, bindRenderbuffer, getRenderbufferParameter, renderbufferStorage, deleteShader, createShader, isShader, attachShader, compileShader, detachShader, getAttachedShaders, getShaderInfoLog, getShaderParameter, getShaderSource, shaderSource, clearStencil, stencilFunc, stencilFuncSeparate, stencilMask, stencilMaskSeparate, stencilOp, stencilOpSeparate, createTexture, deleteTexture, isTexture, bindTexture, activeTexture, copyTexImage2D, copyTexSubImage2D, generateMipmap, getTexParameter, texImage2D, texParameterf, texParameteri, texSubImage2D, getActiveUniform, getUniform, getUniformLocation, uniform1f, uniform1fv, uniform1i, uniform1iv, uniform2f, uniform2fv, uniform2i, uniform2iv, uniform3f, uniform3fv, uniform3i, uniform3iv, uniform4f, uniform4fv, uniform4i, uniform4iv, uniformMatrix2fv, uniformMatrix3fv, uniformMatrix4fv, createVertexArray, deleteVertexArray, isVertexArray, bindVertexArray, drawArraysInstanced, drawElementsInstanced, vertexAttribDivisor, createTransformFeedback, deleteTransformFeedback, isTransformFeedback, bindTransformFeedback, beginTransformFeedback, endTransformFeedback, pauseTransformFeedback, resumeTransformFeedback, transformFeedbackVaryings, getTransformFeedbackVarying, clear, clearColor, clearDepth, colorMask, cullFace, depthFunc, depthMask, depthRange, disable, drawArrays, drawElements, enable, finish, flush, frontFace, getError, getParameter, getRenderTarget, getSupportedExtensions, hint, isEnabled, lineWidth, pixelStorei, polygonOffset, readPixels, sampleCoverage, scissor, viewport
0
rapidsai_public_repos/node/modules
rapidsai_public_repos/node/modules/webgl/tsconfig.json
{ "include": ["src"], "exclude": ["node_modules"], "compilerOptions": { "baseUrl": "./", "paths": { "@rapidsai/webgl": ["src/index"], "@rapidsai/webgl/*": ["src/*"] }, "target": "ESNEXT", "module": "commonjs", "outDir": "./build/js", /* Decorators */ "experimentalDecorators": true, /* Basic stuff */ "moduleResolution": "node", "skipLibCheck": true, "skipDefaultLibCheck": true, "lib": ["dom", "esnext", "esnext.asynciterable"], /* Control what is emitted */ "declaration": true, "declarationMap": true, "noEmitOnError": true, "removeComments": false, "downlevelIteration": true, /* Create inline sourcemaps with sources */ "sourceMap": false, "inlineSources": true, "inlineSourceMap": true, /* The most restrictive settings possible */ "strict": true, "importHelpers": true, "noEmitHelpers": true, "noImplicitAny": true, "noUnusedLocals": true, "noImplicitReturns": true, "allowUnusedLabels": false, "noUnusedParameters": true, "allowUnreachableCode": false, "noFallthroughCasesInSwitch": true, "forceConsistentCasingInFileNames": true } }
0
rapidsai_public_repos/node/modules
rapidsai_public_repos/node/modules/webgl/LICENSE
Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "{}" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright 2019 NVIDIA Corporation 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. -------------------------------------------------------------------------------- include/visit_struct/visit_struct.hpp (modified): BSL 1.0 Boost Software License - Version 1.0 - August 17th, 2003 Permission is hereby granted, free of charge, to any person or organization obtaining a copy of the software and accompanying documentation covered by this license (the "Software") to use, reproduce, display, distribute, execute, and transmit the Software, and to prepare derivative works of the Software, and to permit third-parties to whom the Software is furnished to do so, all subject to the following: The copyright notices in the Software and this entire statement, including the above license grant, this restriction and the following disclaimer, must be included in all copies of the Software, in whole or in part, and all derivative works of the Software, unless such copies or derivative works are solely in the form of machine-executable object code generated by a source language processor. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
0
rapidsai_public_repos/node/modules
rapidsai_public_repos/node/modules/webgl/typedoc.js
module.exports = { entryPoints: ['src/index.ts'], out: 'doc', name: '@rapidsai/webgl', tsconfig: 'tsconfig.json', excludePrivate: true, excludeProtected: true, excludeExternals: true, };
0
rapidsai_public_repos/node/modules/webgl
rapidsai_public_repos/node/modules/webgl/.vscode/launch.json
{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "compounds": [ { "name": "Debug Tests (TS and C++)", "configurations": [ "Debug Tests (launch gdb)", // "Debug Tests (launch lldb)", "Debug Tests (attach node)", ] } ], "configurations": [ { "name": "Debug Tests (TS only)", "type": "node", "request": "launch", "cwd": "${workspaceFolder}", "console": "integratedTerminal", "internalConsoleOptions": "neverOpen", "program": "${workspaceFolder}/node_modules/.bin/jest", "skipFiles": [ "<node_internals>/**", "${workspaceFolder}/node_modules/**" ], "env": { "NODE_NO_WARNINGS": "1", "NODE_ENV": "production", "READABLE_STREAM": "disable", }, "args": [ "--verbose", "--runInBand", "-c", "jest.config.js", "${input:TEST_FILE}" ] }, // { // "name": "Debug Tests (launch lldb)", // // hide the individual configurations from the debug dropdown list // "presentation": { "hidden": true }, // "type": "lldb", // "request": "launch", // "stdio": null, // "cwd": "${workspaceFolder}", // "preLaunchTask": "cpp:ensure:debug:build", // "env": { // "NODE_DEBUG": "1", // "NODE_NO_WARNINGS": "1", // "NODE_ENV": "production", // "READABLE_STREAM": "disable", // }, // "stopOnEntry": false, // "terminal": "console", // "program": "${input:NODE_BINARY}", // "initCommands": [ // "settings set target.disable-aslr false", // ], // "sourceLanguages": ["cpp", "cuda", "javascript"], // "args": [ // "--inspect=9229", // "--expose-internals", // "${workspaceFolder}/node_modules/.bin/jest", // "--verbose", // "--runInBand", // "-c", // "jest.config.js", // "${input:TEST_FILE}" // ], // }, { "name": "Debug Tests (launch gdb)", // hide the individual configurations from the debug dropdown list "presentation": { "hidden": true }, "type": "cppdbg", "request": "launch", "stopAtEntry": false, "externalConsole": false, "cwd": "${workspaceFolder}", "envFile": "${workspaceFolder}/.env", "MIMode": "gdb", "miDebuggerPath": "/usr/bin/gdb", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ], "program": "${input:NODE_BINARY}", "environment": [ { "name": "NODE_DEBUG", "value": "1" }, { "name": "NODE_NO_WARNINGS", "value": "1" }, { "name": "NODE_ENV", "value": "production" }, { "name": "READABLE_STREAM", "value": "disable" }, ], "args": [ "--inspect=9229", "--expose-internals", "${workspaceFolder}/node_modules/.bin/jest", "--verbose", "--runInBand", "-c", "jest.config.js", "${input:TEST_FILE}" ], }, { "name": "Debug Tests (attach node)", "type": "node", "request": "attach", // hide the individual configurations from the debug dropdown list "presentation": { "hidden": true }, "port": 9229, "timeout": 60000, "cwd": "${workspaceFolder}", "skipFiles": [ "<node_internals>/**", "${workspaceFolder}/node_modules/**" ], }, ], "inputs": [ { "type": "command", "id": "NODE_BINARY", "command": "shellCommand.execute", "args": { "description": "path to node", "command": "which node", "useFirstResult": true, } }, { "type": "command", "id": "TEST_FILE", "command": "shellCommand.execute", "args": { "cwd": "${workspaceFolder}/modules/webgl", "description": "Select a file to debug", "command": "./node_modules/.bin/jest --listTests | sed -r \"s@$PWD/test/@@g\"", } }, ], }
0
rapidsai_public_repos/node/modules/webgl
rapidsai_public_repos/node/modules/webgl/.vscode/tasks.json
{ "version": "2.0.0", "tasks": [ { "type": "shell", "label": "Rebuild node_webgl TS and C++ (slow)", "group": { "kind": "build", "isDefault": true, }, "command": "if [[ \"${input:CMAKE_BUILD_TYPE}\" == \"Release\" ]]; then yarn rebuild; else yarn rebuild:debug; fi", "problemMatcher": [ "$tsc", { "owner": "cuda", "fileLocation": ["relative", "${workspaceFolder}/build/${input:CMAKE_BUILD_TYPE}"], "pattern": { "file": 1, "line": 2, "severity": 3, "message": 4, "regexp": "^(.*)\\((\\d+)\\):\\s+(error|warning|note|info):\\s+(.*)$" } }, { "owner": "cpp", "fileLocation": ["relative", "${workspaceFolder}/build/${input:CMAKE_BUILD_TYPE}"], "pattern": { "file": 1, "line": 2, "severity": 4, "message": 5, "regexp": "^(.*):(\\d+):(\\d+):\\s+(error|warning|note|info):\\s+(.*)$" } }, ], }, { "type": "npm", "group": "build", "label": "Recompile node_webgl TS (fast)", "script": "tsc:build", "detail": "yarn tsc:build", "problemMatcher": ["$tsc"], }, { "type": "shell", "group": "build", "label": "Recompile node_webgl C++ (fast)", "command": "ninja -C ${workspaceFolder}/build/${input:CMAKE_BUILD_TYPE}", "problemMatcher": [ { "owner": "cuda", "fileLocation": ["relative", "${workspaceFolder}/build/${input:CMAKE_BUILD_TYPE}"], "pattern": { "file": 1, "line": 2, "severity": 3, "message": 4, "regexp": "^(.*)\\((\\d+)\\):\\s+(error|warning|note|info):\\s+(.*)$" } }, { "owner": "cpp", "fileLocation": ["relative", "${workspaceFolder}/build/${input:CMAKE_BUILD_TYPE}"], "pattern": { "file": 1, "line": 2, "severity": 4, "message": 5, "regexp": "^(.*):(\\d+):(\\d+):\\s+(error|warning|note|info):\\s+(.*)$" } }, ], }, ], "inputs": [ { "type": "pickString", "default": "Release", "id": "CMAKE_BUILD_TYPE", "options": ["Release", "Debug"], "description": "C++ Build Type", } ] }
0
rapidsai_public_repos/node/modules/webgl
rapidsai_public_repos/node/modules/webgl/src/attrib.cpp
// Copyright (c) 2020-2021, NVIDIA CORPORATION. // // 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. #include "macros.hpp" #include "webgl.hpp" #include <nv_node/utilities/args.hpp> #include <nv_node/utilities/cpp_to_napi.hpp> namespace nv { // GLEWAPI void glBindAttribLocation (GLuint program, GLuint index, const GLchar* name); void WebGL2RenderingContext::BindAttribLocation(Napi::CallbackInfo const& info) { CallbackArgs args = info; std::string name = args[2]; GL_EXPORT::glBindAttribLocation(args[0], args[1], name.data()); } // GLEWAPI void glDisableVertexAttribArray (GLuint index); void WebGL2RenderingContext::DisableVertexAttribArray(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glDisableVertexAttribArray(args[0]); } // GLEWAPI void glEnableVertexAttribArray (GLuint index); void WebGL2RenderingContext::EnableVertexAttribArray(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glEnableVertexAttribArray(args[0]); } // GLEWAPI void glGetActiveAttrib (GLuint program, GLuint index, GLsizei maxLength, GLsizei* length, // GLint* size, GLenum* type, GLchar* name); Napi::Value WebGL2RenderingContext::GetActiveAttrib(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLuint program = args[0]; GLuint attrib_ = args[1]; GLint max_len{0}; GL_EXPORT::glGetProgramiv(program, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &max_len); if (max_len > 0) { GLuint type{}; GLint size{0}, length{0}; GLchar* name = reinterpret_cast<GLchar*>(std::malloc(max_len)); GL_EXPORT::glGetActiveAttrib(program, attrib_, max_len, &length, &size, &type, name); return WebGLActiveInfo::New( info.Env(), size, type, std::string{name, static_cast<size_t>(length)}); } return info.Env().Null(); } // GLEWAPI GLint glGetAttribLocation (GLuint program, const GLchar* name); Napi::Value WebGL2RenderingContext::GetAttribLocation(Napi::CallbackInfo const& info) { CallbackArgs args = info; std::string name = args[1]; return CPPToNapi(info)(GL_EXPORT::glGetAttribLocation(args[0], name.data())); } // GLEWAPI void glGetVertexAttribiv (GLuint index, GLenum pname, GLint* params); // GLEWAPI void glGetVertexAttribfv (GLuint index, GLenum pname, GLfloat* params); // GLEWAPI void glGetVertexAttribdv (GLuint index, GLenum pname, GLfloat* params); Napi::Value WebGL2RenderingContext::GetVertexAttrib(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLuint index = args[0]; GLint pname = args[1]; switch (pname) { case GL_VERTEX_ATTRIB_ARRAY_ENABLED: case GL_VERTEX_ATTRIB_ARRAY_INTEGER: case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED: { GLint value{}; GL_EXPORT::glGetVertexAttribiv(index, pname, &value); return CPPToNapi(info)(static_cast<bool>(value)); } case GL_VERTEX_ATTRIB_ARRAY_SIZE: case GL_VERTEX_ATTRIB_ARRAY_TYPE: case GL_VERTEX_ATTRIB_ARRAY_STRIDE: case GL_VERTEX_ATTRIB_ARRAY_DIVISOR: case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: { GLint value{}; GL_EXPORT::glGetVertexAttribiv(index, pname, &value); return CPPToNapi(info)(value); } case GL_CURRENT_VERTEX_ATTRIB: { auto env = info.Env(); auto buf = Napi::ArrayBuffer::New(env, sizeof(GLfloat) * 4); auto ptr = reinterpret_cast<GLfloat*>(buf.Data()); GL_EXPORT::glGetVertexAttribfv(index, pname, ptr); return Napi::Float32Array::New(env, 4, buf, 0); } } GLEW_THROW(info.Env(), GL_INVALID_ENUM); } // GLEWAPI void glGetVertexAttribPointerv (GLuint index, GLenum pname, void** pointer); Napi::Value WebGL2RenderingContext::GetVertexAttribPointerv(Napi::CallbackInfo const& info) { CallbackArgs args = info; void* vertex_attrib{nullptr}; GL_EXPORT::glGetVertexAttribPointerv(args[0], args[1], &vertex_attrib); return CPPToNapi(info)(vertex_attrib); } // GLEWAPI void glVertexAttrib1f (GLuint index, GLfloat x); void WebGL2RenderingContext::VertexAttrib1f(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glVertexAttrib1f(args[0], args[1]); } // GLEWAPI void glVertexAttrib1fv (GLuint index, const GLfloat* v); void WebGL2RenderingContext::VertexAttrib1fv(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glVertexAttrib1fv(args[0], args[1]); } // GLEWAPI void glVertexAttrib2f (GLuint index, GLfloat x, GLfloat y); void WebGL2RenderingContext::VertexAttrib2f(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glVertexAttrib2f(args[0], args[1], args[2]); } // GLEWAPI void glVertexAttrib2fv (GLuint index, const GLfloat* v); void WebGL2RenderingContext::VertexAttrib2fv(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glVertexAttrib2fv(args[0], args[1]); } // GLEWAPI void glVertexAttrib3f (GLuint index, GLfloat x, GLfloat y, GLfloat z); void WebGL2RenderingContext::VertexAttrib3f(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glVertexAttrib3f(args[0], args[1], args[2], args[3]); } // GLEWAPI void glVertexAttrib3fv (GLuint index, const GLfloat* v); void WebGL2RenderingContext::VertexAttrib3fv(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glVertexAttrib3fv(args[0], args[1]); } // GLEWAPI void glVertexAttrib4f (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); void WebGL2RenderingContext::VertexAttrib4f(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glVertexAttrib4f(args[0], args[1], args[2], args[3], args[4]); } // GLEWAPI void glVertexAttrib4fv (GLuint index, const GLfloat* v); void WebGL2RenderingContext::VertexAttrib4fv(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glVertexAttrib4fv(args[0], args[1]); } // GLEWAPI void glVertexAttribPointer (GLuint index, GLint size, GLenum type, GLboolean normalized, // GLsizei stride, const void* pointer); void WebGL2RenderingContext::VertexAttribPointer(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLuint index = args[0]; GLint size = args[1]; GLenum type = args[2]; bool normalized = args[3]; GLsizei stride = args[4]; GLintptr ptr = args[5]; GL_EXPORT::glVertexAttribPointer(index, size, type, normalized ? GL_TRUE : GL_FALSE, stride, ptr == 0 ? NULL : reinterpret_cast<void*>(ptr)); } // GLEWAPI void glVertexAttribI4i (GLuint index, GLint v0, GLint v1, GLint v2, GLint v3); void WebGL2RenderingContext::VertexAttribI4i(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glVertexAttribI4i(args[0], args[1], args[2], args[3], args[4]); } // GLEWAPI void glVertexAttribI4iv (GLuint index, const GLint* v0); void WebGL2RenderingContext::VertexAttribI4iv(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glVertexAttribI4iv(args[0], args[1]); } // GLEWAPI void glVertexAttribI4ui (GLuint index, GLuint v0, GLuint v1, GLuint v2, GLuint v3); void WebGL2RenderingContext::VertexAttribI4ui(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glVertexAttribI4ui(args[0], args[1], args[2], args[3], args[4]); } // GLEWAPI void glVertexAttribI4uiv (GLuint index, const GLuint* v0); void WebGL2RenderingContext::VertexAttribI4uiv(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glVertexAttribI4uiv(args[0], args[1]); } // GLEWAPI void glVertexAttribIPointer (GLuint index, GLint size, GLenum type, GLsizei stride, const // void*pointer); void WebGL2RenderingContext::VertexAttribIPointer(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLuint index = args[0]; GLint size = args[1]; GLenum type = args[2]; GLsizei stride = args[3]; GLintptr ptr = args[4]; GL_EXPORT::glVertexAttribIPointer( index, size, type, stride, ptr == 0 ? NULL : reinterpret_cast<void*>(ptr)); } } // namespace nv
0
rapidsai_public_repos/node/modules/webgl
rapidsai_public_repos/node/modules/webgl/src/query.cpp
// Copyright (c) 2020-2021, NVIDIA CORPORATION. // // 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. #include "macros.hpp" #include "webgl.hpp" #include <nv_node/utilities/args.hpp> #include <nv_node/utilities/cpp_to_napi.hpp> namespace nv { // GL_EXPORT void glBeginQuery (GLenum target, GLuint id); void WebGL2RenderingContext::BeginQuery(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glBeginQuery(args[0], args[1]); } // GL_EXPORT void glGenQueries (GLsizei n, GLuint* ids); Napi::Value WebGL2RenderingContext::CreateQuery(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLuint query{}; GL_EXPORT::glGenQueries(1, &query); return WebGLQuery::New(info.Env(), query); } // GL_EXPORT void glGenQueries (GLsizei n, GLuint* ids); Napi::Value WebGL2RenderingContext::CreateQueries(Napi::CallbackInfo const& info) { CallbackArgs args = info; std::vector<GLuint> queries(static_cast<size_t>(args[0])); GL_EXPORT::glGenQueries(queries.size(), queries.data()); return CPPToNapi(info)(queries); } // GL_EXPORT void glDeleteQueries (GLsizei n, const GLuint* ids); void WebGL2RenderingContext::DeleteQuery(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLuint query = args[0]; GL_EXPORT::glDeleteQueries(1, &query); } // GL_EXPORT void glDeleteQueries (GLsizei n, const GLuint* ids); void WebGL2RenderingContext::DeleteQueries(Napi::CallbackInfo const& info) { CallbackArgs args = info; std::vector<GLuint> queries = args[0]; GL_EXPORT::glDeleteQueries(queries.size(), queries.data()); } // GL_EXPORT void glEndQuery (GLenum target); void WebGL2RenderingContext::EndQuery(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glEndQuery(args[0]); } // GL_EXPORT void glGetQueryiv (GLenum target, GLenum pname, GLint* params); Napi::Value WebGL2RenderingContext::GetQuery(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLint params{}; GL_EXPORT::glGetQueryiv(args[0], args[1], &params); return CPPToNapi(info)(params); } // GL_EXPORT void glGetQueryObjectuiv (GLuint id, GLenum pname, GLuint* params); Napi::Value WebGL2RenderingContext::GetQueryParameter(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLuint target = args[0]; GLuint pname = args[1]; switch (pname) { case GL_QUERY_RESULT: { GLuint params{}; GL_EXPORT::glGetQueryObjectuiv(target, pname, &params); return CPPToNapi(info)(params); } case GL_QUERY_RESULT_AVAILABLE: { GLuint params{}; GL_EXPORT::glGetQueryObjectuiv(target, pname, &params); return CPPToNapi(info)(static_cast<bool>(params)); } } GLEW_THROW(info.Env(), GL_INVALID_ENUM); } // GL_EXPORT GLboolean glIsQuery (GLuint id); Napi::Value WebGL2RenderingContext::IsQuery(Napi::CallbackInfo const& info) { CallbackArgs args = info; auto is_query = GL_EXPORT::glIsQuery(args[0]); return CPPToNapi(info)(is_query); } // GL_EXPORT void glQueryCounter (GLuint id, GLenum target); void WebGL2RenderingContext::QueryCounter(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glQueryCounter(args[0], args[1]); } } // namespace nv
0
rapidsai_public_repos/node/modules/webgl
rapidsai_public_repos/node/modules/webgl/src/webgl.ts
// Copyright (c) 2020-2021, NVIDIA CORPORATION. // // 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. /* eslint-disable prefer-const */ import gl from './addon'; // default WebGLContextAttributes: // alpha: true, // antialias: true, // depth: true, // failIfMajorPerformanceCaveat: false, // powerPreference: 'default', // premultipliedAlpha: true, // preserveDrawingBuffer: false, // stencil: false, // desynchronized: false interface OpenGLESRenderingContext extends WebGL2RenderingContext { // eslint-disable-next-line @typescript-eslint/no-misused-new new(attrs?: WebGLContextAttributes): OpenGLESRenderingContext; webgl1: boolean; webgl2: boolean; opengl: boolean; _version: number; _clearMask: number; } // eslint-disable-next-line @typescript-eslint/no-redeclare const OpenGLESRenderingContext: OpenGLESRenderingContext = gl.WebGL2RenderingContext; OpenGLESRenderingContext.prototype.webgl1 = false; OpenGLESRenderingContext.prototype.webgl2 = true; OpenGLESRenderingContext.prototype.opengl = true; OpenGLESRenderingContext.prototype._version = 2; OpenGLESRenderingContext.prototype.isContextLost = () => false; export const WebGLActiveInfo = gl.WebGLActiveInfo; export const WebGLShaderPrecisionFormat = gl.WebGLShaderPrecisionFormat; export const WebGLBuffer = gl.WebGLBuffer; export const WebGLContextEvent = gl.WebGLContextEvent; export const WebGLFramebuffer = gl.WebGLFramebuffer; export const WebGLProgram = gl.WebGLProgram; export const WebGLQuery = gl.WebGLQuery; export const WebGLRenderbuffer = gl.WebGLRenderbuffer; export const WebGLSampler = gl.WebGLSampler; export const WebGLShader = gl.WebGLShader; export const WebGLSync = gl.WebGLSync; export const WebGLTexture = gl.WebGLTexture; export const WebGLTransformFeedback = gl.WebGLTransformFeedback; export const WebGLUniformLocation = gl.WebGLUniformLocation; export const WebGLVertexArrayObject = gl.WebGLVertexArrayObject; export {OpenGLESRenderingContext as WebGLRenderingContext}; export {OpenGLESRenderingContext as WebGL2RenderingContext}; const gl_bufferData = OpenGLESRenderingContext.prototype.bufferData; OpenGLESRenderingContext.prototype.bufferData = bufferData; function bufferData( this: WebGL2RenderingContext, target: GLenum, size: GLsizeiptr, usage: GLenum): void; function bufferData( this: WebGL2RenderingContext, target: GLenum, srcData: BufferSource|null, usage: GLenum): void; function bufferData(this: WebGL2RenderingContext, target: GLenum, srcData: ArrayBufferView, usage: GLenum, srcOffset: GLuint, srcByteLength?: GLuint): void; function bufferData( this: WebGL2RenderingContext, ...args: [GLenum, GLsizeiptr|BufferSource|null, GLenum, GLuint?, GLuint?]): void { let [target, src, usage, srcOffset, srcByteLength] = args; if (args.length > 3 && src !== null && typeof src !== 'number' && typeof srcOffset === 'number') { let BPM, arr = ArrayBuffer.isView(src) ? src : new Uint8Array(src); [, , , , srcByteLength = arr.byteLength, BPM = (<Uint8Array>arr).BYTES_PER_ELEMENT] = args; src = new Uint8Array(arr.buffer, arr.byteOffset, srcByteLength).subarray(srcOffset * BPM); } return gl_bufferData.call(this, target, src, usage); } const gl_bufferSubData = OpenGLESRenderingContext.prototype.bufferSubData; OpenGLESRenderingContext.prototype.bufferSubData = bufferSubData; function bufferSubData( this: WebGL2RenderingContext, target: GLenum, offset: GLintptr, data: BufferSource): void; function bufferSubData( this: WebGL2RenderingContext, target: GLenum, dstByteOffset: GLintptr, srcData: BufferSource): void; function bufferSubData(this: WebGL2RenderingContext, target: GLenum, dstByteOffset: GLintptr, srcData: ArrayBufferView, srcOffset: GLuint, srcByteLength?: GLuint): void; function bufferSubData( this: WebGL2RenderingContext, ...args: [GLenum, GLintptr, BufferSource|ArrayBufferView, GLuint?, GLuint?]): void { let [target, dstByteOffset, src, srcOffset, srcByteLength] = args; if (args.length > 3 && src !== null && typeof src !== 'number' && typeof srcOffset === 'number') { let BPM, arr = ArrayBuffer.isView(src) ? src : new Uint8Array(src); [, , , , srcByteLength = arr.byteLength, BPM = (<Uint8Array>arr).BYTES_PER_ELEMENT] = args; src = new Uint8Array(arr.buffer, arr.byteOffset, srcByteLength).subarray(srcOffset * BPM); } return gl_bufferSubData.call(this, target, dstByteOffset, src); } const gl_getBufferSubData = OpenGLESRenderingContext.prototype.getBufferSubData; OpenGLESRenderingContext.prototype.getBufferSubData = getBufferSubData; function getBufferSubData(this: WebGL2RenderingContext, target: GLenum, srcByteOffset: GLintptr, dst: ArrayBufferView, dstOffset: GLuint = 0, length?: GLuint): void { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const arr = ArrayBuffer.isView(dst) ? <Uint8Array>dst : toArrayBufferViewSlice(dst, dstOffset)!; const size = typeof length === 'undefined' ? arr.byteLength : length * arr.BYTES_PER_ELEMENT; return gl_getBufferSubData.call(this, target, srcByteOffset, size, arr); } // @ts-ignore // const gl_getExtension = OpenGLESRenderingContext.prototype.getExtension; OpenGLESRenderingContext.prototype.getExtension = getExtension; function getExtension(this: WebGL2RenderingContext, name: string) { const extension = Object.assign({}, extensionsMap[name]); for (const [key, val] of Object.entries(extension)) { if (typeof val === 'function') { extension[key] = val.bind(this); } } return extension; } const gl_getShaderInfoLog = OpenGLESRenderingContext.prototype.getShaderInfoLog; OpenGLESRenderingContext.prototype.getShaderInfoLog = getShaderInfoLog; function getShaderInfoLog(this: WebGL2RenderingContext, shader: WebGLShader): string { const lines: string[] = (gl_getShaderInfoLog.call(this, shader) || '').split(/(\n|\r)/g); // Reformat the error lines to look like webgl errors (todo: is this nvidia-specific?) return lines .map((line) => { let errIndex, numIndex, errMatch, numMatch, type, num; ({index: errIndex, [0]: errMatch, [1]: type} = // eslint-disable-next-line @typescript-eslint/prefer-regexp-exec (lines[0] || '').match(/\s?(warning|error) (\w+|\d+):/) || {index: undefined, 0: '', 1: ''}); ({index: numIndex, [0]: numMatch, [1]: num} = // eslint-disable-next-line @typescript-eslint/prefer-regexp-exec (line.match(/0\((\d+)\) :/) || {index: undefined, 0: '', 1: ''})); if (errIndex !== undefined && numIndex !== undefined && errMatch && type && numMatch && num) { return `${type.toUpperCase()}:${line.slice(errIndex + errMatch.length)}:${num}${ line.slice(numIndex + numMatch.length)}`; } return line; }) .join('\n'); } const gl_texImage2D = OpenGLESRenderingContext.prototype.texImage2D; OpenGLESRenderingContext.prototype.texImage2D = texImage2D; function texImage2D(this: WebGL2RenderingContext, target: GLenum, level: GLint, internalformat: GLint, format: GLenum, type: GLenum, source: TexImageSource): void; function texImage2D(this: WebGL2RenderingContext, target: GLenum, level: GLint, internalformat: GLint, width: GLsizei, height: GLsizei, border: GLint, format: GLenum, type: GLenum, pboOffset: GLintptr): void; function texImage2D(this: WebGL2RenderingContext, target: GLenum, level: GLint, internalformat: GLint, width: GLsizei, height: GLsizei, border: GLint, format: GLenum, type: GLenum, source: TexImageSource): void; function texImage2D(this: WebGL2RenderingContext, target: GLenum, level: GLint, internalformat: GLint, width: GLsizei, height: GLsizei, border: GLint, format: GLenum, type: GLenum, srcData?: ArrayBufferView|null, srcOffset?: GLuint): void; function texImage2D(this: WebGL2RenderingContext, ...args: [ GLenum, GLint, GLint, GLsizei|GLenum, GLsizei|GLenum, GLint|TexImageSource, GLenum?, GLenum?, (GLintptr | TexImageSource | ArrayBufferView | null)?, GLsizei? ]): void { let [target, level, internalformat, width, height, border, format, type, src, offset = 0] = args; switch (args.length) { case 6: { [target, level, internalformat, format, type, src] = (args as [GLenum, GLint, GLint, GLenum, GLenum, TexImageSource]); ({width, height, border = 0} = <any>src); src = pixelsFromImage(src, width, height); break; } case 8: case 9: case 10: { if (typeof args[8] === 'number') { [target, level, internalformat, width, height, border, format, type, src] = (args as [GLenum, GLint, GLint, GLsizei, GLsizei, GLint, GLenum, GLenum, GLintptr]); break; } if (args[8] === null || args[8] === undefined || ArrayBuffer.isView(args[8]) || (args[8] instanceof ArrayBuffer)) { [target, level, internalformat, width, height, border, format, type, src] = (args as [GLenum, GLint, GLint, GLsizei, GLsizei, GLint, GLenum, GLenum, ArrayBufferView]); src = toArrayBufferViewSlice(src, offset); break; } if (args[8] && typeof args[8] === 'object') { [target, level, internalformat, width, height, border, format, type, src] = (args as [GLenum, GLint, GLint, GLsizei, GLsizei, GLint, GLenum, GLenum, TexImageSource]); [width = src.width, height = src.height] = [width, height]; src = pixelsFromImage(src, width, height); break; } throw new TypeError('WebGLRenderingContext texImage2D() invalid texture source'); } default: throw new TypeError('WebGLRenderingContext texImage2D() takes 6, 9, or 10 arguments'); } return gl_texImage2D.call( this, target, level, internalformat, width, height, border, format, type, src); } const gl_texSubImage2D = OpenGLESRenderingContext.prototype.texSubImage2D; OpenGLESRenderingContext.prototype.texSubImage2D = texSubImage2D; function texSubImage2D(this: WebGL2RenderingContext, target: GLenum, level: GLint, xoffset: GLint, yoffset: GLint, width: GLsizei, height: GLsizei, format: GLenum, type: GLenum, pixels: ArrayBufferView|null): void; function texSubImage2D(this: WebGL2RenderingContext, target: GLenum, level: GLint, xoffset: GLint, yoffset: GLint, format: GLenum, type: GLenum, source: TexImageSource): void; function texSubImage2D(this: WebGL2RenderingContext, target: GLenum, level: GLint, xoffset: GLint, yoffset: GLint, width: GLsizei, height: GLsizei, format: GLenum, type: GLenum, pboOffset: GLintptr): void; function texSubImage2D(this: WebGL2RenderingContext, target: GLenum, level: GLint, xoffset: GLint, yoffset: GLint, width: GLsizei, height: GLsizei, format: GLenum, type: GLenum, source: TexImageSource): void; function texSubImage2D(this: WebGL2RenderingContext, target: GLenum, level: GLint, xoffset: GLint, yoffset: GLint, width: GLsizei, height: GLsizei, format: GLenum, type: GLenum, srcData?: ArrayBufferView|null, srcOffset?: GLuint): void; function texSubImage2D(this: WebGL2RenderingContext, ...args: [ GLenum, GLint, GLint, GLint, GLenum|GLsizei, GLenum|GLsizei, GLenum|TexImageSource, GLenum?, (GLintptr | TexImageSource | ArrayBufferView | null)?, GLuint? ]): void { let [target, level, x, y, width, height, format, type, src, offset = 0] = args; switch (args.length) { case 7: { [target, level, x, y, format, type, src] = (args as [GLenum, GLint, GLint, GLint, GLenum, GLenum, TexImageSource]); src = pixelsFromImage(src, width = src.width, height = src.height); break; } case 8: case 9: case 10: { if (typeof args[8] === 'number') { [target, level, x, y, width, height, format, type, src] = (args as [GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, GLintptr]); break; } if (args[8] === null || args[8] === undefined || ArrayBuffer.isView(args[8]) || (args[8] instanceof ArrayBuffer)) { [target, level, x, y, width, height, format, type, src] = (args as [GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, ArrayBufferView | null]); src = toArrayBufferViewSlice(src, offset); break; } if (args[8] && typeof args[8] === 'object') { [target, level, x, y, width, height, format, type, src] = (args as [GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, TexImageSource]); [width = src.width, height = src.height] = [width, height]; src = pixelsFromImage(src, width, height); break; } throw new TypeError('WebGLRenderingContext texSubImage2D() invalid texture source'); } default: throw new TypeError('WebGLRenderingContext texSubImage2D() takes 7, 9, or 10 arguments'); } return gl_texSubImage2D.call(this, target, level, x, y, width, height, format, type, src); } const gl_readPixels = OpenGLESRenderingContext.prototype.readPixels; OpenGLESRenderingContext.prototype.readPixels = readPixels; function readPixels(this: WebGL2RenderingContext, x: GLint, y: GLint, width: GLsizei, height: GLsizei, format: GLenum, type: GLenum, dstData: ArrayBufferView|null): void; function readPixels(this: WebGL2RenderingContext, x: GLint, y: GLint, width: GLsizei, height: GLsizei, format: GLenum, type: GLenum, offset: GLintptr): void; function readPixels(this: WebGL2RenderingContext, x: GLint, y: GLint, width: GLsizei, height: GLsizei, format: GLenum, type: GLenum, dstData: ArrayBufferView, dstOffset: GLuint): void; function readPixels(this: WebGL2RenderingContext, ...args: [ GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, (ArrayBufferView | ArrayBuffer | GLintptr | null)?, GLuint? ]): void { let [x, y, width, height, format, type, dst, offset = 0] = args; switch (args.length) { case 6: case 7: { if (typeof args[6] === 'number') { [x, y, width, height, format, type, dst] = (args as [GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, GLintptr]); break; } if (args[6] === null || args[6] === undefined || ArrayBuffer.isView(args[6]) || (args[6] instanceof ArrayBuffer)) { [x, y, width, height, format, type, dst] = (args as [GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, (ArrayBufferView | null)?]); dst = toArrayBufferViewSlice(dst, offset); break; } throw new TypeError('WebGLRenderingContext readPixels() invalid readPixels target'); } case 8: { [x, y, width, height, format, type, dst, offset = 0] = (args as [GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, ArrayBufferView?, GLuint?]); dst = toArrayBufferViewSlice(dst, offset); break; } default: throw new TypeError('WebGLRenderingContext readPixels() takes 6, 7, or 8 arguments'); } return gl_readPixels.call(this, x, y, width, height, format, type, dst); } const gl_uniform1fv = OpenGLESRenderingContext.prototype.uniform1fv; OpenGLESRenderingContext.prototype.uniform1fv = uniform1fv; function uniform1fv( this: WebGL2RenderingContext, location: WebGLUniformLocation, value: Float32Array|number[]) { return location ? gl_uniform1fv.call( this, location, Array.isArray(value) ? new Float32Array(value) : value) : undefined; } const gl_uniform2fv = OpenGLESRenderingContext.prototype.uniform2fv; OpenGLESRenderingContext.prototype.uniform2fv = uniform2fv; function uniform2fv( this: WebGL2RenderingContext, location: WebGLUniformLocation, value: Float32Array|number[]) { return location ? gl_uniform2fv.call( this, location, Array.isArray(value) ? new Float32Array(value) : value) : undefined; } const gl_uniform3fv = OpenGLESRenderingContext.prototype.uniform3fv; OpenGLESRenderingContext.prototype.uniform3fv = uniform3fv; function uniform3fv( this: WebGL2RenderingContext, location: WebGLUniformLocation, value: Float32Array|number[]) { return location ? gl_uniform3fv.call( this, location, Array.isArray(value) ? new Float32Array(value) : value) : undefined; } const gl_uniform4fv = OpenGLESRenderingContext.prototype.uniform4fv; OpenGLESRenderingContext.prototype.uniform4fv = uniform4fv; function uniform4fv( this: WebGL2RenderingContext, location: WebGLUniformLocation, value: Float32Array|number[]) { return location ? gl_uniform4fv.call( this, location, Array.isArray(value) ? new Float32Array(value) : value) : undefined; } const gl_uniform1iv = OpenGLESRenderingContext.prototype.uniform1iv; OpenGLESRenderingContext.prototype.uniform1iv = uniform1iv; function uniform1iv( this: WebGL2RenderingContext, location: WebGLUniformLocation, value: Int32Array|number[]) { return location ? gl_uniform1iv.call(this, location, Array.isArray(value) ? new Int32Array(value) : value) : undefined; } const gl_uniform2iv = OpenGLESRenderingContext.prototype.uniform2iv; OpenGLESRenderingContext.prototype.uniform2iv = uniform2iv; function uniform2iv( this: WebGL2RenderingContext, location: WebGLUniformLocation, value: Int32Array|number[]) { return location ? gl_uniform2iv.call(this, location, Array.isArray(value) ? new Int32Array(value) : value) : undefined; } const gl_uniform3iv = OpenGLESRenderingContext.prototype.uniform3iv; OpenGLESRenderingContext.prototype.uniform3iv = uniform3iv; function uniform3iv( this: WebGL2RenderingContext, location: WebGLUniformLocation, value: Int32Array|number[]) { return location ? gl_uniform3iv.call(this, location, Array.isArray(value) ? new Int32Array(value) : value) : undefined; } const gl_uniform4iv = OpenGLESRenderingContext.prototype.uniform4iv; OpenGLESRenderingContext.prototype.uniform4iv = uniform4iv; function uniform4iv( this: WebGL2RenderingContext, location: WebGLUniformLocation, value: Int32Array|number[]) { return location ? gl_uniform4iv.call(this, location, Array.isArray(value) ? new Int32Array(value) : value) : undefined; } const gl_uniformMatrix2fv = OpenGLESRenderingContext.prototype.uniformMatrix2fv; OpenGLESRenderingContext.prototype.uniformMatrix2fv = uniformMatrix2fv; function uniformMatrix2fv(this: WebGL2RenderingContext, location: WebGLUniformLocation|null, transpose: GLboolean, data: Float32List, offset: GLuint = 0, length: GLuint = data.length): void { if (ArrayBuffer.isView(data)) { data = data.subarray(offset, offset + length); } return location ? gl_uniformMatrix2fv.call(this, location, transpose, data) : undefined; } const gl_uniformMatrix3fv = OpenGLESRenderingContext.prototype.uniformMatrix3fv; OpenGLESRenderingContext.prototype.uniformMatrix3fv = uniformMatrix3fv; function uniformMatrix3fv(this: WebGL2RenderingContext, location: WebGLUniformLocation|null, transpose: GLboolean, data: Float32List, offset: GLuint = 0, length: GLuint = data.length): void { if (ArrayBuffer.isView(data)) { data = data.subarray(offset, offset + length); } return location ? gl_uniformMatrix3fv.call(this, location, transpose, data) : undefined; } const gl_uniformMatrix4fv = OpenGLESRenderingContext.prototype.uniformMatrix4fv; OpenGLESRenderingContext.prototype.uniformMatrix4fv = uniformMatrix4fv; function uniformMatrix4fv(this: WebGL2RenderingContext, location: WebGLUniformLocation|null, transpose: GLboolean, data: Float32List, offset: GLuint = 0, length: GLuint = data.length): void { if (ArrayBuffer.isView(data)) { data = data.subarray(offset, offset + length); } return location ? gl_uniformMatrix4fv.call(this, location, transpose, data) : undefined; } const gl_uniformMatrix2x3fv = OpenGLESRenderingContext.prototype.uniformMatrix2x3fv; OpenGLESRenderingContext.prototype.uniformMatrix2x3fv = uniformMatrix2x3fv; function uniformMatrix2x3fv(this: WebGL2RenderingContext, location: WebGLUniformLocation|null, transpose: GLboolean, data: Float32List, offset: GLuint = 0, length: GLuint = data.length): void { if (ArrayBuffer.isView(data)) { data = data.subarray(offset, offset + length); } return location ? gl_uniformMatrix2x3fv.call(this, location, transpose, data) : undefined; } const gl_uniformMatrix2x4fv = OpenGLESRenderingContext.prototype.uniformMatrix2x4fv; OpenGLESRenderingContext.prototype.uniformMatrix2x4fv = uniformMatrix2x4fv; function uniformMatrix2x4fv(this: WebGL2RenderingContext, location: WebGLUniformLocation|null, transpose: GLboolean, data: Float32List, offset: GLuint = 0, length: GLuint = data.length): void { if (ArrayBuffer.isView(data)) { data = data.subarray(offset, offset + length); } return location ? gl_uniformMatrix2x4fv.call(this, location, transpose, data) : undefined; } const gl_uniformMatrix3x2fv = OpenGLESRenderingContext.prototype.uniformMatrix3x2fv; OpenGLESRenderingContext.prototype.uniformMatrix3x2fv = uniformMatrix3x2fv; function uniformMatrix3x2fv(this: WebGL2RenderingContext, location: WebGLUniformLocation|null, transpose: GLboolean, data: Float32List, offset: GLuint = 0, length: GLuint = data.length): void { if (ArrayBuffer.isView(data)) { data = data.subarray(offset, offset + length); } return location ? gl_uniformMatrix3x2fv.call(this, location, transpose, data) : undefined; } const gl_uniformMatrix3x4fv = OpenGLESRenderingContext.prototype.uniformMatrix3x4fv; OpenGLESRenderingContext.prototype.uniformMatrix3x4fv = uniformMatrix3x4fv; function uniformMatrix3x4fv(this: WebGL2RenderingContext, location: WebGLUniformLocation|null, transpose: GLboolean, data: Float32List, offset: GLuint = 0, length: GLuint = data.length): void { if (ArrayBuffer.isView(data)) { data = data.subarray(offset, offset + length); } return location ? gl_uniformMatrix3x4fv.call(this, location, transpose, data) : undefined; } const gl_uniformMatrix4x2fv = OpenGLESRenderingContext.prototype.uniformMatrix4x2fv; OpenGLESRenderingContext.prototype.uniformMatrix4x2fv = uniformMatrix4x2fv; function uniformMatrix4x2fv(this: WebGL2RenderingContext, location: WebGLUniformLocation|null, transpose: GLboolean, data: Float32List, offset: GLuint = 0, length: GLuint = data.length): void { if (ArrayBuffer.isView(data)) { data = data.subarray(offset, offset + length); } return location ? gl_uniformMatrix4x2fv.call(this, location, transpose, data) : undefined; } const gl_uniformMatrix4x3fv = OpenGLESRenderingContext.prototype.uniformMatrix4x3fv; OpenGLESRenderingContext.prototype.uniformMatrix4x3fv = uniformMatrix4x3fv; function uniformMatrix4x3fv(this: WebGL2RenderingContext, location: WebGLUniformLocation|null, transpose: GLboolean, data: Float32List, offset: GLuint = 0, length: GLuint = data.length): void { if (ArrayBuffer.isView(data)) { data = data.subarray(offset, offset + length); } return location ? gl_uniformMatrix4x3fv.call(this, location, transpose, data) : undefined; } if (Boolean(process.env.NVIDIA_NODE_WEBGL_TRACE_CALLS) === true) { wrapAndLogGLMethods(OpenGLESRenderingContext.prototype); } //@ts-ignore function wrapAndLogGLMethods(proto: any) { /* eslint-disable @typescript-eslint/restrict-template-expressions */ const listToString = (x: any) => { if (x.length < 10) { return `(length=${x.length}, values=[${x}])`; } return `(length=${x.length}, values=[${x.slice(0, 3)}, ... ${ x.slice((x.length >> 1) - 2, (x.length >> 1) + 1)}, ... ${x.slice(x.length - 3, x.length)}])`; }; const toString = (x: any) => { switch (typeof x) { case 'number': return `${x}`; case 'boolean': return `${x}`; case 'function': return `${x}`; case 'string': return `\`${x}\``; case 'undefined': return 'undefined'; case 'symbol': return `Symbol(${x.description})`; default: if (x === null) return 'null'; if (Array.isArray(x)) return listToString(x); if (ArrayBuffer.isView(x)) return `${x.constructor.name}${listToString(x)}`; if (nodeCustomInspectSym in x) return x[nodeCustomInspectSym](); if (`${x}` === '[object Object]') return JSON.stringify(x); return `${x}`; } }; const glEnumNames = Object.keys(proto) .filter((key) => typeof proto[key] === 'number') .reduce((glEnumNames: any, key) => { glEnumNames[proto[key]] = key; return glEnumNames; }, {}); const enumToString = (x: number) => `gl.${glEnumNames[x]}`; const logArguments = (name: string, fn: any) => function(this: any, ...args: any[]) { const str = (() => { switch (name) { case 'enable': case 'disable': return `gl.${name}(${args.map(enumToString).join(', ')})`; default: return `gl.${name}(${args.map(toString).join(', ')})`; } })(); process.stderr.write(str); try { const ret = fn.apply(this, args); process.stderr.write((ret !== undefined ? `: ${toString(ret)}` : '') + '\n'); return ret; } catch (err) { process.stderr.write((err !== undefined ? `: ${toString(err)}` : '') + '\n'); throw err; } }; Object.keys(proto) .filter((key: any) => typeof proto[key] === 'function') .forEach((key) => proto[key] = logArguments(key, proto[key])); } function toArrayBufferViewSlice(source?: ArrayBuffer|ArrayBufferView|null, offset = 0) { if (source === null || source === undefined) { return null; } if (source instanceof ArrayBuffer) { return new Uint8Array(source).subarray(offset); } else if (source instanceof DataView) { return new Uint8Array(source.buffer).subarray(offset); } else if (ArrayBuffer.isView(source)) { return (<Uint8Array>source).subarray(offset * (<Uint8Array>source).BYTES_PER_ELEMENT); } throw new TypeError('OpenGLESRenderingContext invalid pixel source'); } function pixelsFromImage(source: TexImageSource, width: number, height: number) { if ((typeof HTMLImageElement !== 'undefined') && (source instanceof HTMLImageElement) || (typeof HTMLVideoElement !== 'undefined') && (source instanceof HTMLVideoElement) && source.ownerDocument) { const canvas = source.ownerDocument.createElement('canvas'); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const context = Object.assign(canvas, {width, height}).getContext('2d')!; context.drawImage(source, 0, 0); return context.getImageData(0, 0, width, height).data; } if (source && typeof (<any>source).getContext === 'function') { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const context = (<any>source).getContext('2d'); if (context && typeof context.getImageData === 'function') { const imageData = context.getImageData(0, 0, width, height); if (imageData && ('data' in imageData)) { return imageData.data; } } } if ('data' in source) { return source.data; } throw new TypeError('OpenGLESRenderingContext invalid pixel source'); } const nodeCustomInspectSym = Symbol.for('nodejs.util.inspect.custom'); const extensionsMap: any = { ANGLE_instanced_arrays: { VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE: OpenGLESRenderingContext.prototype.VERTEX_ATTRIB_ARRAY_DIVISOR, drawArraysInstancedANGLE: OpenGLESRenderingContext.prototype.drawArraysInstanced, drawElementsInstancedANGLE: OpenGLESRenderingContext.prototype.drawElementsInstanced, vertexAttribDivisorANGLE: OpenGLESRenderingContext.prototype.vertexAttribDivisor, }, EXT_blend_minmax: { MIN_EXT: OpenGLESRenderingContext.prototype.MIN, MAX_EXT: OpenGLESRenderingContext.prototype.MAX, }, EXT_color_buffer_float: {}, EXT_color_buffer_half_float: { RGBA16F_EXT: OpenGLESRenderingContext.prototype.RGBA16F, RGB16F_EXT: OpenGLESRenderingContext.prototype.RGB16F, FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE_EXT: OpenGLESRenderingContext.prototype.FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE, UNSIGNED_NORMALIZED_EXT: OpenGLESRenderingContext.prototype.UNSIGNED_NORMALIZED, }, EXT_disjoint_timer_query: { CURRENT_QUERY_EXT: OpenGLESRenderingContext.prototype.CURRENT_QUERY, QUERY_RESULT_EXT: OpenGLESRenderingContext.prototype.QUERY_RESULT, QUERY_RESULT_AVAILABLE_EXT: OpenGLESRenderingContext.prototype.QUERY_RESULT_AVAILABLE, TIME_ELAPSED_EXT: OpenGLESRenderingContext.prototype.TIME_ELAPSED, TIMESTAMP_EXT: OpenGLESRenderingContext.prototype.TIMESTAMP, GPU_DISJOINT_EXT: OpenGLESRenderingContext.prototype.GPU_DISJOINT, createQueryEXT: OpenGLESRenderingContext.prototype.createQuery, deleteQueryEXT: OpenGLESRenderingContext.prototype.deleteQuery, isQueryEXT: OpenGLESRenderingContext.prototype.isQuery, beginQueryEXT: OpenGLESRenderingContext.prototype.beginQuery, endQueryEXT: OpenGLESRenderingContext.prototype.endQuery, queryCounterEXT: OpenGLESRenderingContext.prototype.queryCounter, getQueryEXT: OpenGLESRenderingContext.prototype.getQuery, getQueryObjectEXT: OpenGLESRenderingContext.prototype.getQueryParameter, }, EXT_disjoint_timer_query_webgl2: { CURRENT_QUERY: OpenGLESRenderingContext.prototype.CURRENT_QUERY, QUERY_RESULT: OpenGLESRenderingContext.prototype.QUERY_RESULT, QUERY_COUNTER_BITS_EXT: OpenGLESRenderingContext.prototype.QUERY_COUNTER_BITS, QUERY_RESULT_AVAILABLE: OpenGLESRenderingContext.prototype.QUERY_RESULT_AVAILABLE, TIME_ELAPSED_EXT: OpenGLESRenderingContext.prototype.TIME_ELAPSED, TIMESTAMP_EXT: OpenGLESRenderingContext.prototype.TIMESTAMP, GPU_DISJOINT_EXT: OpenGLESRenderingContext.prototype.GPU_DISJOINT, createQuery: OpenGLESRenderingContext.prototype.createQuery, deleteQuery: OpenGLESRenderingContext.prototype.deleteQuery, isQuery: OpenGLESRenderingContext.prototype.isQuery, beginQuery: OpenGLESRenderingContext.prototype.beginQuery, endQuery: OpenGLESRenderingContext.prototype.endQuery, getQuery: OpenGLESRenderingContext.prototype.getQuery, getQueryParameter: OpenGLESRenderingContext.prototype.getQueryParameter, queryCounterEXT: OpenGLESRenderingContext.prototype.queryCounter, }, EXT_frag_depth: {}, EXT_sRGB: { SRGB_EXT: OpenGLESRenderingContext.prototype.SRGB, SRGB_ALPHA_EXT: OpenGLESRenderingContext.prototype.SRGB_ALPHA, SRGB8_ALPHA8_EXT: OpenGLESRenderingContext.prototype.SRGB8_ALPHA8, FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING_EXT: OpenGLESRenderingContext.prototype.FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING, }, EXT_shader_texture_lod: {}, EXT_texture_filter_anisotropic: { MAX_TEXTURE_MAX_ANISOTROPY_EXT: OpenGLESRenderingContext.prototype.MAX_TEXTURE_MAX_ANISOTROPY, TEXTURE_MAX_ANISOTROPY_EXT: OpenGLESRenderingContext.prototype.TEXTURE_MAX_ANISOTROPY, }, OES_element_index_uint: {}, OES_standard_derivatives: { FRAGMENT_SHADER_DERIVATIVE_HINT_OES: OpenGLESRenderingContext.prototype.FRAGMENT_SHADER_DERIVATIVE_HINT, }, OES_texture_float: {}, OES_texture_float_linear: {}, OES_texture_half_float: { HALF_FLOAT_OES: OpenGLESRenderingContext.prototype.HALF_FLOAT, }, OES_texture_half_float_linear: {}, OES_vertex_array_object: { VERTEX_ARRAY_BINDING_OES: OpenGLESRenderingContext.prototype.VERTEX_ARRAY_BINDING, createVertexArrayOES: OpenGLESRenderingContext.prototype.createVertexArray, deleteVertexArrayOES: OpenGLESRenderingContext.prototype.deleteVertexArray, isVertexArrayOES: OpenGLESRenderingContext.prototype.isVertexArray, bindVertexArrayOES: OpenGLESRenderingContext.prototype.bindVertexArray, }, WEBGL_color_buffer_float: { RGBA32F_EXT: OpenGLESRenderingContext.prototype.RGBA32F, RGB32F_EXT: OpenGLESRenderingContext.prototype.RGB32F, FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE_EXT: OpenGLESRenderingContext.prototype.FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE, UNSIGNED_NORMALIZED_EXT: OpenGLESRenderingContext.prototype.UNSIGNED_NORMALIZED, }, WEBGL_compressed_texture_astc: { getSupportedProfiles() {}, COMPRESSED_RGBA_ASTC_4x4_KHR: OpenGLESRenderingContext.prototype.COMPRESSED_RGBA_ASTC_4x4, COMPRESSED_RGBA_ASTC_5x4_KHR: OpenGLESRenderingContext.prototype.COMPRESSED_RGBA_ASTC_5x4, COMPRESSED_RGBA_ASTC_5x5_KHR: OpenGLESRenderingContext.prototype.COMPRESSED_RGBA_ASTC_5x5, COMPRESSED_RGBA_ASTC_6x5_KHR: OpenGLESRenderingContext.prototype.COMPRESSED_RGBA_ASTC_6x5, COMPRESSED_RGBA_ASTC_6x6_KHR: OpenGLESRenderingContext.prototype.COMPRESSED_RGBA_ASTC_6x6, COMPRESSED_RGBA_ASTC_8x5_KHR: OpenGLESRenderingContext.prototype.COMPRESSED_RGBA_ASTC_8x5, COMPRESSED_RGBA_ASTC_8x6_KHR: OpenGLESRenderingContext.prototype.COMPRESSED_RGBA_ASTC_8x6, COMPRESSED_RGBA_ASTC_8x8_KHR: OpenGLESRenderingContext.prototype.COMPRESSED_RGBA_ASTC_8x8, COMPRESSED_RGBA_ASTC_10x5_KHR: OpenGLESRenderingContext.prototype.COMPRESSED_RGBA_ASTC_10x5, COMPRESSED_RGBA_ASTC_10x6_KHR: OpenGLESRenderingContext.prototype.COMPRESSED_RGBA_ASTC_10x6, COMPRESSED_RGBA_ASTC_10x8_KHR: OpenGLESRenderingContext.prototype.COMPRESSED_RGBA_ASTC_10x8, COMPRESSED_RGBA_ASTC_10x10_KHR: OpenGLESRenderingContext.prototype.COMPRESSED_RGBA_ASTC_10x10, COMPRESSED_RGBA_ASTC_12x10_KHR: OpenGLESRenderingContext.prototype.COMPRESSED_RGBA_ASTC_12x10, COMPRESSED_RGBA_ASTC_12x12_KHR: OpenGLESRenderingContext.prototype.COMPRESSED_RGBA_ASTC_12x12, COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR: OpenGLESRenderingContext.prototype.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4, COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR: OpenGLESRenderingContext.prototype.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4, COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR: OpenGLESRenderingContext.prototype.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5, COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR: OpenGLESRenderingContext.prototype.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5, COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR: OpenGLESRenderingContext.prototype.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6, COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR: OpenGLESRenderingContext.prototype.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5, COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR: OpenGLESRenderingContext.prototype.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6, COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR: OpenGLESRenderingContext.prototype.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8, COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR: OpenGLESRenderingContext.prototype.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5, COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR: OpenGLESRenderingContext.prototype.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6, COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR: OpenGLESRenderingContext.prototype.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8, COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR: OpenGLESRenderingContext.prototype.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10, COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR: OpenGLESRenderingContext.prototype.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10, COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR: OpenGLESRenderingContext.prototype.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12, }, WEBGL_compressed_texture_atc: { COMPRESSED_RGB_ATC_WEBGL: OpenGLESRenderingContext.prototype.COMPRESSED_RGB_ATC_WEBGL, COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL: OpenGLESRenderingContext.prototype.COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL, COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL: OpenGLESRenderingContext.prototype.COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL, }, WEBGL_compressed_texture_etc: { COMPRESSED_R11_EAC: OpenGLESRenderingContext.prototype.COMPRESSED_R11_EAC, COMPRESSED_SIGNED_R11_EAC: OpenGLESRenderingContext.prototype.COMPRESSED_SIGNED_R11_EAC, COMPRESSED_RG11_EAC: OpenGLESRenderingContext.prototype.COMPRESSED_RG11_EAC, COMPRESSED_SIGNED_RG11_EAC: OpenGLESRenderingContext.prototype.COMPRESSED_SIGNED_RG11_EAC, COMPRESSED_RGB8_ETC2: OpenGLESRenderingContext.prototype.COMPRESSED_RGB8_ETC2, COMPRESSED_RGBA8_ETC2_EAC: OpenGLESRenderingContext.prototype.COMPRESSED_RGBA8_ETC2_EAC, COMPRESSED_SRGB8_ETC2: OpenGLESRenderingContext.prototype.COMPRESSED_SRGB8_ETC2, COMPRESSED_SRGB8_ALPHA8_ETC2_EAC: OpenGLESRenderingContext.prototype.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2: OpenGLESRenderingContext.prototype.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2: OpenGLESRenderingContext.prototype.COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, }, WEBGL_compressed_texture_etc1: { COMPRESSED_RGB_ETC1_WEBGL: 0x8D64, }, WEBGL_compressed_texture_pvrtc: { COMPRESSED_RGB_PVRTC_4BPPV1_IMG: 0x8C00, COMPRESSED_RGBA_PVRTC_4BPPV1_IMG: 0x8C02, COMPRESSED_RGB_PVRTC_2BPPV1_IMG: 0x8C01, COMPRESSED_RGBA_PVRTC_2BPPV1_IMG: 0x8C03, }, WEBGL_compressed_texture_s3tc: { COMPRESSED_RGB_S3TC_DXT1_EXT: OpenGLESRenderingContext.prototype.COMPRESSED_RGB_S3TC_DXT1, COMPRESSED_RGBA_S3TC_DXT1_EXT: OpenGLESRenderingContext.prototype.COMPRESSED_RGBA_S3TC_DXT1, COMPRESSED_RGBA_S3TC_DXT3_EXT: OpenGLESRenderingContext.prototype.COMPRESSED_RGBA_S3TC_DXT3, COMPRESSED_RGBA_S3TC_DXT5_EXT: OpenGLESRenderingContext.prototype.COMPRESSED_RGBA_S3TC_DXT5, }, WEBGL_compressed_texture_s3tc_srgb: { COMPRESSED_SRGB_S3TC_DXT1_EXT: OpenGLESRenderingContext.prototype.COMPRESSED_SRGB_S3TC_DXT1, COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: OpenGLESRenderingContext.prototype.COMPRESSED_SRGB_ALPHA_S3TC_DXT1, COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: OpenGLESRenderingContext.prototype.COMPRESSED_SRGB_ALPHA_S3TC_DXT3, COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: OpenGLESRenderingContext.prototype.COMPRESSED_SRGB_ALPHA_S3TC_DXT5, }, WEBGL_debug_renderer_info: { UNMASKED_VENDOR_WEBGL: OpenGLESRenderingContext.prototype.UNMASKED_VENDOR_WEBGL, UNMASKED_RENDERER_WEBGL: OpenGLESRenderingContext.prototype.UNMASKED_RENDERER_WEBGL, }, WEBGL_debug_shaders: { getTranslatedShaderSource: OpenGLESRenderingContext.prototype.getTranslatedShaderSource || (() => {}) }, WEBGL_depth_texture: { UNSIGNED_INT_24_8_WEBGL: OpenGLESRenderingContext.prototype.UNSIGNED_INT_24_8, }, WEBGL_draw_buffers: { COLOR_ATTACHMENT0_WEBGL: OpenGLESRenderingContext.prototype.COLOR_ATTACHMENT0, COLOR_ATTACHMENT1_WEBGL: OpenGLESRenderingContext.prototype.COLOR_ATTACHMENT1, COLOR_ATTACHMENT2_WEBGL: OpenGLESRenderingContext.prototype.COLOR_ATTACHMENT2, COLOR_ATTACHMENT3_WEBGL: OpenGLESRenderingContext.prototype.COLOR_ATTACHMENT3, COLOR_ATTACHMENT4_WEBGL: OpenGLESRenderingContext.prototype.COLOR_ATTACHMENT4, COLOR_ATTACHMENT5_WEBGL: OpenGLESRenderingContext.prototype.COLOR_ATTACHMENT5, COLOR_ATTACHMENT6_WEBGL: OpenGLESRenderingContext.prototype.COLOR_ATTACHMENT6, COLOR_ATTACHMENT7_WEBGL: OpenGLESRenderingContext.prototype.COLOR_ATTACHMENT7, COLOR_ATTACHMENT8_WEBGL: OpenGLESRenderingContext.prototype.COLOR_ATTACHMENT8, COLOR_ATTACHMENT9_WEBGL: OpenGLESRenderingContext.prototype.COLOR_ATTACHMENT9, COLOR_ATTACHMENT10_WEBGL: OpenGLESRenderingContext.prototype.COLOR_ATTACHMENT10, COLOR_ATTACHMENT11_WEBGL: OpenGLESRenderingContext.prototype.COLOR_ATTACHMENT11, COLOR_ATTACHMENT12_WEBGL: OpenGLESRenderingContext.prototype.COLOR_ATTACHMENT12, COLOR_ATTACHMENT13_WEBGL: OpenGLESRenderingContext.prototype.COLOR_ATTACHMENT13, COLOR_ATTACHMENT14_WEBGL: OpenGLESRenderingContext.prototype.COLOR_ATTACHMENT14, COLOR_ATTACHMENT15_WEBGL: OpenGLESRenderingContext.prototype.COLOR_ATTACHMENT15, DRAW_BUFFER0_WEBGL: OpenGLESRenderingContext.prototype.DRAW_BUFFER0, DRAW_BUFFER1_WEBGL: OpenGLESRenderingContext.prototype.DRAW_BUFFER1, DRAW_BUFFER2_WEBGL: OpenGLESRenderingContext.prototype.DRAW_BUFFER2, DRAW_BUFFER3_WEBGL: OpenGLESRenderingContext.prototype.DRAW_BUFFER3, DRAW_BUFFER4_WEBGL: OpenGLESRenderingContext.prototype.DRAW_BUFFER4, DRAW_BUFFER5_WEBGL: OpenGLESRenderingContext.prototype.DRAW_BUFFER5, DRAW_BUFFER6_WEBGL: OpenGLESRenderingContext.prototype.DRAW_BUFFER6, DRAW_BUFFER7_WEBGL: OpenGLESRenderingContext.prototype.DRAW_BUFFER7, DRAW_BUFFER8_WEBGL: OpenGLESRenderingContext.prototype.DRAW_BUFFER8, DRAW_BUFFER9_WEBGL: OpenGLESRenderingContext.prototype.DRAW_BUFFER9, DRAW_BUFFER10_WEBGL: OpenGLESRenderingContext.prototype.DRAW_BUFFER10, DRAW_BUFFER11_WEBGL: OpenGLESRenderingContext.prototype.DRAW_BUFFER11, DRAW_BUFFER12_WEBGL: OpenGLESRenderingContext.prototype.DRAW_BUFFER12, DRAW_BUFFER13_WEBGL: OpenGLESRenderingContext.prototype.DRAW_BUFFER13, DRAW_BUFFER14_WEBGL: OpenGLESRenderingContext.prototype.DRAW_BUFFER14, DRAW_BUFFER15_WEBGL: OpenGLESRenderingContext.prototype.DRAW_BUFFER15, MAX_COLOR_ATTACHMENTS_WEBGL: OpenGLESRenderingContext.prototype.MAX_COLOR_ATTACHMENTS, MAX_DRAW_BUFFERS_WEBGL: OpenGLESRenderingContext.prototype.MAX_DRAW_BUFFERS, }, WEBGL_lose_context: { loseContext() {}, restoreContext() {}, }, EXT_float_blend: {}, };
0
rapidsai_public_repos/node/modules/webgl
rapidsai_public_repos/node/modules/webgl/src/index.ts
// Copyright (c) 2020-2021, NVIDIA CORPORATION. // // 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. export * from './webgl';
0
rapidsai_public_repos/node/modules/webgl
rapidsai_public_repos/node/modules/webgl/src/instanced.cpp
// Copyright (c) 2020-2021, NVIDIA CORPORATION. // // 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. #include "macros.hpp" #include "webgl.hpp" #include <nv_node/utilities/args.hpp> #include <nv_node/utilities/cpp_to_napi.hpp> namespace nv { // GL_EXPORT void glDrawArraysInstanced (GLenum mode, GLint first, GLsizei count, GLsizei // primcount); void WebGL2RenderingContext::DrawArraysInstanced(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glDrawArraysInstanced(args[0], args[1], args[2], args[3]); } // GL_EXPORT void glDrawElementsInstanced (GLenum mode, GLsizei count, GLenum type, const void* // indices, GLsizei primcount); void WebGL2RenderingContext::DrawElementsInstanced(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glDrawElementsInstanced(args[0], args[1], args[2], args[3], args[4]); } // GLEWAPI void glVertexAttribDivisor (GLuint index, GLuint divisor); void WebGL2RenderingContext::VertexAttribDivisor(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glVertexAttribDivisor(args[0], args[1]); } } // namespace nv
0
rapidsai_public_repos/node/modules/webgl
rapidsai_public_repos/node/modules/webgl/src/uniform.cpp
// Copyright (c) 2020-2021, NVIDIA CORPORATION. // // 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. #include "macros.hpp" #include "webgl.hpp" #include <nv_node/utilities/args.hpp> #include <nv_node/utilities/cpp_to_napi.hpp> namespace nv { namespace detail { // GL_EXPORT void glGetUniformfv (GLuint program, GLint location, GLfloat* params); Napi::Value glGetUniformfv(Napi::Env const& env, GLuint const program, GLint const location, GLuint const size) { if (size == 1) { GLfloat params{}; GL_EXPORT::glGetUniformfv(program, location, &params); return CPPToNapi(env)(params); } auto buf = Napi::ArrayBuffer::New(env, size * sizeof(GLfloat)); GL_EXPORT::glGetUniformfv(program, location, static_cast<GLfloat*>(buf.Data())); return Napi::Float32Array::New(env, size, buf, 0); } // GL_EXPORT void glGetUniformiv (GLuint program, GLint location, GLint* params); Napi::Value glGetUniformiv(Napi::Env const& env, GLuint const program, GLint const location, GLuint const size) { if (size == 1) { GLint params{}; GL_EXPORT::glGetUniformiv(program, location, &params); return CPPToNapi(env)(params); } auto buf = Napi::ArrayBuffer::New(env, size * sizeof(GLint)); GL_EXPORT::glGetUniformiv(program, location, static_cast<GLint*>(buf.Data())); return Napi::Int32Array::New(env, size, buf, 0); } // GL_EXPORT void glGetUniformuiv (GLuint program, GLint location, GLuint* params); Napi::Value glGetUniformuiv(Napi::Env const& env, GLuint const program, GLint const location, GLuint const size) { if (size == 1) { GLuint params{}; GL_EXPORT::glGetUniformuiv(program, location, &params); return CPPToNapi(env)(params); } auto buf = Napi::ArrayBuffer::New(env, size * sizeof(GLuint)); GL_EXPORT::glGetUniformuiv(program, location, static_cast<GLuint*>(buf.Data())); return Napi::Uint32Array::New(env, size, buf, 0); } // GL_EXPORT void glGetUniformdv (GLuint program, GLint location, GLdouble* params); Napi::Value glGetUniformdv(Napi::Env const& env, GLuint const program, GLint const location, GLuint const size) { if (size == 1) { GLdouble params{}; GL_EXPORT::glGetUniformdv(program, location, &params); return CPPToNapi(env)(params); } auto buf = Napi::ArrayBuffer::New(env, size * sizeof(GLdouble)); GL_EXPORT::glGetUniformdv(program, location, static_cast<GLdouble*>(buf.Data())); return Napi::Float64Array::New(env, size, buf, 0); } // GL_EXPORT void glGetUniformiv (GLuint program, GLint location, GLint* params); Napi::Value glGetUniformbv(Napi::Env const& env, GLuint const program, GLint const location, GLuint const size) { std::vector<bool> bools(size); std::vector<GLint> params(size); GL_EXPORT::glGetUniformiv(program, location, params.data()); std::transform( params.begin(), params.end(), bools.begin(), [&](auto x) { return static_cast<bool>(x); }); if (size == 1) { return CPPToNapi(env)(bools[0]); } else { return CPPToNapi(env)(bools); } } } // namespace detail // GL_EXPORT void glGetActiveUniform (GLuint program, GLuint index, GLsizei maxLength, GLsizei* // length, GLint* size, GLenum* type, GLchar* name); Napi::Value WebGL2RenderingContext::GetActiveUniform(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLuint program = args[0]; GLint max_length{}; GL_EXPORT::glGetProgramiv(program, GL_ACTIVE_UNIFORM_MAX_LENGTH, &max_length); if (max_length > 0) { GLuint type{}; GLint size{}, length{}; GLchar* name = reinterpret_cast<GLchar*>(std::malloc(max_length)); GL_EXPORT::glGetActiveUniform(program, args[1], max_length, &length, &size, &type, name); return CPPToNapi(info)( {"size", "type", "name"}, std::make_tuple(size, type, std::string{name, static_cast<size_t>(length)})); } return info.Env().Null(); } // GL_EXPORT void glGetUniformfv (GLuint program, GLint location, GLfloat* params); // GL_EXPORT void glGetUniformiv (GLuint program, GLint location, GLint* params); // GL_EXPORT void glGetUniformuiv (GLuint program, GLint location, GLuint* params); // GL_EXPORT void glGetUniformdv (GLuint program, GLint location, GLdouble* params); Napi::Value WebGL2RenderingContext::GetUniform(Napi::CallbackInfo const& info) { auto env = info.Env(); CallbackArgs args = info; GLuint program = args[0]; GLint location = args[1]; if (location < 0) { return info.Env().Null(); } GLint size{}; GLuint type{}; GL_EXPORT::glGetActiveUniform(program, location, 0, nullptr, &size, &type, nullptr); switch (type) { case GL_BOOL: return detail::glGetUniformbv(env, program, location, 1); case GL_BOOL_VEC2: return detail::glGetUniformbv(env, program, location, 2); case GL_BOOL_VEC3: return detail::glGetUniformbv(env, program, location, 3); case GL_BOOL_VEC4: return detail::glGetUniformbv(env, program, location, 4); case GL_FLOAT: return detail::glGetUniformfv(env, program, location, 1); case GL_FLOAT_VEC2: return detail::glGetUniformfv(env, program, location, 2); case GL_FLOAT_VEC3: return detail::glGetUniformfv(env, program, location, 3); case GL_FLOAT_VEC4: return detail::glGetUniformfv(env, program, location, 4); case GL_FLOAT_MAT2: return detail::glGetUniformfv(env, program, location, 2 * 2); case GL_FLOAT_MAT3: return detail::glGetUniformfv(env, program, location, 3 * 3); case GL_FLOAT_MAT4: return detail::glGetUniformfv(env, program, location, 4 * 4); case GL_FLOAT_MAT2x3: return detail::glGetUniformfv(env, program, location, 2 * 3); case GL_FLOAT_MAT2x4: return detail::glGetUniformfv(env, program, location, 2 * 4); case GL_FLOAT_MAT3x2: return detail::glGetUniformfv(env, program, location, 3 * 2); case GL_FLOAT_MAT3x4: return detail::glGetUniformfv(env, program, location, 3 * 4); case GL_FLOAT_MAT4x2: return detail::glGetUniformfv(env, program, location, 4 * 2); case GL_FLOAT_MAT4x3: return detail::glGetUniformfv(env, program, location, 4 * 3); case GL_INT: return detail::glGetUniformiv(env, program, location, 1); case GL_INT_VEC2: return detail::glGetUniformiv(env, program, location, 2); case GL_INT_VEC3: return detail::glGetUniformiv(env, program, location, 3); case GL_INT_VEC4: return detail::glGetUniformiv(env, program, location, 4); case GL_INT_SAMPLER_1D: case GL_INT_SAMPLER_2D: case GL_INT_SAMPLER_3D: case GL_INT_SAMPLER_CUBE: // case GL_INT_SAMPLER_1D_ARRAY: // case GL_INT_SAMPLER_2D_ARRAY: case GL_INT_SAMPLER_2D_MULTISAMPLE: // case GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY: case GL_INT_SAMPLER_BUFFER: case GL_INT_SAMPLER_2D_RECT: case GL_INT_IMAGE_1D: case GL_INT_IMAGE_2D: case GL_INT_IMAGE_3D: case GL_INT_IMAGE_2D_RECT: case GL_INT_IMAGE_CUBE: case GL_INT_IMAGE_BUFFER: // case GL_INT_IMAGE_1D_ARRAY: // case GL_INT_IMAGE_2D_ARRAY: case GL_INT_IMAGE_2D_MULTISAMPLE: // case GL_INT_IMAGE_2D_MULTISAMPLE_ARRAY: return detail::glGetUniformiv(env, program, location, 1); case GL_UNSIGNED_INT: return detail::glGetUniformuiv(env, program, location, 1); case GL_UNSIGNED_INT_VEC2: return detail::glGetUniformuiv(env, program, location, 2); case GL_UNSIGNED_INT_VEC3: return detail::glGetUniformuiv(env, program, location, 3); case GL_UNSIGNED_INT_VEC4: return detail::glGetUniformuiv(env, program, location, 4); case GL_UNSIGNED_INT_SAMPLER_1D: case GL_UNSIGNED_INT_SAMPLER_2D: case GL_UNSIGNED_INT_SAMPLER_3D: case GL_UNSIGNED_INT_SAMPLER_CUBE: // case GL_UNSIGNED_INT_SAMPLER_1D_ARRAY: // case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY: case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE: // case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY: case GL_UNSIGNED_INT_SAMPLER_BUFFER: case GL_UNSIGNED_INT_SAMPLER_2D_RECT: case GL_UNSIGNED_INT_IMAGE_1D: case GL_UNSIGNED_INT_IMAGE_2D: case GL_UNSIGNED_INT_IMAGE_3D: case GL_UNSIGNED_INT_IMAGE_2D_RECT: case GL_UNSIGNED_INT_IMAGE_CUBE: case GL_UNSIGNED_INT_IMAGE_BUFFER: // case GL_UNSIGNED_INT_IMAGE_1D_ARRAY: // case GL_UNSIGNED_INT_IMAGE_2D_ARRAY: case GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE: // case GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE_ARRAY: case GL_UNSIGNED_INT_ATOMIC_COUNTER: return detail::glGetUniformuiv(env, program, location, 1); case GL_DOUBLE: return detail::glGetUniformdv(env, program, location, 1); case GL_DOUBLE_VEC2: return detail::glGetUniformdv(env, program, location, 2); case GL_DOUBLE_VEC3: return detail::glGetUniformdv(env, program, location, 3); case GL_DOUBLE_VEC4: return detail::glGetUniformdv(env, program, location, 4); case GL_DOUBLE_MAT2: return detail::glGetUniformdv(env, program, location, 2 * 2); case GL_DOUBLE_MAT3: return detail::glGetUniformdv(env, program, location, 3 * 3); case GL_DOUBLE_MAT4: return detail::glGetUniformdv(env, program, location, 4 * 4); case GL_DOUBLE_MAT2x3: return detail::glGetUniformdv(env, program, location, 2 * 3); case GL_DOUBLE_MAT2x4: return detail::glGetUniformdv(env, program, location, 2 * 4); case GL_DOUBLE_MAT3x2: return detail::glGetUniformdv(env, program, location, 3 * 2); case GL_DOUBLE_MAT3x4: return detail::glGetUniformdv(env, program, location, 3 * 4); case GL_DOUBLE_MAT4x2: return detail::glGetUniformdv(env, program, location, 4 * 2); case GL_DOUBLE_MAT4x3: return detail::glGetUniformdv(env, program, location, 4 * 3); case GL_SAMPLER_1D: case GL_SAMPLER_2D: case GL_SAMPLER_3D: case GL_SAMPLER_CUBE: case GL_SAMPLER_1D_SHADOW: case GL_SAMPLER_2D_SHADOW: // case GL_SAMPLER_1D_ARRAY: // case GL_SAMPLER_2D_ARRAY: // case GL_SAMPLER_1D_ARRAY_SHADOW: // case GL_SAMPLER_2D_ARRAY_SHADOW: case GL_SAMPLER_2D_MULTISAMPLE: // case GL_SAMPLER_2D_MULTISAMPLE_ARRAY: case GL_SAMPLER_CUBE_SHADOW: case GL_SAMPLER_BUFFER: case GL_SAMPLER_2D_RECT: case GL_SAMPLER_2D_RECT_SHADOW: case GL_IMAGE_1D: case GL_IMAGE_2D: case GL_IMAGE_3D: case GL_IMAGE_2D_RECT: case GL_IMAGE_CUBE: case GL_IMAGE_BUFFER: // case GL_IMAGE_1D_ARRAY: // case GL_IMAGE_2D_ARRAY: case GL_IMAGE_2D_MULTISAMPLE: // case GL_IMAGE_2D_MULTISAMPLE_ARRAY: return detail::glGetUniformiv(env, program, location, 1); default: GLEW_THROW(info.Env(), GL_INVALID_ENUM); } } // GL_EXPORT GLint glGetUniformLocation (GLuint program, const GLchar* name); Napi::Value WebGL2RenderingContext::GetUniformLocation(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLuint program = args[0]; std::string name = args[1]; auto const location = GL_EXPORT::glGetUniformLocation(program, name.c_str()); return location > -1 ? WebGLUniformLocation::New(info.Env(), location) : info.Env().Null(); } // GL_EXPORT void glUniform1f (GLint location, GLfloat v0); void WebGL2RenderingContext::Uniform1f(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLint loc = args[0]; GL_EXPORT::glUniform1f(loc, args[1]); } // GL_EXPORT void glUniform1fv (GLint location, GLsizei count, const GLfloat* value); void WebGL2RenderingContext::Uniform1fv(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLint loc = args[0]; static constexpr GLint size{1}; Span<GLfloat> ptr = args[1]; if ((ptr.size() < size) || (ptr.size() % size) != 0) { GLEW_THROW(info.Env(), GL_INVALID_VALUE); } GL_EXPORT::glUniform1fv(loc, ptr.size() / size, ptr.data()); } // GL_EXPORT void glUniform1i (GLint location, GLint v0); void WebGL2RenderingContext::Uniform1i(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLint loc = args[0]; GL_EXPORT::glUniform1i(loc, args[1]); } // GL_EXPORT void glUniform1iv (GLint location, GLsizei count, const GLint* value); void WebGL2RenderingContext::Uniform1iv(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLint loc = args[0]; static constexpr GLint size{1}; Span<GLint> ptr = args[1]; if ((ptr.size() < size) || (ptr.size() % size) != 0) { GLEW_THROW(info.Env(), GL_INVALID_VALUE); } GL_EXPORT::glUniform1iv(loc, ptr.size() / size, ptr.data()); } // GL_EXPORT void glUniform2f (GLint location, GLfloat v0, GLfloat v1); void WebGL2RenderingContext::Uniform2f(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLint loc = args[0]; GL_EXPORT::glUniform2f(loc, args[1], args[2]); } // GL_EXPORT void glUniform2fv (GLint location, GLsizei count, const GLfloat* value); void WebGL2RenderingContext::Uniform2fv(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLint loc = args[0]; static constexpr GLint size{2}; Span<GLfloat> ptr = args[1]; if ((ptr.size() < size) || (ptr.size() % size) != 0) { GLEW_THROW(info.Env(), GL_INVALID_VALUE); } GL_EXPORT::glUniform2fv(loc, ptr.size() / size, ptr.data()); } // GL_EXPORT void glUniform2i (GLint location, GLint v0, GLint v1); void WebGL2RenderingContext::Uniform2i(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLint loc = args[0]; GL_EXPORT::glUniform2i(loc, args[1], args[2]); } // GL_EXPORT void glUniform2iv (GLint location, GLsizei count, const GLint* value); void WebGL2RenderingContext::Uniform2iv(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLint loc = args[0]; static constexpr GLint size{2}; Span<GLint> ptr = args[1]; if ((ptr.size() < size) || (ptr.size() % size) != 0) { GLEW_THROW(info.Env(), GL_INVALID_VALUE); } GL_EXPORT::glUniform2iv(loc, ptr.size() / size, ptr.data()); } // GL_EXPORT void glUniform3f (GLint location, GLfloat v0, GLfloat v1, GLfloat v2); void WebGL2RenderingContext::Uniform3f(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLint loc = args[0]; GL_EXPORT::glUniform3f(loc, args[1], args[2], args[3]); } // GL_EXPORT void glUniform3fv (GLint location, GLsizei count, const GLfloat* value); void WebGL2RenderingContext::Uniform3fv(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLint loc = args[0]; static constexpr GLint size{3}; Span<GLfloat> ptr = args[1]; if ((ptr.size() < size) || (ptr.size() % size) != 0) { GLEW_THROW(info.Env(), GL_INVALID_VALUE); } GL_EXPORT::glUniform3fv(loc, ptr.size() / size, ptr.data()); } // GL_EXPORT void glUniform3i (GLint location, GLint v0, GLint v1, GLint v2); void WebGL2RenderingContext::Uniform3i(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLint loc = args[0]; GL_EXPORT::glUniform3i(loc, args[1], args[2], args[3]); } // GL_EXPORT void glUniform3iv (GLint location, GLsizei count, const GLint* value); void WebGL2RenderingContext::Uniform3iv(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLint loc = args[0]; static constexpr GLint size{3}; Span<GLint> ptr = args[1]; if ((ptr.size() < size) || (ptr.size() % size) != 0) { GLEW_THROW(info.Env(), GL_INVALID_VALUE); } GL_EXPORT::glUniform3iv(loc, ptr.size() / size, ptr.data()); } // GL_EXPORT void glUniform4f (GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); void WebGL2RenderingContext::Uniform4f(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLint loc = args[0]; GL_EXPORT::glUniform4f(loc, args[1], args[2], args[3], args[4]); } // GL_EXPORT void glUniform4fv (GLint location, GLsizei count, const GLfloat* value); void WebGL2RenderingContext::Uniform4fv(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLint loc = args[0]; static constexpr GLint size{4}; Span<GLfloat> ptr = args[1]; if ((ptr.size() < size) || (ptr.size() % size) != 0) { GLEW_THROW(info.Env(), GL_INVALID_VALUE); } GL_EXPORT::glUniform4fv(loc, ptr.size() / size, ptr.data()); } // GL_EXPORT void glUniform4i (GLint location, GLint v0, GLint v1, GLint v2, GLint v3); void WebGL2RenderingContext::Uniform4i(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLint loc = args[0]; GL_EXPORT::glUniform4i(loc, args[1], args[2], args[3], args[4]); } // GL_EXPORT void glUniform4iv (GLint location, GLsizei count, const GLint* value); void WebGL2RenderingContext::Uniform4iv(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLint loc = args[0]; static constexpr GLint size{4}; Span<GLint> ptr = args[1]; if ((ptr.size() < size) || (ptr.size() % size) != 0) { GLEW_THROW(info.Env(), GL_INVALID_VALUE); } GL_EXPORT::glUniform4iv(loc, ptr.size() / size, ptr.data()); } // GL_EXPORT void glUniformMatrix2fv (GLint location, GLsizei count, GLboolean transpose, const // GLfloat* value); void WebGL2RenderingContext::UniformMatrix2fv(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLint loc = args[0]; bool transpose = args[1]; static constexpr GLint size{2 * 2}; Span<GLfloat> ptr = args[2]; if ((ptr.size() < size) || (ptr.size() % size) != 0) { GLEW_THROW(info.Env(), GL_INVALID_VALUE); } GL_EXPORT::glUniformMatrix2fv(loc, ptr.size() / size, transpose, ptr.data()); } // GL_EXPORT void glUniformMatrix3fv (GLint location, GLsizei count, GLboolean transpose, const // GLfloat* value); void WebGL2RenderingContext::UniformMatrix3fv(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLint loc = args[0]; bool transpose = args[1]; static constexpr GLint size{3 * 3}; Span<GLfloat> ptr = args[2]; if ((ptr.size() < size) || (ptr.size() % size) != 0) { GLEW_THROW(info.Env(), GL_INVALID_VALUE); } GL_EXPORT::glUniformMatrix3fv(loc, ptr.size() / size, transpose, ptr.data()); } // GL_EXPORT void glUniformMatrix4fv (GLint location, GLsizei count, GLboolean transpose, const // GLfloat* value); void WebGL2RenderingContext::UniformMatrix4fv(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLint loc = args[0]; bool transpose = args[1]; static constexpr GLint size{4 * 4}; Span<GLfloat> ptr = args[2]; if ((ptr.size() < size) || (ptr.size() % size) != 0) { GLEW_THROW(info.Env(), GL_INVALID_VALUE); } GL_EXPORT::glUniformMatrix4fv(loc, ptr.size() / size, transpose, ptr.data()); } // GL_EXPORT void glUniformMatrix2x3fv (GLint location, GLsizei count, GLboolean transpose, const // GLfloat *value); void WebGL2RenderingContext::UniformMatrix2x3fv(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLint loc = args[0]; bool transpose = args[1]; static constexpr GLint size{2 * 3}; Span<GLfloat> ptr = args[2]; if ((ptr.size() < size) || (ptr.size() % size) != 0) { GLEW_THROW(info.Env(), GL_INVALID_VALUE); } GL_EXPORT::glUniformMatrix2x3fv(loc, ptr.size() / size, transpose, ptr.data()); } // GL_EXPORT void glUniformMatrix2x4fv (GLint location, GLsizei count, GLboolean transpose, const // GLfloat *value); void WebGL2RenderingContext::UniformMatrix2x4fv(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLint loc = args[0]; bool transpose = args[1]; static constexpr GLint size{2 * 4}; Span<GLfloat> ptr = args[2]; if ((ptr.size() < size) || (ptr.size() % size) != 0) { GLEW_THROW(info.Env(), GL_INVALID_VALUE); } GL_EXPORT::glUniformMatrix2x4fv(loc, ptr.size() / size, transpose, ptr.data()); } // GL_EXPORT void glUniformMatrix3x2fv (GLint location, GLsizei count, GLboolean transpose, const // GLfloat *value); void WebGL2RenderingContext::UniformMatrix3x2fv(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLint loc = args[0]; bool transpose = args[1]; static constexpr GLint size{3 * 2}; Span<GLfloat> ptr = args[2]; if ((ptr.size() < size) || (ptr.size() % size) != 0) { GLEW_THROW(info.Env(), GL_INVALID_VALUE); } GL_EXPORT::glUniformMatrix3x2fv(loc, ptr.size() / size, transpose, ptr.data()); } // GL_EXPORT void glUniformMatrix3x4fv (GLint location, GLsizei count, GLboolean transpose, const // GLfloat *value); void WebGL2RenderingContext::UniformMatrix3x4fv(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLint loc = args[0]; bool transpose = args[1]; static constexpr GLint size{3 * 4}; Span<GLfloat> ptr = args[2]; if ((ptr.size() < size) || (ptr.size() % size) != 0) { GLEW_THROW(info.Env(), GL_INVALID_VALUE); } GL_EXPORT::glUniformMatrix3x4fv(loc, ptr.size() / size, transpose, ptr.data()); } // GL_EXPORT void glUniformMatrix4x2fv (GLint location, GLsizei count, GLboolean transpose, const // GLfloat *value); void WebGL2RenderingContext::UniformMatrix4x2fv(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLint loc = args[0]; bool transpose = args[1]; static constexpr GLint size{4 * 2}; Span<GLfloat> ptr = args[2]; if ((ptr.size() < size) || (ptr.size() % size) != 0) { GLEW_THROW(info.Env(), GL_INVALID_VALUE); } GL_EXPORT::glUniformMatrix4x2fv(loc, ptr.size() / size, transpose, ptr.data()); } // GL_EXPORT void glUniformMatrix4x3fv (GLint location, GLsizei count, GLboolean transpose, const // GLfloat *value); void WebGL2RenderingContext::UniformMatrix4x3fv(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLint loc = args[0]; bool transpose = args[1]; static constexpr GLint size{4 * 3}; Span<GLfloat> ptr = args[2]; if ((ptr.size() < size) || (ptr.size() % size) != 0) { GLEW_THROW(info.Env(), GL_INVALID_VALUE); } GL_EXPORT::glUniformMatrix4x3fv(loc, ptr.size() / size, transpose, ptr.data()); } // GL_EXPORT void glUniform1ui (GLint location, GLuint v0); void WebGL2RenderingContext::Uniform1ui(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLint loc = args[0]; GL_EXPORT::glUniform1ui(loc, args[1]); } // GL_EXPORT void glUniform1uiv (GLint location, GLsizei count, const GLuint* value); void WebGL2RenderingContext::Uniform1uiv(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLint loc = args[0]; static constexpr GLint size{1}; Span<GLuint> ptr = args[1]; if ((ptr.size() < size) || (ptr.size() % size) != 0) { GLEW_THROW(info.Env(), GL_INVALID_VALUE); } GL_EXPORT::glUniform1uiv(loc, ptr.size() / size, ptr.data()); } // GL_EXPORT void glUniform2ui (GLint location, GLuint v0, GLuint v1); void WebGL2RenderingContext::Uniform2ui(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLint loc = args[0]; GL_EXPORT::glUniform2ui(loc, args[1], args[2]); } // GL_EXPORT void glUniform2uiv (GLint location, GLsizei count, const GLuint* value); void WebGL2RenderingContext::Uniform2uiv(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLint loc = args[0]; static constexpr GLint size{2}; Span<GLuint> ptr = args[1]; if ((ptr.size() < size) || (ptr.size() % size) != 0) { GLEW_THROW(info.Env(), GL_INVALID_VALUE); } GL_EXPORT::glUniform2uiv(loc, ptr.size() / size, ptr.data()); } // GL_EXPORT void glUniform3ui (GLint location, GLuint v0, GLuint v1, GLuint v2); void WebGL2RenderingContext::Uniform3ui(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLint loc = args[0]; GL_EXPORT::glUniform3ui(loc, args[1], args[2], args[3]); } // GL_EXPORT void glUniform3uiv (GLint location, GLsizei count, const GLuint* value); void WebGL2RenderingContext::Uniform3uiv(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLint loc = args[0]; static constexpr GLint size{3}; Span<GLuint> ptr = args[1]; if ((ptr.size() < size) || (ptr.size() % size) != 0) { GLEW_THROW(info.Env(), GL_INVALID_VALUE); } GL_EXPORT::glUniform3uiv(loc, ptr.size() / size, ptr.data()); } // GL_EXPORT void glUniform4ui (GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3); void WebGL2RenderingContext::Uniform4ui(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLint loc = args[0]; GL_EXPORT::glUniform4ui(loc, args[1], args[2], args[3], args[4]); } // GL_EXPORT void glUniform4uiv (GLint location, GLsizei count, const GLuint* value); void WebGL2RenderingContext::Uniform4uiv(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLint loc = args[0]; static constexpr GLint size{4}; Span<GLuint> ptr = args[1]; if ((ptr.size() < size) || (ptr.size() % size) != 0) { GLEW_THROW(info.Env(), GL_INVALID_VALUE); } GL_EXPORT::glUniform4uiv(loc, ptr.size() / size, ptr.data()); } // GL_EXPORT void glGetActiveUniformBlockName (GLuint program, GLuint uniformBlockIndex, GLsizei // bufSize, GLsizei* length, GLchar* uniformBlockName); Napi::Value WebGL2RenderingContext::GetActiveUniformBlockName(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLuint program = args[0]; GLint max_length{}; GL_EXPORT::glGetProgramInterfaceiv(program, GL_UNIFORM_BLOCK, GL_MAX_NAME_LENGTH, &max_length); if (max_length > 0) { GLint length{}; GLchar* name = reinterpret_cast<GLchar*>(std::malloc(max_length)); GL_EXPORT::glGetActiveUniformBlockName(program, args[1], max_length, &length, name); return CPPToNapi(info.Env())(std::string{name, static_cast<size_t>(length)}); } return info.Env().Null(); } // GL_EXPORT void glGetActiveUniformBlockiv (GLuint program, GLuint uniformBlockIndex, GLenum pname, // GLint* params); Napi::Value WebGL2RenderingContext::GetActiveUniformBlockiv(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLint params{}; GL_EXPORT::glGetActiveUniformBlockiv(args[0], args[1], args[2], &params); return CPPToNapi(info.Env())(params); } // GL_EXPORT void glGetActiveUniformsiv (GLuint program, GLsizei uniformCount, const GLuint* // uniformIndices, GLenum pname, GLint* params); Napi::Value WebGL2RenderingContext::GetActiveUniformsiv(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLint params{}; GL_EXPORT::glGetActiveUniformsiv(args[0], args[1], args[2], args[3], &params); return CPPToNapi(info.Env())(params); } // GL_EXPORT GLuint glGetUniformBlockIndex (GLuint program, const GLchar* uniformBlockName); Napi::Value WebGL2RenderingContext::GetUniformBlockIndex(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLuint program = args[0]; std::string uniformBlockName = args[1]; return CPPToNapi(info.Env())(GL_EXPORT::glGetUniformBlockIndex(program, uniformBlockName.data())); } // GL_EXPORT void glGetUniformIndices (GLuint program, GLsizei uniformCount, const GLchar* const * // uniformNames, GLuint* uniformIndices); Napi::Value WebGL2RenderingContext::GetUniformIndices(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLuint program = args[0]; std::vector<std::string> uniform_names = args[1]; std::vector<GLuint> uniform_indices(uniform_names.size()); std::vector<const GLchar*> uniform_name_ptrs(uniform_names.size()); std::transform(uniform_names.begin(), uniform_names.end(), uniform_name_ptrs.begin(), [&](std::string const& str) { return str.data(); }); GL_EXPORT::glGetUniformIndices( program, uniform_names.size(), uniform_name_ptrs.data(), uniform_indices.data()); return CPPToNapi(info.Env())(uniform_indices); } // GL_EXPORT void glUniformBlockBinding (GLuint program, GLuint uniformBlockIndex, GLuint // uniformBlockBinding); void WebGL2RenderingContext::UniformBlockBinding(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glUniformBlockBinding(args[0], args[1], args[2]); } } // namespace nv
0
rapidsai_public_repos/node/modules/webgl
rapidsai_public_repos/node/modules/webgl/src/iselectron.ts
// based on https://github.com/cheton/is-electron // https://github.com/electron/electron/issues/2288 /* eslint-disable complexity */ export function isElectron(mockUserAgent?: string) { // Renderer process if (typeof window !== 'undefined' && typeof window.process === 'object' && (<any>window.process).type === 'renderer') { if ((<any>window.process).glfwWindow) { return false; } console.log('isElectron=true'); return true; } // Main process if (typeof process !== 'undefined' && typeof process.versions === 'object' && Boolean((<any>process.versions).electron)) { console.log('isElectron=true'); return true; } // Detect the user agent when the `nodeIntegration` option is set to true const realUserAgent = typeof navigator === 'object' && typeof navigator.userAgent === 'string' && navigator.userAgent; const userAgent = mockUserAgent || realUserAgent; if (userAgent && userAgent.indexOf('Electron') >= 0) { console.log('isElectron=true'); return true; } return false; } export default isElectron;
0
rapidsai_public_repos/node/modules/webgl
rapidsai_public_repos/node/modules/webgl/src/sync.cpp
// Copyright (c) 2020-2021, NVIDIA CORPORATION. // // 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. #include "macros.hpp" #include "webgl.hpp" #include <nv_node/utilities/args.hpp> #include <nv_node/utilities/cpp_to_napi.hpp> namespace nv { // GL_EXPORT GLenum glClientWaitSync (GLsync GLsync, GLbitfield flags,GLuint64 timeout); Napi::Value WebGL2RenderingContext::ClientWaitSync(Napi::CallbackInfo const& info) { CallbackArgs args = info; return CPPToNapi(info)( GL_EXPORT::glClientWaitSync(*WebGLSync::Unwrap(args[0].ToObject()), args[1], args[2])); } // GL_EXPORT void glDeleteSync (GLsync GLsync); void WebGL2RenderingContext::DeleteSync(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glDeleteSync(args[0]); } // GL_EXPORT GLsync glFenceSync (GLenum condition, GLbitfield flags); Napi::Value WebGL2RenderingContext::FenceSync(Napi::CallbackInfo const& info) { CallbackArgs args = info; return WebGLSync::New(info.Env(), GL_EXPORT::glFenceSync(args[0], args[1])); } // GL_EXPORT void glGetSynciv (GLsync GLsync, GLenum pname, GLsizei bufSize, GLsizei* length, GLint // *values); Napi::Value WebGL2RenderingContext::GetSyncParameter(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLint params{}; GL_EXPORT::glGetSynciv(args[0], args[1], 1, nullptr, &params); return CPPToNapi(info)(params); } // GL_EXPORT GLboolean glIsSync (GLsync GLsync); Napi::Value WebGL2RenderingContext::IsSync(Napi::CallbackInfo const& info) { CallbackArgs args = info; return CPPToNapi(info)(GL_EXPORT::glIsSync(args[0])); } // GL_EXPORT void glWaitSync (GLsync GLsync, GLbitfield flags, GLuint64 timeout); void WebGL2RenderingContext::WaitSync(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glWaitSync(args[0], args[1], args[2]); } } // namespace nv
0
rapidsai_public_repos/node/modules/webgl
rapidsai_public_repos/node/modules/webgl/src/buffer.cpp
// Copyright (c) 2020-2021, NVIDIA CORPORATION. // // 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. #include "macros.hpp" #include "webgl.hpp" #include <nv_node/utilities/args.hpp> #include <nv_node/utilities/cpp_to_napi.hpp> namespace nv { // GL_EXPORT void glBindBuffer (GLenum target, GLuint buffer); void WebGL2RenderingContext::BindBuffer(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glBindBuffer(args[0], args[1]); } // GL_EXPORT void glBufferData (GLenum target, GLsizeiptr size, const void* data, GLenum usage); void WebGL2RenderingContext::BufferData(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLuint target = args[0]; GLuint usage = args[2]; if (info[1].IsNull() || info[1].IsEmpty() || info[1].IsNumber()) { GL_EXPORT::glBufferData(target, args[1], NULL, usage); } else { Span<char> ptr = args[1]; GL_EXPORT::glBufferData(target, ptr.size(), ptr.data(), usage); } } // GL_EXPORT void glBufferSubData (GLenum target, GLintptr offset, GLsizeiptr size, const void* // data); void WebGL2RenderingContext::BufferSubData(Napi::CallbackInfo const& info) { CallbackArgs args = info; Span<char> ptr = args[2]; if (ptr.size() > 0 && ptr.data() != nullptr) { GL_EXPORT::glBufferSubData(args[0], args[1], ptr.size(), ptr.data()); } } // GL_EXPORT void glCreateBuffers (GLsizei n, GLuint* buffers); Napi::Value WebGL2RenderingContext::CreateBuffer(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLuint buffer{}; GL_EXPORT::glCreateBuffers(1, &buffer); return WebGLBuffer::New(info.Env(), buffer); } // GL_EXPORT void glCreateBuffers (GLsizei n, GLuint* buffers); Napi::Value WebGL2RenderingContext::CreateBuffers(Napi::CallbackInfo const& info) { CallbackArgs args = info; std::vector<GLuint> buffers(args[0].operator size_t()); GL_EXPORT::glCreateBuffers(buffers.size(), buffers.data()); return CPPToNapi(info)(buffers); } // GL_EXPORT void glDeleteBuffers (GLsizei n, const GLuint* buffers); void WebGL2RenderingContext::DeleteBuffer(Napi::CallbackInfo const& info) { CallbackArgs args = info; const GLuint buffer = args[0]; GL_EXPORT::glDeleteBuffers(1, &buffer); } // GL_EXPORT void glDeleteBuffers (GLsizei n, const GLuint* buffers); void WebGL2RenderingContext::DeleteBuffers(Napi::CallbackInfo const& info) { CallbackArgs args = info; std::vector<GLuint> buffers = args[0]; GL_EXPORT::glDeleteBuffers(buffers.size(), buffers.data()); } // GL_EXPORT void glGetBufferParameteriv (GLenum target, GLenum pname, GLint* params); Napi::Value WebGL2RenderingContext::GetBufferParameter(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLint params{}; GL_EXPORT::glGetBufferParameteriv(args[0], args[1], &params); return CPPToNapi(info)(params); } // GL_EXPORT GLboolean glIsBuffer (GLuint buffer); Napi::Value WebGL2RenderingContext::IsBuffer(Napi::CallbackInfo const& info) { CallbackArgs args = info; return CPPToNapi(info)(GL_EXPORT::glIsBuffer(args[0])); } // GL_EXPORT void glBindBufferBase (GLenum target, GLuint index, GLuint buffer); void WebGL2RenderingContext::BindBufferBase(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glBindBufferBase(args[0], args[1], args[2]); } // GL_EXPORT void glBindBufferRange (GLenum target, GLuint index, GLuint buffer, GLintptr offset, // GLsizeiptr size); void WebGL2RenderingContext::BindBufferRange(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glBindBufferRange(args[0], args[1], args[2], args[3], args[4]); } // GL_EXPORT void glClearBufferfv (GLenum buffer, GLint drawBuffer, const GLfloat* value); void WebGL2RenderingContext::ClearBufferfv(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glClearBufferfv(args[0], args[1], args[2]); } // GL_EXPORT void glClearBufferiv (GLenum buffer, GLint drawBuffer, const GLint* value); void WebGL2RenderingContext::ClearBufferiv(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glClearBufferiv(args[0], args[1], args[2]); } // GL_EXPORT void glClearBufferfi (GLenum buffer, GLint drawBuffer, GLfloat depth, GLint stencil); void WebGL2RenderingContext::ClearBufferfi(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glClearBufferfi(args[0], args[1], args[2], args[3]); } // GL_EXPORT void glClearBufferuiv (GLenum buffer, GLint drawBuffer, const GLuint* value); void WebGL2RenderingContext::ClearBufferuiv(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glClearBufferuiv(args[0], args[1], args[2]); } // GL_EXPORT void glCopyBufferSubData (GLenum readtarget, GLenum writetarget, GLintptr readoffset, // GLintptr writeoffset, GLsizeiptr size); void WebGL2RenderingContext::CopyBufferSubData(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glCopyBufferSubData(args[0], args[1], args[2], args[3], args[4]); } // GL_EXPORT void glDrawBuffers (GLsizei n, const GLenum* bufs); void WebGL2RenderingContext::DrawBuffers(Napi::CallbackInfo const& info) { CallbackArgs args = info; std::vector<GLuint> buffers = args[0]; GL_EXPORT::glDrawBuffers(buffers.size(), buffers.data()); } // GL_EXPORT void glGetBufferSubData (GLenum target, GLintptr offset, GLsizeiptr size, void* data); void WebGL2RenderingContext::GetBufferSubData(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glGetBufferSubData(args[0], args[1], args[2], args[3]); } // GL_EXPORT void glReadBuffer (GLenum mode); void WebGL2RenderingContext::ReadBuffer(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glReadBuffer(args[0]); } } // namespace nv
0
rapidsai_public_repos/node/modules/webgl
rapidsai_public_repos/node/modules/webgl/src/webgl.hpp
// Copyright (c) 2020-2021, NVIDIA CORPORATION. // // 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. #pragma once #include "gl.hpp" #include <nv_node/objectwrap.hpp> #include <napi.h> #ifndef GL_GPU_DISJOINT #define GL_GPU_DISJOINT 0x8FBB #endif #ifndef GL_UNMASKED_VENDOR_WEBGL #define GL_UNMASKED_VENDOR_WEBGL 0x9245 #endif #ifndef GL_UNMASKED_RENDERER_WEBGL #define GL_UNMASKED_RENDERER_WEBGL 0x9246 #endif #ifndef GL_UNPACK_FLIP_Y_WEBGL #define GL_UNPACK_FLIP_Y_WEBGL 0x9240 #endif #ifndef GL_UNPACK_PREMULTIPLY_ALPHA_WEBGL #define GL_UNPACK_PREMULTIPLY_ALPHA_WEBGL 0x9241 #endif #ifndef GL_CONTEXT_LOST_WEBGL #define GL_CONTEXT_LOST_WEBGL 0x9242 #endif #ifndef GL_UNPACK_COLORSPACE_CONVERSION_WEBGL #define GL_UNPACK_COLORSPACE_CONVERSION_WEBGL 0x9243 #endif #ifndef GL_BROWSER_DEFAULT_WEBGL #define GL_BROWSER_DEFAULT_WEBGL 0x9244 #endif #ifndef GL_MAX_CLIENT_WAIT_TIMEOUT_WEBGL #define GL_MAX_CLIENT_WAIT_TIMEOUT_WEBGL 0x9247 #endif namespace nv { struct WebGLActiveInfo : public EnvLocalObjectWrap<WebGLActiveInfo> { // using EnvLocalObjectWrap<WebGLActiveInfo>::New; static Napi::Function Init(Napi::Env const& env, Napi::Object exports); static wrapper_t New(Napi::Env const& env, GLint size, GLuint type, std::string name); WebGLActiveInfo(Napi::CallbackInfo const& info); private: Napi::Value ToString(Napi::CallbackInfo const& info); Napi::Value GetSize(Napi::CallbackInfo const& info); Napi::Value GetType(Napi::CallbackInfo const& info); Napi::Value GetName(Napi::CallbackInfo const& info); GLint size_{0}; GLuint type_{0}; std::string name_{""}; }; struct WebGLShaderPrecisionFormat : public EnvLocalObjectWrap<WebGLShaderPrecisionFormat> { // using EnvLocalObjectWrap<WebGLShaderPrecisionFormat>::New; static Napi::Function Init(Napi::Env const& env, Napi::Object exports); static wrapper_t New(Napi::Env const& env, GLint rangeMax, GLint rangeMin, GLint precision); WebGLShaderPrecisionFormat(Napi::CallbackInfo const& info); private: Napi::Value ToString(Napi::CallbackInfo const& info); Napi::Value GetRangeMin(Napi::CallbackInfo const& info); Napi::Value GetRangeMax(Napi::CallbackInfo const& info); Napi::Value GetPrecision(Napi::CallbackInfo const& info); GLint rangeMin_{0}; GLint rangeMax_{0}; GLint precision_{0}; }; struct WebGLBuffer : public EnvLocalObjectWrap<WebGLBuffer> { // using EnvLocalObjectWrap<WebGLBuffer>::New; static Napi::Function Init(Napi::Env const& env, Napi::Object exports); static wrapper_t New(Napi::Env const& env, GLuint value); WebGLBuffer(Napi::CallbackInfo const& info); operator GLuint() { return this->value_; } private: Napi::Value ToString(Napi::CallbackInfo const& info); Napi::Value GetValue(Napi::CallbackInfo const& info); GLuint value_{0}; }; struct WebGLContextEvent : public EnvLocalObjectWrap<WebGLContextEvent> { // using EnvLocalObjectWrap<WebGLContextEvent>::New; static Napi::Function Init(Napi::Env const& env, Napi::Object exports); static wrapper_t New(Napi::Env const& env, GLuint value); WebGLContextEvent(Napi::CallbackInfo const& info); operator GLuint() { return this->value_; } private: Napi::Value ToString(Napi::CallbackInfo const& info); Napi::Value GetValue(Napi::CallbackInfo const& info); GLuint value_{0}; }; struct WebGLFramebuffer : public EnvLocalObjectWrap<WebGLFramebuffer> { // using EnvLocalObjectWrap<WebGLFramebuffer>::New; static Napi::Function Init(Napi::Env const& env, Napi::Object exports); static wrapper_t New(Napi::Env const& env, GLuint value); WebGLFramebuffer(Napi::CallbackInfo const& info); operator GLuint() { return this->value_; } private: Napi::Value ToString(Napi::CallbackInfo const& info); Napi::Value GetValue(Napi::CallbackInfo const& info); GLuint value_{0}; }; struct WebGLProgram : public EnvLocalObjectWrap<WebGLProgram> { // using EnvLocalObjectWrap<WebGLProgram>::New; static Napi::Function Init(Napi::Env const& env, Napi::Object exports); static wrapper_t New(Napi::Env const& env, GLuint value); WebGLProgram(Napi::CallbackInfo const& info); operator GLuint() { return this->value_; } private: Napi::Value ToString(Napi::CallbackInfo const& info); Napi::Value GetValue(Napi::CallbackInfo const& info); GLuint value_{0}; }; struct WebGLQuery : public EnvLocalObjectWrap<WebGLQuery> { // using EnvLocalObjectWrap<WebGLQuery>::New; static Napi::Function Init(Napi::Env const& env, Napi::Object exports); static wrapper_t New(Napi::Env const& env, GLuint value); WebGLQuery(Napi::CallbackInfo const& info); operator GLuint() { return this->value_; } private: Napi::Value ToString(Napi::CallbackInfo const& info); Napi::Value GetValue(Napi::CallbackInfo const& info); GLuint value_{0}; }; struct WebGLRenderbuffer : public EnvLocalObjectWrap<WebGLRenderbuffer> { // using EnvLocalObjectWrap<WebGLRenderbuffer>::New; static Napi::Function Init(Napi::Env const& env, Napi::Object exports); static wrapper_t New(Napi::Env const& env, GLuint value); WebGLRenderbuffer(Napi::CallbackInfo const& info); operator GLuint() { return this->value_; } private: Napi::Value ToString(Napi::CallbackInfo const& info); Napi::Value GetValue(Napi::CallbackInfo const& info); GLuint value_{0}; }; struct WebGLSampler : public EnvLocalObjectWrap<WebGLSampler> { // using EnvLocalObjectWrap<WebGLSampler>::New; static Napi::Function Init(Napi::Env const& env, Napi::Object exports); static wrapper_t New(Napi::Env const& env, GLuint value); WebGLSampler(Napi::CallbackInfo const& info); operator GLuint() { return this->value_; } private: Napi::Value ToString(Napi::CallbackInfo const& info); Napi::Value GetValue(Napi::CallbackInfo const& info); GLuint value_{0}; }; struct WebGLShader : public EnvLocalObjectWrap<WebGLShader> { // using EnvLocalObjectWrap<WebGLShader>::New; static Napi::Function Init(Napi::Env const& env, Napi::Object exports); static wrapper_t New(Napi::Env const& env, GLuint value); WebGLShader(Napi::CallbackInfo const& info); operator GLuint() { return this->value_; } private: Napi::Value ToString(Napi::CallbackInfo const& info); Napi::Value GetValue(Napi::CallbackInfo const& info); GLuint value_{0}; }; struct WebGLSync : public EnvLocalObjectWrap<WebGLSync> { // using EnvLocalObjectWrap<WebGLSync>::New; static Napi::Function Init(Napi::Env const& env, Napi::Object exports); static wrapper_t New(Napi::Env const& env, GLsync value); WebGLSync(Napi::CallbackInfo const& info); operator GLsync() { return this->value_; } private: Napi::Value ToString(Napi::CallbackInfo const& info); Napi::Value GetValue(Napi::CallbackInfo const& info); GLsync value_{0}; }; struct WebGLTexture : public EnvLocalObjectWrap<WebGLTexture> { // using EnvLocalObjectWrap<WebGLTexture>::New; static Napi::Function Init(Napi::Env const& env, Napi::Object exports); static wrapper_t New(Napi::Env const& env, GLuint value); WebGLTexture(Napi::CallbackInfo const& info); operator GLuint() { return this->value_; } private: Napi::Value ToString(Napi::CallbackInfo const& info); Napi::Value GetValue(Napi::CallbackInfo const& info); GLuint value_{0}; }; struct WebGLTransformFeedback : public EnvLocalObjectWrap<WebGLTransformFeedback> { // using EnvLocalObjectWrap<WebGLTransformFeedback>::New; static Napi::Function Init(Napi::Env const& env, Napi::Object exports); static wrapper_t New(Napi::Env const& env, GLuint value); WebGLTransformFeedback(Napi::CallbackInfo const& info); operator GLuint() { return this->value_; } private: Napi::Value ToString(Napi::CallbackInfo const& info); Napi::Value GetValue(Napi::CallbackInfo const& info); GLuint value_{0}; }; struct WebGLUniformLocation : public EnvLocalObjectWrap<WebGLUniformLocation> { // using EnvLocalObjectWrap<WebGLUniformLocation>::New; static Napi::Function Init(Napi::Env const& env, Napi::Object exports); static wrapper_t New(Napi::Env const& env, GLint value); WebGLUniformLocation(Napi::CallbackInfo const& info); operator GLint() { return this->value_; } private: Napi::Value ToString(Napi::CallbackInfo const& info); Napi::Value GetValue(Napi::CallbackInfo const& info); GLint value_{0}; }; struct WebGLVertexArrayObject : public EnvLocalObjectWrap<WebGLVertexArrayObject> { // using EnvLocalObjectWrap<WebGLVertexArrayObject>::New; static Napi::Function Init(Napi::Env const& env, Napi::Object exports); static wrapper_t New(Napi::Env const& env, GLuint value); WebGLVertexArrayObject(Napi::CallbackInfo const& info); operator GLuint() { return this->value_; } private: Napi::Value ToString(Napi::CallbackInfo const& info); Napi::Value GetValue(Napi::CallbackInfo const& info); GLuint value_{0}; }; struct WebGL2RenderingContext : public EnvLocalObjectWrap<WebGL2RenderingContext> { // using EnvLocalObjectWrap<WebGL2RenderingContext>::New; static Napi::Function Init(Napi::Env const& env, Napi::Object exports); WebGL2RenderingContext(Napi::CallbackInfo const& info); private: /// // misc /// // GL_EXPORT void glClear (GLbitfield mask); void Clear(Napi::CallbackInfo const& info); // GL_EXPORT void glClearColor (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha); void ClearColor(Napi::CallbackInfo const& info); // GL_EXPORT void glClearDepth (GLclampd depth); void ClearDepth(Napi::CallbackInfo const& info); // GL_EXPORT void glColorMask (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); void ColorMask(Napi::CallbackInfo const& info); // GL_EXPORT void glCullFace (GLenum mode); void CullFace(Napi::CallbackInfo const& info); // GL_EXPORT void glDepthFunc (GLenum func); void DepthFunc(Napi::CallbackInfo const& info); // GL_EXPORT void glDepthMask (GLboolean flag); void DepthMask(Napi::CallbackInfo const& info); // GL_EXPORT void glDepthRange (GLclampd zNear, GLclampd zFar); void DepthRange(Napi::CallbackInfo const& info); // GL_EXPORT void glDisable (GLenum cap); void Disable(Napi::CallbackInfo const& info); // GL_EXPORT void glDrawArrays (GLenum mode, GLint first, GLsizei count); void DrawArrays(Napi::CallbackInfo const& info); // GL_EXPORT void glDrawElements (GLenum mode, GLsizei count, GLenum type, const void *indices); void DrawElements(Napi::CallbackInfo const& info); // GL_EXPORT void glEnable (GLenum cap); void Enable(Napi::CallbackInfo const& info); // GL_EXPORT void glFinish (void); void Finish(Napi::CallbackInfo const& info); // GL_EXPORT void glFlush (void); void Flush(Napi::CallbackInfo const& info); // GL_EXPORT void glFrontFace (GLenum mode); void FrontFace(Napi::CallbackInfo const& info); // GL_EXPORT GLenum glGetError (void); Napi::Value GetError(Napi::CallbackInfo const& info); // GL_EXPORT void glGetParameter (GLint pname); Napi::Value GetParameter(Napi::CallbackInfo const& info); // GL_EXPORT const GLubyte * glGetString (GL_EXTENSIONS); Napi::Value GetSupportedExtensions(Napi::CallbackInfo const& info); // GL_EXPORT void glHint (GLenum target, GLenum mode); void Hint(Napi::CallbackInfo const& info); // GL_EXPORT GLboolean glIsEnabled (GLenum cap); Napi::Value IsEnabled(Napi::CallbackInfo const& info); // GL_EXPORT void glLineWidth (GLfloat width); void LineWidth(Napi::CallbackInfo const& info); // GL_EXPORT void glPixelStorei (GLenum pname, GLint param); void PixelStorei(Napi::CallbackInfo const& info); // GL_EXPORT void glPolygonOffset (GLfloat factor, GLfloat units); void PolygonOffset(Napi::CallbackInfo const& info); // GL_EXPORT void glReadPixels (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, // GLenum type, void *pixels); void ReadPixels(Napi::CallbackInfo const& info); // GL_EXPORT void glScissor (GLint x, GLint y, GLsizei width, GLsizei height); void Scissor(Napi::CallbackInfo const& info); // GL_EXPORT void glViewport (GLint x, GLint y, GLsizei width, GLsizei height); void Viewport(Napi::CallbackInfo const& info); // GL_EXPORT void glDrawRangeElements (GLenum mode, GLuint start, GLuint end, GLsizei count, // GLenum type, const void *indices); void DrawRangeElements(Napi::CallbackInfo const& info); // GL_EXPORT void glSampleCoverage (GLclampf value, GLboolean invert); void SampleCoverage(Napi::CallbackInfo const& info); // GL_EXPORT GLint glGetFragDataLocation (GLuint program, const GLchar* name); Napi::Value GetFragDataLocation(Napi::CallbackInfo const& info); /// // attrib /// // GL_EXPORT void glBindAttribLocation (GLuint program, GLuint index, const GLchar* name); void BindAttribLocation(Napi::CallbackInfo const& info); // GL_EXPORT void glDisableVertexAttribArray (GLuint index); void DisableVertexAttribArray(Napi::CallbackInfo const& info); // GL_EXPORT void glEnableVertexAttribArray (GLuint index); void EnableVertexAttribArray(Napi::CallbackInfo const& info); // GL_EXPORT void glGetActiveAttrib (GLuint program, GLuint index, GLsizei maxLength, GLsizei* // length, GLint* size, GLenum* type, GLchar* name); Napi::Value GetActiveAttrib(Napi::CallbackInfo const& info); // GL_EXPORT GLint glGetAttribLocation (GLuint program, const GLchar* name); Napi::Value GetAttribLocation(Napi::CallbackInfo const& info); // GL_EXPORT void glGetVertexAttribdv (GLuint index, GLenum pname, GLdouble* params); // GL_EXPORT void glGetVertexAttribfv (GLuint index, GLenum pname, GLfloat* params); // GL_EXPORT void glGetVertexAttribiv (GLuint index, GLenum pname, GLint* params); Napi::Value GetVertexAttrib(Napi::CallbackInfo const& info); // GL_EXPORT void glGetVertexAttribPointerv (GLuint index, GLenum pname, void** pointer); Napi::Value GetVertexAttribPointerv(Napi::CallbackInfo const& info); // GL_EXPORT void glVertexAttrib1f (GLuint index, GLfloat x); void VertexAttrib1f(Napi::CallbackInfo const& info); // GL_EXPORT void glVertexAttrib1fv (GLuint index, const GLfloat* v); void VertexAttrib1fv(Napi::CallbackInfo const& info); // GL_EXPORT void glVertexAttrib2f (GLuint index, GLfloat x, GLfloat y); void VertexAttrib2f(Napi::CallbackInfo const& info); // GL_EXPORT void glVertexAttrib2fv (GLuint index, const GLfloat* v); void VertexAttrib2fv(Napi::CallbackInfo const& info); // GL_EXPORT void glVertexAttrib3f (GLuint index, GLfloat x, GLfloat y, GLfloat z); void VertexAttrib3f(Napi::CallbackInfo const& info); // GL_EXPORT void glVertexAttrib3fv (GLuint index, const GLfloat* v); void VertexAttrib3fv(Napi::CallbackInfo const& info); // GL_EXPORT void glVertexAttrib4f (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); void VertexAttrib4f(Napi::CallbackInfo const& info); // GL_EXPORT void glVertexAttrib4fv (GLuint index, const GLfloat* v); void VertexAttrib4fv(Napi::CallbackInfo const& info); // GL_EXPORT void glVertexAttribPointer (GLuint index, GLint size, GLenum type, GLboolean // normalized, GLsizei stride, const void* pointer); void VertexAttribPointer(Napi::CallbackInfo const& info); // GL_EXPORT void glVertexAttribI4i (GLuint index, GLint v0, GLint v1, GLint v2, GLint v3); void VertexAttribI4i(Napi::CallbackInfo const& info); // GL_EXPORT void glVertexAttribI4iv (GLuint index, const GLint* v0); void VertexAttribI4iv(Napi::CallbackInfo const& info); // GL_EXPORT void glVertexAttribI4ui (GLuint index, GLuint v0, GLuint v1, GLuint v2, GLuint v3); void VertexAttribI4ui(Napi::CallbackInfo const& info); // GL_EXPORT void glVertexAttribI4uiv (GLuint index, const GLuint* v0); void VertexAttribI4uiv(Napi::CallbackInfo const& info); // GL_EXPORT void glVertexAttribIPointer (GLuint index, GLint size, GLenum type, GLsizei stride, // const void*pointer); void VertexAttribIPointer(Napi::CallbackInfo const& info); /// // blend /// // GL_EXPORT void glBlendColor (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha); void BlendColor(Napi::CallbackInfo const& info); // GL_EXPORT void glBlendEquation (GLenum mode); void BlendEquation(Napi::CallbackInfo const& info); // GL_EXPORT void glBlendEquationSeparate (GLenum modeRGB, GLenum modeAlpha); void BlendEquationSeparate(Napi::CallbackInfo const& info); // GL_EXPORT void glBlendFunc (GLenum sfactor, GLenum dfactor); void BlendFunc(Napi::CallbackInfo const& info); // GL_EXPORT void glBlendFuncSeparate (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, // GLenum dfactorAlpha); void BlendFuncSeparate(Napi::CallbackInfo const& info); /// // buffer /// // GL_EXPORT void glBindBuffer (GLenum target, GLuint buffer); void BindBuffer(Napi::CallbackInfo const& info); // GL_EXPORT void glBufferData (GLenum target, GLsizeiptr size, const void* data, GLenum usage); void BufferData(Napi::CallbackInfo const& info); // GL_EXPORT void glBufferSubData (GLenum target, GLintptr offset, GLsizeiptr size, const void* // data); void BufferSubData(Napi::CallbackInfo const& info); // GL_EXPORT void glCreateBuffers (GLsizei n, GLuint* buffers); Napi::Value CreateBuffer(Napi::CallbackInfo const& info); // GL_EXPORT void glCreateBuffers (GLsizei n, GLuint* buffers); Napi::Value CreateBuffers(Napi::CallbackInfo const& info); // GL_EXPORT void glDeleteBuffers (GLsizei n, const GLuint* buffers); void DeleteBuffer(Napi::CallbackInfo const& info); // GL_EXPORT void glDeleteBuffers (GLsizei n, const GLuint* buffers); void DeleteBuffers(Napi::CallbackInfo const& info); // GL_EXPORT void glGetBufferParameter (GLenum target, GLenum pname, GLint* params); Napi::Value GetBufferParameter(Napi::CallbackInfo const& info); // GL_EXPORT GLboolean glIsBuffer (GLuint buffer); Napi::Value IsBuffer(Napi::CallbackInfo const& info); // GL_EXPORT void glBindBufferBase (GLenum target, GLuint index, GLuint buffer); void BindBufferBase(Napi::CallbackInfo const& info); // GL_EXPORT void glBindBufferRange (GLenum target, GLuint index, GLuint buffer, GLintptr offset, // GLsizeiptr size); void BindBufferRange(Napi::CallbackInfo const& info); // GL_EXPORT void glClearBufferfv (GLenum buffer, GLint drawBuffer, const GLfloat* value); void ClearBufferfv(Napi::CallbackInfo const& info); // GL_EXPORT void glClearBufferiv (GLenum buffer, GLint drawBuffer, const GLint* value); void ClearBufferiv(Napi::CallbackInfo const& info); // GL_EXPORT void glClearBufferuiv (GLenum buffer, GLint drawBuffer, const GLuint* value); void ClearBufferuiv(Napi::CallbackInfo const& info); // GL_EXPORT void glClearBufferfi (GLenum buffer, GLint drawBuffer, GLfloat depth, GLint stencil); void ClearBufferfi(Napi::CallbackInfo const& info); // GL_EXPORT void glCopyBufferSubData (GLenum readtarget, GLenum writetarget, GLintptr readoffset, // GLintptr writeoffset, GLsizeiptr size); void CopyBufferSubData(Napi::CallbackInfo const& info); // GL_EXPORT void glDrawBuffers (GLsizei n, const GLenum* bufs); void DrawBuffers(Napi::CallbackInfo const& info); // GL_EXPORT void glGetBufferSubData (GLenum target, GLintptr offset, GLsizeiptr size, void* // data); void GetBufferSubData(Napi::CallbackInfo const& info); // GL_EXPORT void glReadBuffer (GLenum mode); void ReadBuffer(Napi::CallbackInfo const& info); /// // framebuffer /// // GL_EXPORT void glBindFramebuffer (GLenum target, GLuint framebuffer); void BindFramebuffer(Napi::CallbackInfo const& info); // GL_EXPORT GLenum glCheckFramebufferStatus (GLenum target); Napi::Value CheckFramebufferStatus(Napi::CallbackInfo const& info); // GL_EXPORT void glCreateFramebuffers (GLsizei n, GLuint* framebuffers); Napi::Value CreateFramebuffer(Napi::CallbackInfo const& info); // GL_EXPORT void glCreateFramebuffers (GLsizei n, GLuint* framebuffers); Napi::Value CreateFramebuffers(Napi::CallbackInfo const& info); // GL_EXPORT void glDeleteFramebuffers (GLsizei n, const GLuint* framebuffers); void DeleteFramebuffer(Napi::CallbackInfo const& info); // GL_EXPORT void glDeleteFramebuffers (GLsizei n, const GLuint* framebuffers); void DeleteFramebuffers(Napi::CallbackInfo const& info); // GL_EXPORT void glFramebufferRenderbuffer (GLenum target, GLenum attachment, GLenum // renderbuffertarget, GLuint renderbuffer); void FramebufferRenderbuffer(Napi::CallbackInfo const& info); // GL_EXPORT void glFramebufferTexture2D (GLenum target, GLenum attachment, GLenum textarget, // GLuint texture, GLint level); void FramebufferTexture2D(Napi::CallbackInfo const& info); // GL_EXPORT void glGetFramebufferAttachmentParameteriv (GLenum target, GLenum attachment, GLenum // pname, GLint* params); Napi::Value GetFramebufferAttachmentParameter(Napi::CallbackInfo const& info); // GL_EXPORT GLboolean glIsFramebuffer (GLuint framebuffer); Napi::Value IsFramebuffer(Napi::CallbackInfo const& info); // GL_EXPORT void glBlitFramebuffer (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint // dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); void BlitFramebuffer(Napi::CallbackInfo const& info); // GL_EXPORT void glFramebufferTextureLayer (GLenum target,GLenum attachment, GLuint texture,GLint // level,GLint layer); void FramebufferTextureLayer(Napi::CallbackInfo const& info); // GL_EXPORT void glInvalidateFramebuffer (GLenum target, GLsizei numAttachments, const GLenum* // attachments); void InvalidateFramebuffer(Napi::CallbackInfo const& info); // GL_EXPORT void glInvalidateSubFramebuffer (GLenum target, GLsizei numAttachments, const GLenum* // attachments, GLint x, GLint y, GLsizei width, GLsizei height); void InvalidateSubFramebuffer(Napi::CallbackInfo const& info); /// // instanced /// // GL_EXPORT void glDrawArraysInstanced (GLenum mode, GLint first, GLsizei count, GLsizei // primcount); void DrawArraysInstanced(Napi::CallbackInfo const& info); // GL_EXPORT void glDrawElementsInstanced (GLenum mode, GLsizei count, GLenum type, const void* // indices, GLsizei primcount); void DrawElementsInstanced(Napi::CallbackInfo const& info); // GL_EXPORT void glVertexAttribDivisor (GLuint index, GLuint divisor); void VertexAttribDivisor(Napi::CallbackInfo const& info); /// // program /// // GL_EXPORT GLuint glCreateProgram (void); Napi::Value CreateProgram(Napi::CallbackInfo const& info); // GL_EXPORT void glDeleteProgram (GLuint program); void DeleteProgram(Napi::CallbackInfo const& info); // GL_EXPORT void glGetProgramInfoLog (GLuint program, GLsizei bufSize, GLsizei* length, GLchar* // infoLog); Napi::Value GetProgramInfoLog(Napi::CallbackInfo const& info); // GL_EXPORT void glGetProgramiv (GLuint program, GLenum pname, GLint* param); Napi::Value GetProgramParameter(Napi::CallbackInfo const& info); // GL_EXPORT GLboolean glIsProgram (GLuint program); Napi::Value IsProgram(Napi::CallbackInfo const& info); // GL_EXPORT void glLinkProgram (GLuint program); void LinkProgram(Napi::CallbackInfo const& info); // GL_EXPORT void glUseProgram (GLuint program); void UseProgram(Napi::CallbackInfo const& info); // GL_EXPORT void glValidateProgram (GLuint program); void ValidateProgram(Napi::CallbackInfo const& info); /// // query /// // GL_EXPORT void glBeginQuery (GLenum target, GLuint id); void BeginQuery(Napi::CallbackInfo const& info); // GL_EXPORT void glGenQueries (GLsizei n, GLuint* ids); Napi::Value CreateQuery(Napi::CallbackInfo const& info); // GL_EXPORT void glGenQueries (GLsizei n, GLuint* ids); Napi::Value CreateQueries(Napi::CallbackInfo const& info); // GL_EXPORT void glDeleteQueries (GLsizei n, const GLuint* ids); void DeleteQuery(Napi::CallbackInfo const& info); // GL_EXPORT void glDeleteQueries (GLsizei n, const GLuint* ids); void DeleteQueries(Napi::CallbackInfo const& info); // GL_EXPORT void glEndQuery (GLenum target); void EndQuery(Napi::CallbackInfo const& info); // GL_EXPORT void glGetQueryiv (GLenum target, GLenum pname, GLint* params); Napi::Value GetQuery(Napi::CallbackInfo const& info); // GL_EXPORT void glGetQueryObjectuiv (GLuint id, GLenum pname, GLuint* params); Napi::Value GetQueryParameter(Napi::CallbackInfo const& info); // GL_EXPORT GLboolean glIsQuery (GLuint id); Napi::Value IsQuery(Napi::CallbackInfo const& info); // GL_EXPORT void glQueryCounter (GLuint id, GLenum target); void QueryCounter(Napi::CallbackInfo const& info); /// // renderbuffer /// // GL_EXPORT void glCreateRenderbuffers (GLsizei n, GLuint* renderbuffers); Napi::Value CreateRenderbuffer(Napi::CallbackInfo const& info); // GL_EXPORT void glCreateRenderbuffers (GLsizei n, GLuint* renderbuffers); Napi::Value CreateRenderbuffers(Napi::CallbackInfo const& info); // GL_EXPORT void glBindRenderbuffer (GLenum target, GLuint renderbuffer); void BindRenderbuffer(Napi::CallbackInfo const& info); // GL_EXPORT void glDeleteRenderbuffers (GLsizei n, const GLuint* renderbuffers); void DeleteRenderbuffer(Napi::CallbackInfo const& info); // GL_EXPORT void glDeleteRenderbuffers (GLsizei n, const GLuint* renderbuffers); void DeleteRenderbuffers(Napi::CallbackInfo const& info); // GL_EXPORT void glGetRenderbufferParameteriv (GLenum target, GLenum pname, GLint* params); Napi::Value GetRenderbufferParameteriv(Napi::CallbackInfo const& info); // GL_EXPORT GLboolean glIsRenderbuffer (GLuint renderbuffer); Napi::Value IsRenderbuffer(Napi::CallbackInfo const& info); // GL_EXPORT void glRenderbufferStorage (GLenum target, GLenum internalformat, GLsizei width, // GLsizei height); void RenderbufferStorage(Napi::CallbackInfo const& info); // GL_EXPORT void glRenderbufferStorageMultisample (GLenum target, GLsizei samples, GLenum // internalformat, GLsizei width, GLsizei height); void RenderbufferStorageMultisample(Napi::CallbackInfo const& info); /// // sampler /// // GL_EXPORT void glBindSampler (GLuint unit, GLuint sampler); void BindSampler(Napi::CallbackInfo const& info); // GL_EXPORT void glCreateSamplers (GLsizei n, GLuint* samplers); Napi::Value CreateSampler(Napi::CallbackInfo const& info); // GL_EXPORT void glCreateSamplers (GLsizei n, GLuint* samplers); Napi::Value CreateSamplers(Napi::CallbackInfo const& info); // GL_EXPORT void glDeleteSamplers (GLsizei count, const GLuint * samplers); void DeleteSampler(Napi::CallbackInfo const& info); // GL_EXPORT void glDeleteSamplers (GLsizei count, const GLuint * samplers); void DeleteSamplers(Napi::CallbackInfo const& info); // GL_EXPORT void glGetSamplerParameterfv (GLuint sampler, GLenum pname, GLfloat* params); // GL_EXPORT void glGetSamplerParameteriv (GLuint sampler, GLenum pname, GLint* params); Napi::Value GetSamplerParameter(Napi::CallbackInfo const& info); // GL_EXPORT GLboolean glIsSampler (GLuint sampler); Napi::Value IsSampler(Napi::CallbackInfo const& info); // GL_EXPORT void glSamplerParameterf (GLuint sampler, GLenum pname, GLfloat param); void SamplerParameterf(Napi::CallbackInfo const& info); // GL_EXPORT void glSamplerParameteri (GLuint sampler, GLenum pname, GLint param); void SamplerParameteri(Napi::CallbackInfo const& info); /// // shader /// // GL_EXPORT void glAttachShader (GLuint program, GLuint shader); void AttachShader(Napi::CallbackInfo const& info); // GL_EXPORT void glCompileShader (GLuint shader); void CompileShader(Napi::CallbackInfo const& info); // GL_EXPORT GLuint glCreateShader (GLenum type); Napi::Value CreateShader(Napi::CallbackInfo const& info); // GL_EXPORT void glDeleteShader (GLuint shader); void DeleteShader(Napi::CallbackInfo const& info); // GL_EXPORT void glDetachShader (GLuint program, GLuint shader); void DetachShader(Napi::CallbackInfo const& info); // GL_EXPORT void glGetAttachedShaders (GLuint program, GLsizei maxCount, GLsizei* count, GLuint* // shaders); Napi::Value GetAttachedShaders(Napi::CallbackInfo const& info); // GL_EXPORT void glGetShaderInfoLog (GLuint shader, GLsizei bufSize, GLsizei* length, GLchar* // infoLog); Napi::Value GetShaderInfoLog(Napi::CallbackInfo const& info); // GL_EXPORT void glGetShaderiv (GLuint shader, GLenum pname, GLint* param); Napi::Value GetShaderParameter(Napi::CallbackInfo const& info); // GL_EXPORT void glGetShaderPrecisionFormat (GLenum shadertype, GLenum precisiontype, GLint* // range, GLint *precision); Napi::Value GetShaderPrecisionFormat(Napi::CallbackInfo const& info); // GL_EXPORT void glGetShaderSource (GLuint obj, GLsizei maxLength, GLsizei* length, GLchar* // source); Napi::Value GetShaderSource(Napi::CallbackInfo const& info); // GL_EXPORT void glGetTranslatedShaderSourceANGLE(GLuint shader, GLsizei bufsize, GLsizei* // length, GLchar* source); Napi::Value GetTranslatedShaderSource(Napi::CallbackInfo const& info); // GL_EXPORT GLboolean glIsShader (GLuint shader); Napi::Value IsShader(Napi::CallbackInfo const& info); // GL_EXPORT void glShaderSource (GLuint shader, GLsizei count, const GLchar *const* string, const // GLint* length); void ShaderSource(Napi::CallbackInfo const& info); /// // stencil /// // GL_EXPORT void glClearStencil (GLint s); void ClearStencil(Napi::CallbackInfo const& info); // GL_EXPORT void glStencilFunc (GLenum func, GLint ref, GLuint mask); void StencilFunc(Napi::CallbackInfo const& info); // GL_EXPORT void glStencilFuncSeparate (GLenum frontfunc, GLenum backfunc, GLint ref, GLuint // mask); void StencilFuncSeparate(Napi::CallbackInfo const& info); // GL_EXPORT void glStencilMask (GLuint mask); void StencilMask(Napi::CallbackInfo const& info); // GL_EXPORT void glStencilMaskSeparate (GLenum face, GLuint mask); void StencilMaskSeparate(Napi::CallbackInfo const& info); // GL_EXPORT void glStencilOp (GLenum fail, GLenum zfail, GLenum zpass); void StencilOp(Napi::CallbackInfo const& info); // GL_EXPORT void glStencilOpSeparate (GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass); void StencilOpSeparate(Napi::CallbackInfo const& info); /// // sync /// // GL_EXPORT GLenum glClientWaitSync (GLsync GLsync, GLbitfield flags,GLuint64 timeout); Napi::Value ClientWaitSync(Napi::CallbackInfo const& info); // GL_EXPORT void glDeleteSync (GLsync GLsync); void DeleteSync(Napi::CallbackInfo const& info); // GL_EXPORT GLsync glFenceSync (GLenum condition, GLbitfield flags); Napi::Value FenceSync(Napi::CallbackInfo const& info); // GL_EXPORT void glGetSynciv (GLsync GLsync,GLenum pname,GLsizei bufSize,GLsizei* length, GLint // *values); Napi::Value GetSyncParameter(Napi::CallbackInfo const& info); // GL_EXPORT GLboolean glIsSync (GLsync GLsync); Napi::Value IsSync(Napi::CallbackInfo const& info); // GL_EXPORT void glWaitSync (GLsync GLsync, GLbitfield flags, GLuint64 timeout); void WaitSync(Napi::CallbackInfo const& info); /// // texture /// // GL_EXPORT void glActiveTexture (GLenum texture); void ActiveTexture(Napi::CallbackInfo const& info); // GL_EXPORT void glBindTexture (GLenum target, GLuint texture); void BindTexture(Napi::CallbackInfo const& info); // GL_EXPORT void glCompressedTexImage2D (GLenum target, GLint level, GLenum internalformat, // GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const void *data); void CompressedTexImage2D(Napi::CallbackInfo const& info); // GL_EXPORT void glCompressedTexImage3D (GLenum target, GLint level, GLenum internalformat, // GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const void // *data); void CompressedTexImage3D(Napi::CallbackInfo const& info); // GL_EXPORT void glCompressedTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint // yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *data); void CompressedTexSubImage2D(Napi::CallbackInfo const& info); // GL_EXPORT void glCopyTexImage2D (GLenum target, GLint level, GLenum internalFormat, GLint x, // GLint y, GLsizei width, GLsizei height, GLint border); void CopyTexImage2D(Napi::CallbackInfo const& info); // GL_EXPORT void glCopyTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, // GLint x, GLint y, GLsizei width, GLsizei height); void CopyTexSubImage2D(Napi::CallbackInfo const& info); // GL_EXPORT void glGenTextures (GLsizei n, GLuint* textures); Napi::Value CreateTexture(Napi::CallbackInfo const& info); // GL_EXPORT void glGenTextures (GLsizei n, GLuint* textures); Napi::Value GenTextures(Napi::CallbackInfo const& info); // GL_EXPORT void glDeleteTextures (GLsizei n, const GLuint *textures); void DeleteTexture(Napi::CallbackInfo const& info); // GL_EXPORT void glDeleteTextures (GLsizei n, const GLuint *textures); void DeleteTextures(Napi::CallbackInfo const& info); // GL_EXPORT void glGenerateMipmap (GLenum target); void GenerateMipmap(Napi::CallbackInfo const& info); // GL_EXPORT void glGetTexParameterfv (GLenum target, GLenum pname, GLfloat *params); // GL_EXPORT void glGetTexParameteriv (GLenum target, GLenum pname, GLint *params); // GL_EXPORT void glGetTexParameterIiv (GLenum target, GLenum pname, GLint* params); // GL_EXPORT void glGetTexParameterIuiv (GLenum target, GLenum pname, GLuint* params); Napi::Value GetTexParameter(Napi::CallbackInfo const& info); // GL_EXPORT GLboolean glIsTexture (GLuint texture); Napi::Value IsTexture(Napi::CallbackInfo const& info); // GL_EXPORT void glTexImage2D (GLenum target, GLint level, GLint internalformat, GLsizei width, // GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels); void TexImage2D(Napi::CallbackInfo const& info); // GL_EXPORT void glTexParameterf (GLenum target, GLenum pname, GLfloat param); void TexParameterf(Napi::CallbackInfo const& info); // GL_EXPORT void glTexParameteri (GLenum target, GLenum pname, GLint param); void TexParameteri(Napi::CallbackInfo const& info); // GL_EXPORT void glTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, // GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels); void TexSubImage2D(Napi::CallbackInfo const& info); // GL_EXPORT void glCompressedTexSubImage3D (GLenum target, GLint level, GLint xoffset, GLint // yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei // imageSize, const void *data); void CompressedTexSubImage3D(Napi::CallbackInfo const& info); // GL_EXPORT void glCopyTexSubImage3D (GLenum target, GLint level, GLint xoffset, GLint yoffset, // GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); void CopyTexSubImage3D(Napi::CallbackInfo const& info); // GL_EXPORT void glTexImage3D (GLenum target, GLint level, GLint internalFormat, GLsizei width, // GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const void *pixels); void TexImage3D(Napi::CallbackInfo const& info); // GL_EXPORT void glTexStorage2D (GLenum target, GLsizei levels, GLenum internalformat, GLsizei // width, GLsizei height); void TexStorage2D(Napi::CallbackInfo const& info); // GL_EXPORT void glTexStorage3D (GLenum target, GLsizei levels, GLenum internalformat, GLsizei // width, GLsizei height, GLsizei depth); void TexStorage3D(Napi::CallbackInfo const& info); // GL_EXPORT void glTexSubImage3D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint // zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void // *pixels); void TexSubImage3D(Napi::CallbackInfo const& info); /// // transform feedback /// // GL_EXPORT void glBeginTransformFeedback (GLenum primitiveMode); void BeginTransformFeedback(Napi::CallbackInfo const& info); // GL_EXPORT void glBindTransformFeedback (GLenum target, GLuint id); void BindTransformFeedback(Napi::CallbackInfo const& info); // GL_EXPORT void glCreateTransformFeedbacks (GLsizei n, GLuint* ids); Napi::Value CreateTransformFeedback(Napi::CallbackInfo const& info); // GL_EXPORT void glCreateTransformFeedbacks (GLsizei n, GLuint* ids); Napi::Value CreateTransformFeedbacks(Napi::CallbackInfo const& info); // GL_EXPORT void glDeleteTransformFeedbacks (GLsizei n, const GLuint* ids); void DeleteTransformFeedback(Napi::CallbackInfo const& info); // GL_EXPORT void glDeleteTransformFeedbacks (GLsizei n, const GLuint* ids); void DeleteTransformFeedbacks(Napi::CallbackInfo const& info); // GL_EXPORT void glEndTransformFeedback (void); void EndTransformFeedback(Napi::CallbackInfo const& info); // GL_EXPORT void glGetTransformFeedbackVarying (GLuint program, GLuint index, GLsizei bufSize, // GLsizei * length, GLsizei * size, GLenum * type, GLchar * name); Napi::Value GetTransformFeedbackVarying(Napi::CallbackInfo const& info); // GL_EXPORT GLboolean glIsTransformFeedback (GLuint id); Napi::Value IsTransformFeedback(Napi::CallbackInfo const& info); // GL_EXPORT void glPauseTransformFeedback (void); void PauseTransformFeedback(Napi::CallbackInfo const& info); // GL_EXPORT void glResumeTransformFeedback (void); void ResumeTransformFeedback(Napi::CallbackInfo const& info); // GL_EXPORT void glTransformFeedbackVaryings (GLuint program, GLsizei count, const GLchar *const* // varyings, GLenum bufferMode); void TransformFeedbackVaryings(Napi::CallbackInfo const& info); /// // uniforms /// // GL_EXPORT void glGetActiveUniform (GLuint program, GLuint index, GLsizei maxLength, GLsizei* // length, GLint* size, GLenum* type, GLchar* name); Napi::Value GetActiveUniform(Napi::CallbackInfo const& info); // GL_EXPORT void glGetUniformfv (GLuint program, GLint location, GLfloat* params); // GL_EXPORT void glGetUniformiv (GLuint program, GLint location, GLint* params); // GL_EXPORT void glGetUniformuiv (GLuint program, GLint location, GLuint* params); // GL_EXPORT void glGetUniformdv (GLuint program, GLint location, GLdouble* params); Napi::Value GetUniform(Napi::CallbackInfo const& info); // GL_EXPORT GLint glGetUniformLocation (GLuint program, const GLchar* name); Napi::Value GetUniformLocation(Napi::CallbackInfo const& info); // GL_EXPORT void glUniform1f (GLint location, GLfloat v0); void Uniform1f(Napi::CallbackInfo const& info); // GL_EXPORT void glUniform1fv (GLint location, GLsizei count, const GLfloat* value); void Uniform1fv(Napi::CallbackInfo const& info); // GL_EXPORT void glUniform1i (GLint location, GLint v0); void Uniform1i(Napi::CallbackInfo const& info); // GL_EXPORT void glUniform1iv (GLint location, GLsizei count, const GLint* value); void Uniform1iv(Napi::CallbackInfo const& info); // GL_EXPORT void glUniform2f (GLint location, GLfloat v0, GLfloat v1); void Uniform2f(Napi::CallbackInfo const& info); // GL_EXPORT void glUniform2fv (GLint location, GLsizei count, const GLfloat* value); void Uniform2fv(Napi::CallbackInfo const& info); // GL_EXPORT void glUniform2i (GLint location, GLint v0, GLint v1); void Uniform2i(Napi::CallbackInfo const& info); // GL_EXPORT void glUniform2iv (GLint location, GLsizei count, const GLint* value); void Uniform2iv(Napi::CallbackInfo const& info); // GL_EXPORT void glUniform3f (GLint location, GLfloat v0, GLfloat v1, GLfloat v2); void Uniform3f(Napi::CallbackInfo const& info); // GL_EXPORT void glUniform3fv (GLint location, GLsizei count, const GLfloat* value); void Uniform3fv(Napi::CallbackInfo const& info); // GL_EXPORT void glUniform3i (GLint location, GLint v0, GLint v1, GLint v2); void Uniform3i(Napi::CallbackInfo const& info); // GL_EXPORT void glUniform3iv (GLint location, GLsizei count, const GLint* value); void Uniform3iv(Napi::CallbackInfo const& info); // GL_EXPORT void glUniform4f (GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); void Uniform4f(Napi::CallbackInfo const& info); // GL_EXPORT void glUniform4fv (GLint location, GLsizei count, const GLfloat* value); void Uniform4fv(Napi::CallbackInfo const& info); // GL_EXPORT void glUniform4i (GLint location, GLint v0, GLint v1, GLint v2, GLint v3); void Uniform4i(Napi::CallbackInfo const& info); // GL_EXPORT void glUniform4iv (GLint location, GLsizei count, const GLint* value); void Uniform4iv(Napi::CallbackInfo const& info); // GL_EXPORT void glUniformMatrix2fv (GLint location, GLsizei count, GLboolean transpose, const // GLfloat* value); void UniformMatrix2fv(Napi::CallbackInfo const& info); // GL_EXPORT void glUniformMatrix3fv (GLint location, GLsizei count, GLboolean transpose, const // GLfloat* value); void UniformMatrix3fv(Napi::CallbackInfo const& info); // GL_EXPORT void glUniformMatrix4fv (GLint location, GLsizei count, GLboolean transpose, const // GLfloat* value); void UniformMatrix4fv(Napi::CallbackInfo const& info); // GL_EXPORT void glUniformMatrix2x3fv (GLint location, GLsizei count, GLboolean transpose, const // GLfloat *value); void UniformMatrix2x3fv(Napi::CallbackInfo const& info); // GL_EXPORT void glUniformMatrix2x4fv (GLint location, GLsizei count, GLboolean transpose, const // GLfloat *value); void UniformMatrix2x4fv(Napi::CallbackInfo const& info); // GL_EXPORT void glUniformMatrix3x2fv (GLint location, GLsizei count, GLboolean transpose, const // GLfloat *value); void UniformMatrix3x2fv(Napi::CallbackInfo const& info); // GL_EXPORT void glUniformMatrix3x4fv (GLint location, GLsizei count, GLboolean transpose, const // GLfloat *value); void UniformMatrix3x4fv(Napi::CallbackInfo const& info); // GL_EXPORT void glUniformMatrix4x2fv (GLint location, GLsizei count, GLboolean transpose, const // GLfloat *value); void UniformMatrix4x2fv(Napi::CallbackInfo const& info); // GL_EXPORT void glUniformMatrix4x3fv (GLint location, GLsizei count, GLboolean transpose, const // GLfloat *value); void UniformMatrix4x3fv(Napi::CallbackInfo const& info); // GL_EXPORT void glUniform1ui (GLint location, GLuint v0); void Uniform1ui(Napi::CallbackInfo const& info); // GL_EXPORT void glUniform1uiv (GLint location, GLsizei count, const GLuint* value); void Uniform1uiv(Napi::CallbackInfo const& info); // GL_EXPORT void glUniform2ui (GLint location, GLuint v0, GLuint v1); void Uniform2ui(Napi::CallbackInfo const& info); // GL_EXPORT void glUniform2uiv (GLint location, GLsizei count, const GLuint* value); void Uniform2uiv(Napi::CallbackInfo const& info); // GL_EXPORT void glUniform3ui (GLint location, GLuint v0, GLuint v1, GLuint v2); void Uniform3ui(Napi::CallbackInfo const& info); // GL_EXPORT void glUniform3uiv (GLint location, GLsizei count, const GLuint* value); void Uniform3uiv(Napi::CallbackInfo const& info); // GL_EXPORT void glUniform4ui (GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3); void Uniform4ui(Napi::CallbackInfo const& info); // GL_EXPORT void glUniform4uiv (GLint location, GLsizei count, const GLuint* value); void Uniform4uiv(Napi::CallbackInfo const& info); // GL_EXPORT void glGetActiveUniformBlockName (GLuint program, GLuint uniformBlockIndex, GLsizei // bufSize, GLsizei* length, GLchar* uniformBlockName); Napi::Value GetActiveUniformBlockName(Napi::CallbackInfo const& info); // GL_EXPORT void glGetActiveUniformBlockiv (GLuint program, GLuint uniformBlockIndex, GLenum // pname, GLint* params); Napi::Value GetActiveUniformBlockiv(Napi::CallbackInfo const& info); // GL_EXPORT void glGetActiveUniformsiv (GLuint program, GLsizei uniformCount, const GLuint* // uniformIndices, GLenum pname, GLint* params); Napi::Value GetActiveUniformsiv(Napi::CallbackInfo const& info); // GL_EXPORT GLuint glGetUniformBlockIndex (GLuint program, const GLchar* uniformBlockName); Napi::Value GetUniformBlockIndex(Napi::CallbackInfo const& info); // GL_EXPORT void glGetUniformIndices (GLuint program, GLsizei uniformCount, const GLchar* const * // uniformNames, GLuint* uniformIndices); Napi::Value GetUniformIndices(Napi::CallbackInfo const& info); // GL_EXPORT void glUniformBlockBinding (GLuint program, GLuint uniformBlockIndex, GLuint // uniformBlockBinding); void UniformBlockBinding(Napi::CallbackInfo const& info); /// // vertex array objects /// // GL_EXPORT void glCreateVertexArrays (GLsizei n, GLuint* arrays); Napi::Value CreateVertexArray(Napi::CallbackInfo const& info); // GL_EXPORT void glCreateVertexArrays (GLsizei n, GLuint* arrays); Napi::Value CreateVertexArrays(Napi::CallbackInfo const& info); // GL_EXPORT void glBindVertexArray (GLuint array); void BindVertexArray(Napi::CallbackInfo const& info); // GL_EXPORT void glDeleteVertexArrays (GLsizei n, const GLuint* arrays); void DeleteVertexArray(Napi::CallbackInfo const& info); // GL_EXPORT void glDeleteVertexArrays (GLsizei n, const GLuint* arrays); void DeleteVertexArrays(Napi::CallbackInfo const& info); // GL_EXPORT GLboolean glIsVertexArray (GLuint array); Napi::Value IsVertexArray(Napi::CallbackInfo const& info); Napi::Value GetContextAttributes(Napi::CallbackInfo const& info); Napi::Value GetClearMask_(Napi::CallbackInfo const& info); void SetClearMask_(Napi::CallbackInfo const& info, Napi::Value const& value); GLbitfield clear_mask_{}; Napi::ObjectReference context_attributes_; // Pixel storage flags bool unpack_flip_y_{}; bool unpack_premultiply_alpha_{}; GLint unpack_colorspace_conversion_{}; GLint unpack_alignment_{}; }; } // namespace nv
0
rapidsai_public_repos/node/modules/webgl
rapidsai_public_repos/node/modules/webgl/src/blend.cpp
// Copyright (c) 2020-2021, NVIDIA CORPORATION. // // 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. #include "macros.hpp" #include "webgl.hpp" #include <nv_node/utilities/args.hpp> #include <nv_node/utilities/cpp_to_napi.hpp> namespace nv { // GL_EXPORT void glBlendColor (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha); void WebGL2RenderingContext::BlendColor(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glBlendColor(args[0], args[1], args[2], args[3]); } // GL_EXPORT void glBlendEquation (GLenum mode); void WebGL2RenderingContext::BlendEquation(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glBlendEquation(args[0]); } // GL_EXPORT void glBlendEquationSeparate (GLenum modeRGB, GLenum modeAlpha); void WebGL2RenderingContext::BlendEquationSeparate(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glBlendEquationSeparate(args[0], args[1]); } // GL_EXPORT void glBlendFunc (GLenum sfactor, GLenum dfactor); void WebGL2RenderingContext::BlendFunc(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glBlendFunc(args[0], args[1]); } // GL_EXPORT void glBlendFuncSeparate (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, // GLenum dfactorAlpha); void WebGL2RenderingContext::BlendFuncSeparate(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glBlendFuncSeparate(args[0], args[1], args[2], args[3]); } } // namespace nv
0
rapidsai_public_repos/node/modules/webgl
rapidsai_public_repos/node/modules/webgl/src/renderbuffer.cpp
// Copyright (c) 2020-2021, NVIDIA CORPORATION. // // 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. #include "macros.hpp" #include "webgl.hpp" #include <nv_node/utilities/args.hpp> #include <nv_node/utilities/cpp_to_napi.hpp> namespace nv { // GL_EXPORT void glCreateRenderbuffers (GLsizei n, GLuint* renderbuffers); Napi::Value WebGL2RenderingContext::CreateRenderbuffer(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLuint renderbuffer{}; GL_EXPORT::glCreateRenderbuffers(1, &renderbuffer); return WebGLRenderbuffer::New(info.Env(), renderbuffer); } // GL_EXPORT void glCreateRenderbuffers (GLsizei n, GLuint* renderbuffers); Napi::Value WebGL2RenderingContext::CreateRenderbuffers(Napi::CallbackInfo const& info) { CallbackArgs args = info; std::vector<GLuint> renderbuffers(args[0].operator size_t()); GL_EXPORT::glCreateRenderbuffers(renderbuffers.size(), renderbuffers.data()); return CPPToNapi(info)(renderbuffers); } // GL_EXPORT void glBindRenderbuffer (GLenum target, GLuint renderbuffer); void WebGL2RenderingContext::BindRenderbuffer(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glBindRenderbuffer(args[0], args[1]); } // GL_EXPORT void glDeleteRenderbuffers (GLsizei n, const GLuint* renderbuffers); void WebGL2RenderingContext::DeleteRenderbuffer(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLuint renderbuffer = args[0]; GL_EXPORT::glDeleteRenderbuffers(1, &renderbuffer); } // GL_EXPORT void glDeleteRenderbuffers (GLsizei n, const GLuint* renderbuffers); void WebGL2RenderingContext::DeleteRenderbuffers(Napi::CallbackInfo const& info) { CallbackArgs args = info; std::vector<GLuint> renderbuffers = args[0]; GL_EXPORT::glDeleteRenderbuffers(renderbuffers.size(), renderbuffers.data()); } // GL_EXPORT void glGetRenderbufferParameteriv (GLenum target, GLenum pname, GLint* params); Napi::Value WebGL2RenderingContext::GetRenderbufferParameteriv(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLint params{}; GL_EXPORT::glGetRenderbufferParameteriv(args[0], args[1], &params); return CPPToNapi(info)(params); } // GL_EXPORT GLboolean glIsRenderbuffer (GLuint renderbuffer); Napi::Value WebGL2RenderingContext::IsRenderbuffer(Napi::CallbackInfo const& info) { CallbackArgs args = info; return CPPToNapi(info)(GL_EXPORT::glIsRenderbuffer(args[0])); } // GL_EXPORT void glRenderbufferStorage (GLenum target, GLenum internalformat, GLsizei width, // GLsizei height); void WebGL2RenderingContext::RenderbufferStorage(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glRenderbufferStorage(args[0], args[1], args[2], args[3]); } // GL_EXPORT void glRenderbufferStorageMultisample (GLenum target, GLsizei samples, GLenum // internalformat, GLsizei width, GLsizei height); void WebGL2RenderingContext::RenderbufferStorageMultisample(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glRenderbufferStorageMultisample(args[0], args[1], args[2], args[3], args[4]); } } // namespace nv
0
rapidsai_public_repos/node/modules/webgl
rapidsai_public_repos/node/modules/webgl/src/texture.cpp
// Copyright (c) 2020-2021, NVIDIA CORPORATION. // // 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. #include "macros.hpp" #include "webgl.hpp" #include <nv_node/utilities/args.hpp> #include <nv_node/utilities/cpp_to_napi.hpp> namespace nv { // GL_EXPORT void glActiveTexture (GLenum texture); void WebGL2RenderingContext::ActiveTexture(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glActiveTexture(args[0]); } // GL_EXPORT void glBindTexture (GLenum target, GLuint texture); void WebGL2RenderingContext::BindTexture(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glBindTexture(args[0], args[1]); } // GL_EXPORT void glCompressedTexImage2D (GLenum target, GLint level, GLenum internalformat, GLsizei // width, GLsizei height, GLint border, GLsizei imageSize, const void *data); void WebGL2RenderingContext::CompressedTexImage2D(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glCompressedTexImage2D( args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7]); } // GL_EXPORT void glCompressedTexImage3D (GLenum target, GLint level, GLenum internalformat, GLsizei // width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const void *data); void WebGL2RenderingContext::CompressedTexImage3D(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glCompressedTexImage3D( args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8]); } // GL_EXPORT void glCompressedTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint // yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *data); void WebGL2RenderingContext::CompressedTexSubImage2D(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glCompressedTexSubImage2D( args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8]); } // GL_EXPORT void glCopyTexImage2D (GLenum target, GLint level, GLenum internalFormat, GLint x, // GLint y, GLsizei width, GLsizei height, GLint border); void WebGL2RenderingContext::CopyTexImage2D(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glCopyTexImage2D( args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7]); } // GL_EXPORT void glCopyTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, // GLint x, GLint y, GLsizei width, GLsizei height); void WebGL2RenderingContext::CopyTexSubImage2D(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glCopyTexSubImage2D( args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7]); } // GL_EXPORT void glGenTextures (GLsizei n, GLuint* textures); Napi::Value WebGL2RenderingContext::CreateTexture(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLuint texture{}; GL_EXPORT::glGenTextures(1, &texture); return WebGLTexture::New(info.Env(), texture); } // GL_EXPORT void glGenTextures (GLsizei n, GLuint* textures); Napi::Value WebGL2RenderingContext::GenTextures(Napi::CallbackInfo const& info) { CallbackArgs args = info; std::vector<GLuint> textures(static_cast<size_t>(args[0])); GL_EXPORT::glGenTextures(textures.size(), textures.data()); return CPPToNapi(info)(textures); } // GL_EXPORT void glDeleteTextures (GLsizei n, const GLuint *textures); void WebGL2RenderingContext::DeleteTexture(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLuint texture = args[0]; GL_EXPORT::glDeleteTextures(1, &texture); } // GL_EXPORT void glDeleteTextures (GLsizei n, const GLuint *textures); void WebGL2RenderingContext::DeleteTextures(Napi::CallbackInfo const& info) { CallbackArgs args = info; std::vector<GLuint> textures = args[0]; GL_EXPORT::glDeleteTextures(textures.size(), textures.data()); } // GL_EXPORT void glGenerateMipmap (GLenum target); void WebGL2RenderingContext::GenerateMipmap(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glGenerateMipmap(args[0]); } // GL_EXPORT void glGetTexParameterfv (GLenum target, GLenum pname, GLfloat *params); // GL_EXPORT void glGetTexParameteriv (GLenum target, GLenum pname, GLint *params); // GL_EXPORT void glGetTexParameterIiv (GLenum target, GLenum pname, GLint* params); // GL_EXPORT void glGetTexParameterIuiv (GLenum target, GLenum pname, GLuint* params); Napi::Value WebGL2RenderingContext::GetTexParameter(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLint target = args[0]; GLint pname = args[1]; switch (pname) { case GL_TEXTURE_IMMUTABLE_FORMAT: { GLint params{}; GL_EXPORT::glGetTexParameteriv(target, pname, &params); return CPPToNapi(info)(static_cast<bool>(params)); } case GL_TEXTURE_MAG_FILTER: case GL_TEXTURE_MIN_FILTER: case GL_TEXTURE_WRAP_S: case GL_TEXTURE_WRAP_T: case GL_TEXTURE_COMPARE_FUNC: case GL_TEXTURE_COMPARE_MODE: case GL_TEXTURE_WRAP_R: case GL_TEXTURE_BASE_LEVEL: case GL_TEXTURE_MAX_LEVEL: { GLint params{}; GL_EXPORT::glGetTexParameteriv(target, pname, &params); return CPPToNapi(info)(params); } case GL_TEXTURE_IMMUTABLE_LEVELS: { GLuint params{}; GL_EXPORT::glGetTexParameterIuiv(target, pname, &params); return CPPToNapi(info)(params); } case GL_TEXTURE_MAX_LOD: case GL_TEXTURE_MIN_LOD: case GL_TEXTURE_MAX_ANISOTROPY_EXT: { GLfloat params{}; GL_EXPORT::glGetTexParameterfv(target, pname, &params); return CPPToNapi(info)(params); } default: GLEW_THROW(info.Env(), GL_INVALID_ENUM); } } // GL_EXPORT GLboolean glIsTexture (GLuint texture); Napi::Value WebGL2RenderingContext::IsTexture(Napi::CallbackInfo const& info) { CallbackArgs args = info; auto is_texture = GL_EXPORT::glIsTexture(args[0]); return CPPToNapi(info.Env())(is_texture); } // GL_EXPORT void glTexImage2D (GLenum target, GLint level, GLint internalformat, GLsizei width, // GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels); void WebGL2RenderingContext::TexImage2D(Napi::CallbackInfo const& info) { CallbackArgs args = info; if (info.Length() < 9 || info[8].IsEmpty() || info[8].IsNull()) { GL_EXPORT::glTexImage2D( args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], nullptr); } else if (info[8].IsNumber()) { GLint offset = args[8]; GL_EXPORT::glTexImage2D(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], reinterpret_cast<void*>(offset)); } else { void* pixels = args[8]; GL_EXPORT::glTexImage2D( args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], pixels); } } // GL_EXPORT void glTexParameterf (GLenum target, GLenum pname, GLfloat param); void WebGL2RenderingContext::TexParameterf(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glTexParameterf(args[0], args[1], args[2]); } // GL_EXPORT void glTexParameteri (GLenum target, GLenum pname, GLint param); void WebGL2RenderingContext::TexParameteri(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glTexParameteri(args[0], args[1], args[2]); } // GL_EXPORT void glTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei // width, GLsizei height, GLenum format, GLenum type, const void *pixels); void WebGL2RenderingContext::TexSubImage2D(Napi::CallbackInfo const& info) { CallbackArgs args = info; if (info.Length() < 9 || info[8].IsEmpty() || info[8].IsNull()) { GL_EXPORT::glTexSubImage2D( args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], nullptr); } else if (info[8].IsNumber()) { GLint offset = args[8]; GL_EXPORT::glTexSubImage2D(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], reinterpret_cast<void*>(offset)); } else { void* pixels = args[8]; GL_EXPORT::glTexSubImage2D( args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], pixels); } } // GL_EXPORT void glCompressedTexSubImage3D (GLenum target, GLint level, GLint xoffset, GLint // yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei // imageSize, const void *data); void WebGL2RenderingContext::CompressedTexSubImage3D(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glCompressedTexSubImage3D(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9], args[10]); } // GL_EXPORT void glCopyTexSubImage3D (GLenum target, GLint level, GLint xoffset, GLint yoffset, // GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); void WebGL2RenderingContext::CopyTexSubImage3D(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glCopyTexSubImage3D( args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8]); } // GL_EXPORT void glTexImage3D (GLenum target, GLint level, GLint internalFormat, GLsizei width, // GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const void *pixels); void WebGL2RenderingContext::TexImage3D(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glTexImage3D( args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9]); } // GL_EXPORT void glTexStorage2D (GLenum target, GLsizei levels, GLenum internalformat, GLsizei // width, GLsizei height); void WebGL2RenderingContext::TexStorage2D(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glTexStorage2D(args[0], args[1], args[2], args[3], args[4]); } // GL_EXPORT void glTexStorage3D (GLenum target, GLsizei levels, GLenum internalformat, GLsizei // width, GLsizei height, GLsizei depth); void WebGL2RenderingContext::TexStorage3D(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glTexStorage3D(args[0], args[1], args[2], args[3], args[4], args[5]); } // GL_EXPORT void glTexSubImage3D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint // zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void // *pixels); void WebGL2RenderingContext::TexSubImage3D(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glTexSubImage3D(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9], args[10]); } } // namespace nv
0
rapidsai_public_repos/node/modules/webgl
rapidsai_public_repos/node/modules/webgl/src/gl.hpp
// Copyright (c) 2020-2021, NVIDIA CORPORATION. // // 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. #pragma once #include <GL/glew.h> #define GL_EXPORT GLAPIENTRY
0
rapidsai_public_repos/node/modules/webgl
rapidsai_public_repos/node/modules/webgl/src/framebuffer.cpp
// Copyright (c) 2020-2021, NVIDIA CORPORATION. // // 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. #include "macros.hpp" #include "webgl.hpp" #include <nv_node/utilities/args.hpp> #include <nv_node/utilities/cpp_to_napi.hpp> namespace nv { // GL_EXPORT void glBindFramebuffer (GLenum target, GLuint framebuffer); void WebGL2RenderingContext::BindFramebuffer(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glBindFramebuffer(args[0], args[1]); } // GL_EXPORT GLenum glCheckFramebufferStatus (GLenum target); Napi::Value WebGL2RenderingContext::CheckFramebufferStatus(Napi::CallbackInfo const& info) { CallbackArgs args = info; return CPPToNapi(info)(GL_EXPORT::glCheckFramebufferStatus(args[0])); } // GL_EXPORT void glCreateFramebuffers (GLsizei n, GLuint* framebuffers); Napi::Value WebGL2RenderingContext::CreateFramebuffer(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLuint framebuffer{}; GL_EXPORT::glCreateFramebuffers(1, &framebuffer); return WebGLFramebuffer::New(info.Env(), framebuffer); } // GL_EXPORT void glCreateFramebuffers (GLsizei n, GLuint* framebuffers); Napi::Value WebGL2RenderingContext::CreateFramebuffers(Napi::CallbackInfo const& info) { CallbackArgs args = info; std::vector<GLuint> framebuffers(args[0].operator size_t()); GL_EXPORT::glCreateFramebuffers(framebuffers.size(), framebuffers.data()); return CPPToNapi(info)(framebuffers); } // GL_EXPORT void glDeleteFramebuffers (GLsizei n, const GLuint* framebuffers); void WebGL2RenderingContext::DeleteFramebuffer(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLuint framebuffer = args[0]; GL_EXPORT::glDeleteFramebuffers(1, &framebuffer); } // GL_EXPORT void glDeleteFramebuffers (GLsizei n, const GLuint* framebuffers); void WebGL2RenderingContext::DeleteFramebuffers(Napi::CallbackInfo const& info) { CallbackArgs args = info; std::vector<GLuint> framebuffers = args[0]; GL_EXPORT::glDeleteFramebuffers(framebuffers.size(), framebuffers.data()); } // GL_EXPORT void glFramebufferRenderbuffer (GLenum target, GLenum attachment, GLenum // renderbuffertarget, GLuint renderbuffer); void WebGL2RenderingContext::FramebufferRenderbuffer(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glFramebufferRenderbuffer(args[0], args[1], args[2], args[3]); } // GL_EXPORT void glFramebufferTexture2D (GLenum target, GLenum attachment, GLenum textarget, GLuint // texture, GLint level); void WebGL2RenderingContext::FramebufferTexture2D(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glFramebufferTexture2D(args[0], args[1], args[2], args[3], args[4]); } // GL_EXPORT void glGetFramebufferAttachmentParameteriv (GLenum target, GLenum attachment, GLenum // pname, GLint* params); Napi::Value WebGL2RenderingContext::GetFramebufferAttachmentParameter( Napi::CallbackInfo const& info) { CallbackArgs args = info; GLint params{}; GL_EXPORT::glGetFramebufferAttachmentParameteriv(args[0], args[1], args[2], &params); return CPPToNapi(info)(params); } // GL_EXPORT GLboolean glIsFramebuffer (GLuint framebuffer); Napi::Value WebGL2RenderingContext::IsFramebuffer(Napi::CallbackInfo const& info) { CallbackArgs args = info; return CPPToNapi(info)(GL_EXPORT::glIsFramebuffer(args[0])); } // GL_EXPORT void glBlitFramebuffer (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint // dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); void WebGL2RenderingContext::BlitFramebuffer(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glBlitFramebuffer( args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9]); } // GL_EXPORT void glFramebufferTextureLayer (GLenum target,GLenum attachment, GLuint texture,GLint // level,GLint layer); void WebGL2RenderingContext::FramebufferTextureLayer(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glFramebufferTextureLayer(args[0], args[1], args[2], args[3], args[4]); } // GL_EXPORT void glInvalidateFramebuffer (GLenum target, GLsizei numAttachments, const GLenum* // attachments); void WebGL2RenderingContext::InvalidateFramebuffer(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glInvalidateFramebuffer(args[0], args[1], args[2]); } // GL_EXPORT void glInvalidateSubFramebuffer (GLenum target, GLsizei numAttachments, const GLenum* // attachments, GLint x, GLint y, GLsizei width, GLsizei height); void WebGL2RenderingContext::InvalidateSubFramebuffer(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glInvalidateSubFramebuffer( args[0], args[1], args[2], args[3], args[4], args[5], args[6]); } } // namespace nv
0
rapidsai_public_repos/node/modules/webgl
rapidsai_public_repos/node/modules/webgl/src/program.cpp
// Copyright (c) 2020-2021, NVIDIA CORPORATION. // // 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. #include "macros.hpp" #include "webgl.hpp" #include <nv_node/utilities/args.hpp> #include <nv_node/utilities/cpp_to_napi.hpp> namespace nv { // GL_EXPORT GLuint glCreateProgram (void); Napi::Value WebGL2RenderingContext::CreateProgram(Napi::CallbackInfo const& info) { return WebGLProgram::New(info.Env(), GL_EXPORT::glCreateProgram()); } // GL_EXPORT void glDeleteProgram (GLuint program); void WebGL2RenderingContext::DeleteProgram(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glDeleteProgram(args[0]); } // GL_EXPORT void glGetProgramInfoLog (GLuint program, GLsizei bufSize, GLsizei* length, GLchar* // infoLog); Napi::Value WebGL2RenderingContext::GetProgramInfoLog(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLint program = args[0]; GLint max_length{}; GL_EXPORT::glGetProgramiv(program, GL_INFO_LOG_LENGTH, &max_length); if (max_length > 0) { GLint length{}; GLchar* info_log = reinterpret_cast<GLchar*>(std::malloc(max_length)); GL_EXPORT::glGetProgramInfoLog(program, max_length, &length, info_log); return CPPToNapi(info)(std::string{info_log, static_cast<size_t>(length)}); } return info.Env().Null(); } // GL_EXPORT void glGetProgramiv (GLuint program, GLenum pname, GLint* param); Napi::Value WebGL2RenderingContext::GetProgramParameter(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLuint program = args[0]; GLuint pname = args[1]; switch (pname) { case GL_LINK_STATUS: case GL_DELETE_STATUS: case GL_VALIDATE_STATUS: { GLint param{}; GL_EXPORT::glGetProgramiv(program, pname, &param); return CPPToNapi(info)(static_cast<bool>(param)); } case GL_ACTIVE_UNIFORMS: case GL_ATTACHED_SHADERS: case GL_ACTIVE_ATTRIBUTES: case GL_ACTIVE_UNIFORM_BLOCKS: case GL_TRANSFORM_FEEDBACK_VARYINGS: case GL_TRANSFORM_FEEDBACK_BUFFER_MODE: { GLint param{}; GL_EXPORT::glGetProgramiv(program, pname, &param); return CPPToNapi(info)(param); } default: GLEW_THROW(info.Env(), GL_INVALID_ENUM); } } // GL_EXPORT GLboolean glIsProgram (GLuint program); Napi::Value WebGL2RenderingContext::IsProgram(Napi::CallbackInfo const& info) { CallbackArgs args = info; auto is_program = GL_EXPORT::glIsProgram(args[0]); return CPPToNapi(info.Env())(is_program); } // GL_EXPORT void glLinkProgram (GLuint program); void WebGL2RenderingContext::LinkProgram(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glLinkProgram(args[0]); } // GL_EXPORT void glUseProgram (GLuint program); void WebGL2RenderingContext::UseProgram(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glUseProgram(args[0]); } // GL_EXPORT void glValidateProgram (GLuint program); void WebGL2RenderingContext::ValidateProgram(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glValidateProgram(args[0]); } } // namespace nv
0
rapidsai_public_repos/node/modules/webgl
rapidsai_public_repos/node/modules/webgl/src/webgl.cpp
// Copyright (c) 2020-2021, NVIDIA CORPORATION. // // 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. #include "webgl.hpp" namespace nv { WebGLActiveInfo::WebGLActiveInfo(Napi::CallbackInfo const& info) : EnvLocalObjectWrap<WebGLActiveInfo>(info) { if (info.Length() > 0) size_ = info[0].ToNumber(); if (info.Length() > 1) type_ = info[1].ToNumber(); if (info.Length() > 2) name_ = info[2].ToString(); }; Napi::Function WebGLActiveInfo::Init(Napi::Env const& env, Napi::Object exports) { return DefineClass( env, "WebGLActiveInfo", { InstanceAccessor("size", &WebGLActiveInfo::GetSize, nullptr, napi_enumerable), InstanceAccessor("type", &WebGLActiveInfo::GetType, nullptr, napi_enumerable), InstanceAccessor("name", &WebGLActiveInfo::GetName, nullptr, napi_enumerable), InstanceMethod("toString", &WebGLActiveInfo::ToString), }); }; WebGLActiveInfo::wrapper_t WebGLActiveInfo::New(Napi::Env const& env, GLint size, GLuint type, std::string name) { return EnvLocalObjectWrap<WebGLActiveInfo>::New(env, size, type, name); }; Napi::Value WebGLActiveInfo::GetSize(Napi::CallbackInfo const& info) { return Napi::Number::New(this->Env(), this->size_); } Napi::Value WebGLActiveInfo::GetType(Napi::CallbackInfo const& info) { return Napi::Number::New(this->Env(), this->type_); } Napi::Value WebGLActiveInfo::GetName(Napi::CallbackInfo const& info) { return Napi::String::New(this->Env(), this->name_); } Napi::Value WebGLActiveInfo::ToString(Napi::CallbackInfo const& info) { return Napi::String::New(this->Env(), std::string{"[ WebGLActiveInfo"} + " size=" + std::to_string(size_) + " type=" + std::to_string(type_) + " name='" + name_ + "' ]"); } WebGLShaderPrecisionFormat::WebGLShaderPrecisionFormat(Napi::CallbackInfo const& info) : EnvLocalObjectWrap<WebGLShaderPrecisionFormat>(info) { if (info.Length() > 0) rangeMin_ = info[0].ToNumber(); if (info.Length() > 1) rangeMax_ = info[1].ToNumber(); if (info.Length() > 2) precision_ = info[2].ToNumber(); }; Napi::Function WebGLShaderPrecisionFormat::Init(Napi::Env const& env, Napi::Object exports) { return DefineClass( env, "WebGLShaderPrecisionFormat", { InstanceAccessor( "rangeMin", &WebGLShaderPrecisionFormat::GetRangeMax, nullptr, napi_enumerable), InstanceAccessor( "rangeMax", &WebGLShaderPrecisionFormat::GetRangeMin, nullptr, napi_enumerable), InstanceAccessor( "precision", &WebGLShaderPrecisionFormat::GetPrecision, nullptr, napi_enumerable), InstanceMethod("toString", &WebGLShaderPrecisionFormat::ToString), }); }; WebGLShaderPrecisionFormat::wrapper_t WebGLShaderPrecisionFormat::New(Napi::Env const& env, GLint rangeMin, GLint rangeMax, GLint precision) { return EnvLocalObjectWrap<WebGLShaderPrecisionFormat>::New(env, rangeMin, rangeMax, precision); }; Napi::Value WebGLShaderPrecisionFormat::GetRangeMin(Napi::CallbackInfo const& info) { return Napi::Number::New(this->Env(), this->rangeMin_); } Napi::Value WebGLShaderPrecisionFormat::GetRangeMax(Napi::CallbackInfo const& info) { return Napi::Number::New(this->Env(), this->rangeMax_); } Napi::Value WebGLShaderPrecisionFormat::GetPrecision(Napi::CallbackInfo const& info) { return Napi::Number::New(this->Env(), this->precision_); } Napi::Value WebGLShaderPrecisionFormat::ToString(Napi::CallbackInfo const& info) { return Napi::String::New( this->Env(), std::string{"[ WebGLShaderPrecisionFormat"} + " rangeMax=" + std::to_string(rangeMax_) + " rangeMin=" + std::to_string(rangeMin_) + " precision=" + std::to_string(precision_) + " ]"); } WebGLBuffer::WebGLBuffer(Napi::CallbackInfo const& info) : EnvLocalObjectWrap<WebGLBuffer>(info) { if (info.Length() > 0) value_ = info[0].ToNumber(); }; WebGLBuffer::wrapper_t WebGLBuffer::New(Napi::Env const& env, GLuint value) { return EnvLocalObjectWrap<WebGLBuffer>::New(env, value); }; Napi::Function WebGLBuffer::Init(Napi::Env const& env, Napi::Object exports) { return DefineClass(env, "WebGLBuffer", { InstanceAccessor("ptr", &WebGLBuffer::GetValue, nullptr, napi_enumerable), InstanceMethod("toString", &WebGLBuffer::ToString), }); }; Napi::Value WebGLBuffer::ToString(Napi::CallbackInfo const& info) { return Napi::String::New(this->Env(), "[ WebGLBuffer " + std::to_string(this->value_) + " ]"); } Napi::Value WebGLBuffer::GetValue(Napi::CallbackInfo const& info) { return Napi::Number::New(this->Env(), this->value_); } WebGLContextEvent::WebGLContextEvent(Napi::CallbackInfo const& info) : EnvLocalObjectWrap<WebGLContextEvent>(info) { if (info.Length() > 0) value_ = info[0].ToNumber(); }; WebGLContextEvent::wrapper_t WebGLContextEvent::New(Napi::Env const& env, GLuint value) { return EnvLocalObjectWrap<WebGLContextEvent>::New(env, value); }; Napi::Function WebGLContextEvent::Init(Napi::Env const& env, Napi::Object exports) { return DefineClass( env, "WebGLContextEvent", { InstanceAccessor("ptr", &WebGLContextEvent::GetValue, nullptr, napi_enumerable), InstanceMethod("toString", &WebGLContextEvent::ToString), }); }; Napi::Value WebGLContextEvent::ToString(Napi::CallbackInfo const& info) { return Napi::String::New(this->Env(), "[ WebGLContextEvent " + std::to_string(this->value_) + " ]"); } Napi::Value WebGLContextEvent::GetValue(Napi::CallbackInfo const& info) { return Napi::Number::New(this->Env(), this->value_); } WebGLFramebuffer::WebGLFramebuffer(Napi::CallbackInfo const& info) : EnvLocalObjectWrap<WebGLFramebuffer>(info) { if (info.Length() > 0) value_ = info[0].ToNumber(); }; WebGLFramebuffer::wrapper_t WebGLFramebuffer::New(Napi::Env const& env, GLuint value) { return EnvLocalObjectWrap<WebGLFramebuffer>::New(env, value); }; Napi::Function WebGLFramebuffer::Init(Napi::Env const& env, Napi::Object exports) { return DefineClass( env, "WebGLFramebuffer", { InstanceAccessor("ptr", &WebGLFramebuffer::GetValue, nullptr, napi_enumerable), InstanceMethod("toString", &WebGLFramebuffer::ToString), }); }; Napi::Value WebGLFramebuffer::ToString(Napi::CallbackInfo const& info) { return Napi::String::New(this->Env(), "[ WebGLFramebuffer " + std::to_string(this->value_) + " ]"); } Napi::Value WebGLFramebuffer::GetValue(Napi::CallbackInfo const& info) { return Napi::Number::New(this->Env(), this->value_); } WebGLProgram::WebGLProgram(Napi::CallbackInfo const& info) : EnvLocalObjectWrap<WebGLProgram>(info) { if (info.Length() > 0) value_ = info[0].ToNumber(); }; WebGLProgram::wrapper_t WebGLProgram::New(Napi::Env const& env, GLuint value) { return EnvLocalObjectWrap<WebGLProgram>::New(env, value); }; Napi::Function WebGLProgram::Init(Napi::Env const& env, Napi::Object exports) { return DefineClass(env, "WebGLProgram", { InstanceAccessor("ptr", &WebGLProgram::GetValue, nullptr, napi_enumerable), InstanceMethod("toString", &WebGLProgram::ToString), }); }; Napi::Value WebGLProgram::ToString(Napi::CallbackInfo const& info) { return Napi::String::New(this->Env(), "[ WebGLProgram " + std::to_string(this->value_) + " ]"); } Napi::Value WebGLProgram::GetValue(Napi::CallbackInfo const& info) { return Napi::Number::New(this->Env(), this->value_); } WebGLQuery::WebGLQuery(Napi::CallbackInfo const& info) : EnvLocalObjectWrap<WebGLQuery>(info) { if (info.Length() > 0) value_ = info[0].ToNumber(); }; WebGLQuery::wrapper_t WebGLQuery::New(Napi::Env const& env, GLuint value) { return EnvLocalObjectWrap<WebGLQuery>::New(env, value); }; Napi::Function WebGLQuery::Init(Napi::Env const& env, Napi::Object exports) { return DefineClass(env, "WebGLQuery", { InstanceAccessor("ptr", &WebGLQuery::GetValue, nullptr, napi_enumerable), InstanceMethod("toString", &WebGLQuery::ToString), }); }; Napi::Value WebGLQuery::ToString(Napi::CallbackInfo const& info) { return Napi::String::New(this->Env(), "[ WebGLQuery " + std::to_string(this->value_) + " ]"); } Napi::Value WebGLQuery::GetValue(Napi::CallbackInfo const& info) { return Napi::Number::New(this->Env(), this->value_); } WebGLRenderbuffer::WebGLRenderbuffer(Napi::CallbackInfo const& info) : EnvLocalObjectWrap<WebGLRenderbuffer>(info) { if (info.Length() > 0) value_ = info[0].ToNumber(); }; WebGLRenderbuffer::wrapper_t WebGLRenderbuffer::New(Napi::Env const& env, GLuint value) { return EnvLocalObjectWrap<WebGLRenderbuffer>::New(env, value); }; Napi::Function WebGLRenderbuffer::Init(Napi::Env const& env, Napi::Object exports) { return DefineClass( env, "WebGLRenderbuffer", { InstanceAccessor("ptr", &WebGLRenderbuffer::GetValue, nullptr, napi_enumerable), InstanceMethod("toString", &WebGLRenderbuffer::ToString), }); }; Napi::Value WebGLRenderbuffer::ToString(Napi::CallbackInfo const& info) { return Napi::String::New(this->Env(), "[ WebGLRenderbuffer " + std::to_string(this->value_) + " ]"); } Napi::Value WebGLRenderbuffer::GetValue(Napi::CallbackInfo const& info) { return Napi::Number::New(this->Env(), this->value_); } WebGLSampler::WebGLSampler(Napi::CallbackInfo const& info) : EnvLocalObjectWrap<WebGLSampler>(info) { if (info.Length() > 0) value_ = info[0].ToNumber(); }; WebGLSampler::wrapper_t WebGLSampler::New(Napi::Env const& env, GLuint value) { return EnvLocalObjectWrap<WebGLSampler>::New(env, value); }; Napi::Function WebGLSampler::Init(Napi::Env const& env, Napi::Object exports) { return DefineClass(env, "WebGLSampler", { InstanceAccessor("ptr", &WebGLSampler::GetValue, nullptr, napi_enumerable), InstanceMethod("toString", &WebGLSampler::ToString), }); }; Napi::Value WebGLSampler::ToString(Napi::CallbackInfo const& info) { return Napi::String::New(this->Env(), "[ WebGLSampler " + std::to_string(this->value_) + " ]"); } Napi::Value WebGLSampler::GetValue(Napi::CallbackInfo const& info) { return Napi::Number::New(this->Env(), this->value_); } WebGLShader::WebGLShader(Napi::CallbackInfo const& info) : EnvLocalObjectWrap<WebGLShader>(info) { if (info.Length() > 0) value_ = info[0].ToNumber(); }; WebGLShader::wrapper_t WebGLShader::New(Napi::Env const& env, GLuint value) { return EnvLocalObjectWrap<WebGLShader>::New(env, value); }; Napi::Function WebGLShader::Init(Napi::Env const& env, Napi::Object exports) { return DefineClass(env, "WebGLShader", { InstanceAccessor("ptr", &WebGLShader::GetValue, nullptr, napi_enumerable), InstanceMethod("toString", &WebGLShader::ToString), }); }; Napi::Value WebGLShader::ToString(Napi::CallbackInfo const& info) { return Napi::String::New(this->Env(), "[ WebGLShader " + std::to_string(this->value_) + " ]"); } Napi::Value WebGLShader::GetValue(Napi::CallbackInfo const& info) { return Napi::Number::New(this->Env(), this->value_); } WebGLSync::WebGLSync(Napi::CallbackInfo const& info) : EnvLocalObjectWrap<WebGLSync>(info) { if (info.Length() > 0) { value_ = reinterpret_cast<GLsync>(info[0].As<Napi::External<void>>().Data()); } }; WebGLSync::wrapper_t WebGLSync::New(Napi::Env const& env, GLsync value) { return EnvLocalObjectWrap<WebGLSync>::New(env, {Napi::External<void>::New(env, value)}); }; Napi::Function WebGLSync::Init(Napi::Env const& env, Napi::Object exports) { return DefineClass(env, "WebGLSync", { InstanceAccessor("ptr", &WebGLSync::GetValue, nullptr, napi_enumerable), InstanceMethod("toString", &WebGLSync::ToString), }); }; Napi::Value WebGLSync::ToString(Napi::CallbackInfo const& info) { return Napi::String::New( this->Env(), "[ WebGLSync " + std::to_string(reinterpret_cast<uintptr_t>(this->value_)) + " ]"); } Napi::Value WebGLSync::GetValue(Napi::CallbackInfo const& info) { return Napi::Number::New(this->Env(), reinterpret_cast<uintptr_t>(this->value_)); } WebGLTexture::WebGLTexture(Napi::CallbackInfo const& info) : EnvLocalObjectWrap<WebGLTexture>(info) { if (info.Length() > 0) value_ = info[0].ToNumber(); }; WebGLTexture::wrapper_t WebGLTexture::New(Napi::Env const& env, GLuint value) { return EnvLocalObjectWrap<WebGLTexture>::New(env, value); }; Napi::Function WebGLTexture::Init(Napi::Env const& env, Napi::Object exports) { return DefineClass(env, "WebGLTexture", { InstanceAccessor("ptr", &WebGLTexture::GetValue, nullptr, napi_enumerable), InstanceMethod("toString", &WebGLTexture::ToString), }); }; Napi::Value WebGLTexture::ToString(Napi::CallbackInfo const& info) { return Napi::String::New(this->Env(), "[ WebGLTexture " + std::to_string(this->value_) + " ]"); } Napi::Value WebGLTexture::GetValue(Napi::CallbackInfo const& info) { return Napi::Number::New(this->Env(), this->value_); } WebGLTransformFeedback::WebGLTransformFeedback(Napi::CallbackInfo const& info) : EnvLocalObjectWrap<WebGLTransformFeedback>(info) { if (info.Length() > 0) value_ = info[0].ToNumber(); }; WebGLTransformFeedback::wrapper_t WebGLTransformFeedback::New(Napi::Env const& env, GLuint value) { return EnvLocalObjectWrap<WebGLTransformFeedback>::New(env, value); }; Napi::Function WebGLTransformFeedback::Init(Napi::Env const& env, Napi::Object exports) { return DefineClass( env, "WebGLTransformFeedback", { InstanceAccessor("ptr", &WebGLTransformFeedback::GetValue, nullptr, napi_enumerable), InstanceMethod("toString", &WebGLTransformFeedback::ToString), }); }; Napi::Value WebGLTransformFeedback::ToString(Napi::CallbackInfo const& info) { return Napi::String::New(this->Env(), "[ WebGLTransformFeedback " + std::to_string(this->value_) + " ]"); } Napi::Value WebGLTransformFeedback::GetValue(Napi::CallbackInfo const& info) { return Napi::Number::New(this->Env(), this->value_); } WebGLUniformLocation::WebGLUniformLocation(Napi::CallbackInfo const& info) : EnvLocalObjectWrap<WebGLUniformLocation>(info) { if (info.Length() > 0) value_ = info[0].ToNumber(); }; WebGLUniformLocation::wrapper_t WebGLUniformLocation::New(Napi::Env const& env, GLint value) { return EnvLocalObjectWrap<WebGLUniformLocation>::New(env, value); }; Napi::Function WebGLUniformLocation::Init(Napi::Env const& env, Napi::Object exports) { return DefineClass( env, "WebGLUniformLocation", { InstanceAccessor("ptr", &WebGLUniformLocation::GetValue, nullptr, napi_enumerable), InstanceMethod("toString", &WebGLUniformLocation::ToString), }); }; Napi::Value WebGLUniformLocation::ToString(Napi::CallbackInfo const& info) { return Napi::String::New(this->Env(), "[ WebGLUniformLocation " + std::to_string(this->value_) + " ]"); } Napi::Value WebGLUniformLocation::GetValue(Napi::CallbackInfo const& info) { return Napi::Number::New(this->Env(), this->value_); } WebGLVertexArrayObject::WebGLVertexArrayObject(Napi::CallbackInfo const& info) : EnvLocalObjectWrap<WebGLVertexArrayObject>(info) { if (info.Length() > 0) value_ = info[0].ToNumber(); }; WebGLVertexArrayObject::wrapper_t WebGLVertexArrayObject::New(Napi::Env const& env, GLuint value) { return EnvLocalObjectWrap<WebGLVertexArrayObject>::New(env, value); }; Napi::Function WebGLVertexArrayObject::Init(Napi::Env const& env, Napi::Object exports) { return DefineClass( env, "WebGLVertexArrayObject", { InstanceAccessor("ptr", &WebGLVertexArrayObject::GetValue, nullptr, napi_enumerable), InstanceMethod("toString", &WebGLVertexArrayObject::ToString), }); }; Napi::Value WebGLVertexArrayObject::ToString(Napi::CallbackInfo const& info) { return Napi::String::New(this->Env(), "[ WebGLVertexArrayObject " + std::to_string(this->value_) + " ]"); } Napi::Value WebGLVertexArrayObject::GetValue(Napi::CallbackInfo const& info) { return Napi::Number::New(this->Env(), this->value_); } } // namespace nv
0
rapidsai_public_repos/node/modules/webgl
rapidsai_public_repos/node/modules/webgl/src/addon.cpp
// Copyright (c) 2020-2021, NVIDIA CORPORATION. // // 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. #include "webgl.hpp" #include <nv_node/addon.hpp> #include <nv_node/utilities/napi_to_cpp.hpp> #include <napi.h> struct rapidsai_webgl : public nv::EnvLocalAddon, public Napi::Addon<rapidsai_webgl> { rapidsai_webgl(Napi::Env const& env, Napi::Object exports) : nv::EnvLocalAddon(env, exports) { DefineAddon( exports, { InstanceValue("_cpp_exports", _cpp_exports.Value()), InstanceMethod("init", &rapidsai_webgl::InitAddon), InstanceValue("WebGL2RenderingContext", InitClass<nv::WebGL2RenderingContext>(env, exports)), InstanceValue("WebGLActiveInfo", InitClass<nv::WebGLActiveInfo>(env, exports)), InstanceValue("WebGLShaderPrecisionFormat", InitClass<nv::WebGLShaderPrecisionFormat>(env, exports)), InstanceValue("WebGLBuffer", InitClass<nv::WebGLBuffer>(env, exports)), InstanceValue("WebGLContextEvent", InitClass<nv::WebGLContextEvent>(env, exports)), InstanceValue("WebGLFramebuffer", InitClass<nv::WebGLFramebuffer>(env, exports)), InstanceValue("WebGLProgram", InitClass<nv::WebGLProgram>(env, exports)), InstanceValue("WebGLQuery", InitClass<nv::WebGLQuery>(env, exports)), InstanceValue("WebGLRenderbuffer", InitClass<nv::WebGLRenderbuffer>(env, exports)), InstanceValue("WebGLSampler", InitClass<nv::WebGLSampler>(env, exports)), InstanceValue("WebGLShader", InitClass<nv::WebGLShader>(env, exports)), InstanceValue("WebGLSync", InitClass<nv::WebGLSync>(env, exports)), InstanceValue("WebGLTexture", InitClass<nv::WebGLTexture>(env, exports)), InstanceValue("WebGLTransformFeedback", InitClass<nv::WebGLTransformFeedback>(env, exports)), InstanceValue("WebGLUniformLocation", InitClass<nv::WebGLUniformLocation>(env, exports)), InstanceValue("WebGLVertexArrayObject", InitClass<nv::WebGLVertexArrayObject>(env, exports)), }); } }; NODE_API_ADDON(rapidsai_webgl);
0
rapidsai_public_repos/node/modules/webgl
rapidsai_public_repos/node/modules/webgl/src/sampler.cpp
// Copyright (c) 2020-2021, NVIDIA CORPORATION. // // 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. #include "macros.hpp" #include "webgl.hpp" #include <nv_node/utilities/args.hpp> #include <nv_node/utilities/cpp_to_napi.hpp> namespace nv { // GL_EXPORT void glBindSampler (GLuint unit, GLuint sampler); void WebGL2RenderingContext::BindSampler(Napi::CallbackInfo const& info) { CallbackArgs args = info; std::vector<GLuint> samplers = args[0]; GL_EXPORT::glBindSampler(args[0], args[1]); } // GL_EXPORT void glCreateSamplers (GLsizei n, GLuint* samplers); Napi::Value WebGL2RenderingContext::CreateSampler(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLuint sampler{}; GL_EXPORT::glCreateSamplers(1, &sampler); return WebGLSampler::New(info.Env(), sampler); } // GL_EXPORT void glCreateSamplers (GLsizei n, GLuint* samplers); Napi::Value WebGL2RenderingContext::CreateSamplers(Napi::CallbackInfo const& info) { CallbackArgs args = info; std::vector<GLuint> samplers(static_cast<size_t>(args[0])); GL_EXPORT::glCreateSamplers(samplers.size(), samplers.data()); return CPPToNapi(info)(samplers); } // GL_EXPORT void glDeleteSamplers (GLsizei count, const GLuint * samplers); void WebGL2RenderingContext::DeleteSampler(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLuint sampler = args[0]; GL_EXPORT::glDeleteSamplers(1, &sampler); } // GL_EXPORT void glDeleteSamplers (GLsizei count, const GLuint * samplers); void WebGL2RenderingContext::DeleteSamplers(Napi::CallbackInfo const& info) { CallbackArgs args = info; std::vector<GLuint> samplers = args[0]; GL_EXPORT::glDeleteSamplers(samplers.size(), samplers.data()); } // GL_EXPORT void glGetSamplerParameterfv (GLuint sampler, GLenum pname, GLfloat* params); // GL_EXPORT void glGetSamplerParameteriv (GLuint sampler, GLenum pname, GLint* params); Napi::Value WebGL2RenderingContext::GetSamplerParameter(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLuint sampler = args[0]; GLint pname = args[1]; switch (pname) { case GL_TEXTURE_MAX_LOD: case GL_TEXTURE_MIN_LOD: { GLfloat params{}; GL_EXPORT::glGetSamplerParameterfv(sampler, pname, &params); return CPPToNapi(info)(params); } case GL_TEXTURE_WRAP_R: case GL_TEXTURE_WRAP_S: case GL_TEXTURE_WRAP_T: case GL_TEXTURE_MAG_FILTER: case GL_TEXTURE_MIN_FILTER: case GL_TEXTURE_COMPARE_FUNC: case GL_TEXTURE_COMPARE_MODE: { GLint params{}; GL_EXPORT::glGetSamplerParameteriv(sampler, pname, &params); return CPPToNapi(info)(params); } default: GLEW_THROW(info.Env(), GL_INVALID_ENUM); } } // GL_EXPORT GLboolean glIsSampler (GLuint sampler); Napi::Value WebGL2RenderingContext::IsSampler(Napi::CallbackInfo const& info) { CallbackArgs args = info; auto is_sampler = GL_EXPORT::glIsSampler(args[0]); return CPPToNapi(info.Env())(is_sampler); } // GL_EXPORT void glSamplerParameterf (GLuint sampler, GLenum pname, GLfloat param); void WebGL2RenderingContext::SamplerParameterf(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glSamplerParameterf(args[0], args[1], args[2]); } // GL_EXPORT void glSamplerParameteri (GLuint sampler, GLenum pname, GLint param); void WebGL2RenderingContext::SamplerParameteri(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glSamplerParameteri(args[0], args[1], args[2]); } } // namespace nv
0
rapidsai_public_repos/node/modules/webgl
rapidsai_public_repos/node/modules/webgl/src/context.cpp
// Copyright (c) 2020-2021, NVIDIA CORPORATION. // // 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. #include "macros.hpp" #include "webgl.hpp" #include <nv_node/utilities/args.hpp> #include <nv_node/utilities/cpp_to_napi.hpp> #include <iterator> #include <sstream> namespace nv { WebGL2RenderingContext::WebGL2RenderingContext(Napi::CallbackInfo const& info) : EnvLocalObjectWrap<WebGL2RenderingContext>(info) { glewExperimental = GL_TRUE; GL_EXPECT_OK(Env(), GLEWAPIENTRY::glewInit()); if (info[0].IsNull() || info[0].IsEmpty() || !info[0].IsObject()) { context_attributes_ = Napi::Persistent(Napi::Object::New(Env())); } else { context_attributes_ = Napi::Persistent(info[0].As<Napi::Object>()); } // TODO: Is this necessary? // // auto attrs = context_attributes_.Value(); // if (attrs.Has("antialias") && attrs.Get("antialias").ToBoolean().Value() == true) { // GL_EXPORT::glEnable(GL_LINE_SMOOTH); // GL_EXPORT::glEnable(GL_POLYGON_SMOOTH); // } // // GL_EXPORT::glEnable(GL_PROGRAM_POINT_SIZE); // GL_EXPORT::glEnable(GL_POINT_SPRITE); }; Napi::Function WebGL2RenderingContext::Init(Napi::Env const& env, Napi::Object exports) { return DefineClass( env, "WebGL2RenderingContext", { InstanceAccessor("_clearMask", &WebGL2RenderingContext::GetClearMask_, &WebGL2RenderingContext::SetClearMask_, napi_default), #define INST_METHOD(key, func) \ InstanceMethod( \ key, \ func, \ static_cast<napi_property_attributes>(napi_writable | napi_enumerable | napi_configurable)) // INST_METHOD("isSupported", &WebGL2RenderingContext::IsSupported), // INST_METHOD("getExtension", &WebGL2RenderingContext::GetExtension), // INST_METHOD("getString", &WebGL2RenderingContext::GetString), // INST_METHOD("getErrorString", &WebGL2RenderingContext::GetErrorString), INST_METHOD("clear", &WebGL2RenderingContext::Clear), INST_METHOD("clearColor", &WebGL2RenderingContext::ClearColor), INST_METHOD("clearDepth", &WebGL2RenderingContext::ClearDepth), INST_METHOD("colorMask", &WebGL2RenderingContext::ColorMask), INST_METHOD("cullFace", &WebGL2RenderingContext::CullFace), INST_METHOD("depthFunc", &WebGL2RenderingContext::DepthFunc), INST_METHOD("depthMask", &WebGL2RenderingContext::DepthMask), INST_METHOD("depthRange", &WebGL2RenderingContext::DepthRange), INST_METHOD("disable", &WebGL2RenderingContext::Disable), INST_METHOD("drawArrays", &WebGL2RenderingContext::DrawArrays), INST_METHOD("drawElements", &WebGL2RenderingContext::DrawElements), INST_METHOD("enable", &WebGL2RenderingContext::Enable), INST_METHOD("finish", &WebGL2RenderingContext::Finish), INST_METHOD("flush", &WebGL2RenderingContext::Flush), INST_METHOD("frontFace", &WebGL2RenderingContext::FrontFace), INST_METHOD("getError", &WebGL2RenderingContext::GetError), INST_METHOD("hint", &WebGL2RenderingContext::Hint), INST_METHOD("isEnabled", &WebGL2RenderingContext::IsEnabled), INST_METHOD("lineWidth", &WebGL2RenderingContext::LineWidth), INST_METHOD("pixelStorei", &WebGL2RenderingContext::PixelStorei), INST_METHOD("polygonOffset", &WebGL2RenderingContext::PolygonOffset), INST_METHOD("readPixels", &WebGL2RenderingContext::ReadPixels), INST_METHOD("scissor", &WebGL2RenderingContext::Scissor), INST_METHOD("viewport", &WebGL2RenderingContext::Viewport), INST_METHOD("drawRangeElements", &WebGL2RenderingContext::DrawRangeElements), INST_METHOD("sampleCoverage", &WebGL2RenderingContext::SampleCoverage), INST_METHOD("getContextAttributes", &WebGL2RenderingContext::GetContextAttributes), INST_METHOD("getFragDataLocation", &WebGL2RenderingContext::GetFragDataLocation), INST_METHOD("getParameter", &WebGL2RenderingContext::GetParameter), INST_METHOD("getSupportedExtensions", &WebGL2RenderingContext::GetSupportedExtensions), INST_METHOD("bindAttribLocation", &WebGL2RenderingContext::BindAttribLocation), INST_METHOD("disableVertexAttribArray", &WebGL2RenderingContext::DisableVertexAttribArray), INST_METHOD("enableVertexAttribArray", &WebGL2RenderingContext::EnableVertexAttribArray), INST_METHOD("getActiveAttrib", &WebGL2RenderingContext::GetActiveAttrib), INST_METHOD("getAttribLocation", &WebGL2RenderingContext::GetAttribLocation), INST_METHOD("getVertexAttrib", &WebGL2RenderingContext::GetVertexAttrib), INST_METHOD("getVertexAttribOffset", &WebGL2RenderingContext::GetVertexAttribPointerv), INST_METHOD("vertexAttrib1f", &WebGL2RenderingContext::VertexAttrib1f), INST_METHOD("vertexAttrib1fv", &WebGL2RenderingContext::VertexAttrib1fv), INST_METHOD("vertexAttrib2f", &WebGL2RenderingContext::VertexAttrib2f), INST_METHOD("vertexAttrib2fv", &WebGL2RenderingContext::VertexAttrib2fv), INST_METHOD("vertexAttrib3f", &WebGL2RenderingContext::VertexAttrib3f), INST_METHOD("vertexAttrib3fv", &WebGL2RenderingContext::VertexAttrib3fv), INST_METHOD("vertexAttrib4f", &WebGL2RenderingContext::VertexAttrib4f), INST_METHOD("vertexAttrib4fv", &WebGL2RenderingContext::VertexAttrib4fv), INST_METHOD("vertexAttribPointer", &WebGL2RenderingContext::VertexAttribPointer), INST_METHOD("vertexAttribI4i", &WebGL2RenderingContext::VertexAttribI4i), INST_METHOD("vertexAttribI4iv", &WebGL2RenderingContext::VertexAttribI4iv), INST_METHOD("vertexAttribI4ui", &WebGL2RenderingContext::VertexAttribI4ui), INST_METHOD("vertexAttribI4uiv", &WebGL2RenderingContext::VertexAttribI4uiv), INST_METHOD("vertexAttribIPointer", &WebGL2RenderingContext::VertexAttribIPointer), INST_METHOD("blendColor", &WebGL2RenderingContext::BlendColor), INST_METHOD("blendEquation", &WebGL2RenderingContext::BlendEquation), INST_METHOD("blendEquationSeparate", &WebGL2RenderingContext::BlendEquationSeparate), INST_METHOD("blendFunc", &WebGL2RenderingContext::BlendFunc), INST_METHOD("blendFuncSeparate", &WebGL2RenderingContext::BlendFuncSeparate), INST_METHOD("bindBuffer", &WebGL2RenderingContext::BindBuffer), INST_METHOD("bufferData", &WebGL2RenderingContext::BufferData), INST_METHOD("bufferSubData", &WebGL2RenderingContext::BufferSubData), INST_METHOD("createBuffer", &WebGL2RenderingContext::CreateBuffer), INST_METHOD("createBuffers", &WebGL2RenderingContext::CreateBuffers), INST_METHOD("deleteBuffer", &WebGL2RenderingContext::DeleteBuffer), INST_METHOD("deleteBuffers", &WebGL2RenderingContext::DeleteBuffers), INST_METHOD("getBufferParameter", &WebGL2RenderingContext::GetBufferParameter), INST_METHOD("isBuffer", &WebGL2RenderingContext::IsBuffer), INST_METHOD("bindBufferBase", &WebGL2RenderingContext::BindBufferBase), INST_METHOD("bindBufferRange", &WebGL2RenderingContext::BindBufferRange), INST_METHOD("clearBufferfv", &WebGL2RenderingContext::ClearBufferfv), INST_METHOD("clearBufferiv", &WebGL2RenderingContext::ClearBufferiv), INST_METHOD("clearBufferuiv", &WebGL2RenderingContext::ClearBufferuiv), INST_METHOD("clearBufferfi", &WebGL2RenderingContext::ClearBufferfi), INST_METHOD("copyBufferSubData", &WebGL2RenderingContext::CopyBufferSubData), INST_METHOD("drawBuffers", &WebGL2RenderingContext::DrawBuffers), INST_METHOD("getBufferSubData", &WebGL2RenderingContext::GetBufferSubData), INST_METHOD("readBuffer", &WebGL2RenderingContext::ReadBuffer), INST_METHOD("bindFramebuffer", &WebGL2RenderingContext::BindFramebuffer), INST_METHOD("checkFramebufferStatus", &WebGL2RenderingContext::CheckFramebufferStatus), INST_METHOD("createFramebuffer", &WebGL2RenderingContext::CreateFramebuffer), INST_METHOD("createFramebuffers", &WebGL2RenderingContext::CreateFramebuffers), INST_METHOD("deleteFramebuffer", &WebGL2RenderingContext::DeleteFramebuffer), INST_METHOD("deleteFramebuffers", &WebGL2RenderingContext::DeleteFramebuffers), INST_METHOD("framebufferRenderbuffer", &WebGL2RenderingContext::FramebufferRenderbuffer), INST_METHOD("framebufferTexture2D", &WebGL2RenderingContext::FramebufferTexture2D), INST_METHOD("getFramebufferAttachmentParameter", &WebGL2RenderingContext::GetFramebufferAttachmentParameter), INST_METHOD("isFramebuffer", &WebGL2RenderingContext::IsFramebuffer), INST_METHOD("blitFramebuffer", &WebGL2RenderingContext::BlitFramebuffer), INST_METHOD("framebufferTextureLayer", &WebGL2RenderingContext::FramebufferTextureLayer), INST_METHOD("invalidateFramebuffer", &WebGL2RenderingContext::InvalidateFramebuffer), INST_METHOD("invalidateSubFramebuffer", &WebGL2RenderingContext::InvalidateSubFramebuffer), INST_METHOD("drawArraysInstanced", &WebGL2RenderingContext::DrawArraysInstanced), INST_METHOD("drawElementsInstanced", &WebGL2RenderingContext::DrawElementsInstanced), INST_METHOD("vertexAttribDivisor", &WebGL2RenderingContext::VertexAttribDivisor), INST_METHOD("createProgram", &WebGL2RenderingContext::CreateProgram), INST_METHOD("deleteProgram", &WebGL2RenderingContext::DeleteProgram), INST_METHOD("getProgramInfoLog", &WebGL2RenderingContext::GetProgramInfoLog), INST_METHOD("getProgramParameter", &WebGL2RenderingContext::GetProgramParameter), INST_METHOD("isProgram", &WebGL2RenderingContext::IsProgram), INST_METHOD("linkProgram", &WebGL2RenderingContext::LinkProgram), INST_METHOD("useProgram", &WebGL2RenderingContext::UseProgram), INST_METHOD("validateProgram", &WebGL2RenderingContext::ValidateProgram), INST_METHOD("beginQuery", &WebGL2RenderingContext::BeginQuery), INST_METHOD("createQuery", &WebGL2RenderingContext::CreateQuery), INST_METHOD("createQueries", &WebGL2RenderingContext::CreateQueries), INST_METHOD("deleteQuery", &WebGL2RenderingContext::DeleteQuery), INST_METHOD("deleteQueries", &WebGL2RenderingContext::DeleteQueries), INST_METHOD("endQuery", &WebGL2RenderingContext::EndQuery), INST_METHOD("getQuery", &WebGL2RenderingContext::GetQuery), INST_METHOD("getQueryParameter", &WebGL2RenderingContext::GetQueryParameter), INST_METHOD("isQuery", &WebGL2RenderingContext::IsQuery), INST_METHOD("queryCounter", &WebGL2RenderingContext::QueryCounter), INST_METHOD("bindSampler", &WebGL2RenderingContext::BindSampler), INST_METHOD("createSampler", &WebGL2RenderingContext::CreateSampler), INST_METHOD("createSamplers", &WebGL2RenderingContext::CreateSamplers), INST_METHOD("deleteSampler", &WebGL2RenderingContext::DeleteSampler), INST_METHOD("deleteSamplers", &WebGL2RenderingContext::DeleteSamplers), INST_METHOD("getSamplerParameter", &WebGL2RenderingContext::GetSamplerParameter), INST_METHOD("isSampler", &WebGL2RenderingContext::IsSampler), INST_METHOD("samplerParameterf", &WebGL2RenderingContext::SamplerParameterf), INST_METHOD("samplerParameteri", &WebGL2RenderingContext::SamplerParameteri), INST_METHOD("attachShader", &WebGL2RenderingContext::AttachShader), INST_METHOD("compileShader", &WebGL2RenderingContext::CompileShader), INST_METHOD("createShader", &WebGL2RenderingContext::CreateShader), INST_METHOD("deleteShader", &WebGL2RenderingContext::DeleteShader), INST_METHOD("detachShader", &WebGL2RenderingContext::DetachShader), INST_METHOD("getAttachedShaders", &WebGL2RenderingContext::GetAttachedShaders), INST_METHOD("getShaderInfoLog", &WebGL2RenderingContext::GetShaderInfoLog), INST_METHOD("getShaderParameter", &WebGL2RenderingContext::GetShaderParameter), INST_METHOD("getShaderPrecisionFormat", &WebGL2RenderingContext::GetShaderPrecisionFormat), INST_METHOD("getShaderSource", &WebGL2RenderingContext::GetShaderSource), INST_METHOD("isShader", &WebGL2RenderingContext::IsShader), INST_METHOD("shaderSource", &WebGL2RenderingContext::ShaderSource), INST_METHOD("clearStencil", &WebGL2RenderingContext::ClearStencil), INST_METHOD("stencilFunc", &WebGL2RenderingContext::StencilFunc), INST_METHOD("stencilFuncSeparate", &WebGL2RenderingContext::StencilFuncSeparate), INST_METHOD("stencilMask", &WebGL2RenderingContext::StencilMask), INST_METHOD("stencilMaskSeparate", &WebGL2RenderingContext::StencilMaskSeparate), INST_METHOD("stencilOp", &WebGL2RenderingContext::StencilOp), INST_METHOD("stencilOpSeparate", &WebGL2RenderingContext::StencilOpSeparate), INST_METHOD("clientWaitSync", &WebGL2RenderingContext::ClientWaitSync), INST_METHOD("deleteSync", &WebGL2RenderingContext::DeleteSync), INST_METHOD("fenceSync", &WebGL2RenderingContext::FenceSync), INST_METHOD("getSyncParameter", &WebGL2RenderingContext::GetSyncParameter), INST_METHOD("isSync", &WebGL2RenderingContext::IsSync), INST_METHOD("waitSync", &WebGL2RenderingContext::WaitSync), INST_METHOD("bindRenderbuffer", &WebGL2RenderingContext::BindRenderbuffer), INST_METHOD("createRenderbuffer", &WebGL2RenderingContext::CreateRenderbuffer), INST_METHOD("createRenderbuffers", &WebGL2RenderingContext::CreateRenderbuffers), INST_METHOD("deleteRenderbuffer", &WebGL2RenderingContext::DeleteRenderbuffer), INST_METHOD("deleteRenderbuffers", &WebGL2RenderingContext::DeleteRenderbuffers), INST_METHOD("getRenderbufferParameteriv", &WebGL2RenderingContext::GetRenderbufferParameteriv), INST_METHOD("isRenderbuffer", &WebGL2RenderingContext::IsRenderbuffer), INST_METHOD("renderbufferStorage", &WebGL2RenderingContext::RenderbufferStorage), INST_METHOD("renderbufferStorageMultisample", &WebGL2RenderingContext::RenderbufferStorageMultisample), INST_METHOD("activeTexture", &WebGL2RenderingContext::ActiveTexture), INST_METHOD("bindTexture", &WebGL2RenderingContext::BindTexture), INST_METHOD("compressedTexImage2D", &WebGL2RenderingContext::CompressedTexImage2D), INST_METHOD("compressedTexImage3D", &WebGL2RenderingContext::CompressedTexImage3D), INST_METHOD("compressedTexSubImage2D", &WebGL2RenderingContext::CompressedTexSubImage2D), INST_METHOD("copyTexImage2D", &WebGL2RenderingContext::CopyTexImage2D), INST_METHOD("copyTexSubImage2D", &WebGL2RenderingContext::CopyTexSubImage2D), INST_METHOD("createTexture", &WebGL2RenderingContext::CreateTexture), INST_METHOD("genTextures", &WebGL2RenderingContext::GenTextures), INST_METHOD("deleteTexture", &WebGL2RenderingContext::DeleteTexture), INST_METHOD("deleteTextures", &WebGL2RenderingContext::DeleteTextures), INST_METHOD("generateMipmap", &WebGL2RenderingContext::GenerateMipmap), INST_METHOD("getTexParameter", &WebGL2RenderingContext::GetTexParameter), INST_METHOD("isTexture", &WebGL2RenderingContext::IsTexture), INST_METHOD("texImage2D", &WebGL2RenderingContext::TexImage2D), INST_METHOD("texParameterf", &WebGL2RenderingContext::TexParameterf), INST_METHOD("texParameteri", &WebGL2RenderingContext::TexParameteri), INST_METHOD("texSubImage2D", &WebGL2RenderingContext::TexSubImage2D), INST_METHOD("compressedTexSubImage3D", &WebGL2RenderingContext::CompressedTexSubImage3D), INST_METHOD("copyTexSubImage3D", &WebGL2RenderingContext::CopyTexSubImage3D), INST_METHOD("texImage3D", &WebGL2RenderingContext::TexImage3D), INST_METHOD("texStorage2D", &WebGL2RenderingContext::TexStorage2D), INST_METHOD("texStorage3D", &WebGL2RenderingContext::TexStorage3D), INST_METHOD("texSubImage3D", &WebGL2RenderingContext::TexSubImage3D), INST_METHOD("beginTransformFeedback", &WebGL2RenderingContext::BeginTransformFeedback), INST_METHOD("bindTransformFeedback", &WebGL2RenderingContext::BindTransformFeedback), INST_METHOD("createTransformFeedback", &WebGL2RenderingContext::CreateTransformFeedback), INST_METHOD("createTransformFeedbacks", &WebGL2RenderingContext::CreateTransformFeedbacks), INST_METHOD("deleteTransformFeedback", &WebGL2RenderingContext::DeleteTransformFeedback), INST_METHOD("deleteTransformFeedbacks", &WebGL2RenderingContext::DeleteTransformFeedbacks), INST_METHOD("endTransformFeedback", &WebGL2RenderingContext::EndTransformFeedback), INST_METHOD("getTransformFeedbackVarying", &WebGL2RenderingContext::GetTransformFeedbackVarying), INST_METHOD("isTransformFeedback", &WebGL2RenderingContext::IsTransformFeedback), INST_METHOD("pauseTransformFeedback", &WebGL2RenderingContext::PauseTransformFeedback), INST_METHOD("resumeTransformFeedback", &WebGL2RenderingContext::ResumeTransformFeedback), INST_METHOD("transformFeedbackVaryings", &WebGL2RenderingContext::TransformFeedbackVaryings), INST_METHOD("getActiveUniform", &WebGL2RenderingContext::GetActiveUniform), INST_METHOD("getUniform", &WebGL2RenderingContext::GetUniform), INST_METHOD("getUniformLocation", &WebGL2RenderingContext::GetUniformLocation), INST_METHOD("uniform1f", &WebGL2RenderingContext::Uniform1f), INST_METHOD("uniform1fv", &WebGL2RenderingContext::Uniform1fv), INST_METHOD("uniform1i", &WebGL2RenderingContext::Uniform1i), INST_METHOD("uniform1iv", &WebGL2RenderingContext::Uniform1iv), INST_METHOD("uniform2f", &WebGL2RenderingContext::Uniform2f), INST_METHOD("uniform2fv", &WebGL2RenderingContext::Uniform2fv), INST_METHOD("uniform2i", &WebGL2RenderingContext::Uniform2i), INST_METHOD("uniform2iv", &WebGL2RenderingContext::Uniform2iv), INST_METHOD("uniform3f", &WebGL2RenderingContext::Uniform3f), INST_METHOD("uniform3fv", &WebGL2RenderingContext::Uniform3fv), INST_METHOD("uniform3i", &WebGL2RenderingContext::Uniform3i), INST_METHOD("uniform3iv", &WebGL2RenderingContext::Uniform3iv), INST_METHOD("uniform4f", &WebGL2RenderingContext::Uniform4f), INST_METHOD("uniform4fv", &WebGL2RenderingContext::Uniform4fv), INST_METHOD("uniform4i", &WebGL2RenderingContext::Uniform4i), INST_METHOD("uniform4iv", &WebGL2RenderingContext::Uniform4iv), INST_METHOD("uniformMatrix2fv", &WebGL2RenderingContext::UniformMatrix2fv), INST_METHOD("uniformMatrix3fv", &WebGL2RenderingContext::UniformMatrix3fv), INST_METHOD("uniformMatrix4fv", &WebGL2RenderingContext::UniformMatrix4fv), INST_METHOD("uniformMatrix2x3fv", &WebGL2RenderingContext::UniformMatrix2x3fv), INST_METHOD("uniformMatrix2x4fv", &WebGL2RenderingContext::UniformMatrix2x4fv), INST_METHOD("uniformMatrix3x2fv", &WebGL2RenderingContext::UniformMatrix3x2fv), INST_METHOD("uniformMatrix3x4fv", &WebGL2RenderingContext::UniformMatrix3x4fv), INST_METHOD("uniformMatrix4x2fv", &WebGL2RenderingContext::UniformMatrix4x2fv), INST_METHOD("uniformMatrix4x3fv", &WebGL2RenderingContext::UniformMatrix4x3fv), INST_METHOD("uniform1ui", &WebGL2RenderingContext::Uniform1ui), INST_METHOD("uniform1uiv", &WebGL2RenderingContext::Uniform1uiv), INST_METHOD("uniform2ui", &WebGL2RenderingContext::Uniform2ui), INST_METHOD("uniform2uiv", &WebGL2RenderingContext::Uniform2uiv), INST_METHOD("uniform3ui", &WebGL2RenderingContext::Uniform3ui), INST_METHOD("uniform3uiv", &WebGL2RenderingContext::Uniform3uiv), INST_METHOD("uniform4ui", &WebGL2RenderingContext::Uniform4ui), INST_METHOD("uniform4uiv", &WebGL2RenderingContext::Uniform4uiv), INST_METHOD("getActiveUniformBlockName", &WebGL2RenderingContext::GetActiveUniformBlockName), INST_METHOD("getActiveUniformBlockParameter", &WebGL2RenderingContext::GetActiveUniformBlockiv), INST_METHOD("getActiveUniforms", &WebGL2RenderingContext::GetActiveUniformsiv), INST_METHOD("getUniformBlockIndex", &WebGL2RenderingContext::GetUniformBlockIndex), INST_METHOD("getUniformIndices", &WebGL2RenderingContext::GetUniformIndices), INST_METHOD("uniformBlockBinding", &WebGL2RenderingContext::UniformBlockBinding), INST_METHOD("createVertexArray", &WebGL2RenderingContext::CreateVertexArray), INST_METHOD("createVertexArrays", &WebGL2RenderingContext::CreateVertexArrays), INST_METHOD("bindVertexArray", &WebGL2RenderingContext::BindVertexArray), INST_METHOD("deleteVertexArray", &WebGL2RenderingContext::DeleteVertexArray), INST_METHOD("deleteVertexArrays", &WebGL2RenderingContext::DeleteVertexArrays), INST_METHOD("isVertexArray", &WebGL2RenderingContext::IsVertexArray), #undef INST_METHOD #define INST_ENUM(key, val) \ InstanceValue(key, Napi::Number::New(env, static_cast<int64_t>(val)), napi_enumerable) INST_ENUM("READ_BUFFER", GL_READ_BUFFER), INST_ENUM("UNPACK_ROW_LENGTH", GL_UNPACK_ROW_LENGTH), INST_ENUM("UNPACK_SKIP_ROWS", GL_UNPACK_SKIP_ROWS), INST_ENUM("UNPACK_SKIP_PIXELS", GL_UNPACK_SKIP_PIXELS), INST_ENUM("PACK_ROW_LENGTH", GL_PACK_ROW_LENGTH), INST_ENUM("PACK_SKIP_ROWS", GL_PACK_SKIP_ROWS), INST_ENUM("PACK_SKIP_PIXELS", GL_PACK_SKIP_PIXELS), INST_ENUM("COLOR", GL_COLOR), INST_ENUM("DEPTH", GL_DEPTH), INST_ENUM("STENCIL", GL_STENCIL), INST_ENUM("RED", GL_RED), INST_ENUM("RGB8", GL_RGB8), INST_ENUM("RGBA8", GL_RGBA8), INST_ENUM("RGB10_A2", GL_RGB10_A2), INST_ENUM("TEXTURE_BINDING_3D", GL_TEXTURE_BINDING_3D), INST_ENUM("UNPACK_SKIP_IMAGES", GL_UNPACK_SKIP_IMAGES), INST_ENUM("UNPACK_IMAGE_HEIGHT", GL_UNPACK_IMAGE_HEIGHT), INST_ENUM("TEXTURE_3D", GL_TEXTURE_3D), INST_ENUM("TEXTURE_WRAP_R", GL_TEXTURE_WRAP_R), INST_ENUM("MAX_3D_TEXTURE_SIZE", GL_MAX_3D_TEXTURE_SIZE), INST_ENUM("UNSIGNED_INT_2_10_10_10_REV", GL_UNSIGNED_INT_2_10_10_10_REV), INST_ENUM("MAX_ELEMENTS_VERTICES", GL_MAX_ELEMENTS_VERTICES), INST_ENUM("MAX_ELEMENTS_INDICES", GL_MAX_ELEMENTS_INDICES), INST_ENUM("TEXTURE_MIN_LOD", GL_TEXTURE_MIN_LOD), INST_ENUM("TEXTURE_MAX_LOD", GL_TEXTURE_MAX_LOD), INST_ENUM("TEXTURE_BASE_LEVEL", GL_TEXTURE_BASE_LEVEL), INST_ENUM("TEXTURE_MAX_LEVEL", GL_TEXTURE_MAX_LEVEL), INST_ENUM("MIN", GL_MIN), INST_ENUM("MAX", GL_MAX), INST_ENUM("DEPTH_COMPONENT24", GL_DEPTH_COMPONENT24), INST_ENUM("MAX_TEXTURE_LOD_BIAS", GL_MAX_TEXTURE_LOD_BIAS), INST_ENUM("TEXTURE_COMPARE_MODE", GL_TEXTURE_COMPARE_MODE), INST_ENUM("TEXTURE_COMPARE_FUNC", GL_TEXTURE_COMPARE_FUNC), INST_ENUM("CURRENT_QUERY", GL_CURRENT_QUERY), INST_ENUM("QUERY_RESULT", GL_QUERY_RESULT), INST_ENUM("QUERY_COUNTER_BITS", GL_QUERY_COUNTER_BITS), INST_ENUM("QUERY_RESULT_AVAILABLE", GL_QUERY_RESULT_AVAILABLE), INST_ENUM("TIMESTAMP", GL_TIMESTAMP), INST_ENUM("TIME_ELAPSED", GL_TIME_ELAPSED), INST_ENUM("GPU_DISJOINT", GL_GPU_DISJOINT), INST_ENUM("STREAM_READ", GL_STREAM_READ), INST_ENUM("STREAM_COPY", GL_STREAM_COPY), INST_ENUM("STATIC_READ", GL_STATIC_READ), INST_ENUM("STATIC_COPY", GL_STATIC_COPY), INST_ENUM("DYNAMIC_READ", GL_DYNAMIC_READ), INST_ENUM("DYNAMIC_COPY", GL_DYNAMIC_COPY), INST_ENUM("MAX_DRAW_BUFFERS", GL_MAX_DRAW_BUFFERS), INST_ENUM("DRAW_BUFFER0", GL_DRAW_BUFFER0), INST_ENUM("DRAW_BUFFER1", GL_DRAW_BUFFER1), INST_ENUM("DRAW_BUFFER2", GL_DRAW_BUFFER2), INST_ENUM("DRAW_BUFFER3", GL_DRAW_BUFFER3), INST_ENUM("DRAW_BUFFER4", GL_DRAW_BUFFER4), INST_ENUM("DRAW_BUFFER5", GL_DRAW_BUFFER5), INST_ENUM("DRAW_BUFFER6", GL_DRAW_BUFFER6), INST_ENUM("DRAW_BUFFER7", GL_DRAW_BUFFER7), INST_ENUM("DRAW_BUFFER8", GL_DRAW_BUFFER8), INST_ENUM("DRAW_BUFFER9", GL_DRAW_BUFFER9), INST_ENUM("DRAW_BUFFER10", GL_DRAW_BUFFER10), INST_ENUM("DRAW_BUFFER11", GL_DRAW_BUFFER11), INST_ENUM("DRAW_BUFFER12", GL_DRAW_BUFFER12), INST_ENUM("DRAW_BUFFER13", GL_DRAW_BUFFER13), INST_ENUM("DRAW_BUFFER14", GL_DRAW_BUFFER14), INST_ENUM("DRAW_BUFFER15", GL_DRAW_BUFFER15), INST_ENUM("MAX_FRAGMENT_UNIFORM_COMPONENTS", GL_MAX_FRAGMENT_UNIFORM_COMPONENTS), INST_ENUM("MAX_VERTEX_UNIFORM_COMPONENTS", GL_MAX_VERTEX_UNIFORM_COMPONENTS), INST_ENUM("SAMPLER_3D", GL_SAMPLER_3D), INST_ENUM("SAMPLER_2D_SHADOW", GL_SAMPLER_2D_SHADOW), INST_ENUM("FRAGMENT_SHADER_DERIVATIVE_HINT", GL_FRAGMENT_SHADER_DERIVATIVE_HINT), INST_ENUM("PIXEL_PACK_BUFFER", GL_PIXEL_PACK_BUFFER), INST_ENUM("PIXEL_UNPACK_BUFFER", GL_PIXEL_UNPACK_BUFFER), INST_ENUM("PIXEL_PACK_BUFFER_BINDING", GL_PIXEL_PACK_BUFFER_BINDING), INST_ENUM("PIXEL_UNPACK_BUFFER_BINDING", GL_PIXEL_UNPACK_BUFFER_BINDING), INST_ENUM("SRGB", GL_SRGB), INST_ENUM("SRGB8", GL_SRGB8), INST_ENUM("SRGB8_ALPHA8", GL_SRGB8_ALPHA8), INST_ENUM("COMPARE_REF_TO_TEXTURE", GL_COMPARE_REF_TO_TEXTURE), INST_ENUM("RGBA32F", GL_RGBA32F), INST_ENUM("RGB32F", GL_RGB32F), INST_ENUM("RGBA16F", GL_RGBA16F), INST_ENUM("RGB16F", GL_RGB16F), INST_ENUM("VERTEX_ATTRIB_ARRAY_INTEGER", GL_VERTEX_ATTRIB_ARRAY_INTEGER), INST_ENUM("MAX_ARRAY_TEXTURE_LAYERS", GL_MAX_ARRAY_TEXTURE_LAYERS), INST_ENUM("MIN_PROGRAM_TEXEL_OFFSET", GL_MIN_PROGRAM_TEXEL_OFFSET), INST_ENUM("MAX_PROGRAM_TEXEL_OFFSET", GL_MAX_PROGRAM_TEXEL_OFFSET), INST_ENUM("MAX_VARYING_COMPONENTS", GL_MAX_VARYING_COMPONENTS), INST_ENUM("TEXTURE_2D_ARRAY", GL_TEXTURE_2D_ARRAY), INST_ENUM("TEXTURE_BINDING_2D_ARRAY", GL_TEXTURE_BINDING_2D_ARRAY), INST_ENUM("R11F_G11F_B10F", GL_R11F_G11F_B10F), INST_ENUM("UNSIGNED_INT_10F_11F_11F_REV", GL_UNSIGNED_INT_10F_11F_11F_REV), INST_ENUM("RGB9_E5", GL_RGB9_E5), INST_ENUM("UNSIGNED_INT_5_9_9_9_REV", GL_UNSIGNED_INT_5_9_9_9_REV), INST_ENUM("TRANSFORM_FEEDBACK_BUFFER_MODE", GL_TRANSFORM_FEEDBACK_BUFFER_MODE), INST_ENUM("MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS", GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS), INST_ENUM("TRANSFORM_FEEDBACK_VARYINGS", GL_TRANSFORM_FEEDBACK_VARYINGS), INST_ENUM("TRANSFORM_FEEDBACK_BUFFER_START", GL_TRANSFORM_FEEDBACK_BUFFER_START), INST_ENUM("TRANSFORM_FEEDBACK_BUFFER_SIZE", GL_TRANSFORM_FEEDBACK_BUFFER_SIZE), INST_ENUM("TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN", GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN), INST_ENUM("RASTERIZER_DISCARD", GL_RASTERIZER_DISCARD), INST_ENUM("MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS", GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS), INST_ENUM("MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS", GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS), INST_ENUM("INTERLEAVED_ATTRIBS", GL_INTERLEAVED_ATTRIBS), INST_ENUM("SEPARATE_ATTRIBS", GL_SEPARATE_ATTRIBS), INST_ENUM("TRANSFORM_FEEDBACK_BUFFER", GL_TRANSFORM_FEEDBACK_BUFFER), INST_ENUM("TRANSFORM_FEEDBACK_BUFFER_BINDING", GL_TRANSFORM_FEEDBACK_BUFFER_BINDING), INST_ENUM("RGBA32UI", GL_RGBA32UI), INST_ENUM("RGB32UI", GL_RGB32UI), INST_ENUM("RGBA16UI", GL_RGBA16UI), INST_ENUM("RGB16UI", GL_RGB16UI), INST_ENUM("RGBA8UI", GL_RGBA8UI), INST_ENUM("RGB8UI", GL_RGB8UI), INST_ENUM("RGBA32I", GL_RGBA32I), INST_ENUM("RGB32I", GL_RGB32I), INST_ENUM("RGBA16I", GL_RGBA16I), INST_ENUM("RGB16I", GL_RGB16I), INST_ENUM("RGBA8I", GL_RGBA8I), INST_ENUM("RGB8I", GL_RGB8I), INST_ENUM("RED_INTEGER", GL_RED_INTEGER), INST_ENUM("RGB_INTEGER", GL_RGB_INTEGER), INST_ENUM("RGBA_INTEGER", GL_RGBA_INTEGER), INST_ENUM("SAMPLER_2D_ARRAY", GL_SAMPLER_2D_ARRAY), INST_ENUM("SAMPLER_2D_ARRAY_SHADOW", GL_SAMPLER_2D_ARRAY_SHADOW), INST_ENUM("SAMPLER_CUBE_SHADOW", GL_SAMPLER_CUBE_SHADOW), INST_ENUM("UNSIGNED_INT_VEC2", GL_UNSIGNED_INT_VEC2), INST_ENUM("UNSIGNED_INT_VEC3", GL_UNSIGNED_INT_VEC3), INST_ENUM("UNSIGNED_INT_VEC4", GL_UNSIGNED_INT_VEC4), INST_ENUM("INT_SAMPLER_2D", GL_INT_SAMPLER_2D), INST_ENUM("INT_SAMPLER_3D", GL_INT_SAMPLER_3D), INST_ENUM("INT_SAMPLER_CUBE", GL_INT_SAMPLER_CUBE), INST_ENUM("INT_SAMPLER_2D_ARRAY", GL_INT_SAMPLER_2D_ARRAY), INST_ENUM("UNSIGNED_INT_SAMPLER_2D", GL_UNSIGNED_INT_SAMPLER_2D), INST_ENUM("UNSIGNED_INT_SAMPLER_3D", GL_UNSIGNED_INT_SAMPLER_3D), INST_ENUM("UNSIGNED_INT_SAMPLER_CUBE", GL_UNSIGNED_INT_SAMPLER_CUBE), INST_ENUM("UNSIGNED_INT_SAMPLER_2D_ARRAY", GL_UNSIGNED_INT_SAMPLER_2D_ARRAY), INST_ENUM("DEPTH_COMPONENT32F", GL_DEPTH_COMPONENT32F), INST_ENUM("DEPTH32F_STENCIL8", GL_DEPTH32F_STENCIL8), INST_ENUM("FLOAT_32_UNSIGNED_INT_24_8_REV", GL_FLOAT_32_UNSIGNED_INT_24_8_REV), INST_ENUM("FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING", GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING), INST_ENUM("FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE", GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE), INST_ENUM("FRAMEBUFFER_ATTACHMENT_RED_SIZE", GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE), INST_ENUM("FRAMEBUFFER_ATTACHMENT_GREEN_SIZE", GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE), INST_ENUM("FRAMEBUFFER_ATTACHMENT_BLUE_SIZE", GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE), INST_ENUM("FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE", GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE), INST_ENUM("FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE", GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE), INST_ENUM("FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE", GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE), INST_ENUM("FRAMEBUFFER_DEFAULT", GL_FRAMEBUFFER_DEFAULT), INST_ENUM("UNSIGNED_INT_24_8", GL_UNSIGNED_INT_24_8), INST_ENUM("DEPTH24_STENCIL8", GL_DEPTH24_STENCIL8), INST_ENUM("UNSIGNED_NORMALIZED", GL_UNSIGNED_NORMALIZED), INST_ENUM("DRAW_FRAMEBUFFER_BINDING", GL_DRAW_FRAMEBUFFER_BINDING), INST_ENUM("READ_FRAMEBUFFER", GL_READ_FRAMEBUFFER), INST_ENUM("DRAW_FRAMEBUFFER", GL_DRAW_FRAMEBUFFER), INST_ENUM("READ_FRAMEBUFFER_BINDING", GL_READ_FRAMEBUFFER_BINDING), INST_ENUM("RENDERBUFFER_SAMPLES", GL_RENDERBUFFER_SAMPLES), INST_ENUM("FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER", GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER), INST_ENUM("MAX_COLOR_ATTACHMENTS", GL_MAX_COLOR_ATTACHMENTS), INST_ENUM("COLOR_ATTACHMENT1", GL_COLOR_ATTACHMENT1), INST_ENUM("COLOR_ATTACHMENT2", GL_COLOR_ATTACHMENT2), INST_ENUM("COLOR_ATTACHMENT3", GL_COLOR_ATTACHMENT3), INST_ENUM("COLOR_ATTACHMENT4", GL_COLOR_ATTACHMENT4), INST_ENUM("COLOR_ATTACHMENT5", GL_COLOR_ATTACHMENT5), INST_ENUM("COLOR_ATTACHMENT6", GL_COLOR_ATTACHMENT6), INST_ENUM("COLOR_ATTACHMENT7", GL_COLOR_ATTACHMENT7), INST_ENUM("COLOR_ATTACHMENT8", GL_COLOR_ATTACHMENT8), INST_ENUM("COLOR_ATTACHMENT9", GL_COLOR_ATTACHMENT9), INST_ENUM("COLOR_ATTACHMENT10", GL_COLOR_ATTACHMENT10), INST_ENUM("COLOR_ATTACHMENT11", GL_COLOR_ATTACHMENT11), INST_ENUM("COLOR_ATTACHMENT12", GL_COLOR_ATTACHMENT12), INST_ENUM("COLOR_ATTACHMENT13", GL_COLOR_ATTACHMENT13), INST_ENUM("COLOR_ATTACHMENT14", GL_COLOR_ATTACHMENT14), INST_ENUM("COLOR_ATTACHMENT15", GL_COLOR_ATTACHMENT15), INST_ENUM("FRAMEBUFFER_INCOMPLETE_MULTISAMPLE", GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE), INST_ENUM("MAX_SAMPLES", GL_MAX_SAMPLES), INST_ENUM("HALF_FLOAT", GL_HALF_FLOAT), INST_ENUM("RG", GL_RG), INST_ENUM("RG_INTEGER", GL_RG_INTEGER), INST_ENUM("R8", GL_R8), INST_ENUM("RG8", GL_RG8), INST_ENUM("R16F", GL_R16F), INST_ENUM("R32F", GL_R32F), INST_ENUM("RG16F", GL_RG16F), INST_ENUM("RG32F", GL_RG32F), INST_ENUM("R8I", GL_R8I), INST_ENUM("R8UI", GL_R8UI), INST_ENUM("R16I", GL_R16I), INST_ENUM("R16UI", GL_R16UI), INST_ENUM("R32I", GL_R32I), INST_ENUM("R32UI", GL_R32UI), INST_ENUM("RG8I", GL_RG8I), INST_ENUM("RG8UI", GL_RG8UI), INST_ENUM("RG16I", GL_RG16I), INST_ENUM("RG16UI", GL_RG16UI), INST_ENUM("RG32I", GL_RG32I), INST_ENUM("RG32UI", GL_RG32UI), INST_ENUM("VERTEX_ARRAY_BINDING", GL_VERTEX_ARRAY_BINDING), INST_ENUM("R8_SNORM", GL_R8_SNORM), INST_ENUM("RG8_SNORM", GL_RG8_SNORM), INST_ENUM("RGB8_SNORM", GL_RGB8_SNORM), INST_ENUM("RGBA8_SNORM", GL_RGBA8_SNORM), INST_ENUM("SIGNED_NORMALIZED", GL_SIGNED_NORMALIZED), INST_ENUM("COPY_READ_BUFFER", GL_COPY_READ_BUFFER), INST_ENUM("COPY_WRITE_BUFFER", GL_COPY_WRITE_BUFFER), INST_ENUM("COPY_READ_BUFFER_BINDING", GL_COPY_READ_BUFFER_BINDING), INST_ENUM("COPY_WRITE_BUFFER_BINDING", GL_COPY_WRITE_BUFFER_BINDING), INST_ENUM("UNIFORM_BUFFER", GL_UNIFORM_BUFFER), INST_ENUM("UNIFORM_BUFFER_BINDING", GL_UNIFORM_BUFFER_BINDING), INST_ENUM("UNIFORM_BUFFER_START", GL_UNIFORM_BUFFER_START), INST_ENUM("UNIFORM_BUFFER_SIZE", GL_UNIFORM_BUFFER_SIZE), INST_ENUM("MAX_VERTEX_UNIFORM_BLOCKS", GL_MAX_VERTEX_UNIFORM_BLOCKS), INST_ENUM("MAX_FRAGMENT_UNIFORM_BLOCKS", GL_MAX_FRAGMENT_UNIFORM_BLOCKS), INST_ENUM("MAX_COMBINED_UNIFORM_BLOCKS", GL_MAX_COMBINED_UNIFORM_BLOCKS), INST_ENUM("MAX_UNIFORM_BUFFER_BINDINGS", GL_MAX_UNIFORM_BUFFER_BINDINGS), INST_ENUM("MAX_UNIFORM_BLOCK_SIZE", GL_MAX_UNIFORM_BLOCK_SIZE), INST_ENUM("MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS", GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS), INST_ENUM("MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS", GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS), INST_ENUM("UNIFORM_BUFFER_OFFSET_ALIGNMENT", GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT), INST_ENUM("ACTIVE_UNIFORM_BLOCKS", GL_ACTIVE_UNIFORM_BLOCKS), INST_ENUM("UNIFORM_TYPE", GL_UNIFORM_TYPE), INST_ENUM("UNIFORM_SIZE", GL_UNIFORM_SIZE), INST_ENUM("UNIFORM_BLOCK_INDEX", GL_UNIFORM_BLOCK_INDEX), INST_ENUM("UNIFORM_OFFSET", GL_UNIFORM_OFFSET), INST_ENUM("UNIFORM_ARRAY_STRIDE", GL_UNIFORM_ARRAY_STRIDE), INST_ENUM("UNIFORM_MATRIX_STRIDE", GL_UNIFORM_MATRIX_STRIDE), INST_ENUM("UNIFORM_IS_ROW_MAJOR", GL_UNIFORM_IS_ROW_MAJOR), INST_ENUM("UNIFORM_BLOCK_BINDING", GL_UNIFORM_BLOCK_BINDING), INST_ENUM("UNIFORM_BLOCK_DATA_SIZE", GL_UNIFORM_BLOCK_DATA_SIZE), INST_ENUM("UNIFORM_BLOCK_ACTIVE_UNIFORMS", GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS), INST_ENUM("UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES", GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES), INST_ENUM("UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER", GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER), INST_ENUM("UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER", GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER), INST_ENUM("INVALID_INDEX", GL_INVALID_INDEX), INST_ENUM("MAX_VERTEX_OUTPUT_COMPONENTS", GL_MAX_VERTEX_OUTPUT_COMPONENTS), INST_ENUM("MAX_FRAGMENT_INPUT_COMPONENTS", GL_MAX_FRAGMENT_INPUT_COMPONENTS), INST_ENUM("MAX_SERVER_WAIT_TIMEOUT", GL_MAX_SERVER_WAIT_TIMEOUT), INST_ENUM("OBJECT_TYPE", GL_OBJECT_TYPE), INST_ENUM("SYNC_CONDITION", GL_SYNC_CONDITION), INST_ENUM("SYNC_STATUS", GL_SYNC_STATUS), INST_ENUM("SYNC_FLAGS", GL_SYNC_FLAGS), INST_ENUM("SYNC_FENCE", GL_SYNC_FENCE), INST_ENUM("SYNC_GPU_COMMANDS_COMPLETE", GL_SYNC_GPU_COMMANDS_COMPLETE), INST_ENUM("UNSIGNALED", GL_UNSIGNALED), INST_ENUM("SIGNALED", GL_SIGNALED), INST_ENUM("ALREADY_SIGNALED", GL_ALREADY_SIGNALED), INST_ENUM("TIMEOUT_EXPIRED", GL_TIMEOUT_EXPIRED), INST_ENUM("CONDITION_SATISFIED", GL_CONDITION_SATISFIED), INST_ENUM("WAIT_FAILED", GL_WAIT_FAILED), INST_ENUM("SYNC_FLUSH_COMMANDS_BIT", GL_SYNC_FLUSH_COMMANDS_BIT), INST_ENUM("VERTEX_ATTRIB_ARRAY_DIVISOR", GL_VERTEX_ATTRIB_ARRAY_DIVISOR), INST_ENUM("ANY_SAMPLES_PASSED", GL_ANY_SAMPLES_PASSED), INST_ENUM("ANY_SAMPLES_PASSED_CONSERVATIVE", GL_ANY_SAMPLES_PASSED_CONSERVATIVE), INST_ENUM("SAMPLER_BINDING", GL_SAMPLER_BINDING), INST_ENUM("RGB10_A2UI", GL_RGB10_A2UI), INST_ENUM("INT_2_10_10_10_REV", GL_INT_2_10_10_10_REV), INST_ENUM("TRANSFORM_FEEDBACK", GL_TRANSFORM_FEEDBACK), INST_ENUM("TRANSFORM_FEEDBACK_PAUSED", GL_TRANSFORM_FEEDBACK_PAUSED), INST_ENUM("TRANSFORM_FEEDBACK_ACTIVE", GL_TRANSFORM_FEEDBACK_ACTIVE), INST_ENUM("TRANSFORM_FEEDBACK_BINDING", GL_TRANSFORM_FEEDBACK_BINDING), INST_ENUM("TEXTURE_IMMUTABLE_FORMAT", GL_TEXTURE_IMMUTABLE_FORMAT), INST_ENUM("MAX_ELEMENT_INDEX", GL_MAX_ELEMENT_INDEX), INST_ENUM("TEXTURE_IMMUTABLE_LEVELS", GL_TEXTURE_IMMUTABLE_LEVELS), INST_ENUM("TIMEOUT_IGNORED", GL_TIMEOUT_IGNORED), INST_ENUM("MAX_CLIENT_WAIT_TIMEOUT_WEBGL", GL_MAX_CLIENT_WAIT_TIMEOUT_WEBGL), INST_ENUM("DEPTH_BUFFER_BIT", GL_DEPTH_BUFFER_BIT), INST_ENUM("STENCIL_BUFFER_BIT", GL_STENCIL_BUFFER_BIT), INST_ENUM("COLOR_BUFFER_BIT", GL_COLOR_BUFFER_BIT), INST_ENUM("POINTS", GL_POINTS), INST_ENUM("POINT_SPRITE", GL_POINT_SPRITE), INST_ENUM("PROGRAM_POINT_SIZE", GL_PROGRAM_POINT_SIZE), INST_ENUM("LINES", GL_LINES), INST_ENUM("LINE_LOOP", GL_LINE_LOOP), INST_ENUM("LINE_STRIP", GL_LINE_STRIP), INST_ENUM("TRIANGLES", GL_TRIANGLES), INST_ENUM("TRIANGLE_STRIP", GL_TRIANGLE_STRIP), INST_ENUM("TRIANGLE_FAN", GL_TRIANGLE_FAN), INST_ENUM("ZERO", GL_ZERO), INST_ENUM("ONE", GL_ONE), INST_ENUM("SRC_COLOR", GL_SRC_COLOR), INST_ENUM("ONE_MINUS_SRC_COLOR", GL_ONE_MINUS_SRC_COLOR), INST_ENUM("SRC_ALPHA", GL_SRC_ALPHA), INST_ENUM("ONE_MINUS_SRC_ALPHA", GL_ONE_MINUS_SRC_ALPHA), INST_ENUM("DST_ALPHA", GL_DST_ALPHA), INST_ENUM("ONE_MINUS_DST_ALPHA", GL_ONE_MINUS_DST_ALPHA), INST_ENUM("DST_COLOR", GL_DST_COLOR), INST_ENUM("ONE_MINUS_DST_COLOR", GL_ONE_MINUS_DST_COLOR), INST_ENUM("SRC_ALPHA_SATURATE", GL_SRC_ALPHA_SATURATE), INST_ENUM("FUNC_ADD", GL_FUNC_ADD), INST_ENUM("BLEND_EQUATION", GL_BLEND_EQUATION), INST_ENUM("BLEND_EQUATION_RGB", GL_BLEND_EQUATION_RGB), INST_ENUM("BLEND_EQUATION_ALPHA", GL_BLEND_EQUATION_ALPHA), INST_ENUM("FUNC_SUBTRACT", GL_FUNC_SUBTRACT), INST_ENUM("FUNC_REVERSE_SUBTRACT", GL_FUNC_REVERSE_SUBTRACT), INST_ENUM("BLEND_DST_RGB", GL_BLEND_DST_RGB), INST_ENUM("BLEND_SRC_RGB", GL_BLEND_SRC_RGB), INST_ENUM("BLEND_DST_ALPHA", GL_BLEND_DST_ALPHA), INST_ENUM("BLEND_SRC_ALPHA", GL_BLEND_SRC_ALPHA), INST_ENUM("CONSTANT_COLOR", GL_CONSTANT_COLOR), INST_ENUM("ONE_MINUS_CONSTANT_COLOR", GL_ONE_MINUS_CONSTANT_COLOR), INST_ENUM("CONSTANT_ALPHA", GL_CONSTANT_ALPHA), INST_ENUM("ONE_MINUS_CONSTANT_ALPHA", GL_ONE_MINUS_CONSTANT_ALPHA), INST_ENUM("BLEND_COLOR", GL_BLEND_COLOR), INST_ENUM("ARRAY_BUFFER", GL_ARRAY_BUFFER), INST_ENUM("ELEMENT_ARRAY_BUFFER", GL_ELEMENT_ARRAY_BUFFER), INST_ENUM("ARRAY_BUFFER_BINDING", GL_ARRAY_BUFFER_BINDING), INST_ENUM("ELEMENT_ARRAY_BUFFER_BINDING", GL_ELEMENT_ARRAY_BUFFER_BINDING), INST_ENUM("STREAM_DRAW", GL_STREAM_DRAW), INST_ENUM("STATIC_DRAW", GL_STATIC_DRAW), INST_ENUM("DYNAMIC_DRAW", GL_DYNAMIC_DRAW), INST_ENUM("BUFFER_SIZE", GL_BUFFER_SIZE), INST_ENUM("BUFFER_USAGE", GL_BUFFER_USAGE), INST_ENUM("CURRENT_VERTEX_ATTRIB", GL_CURRENT_VERTEX_ATTRIB), INST_ENUM("FRONT", GL_FRONT), INST_ENUM("BACK", GL_BACK), INST_ENUM("FRONT_AND_BACK", GL_FRONT_AND_BACK), INST_ENUM("TEXTURE_2D", GL_TEXTURE_2D), INST_ENUM("CULL_FACE", GL_CULL_FACE), INST_ENUM("BLEND", GL_BLEND), INST_ENUM("DITHER", GL_DITHER), INST_ENUM("STENCIL_TEST", GL_STENCIL_TEST), INST_ENUM("DEPTH_TEST", GL_DEPTH_TEST), INST_ENUM("SCISSOR_TEST", GL_SCISSOR_TEST), INST_ENUM("POLYGON_OFFSET_FILL", GL_POLYGON_OFFSET_FILL), INST_ENUM("SAMPLE_ALPHA_TO_COVERAGE", GL_SAMPLE_ALPHA_TO_COVERAGE), INST_ENUM("SAMPLE_COVERAGE", GL_SAMPLE_COVERAGE), INST_ENUM("NO_ERROR", GL_NO_ERROR), INST_ENUM("INVALID_ENUM", GL_INVALID_ENUM), INST_ENUM("INVALID_VALUE", GL_INVALID_VALUE), INST_ENUM("INVALID_OPERATION", GL_INVALID_OPERATION), INST_ENUM("OUT_OF_MEMORY", GL_OUT_OF_MEMORY), INST_ENUM("CW", GL_CW), INST_ENUM("CCW", GL_CCW), INST_ENUM("LINE_WIDTH", GL_LINE_WIDTH), INST_ENUM("ALIASED_POINT_SIZE_RANGE", GL_ALIASED_POINT_SIZE_RANGE), INST_ENUM("ALIASED_LINE_WIDTH_RANGE", GL_ALIASED_LINE_WIDTH_RANGE), INST_ENUM("CULL_FACE_MODE", GL_CULL_FACE_MODE), INST_ENUM("FRONT_FACE", GL_FRONT_FACE), INST_ENUM("DEPTH_RANGE", GL_DEPTH_RANGE), INST_ENUM("DEPTH_WRITEMASK", GL_DEPTH_WRITEMASK), INST_ENUM("DEPTH_CLEAR_VALUE", GL_DEPTH_CLEAR_VALUE), INST_ENUM("DEPTH_FUNC", GL_DEPTH_FUNC), INST_ENUM("STENCIL_CLEAR_VALUE", GL_STENCIL_CLEAR_VALUE), INST_ENUM("STENCIL_FUNC", GL_STENCIL_FUNC), INST_ENUM("STENCIL_FAIL", GL_STENCIL_FAIL), INST_ENUM("STENCIL_PASS_DEPTH_FAIL", GL_STENCIL_PASS_DEPTH_FAIL), INST_ENUM("STENCIL_PASS_DEPTH_PASS", GL_STENCIL_PASS_DEPTH_PASS), INST_ENUM("STENCIL_REF", GL_STENCIL_REF), INST_ENUM("STENCIL_VALUE_MASK", GL_STENCIL_VALUE_MASK), INST_ENUM("STENCIL_WRITEMASK", GL_STENCIL_WRITEMASK), INST_ENUM("STENCIL_BACK_FUNC", GL_STENCIL_BACK_FUNC), INST_ENUM("STENCIL_BACK_FAIL", GL_STENCIL_BACK_FAIL), INST_ENUM("STENCIL_BACK_PASS_DEPTH_FAIL", GL_STENCIL_BACK_PASS_DEPTH_FAIL), INST_ENUM("STENCIL_BACK_PASS_DEPTH_PASS", GL_STENCIL_BACK_PASS_DEPTH_PASS), INST_ENUM("STENCIL_BACK_REF", GL_STENCIL_BACK_REF), INST_ENUM("STENCIL_BACK_VALUE_MASK", GL_STENCIL_BACK_VALUE_MASK), INST_ENUM("STENCIL_BACK_WRITEMASK", GL_STENCIL_BACK_WRITEMASK), INST_ENUM("VIEWPORT", GL_VIEWPORT), INST_ENUM("SCISSOR_BOX", GL_SCISSOR_BOX), INST_ENUM("COLOR_CLEAR_VALUE", GL_COLOR_CLEAR_VALUE), INST_ENUM("COLOR_WRITEMASK", GL_COLOR_WRITEMASK), INST_ENUM("UNPACK_ALIGNMENT", GL_UNPACK_ALIGNMENT), INST_ENUM("PACK_ALIGNMENT", GL_PACK_ALIGNMENT), INST_ENUM("MAX_TEXTURE_SIZE", GL_MAX_TEXTURE_SIZE), INST_ENUM("MAX_VIEWPORT_DIMS", GL_MAX_VIEWPORT_DIMS), INST_ENUM("SUBPIXEL_BITS", GL_SUBPIXEL_BITS), INST_ENUM("RED_BITS", GL_RED_BITS), INST_ENUM("GREEN_BITS", GL_GREEN_BITS), INST_ENUM("BLUE_BITS", GL_BLUE_BITS), INST_ENUM("ALPHA_BITS", GL_ALPHA_BITS), INST_ENUM("DEPTH_BITS", GL_DEPTH_BITS), INST_ENUM("STENCIL_BITS", GL_STENCIL_BITS), INST_ENUM("POLYGON_OFFSET_UNITS", GL_POLYGON_OFFSET_UNITS), INST_ENUM("POLYGON_OFFSET_FACTOR", GL_POLYGON_OFFSET_FACTOR), INST_ENUM("TEXTURE_BINDING_2D", GL_TEXTURE_BINDING_2D), INST_ENUM("SAMPLE_BUFFERS", GL_SAMPLE_BUFFERS), INST_ENUM("SAMPLES", GL_SAMPLES), INST_ENUM("SAMPLE_COVERAGE_VALUE", GL_SAMPLE_COVERAGE_VALUE), INST_ENUM("SAMPLE_COVERAGE_INVERT", GL_SAMPLE_COVERAGE_INVERT), INST_ENUM("COMPRESSED_TEXTURE_FORMATS", GL_COMPRESSED_TEXTURE_FORMATS), INST_ENUM("DONT_CARE", GL_DONT_CARE), INST_ENUM("FASTEST", GL_FASTEST), INST_ENUM("NICEST", GL_NICEST), INST_ENUM("GENERATE_MIPMAP_HINT", GL_GENERATE_MIPMAP_HINT), INST_ENUM("BYTE", GL_BYTE), INST_ENUM("UNSIGNED_BYTE", GL_UNSIGNED_BYTE), INST_ENUM("SHORT", GL_SHORT), INST_ENUM("UNSIGNED_SHORT", GL_UNSIGNED_SHORT), INST_ENUM("INT", GL_INT), INST_ENUM("UNSIGNED_INT", GL_UNSIGNED_INT), INST_ENUM("FLOAT", GL_FLOAT), INST_ENUM("DEPTH_COMPONENT", GL_DEPTH_COMPONENT), INST_ENUM("ALPHA", GL_ALPHA), INST_ENUM("RGB", GL_RGB), INST_ENUM("RGBA", GL_RGBA), INST_ENUM("BGR", GL_BGR), INST_ENUM("BGRA", GL_BGRA), INST_ENUM("LUMINANCE", GL_LUMINANCE), INST_ENUM("LUMINANCE_ALPHA", GL_LUMINANCE_ALPHA), INST_ENUM("UNSIGNED_SHORT_4_4_4_4", GL_UNSIGNED_SHORT_4_4_4_4), INST_ENUM("UNSIGNED_SHORT_5_5_5_1", GL_UNSIGNED_SHORT_5_5_5_1), INST_ENUM("UNSIGNED_SHORT_5_6_5", GL_UNSIGNED_SHORT_5_6_5), INST_ENUM("FRAGMENT_SHADER", GL_FRAGMENT_SHADER), INST_ENUM("VERTEX_SHADER", GL_VERTEX_SHADER), INST_ENUM("MAX_VERTEX_ATTRIBS", GL_MAX_VERTEX_ATTRIBS), INST_ENUM("MAX_VERTEX_UNIFORM_VECTORS", GL_MAX_VERTEX_UNIFORM_VECTORS), INST_ENUM("MAX_VARYING_VECTORS", GL_MAX_VARYING_VECTORS), INST_ENUM("MAX_COMBINED_TEXTURE_IMAGE_UNITS", GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS), INST_ENUM("MAX_VERTEX_TEXTURE_IMAGE_UNITS", GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS), INST_ENUM("MAX_TEXTURE_IMAGE_UNITS", GL_MAX_TEXTURE_IMAGE_UNITS), INST_ENUM("MAX_FRAGMENT_UNIFORM_VECTORS", GL_MAX_FRAGMENT_UNIFORM_VECTORS), INST_ENUM("SHADER_TYPE", GL_SHADER_TYPE), INST_ENUM("DELETE_STATUS", GL_DELETE_STATUS), INST_ENUM("LINK_STATUS", GL_LINK_STATUS), INST_ENUM("VALIDATE_STATUS", GL_VALIDATE_STATUS), INST_ENUM("ATTACHED_SHADERS", GL_ATTACHED_SHADERS), INST_ENUM("ACTIVE_UNIFORMS", GL_ACTIVE_UNIFORMS), INST_ENUM("ACTIVE_ATTRIBUTES", GL_ACTIVE_ATTRIBUTES), INST_ENUM("SHADING_LANGUAGE_VERSION", GL_SHADING_LANGUAGE_VERSION), INST_ENUM("CURRENT_PROGRAM", GL_CURRENT_PROGRAM), INST_ENUM("NEVER", GL_NEVER), INST_ENUM("LESS", GL_LESS), INST_ENUM("EQUAL", GL_EQUAL), INST_ENUM("LEQUAL", GL_LEQUAL), INST_ENUM("GREATER", GL_GREATER), INST_ENUM("NOTEQUAL", GL_NOTEQUAL), INST_ENUM("GEQUAL", GL_GEQUAL), INST_ENUM("ALWAYS", GL_ALWAYS), INST_ENUM("KEEP", GL_KEEP), INST_ENUM("REPLACE", GL_REPLACE), INST_ENUM("INCR", GL_INCR), INST_ENUM("DECR", GL_DECR), INST_ENUM("INVERT", GL_INVERT), INST_ENUM("INCR_WRAP", GL_INCR_WRAP), INST_ENUM("DECR_WRAP", GL_DECR_WRAP), INST_ENUM("VENDOR", GL_VENDOR), INST_ENUM("RENDERER", GL_RENDERER), INST_ENUM("VERSION", GL_VERSION), INST_ENUM("NEAREST", GL_NEAREST), INST_ENUM("LINEAR", GL_LINEAR), INST_ENUM("NEAREST_MIPMAP_NEAREST", GL_NEAREST_MIPMAP_NEAREST), INST_ENUM("LINEAR_MIPMAP_NEAREST", GL_LINEAR_MIPMAP_NEAREST), INST_ENUM("NEAREST_MIPMAP_LINEAR", GL_NEAREST_MIPMAP_LINEAR), INST_ENUM("LINEAR_MIPMAP_LINEAR", GL_LINEAR_MIPMAP_LINEAR), INST_ENUM("TEXTURE_MAG_FILTER", GL_TEXTURE_MAG_FILTER), INST_ENUM("TEXTURE_MIN_FILTER", GL_TEXTURE_MIN_FILTER), INST_ENUM("TEXTURE_WRAP_S", GL_TEXTURE_WRAP_S), INST_ENUM("TEXTURE_WRAP_T", GL_TEXTURE_WRAP_T), INST_ENUM("TEXTURE", GL_TEXTURE), INST_ENUM("TEXTURE_CUBE_MAP", GL_TEXTURE_CUBE_MAP), INST_ENUM("TEXTURE_BINDING_CUBE_MAP", GL_TEXTURE_BINDING_CUBE_MAP), INST_ENUM("TEXTURE_CUBE_MAP_POSITIVE_X", GL_TEXTURE_CUBE_MAP_POSITIVE_X), INST_ENUM("TEXTURE_CUBE_MAP_NEGATIVE_X", GL_TEXTURE_CUBE_MAP_NEGATIVE_X), INST_ENUM("TEXTURE_CUBE_MAP_POSITIVE_Y", GL_TEXTURE_CUBE_MAP_POSITIVE_Y), INST_ENUM("TEXTURE_CUBE_MAP_NEGATIVE_Y", GL_TEXTURE_CUBE_MAP_NEGATIVE_Y), INST_ENUM("TEXTURE_CUBE_MAP_POSITIVE_Z", GL_TEXTURE_CUBE_MAP_POSITIVE_Z), INST_ENUM("TEXTURE_CUBE_MAP_NEGATIVE_Z", GL_TEXTURE_CUBE_MAP_NEGATIVE_Z), INST_ENUM("MAX_CUBE_MAP_TEXTURE_SIZE", GL_MAX_CUBE_MAP_TEXTURE_SIZE), INST_ENUM("TEXTURE0", GL_TEXTURE0), INST_ENUM("TEXTURE1", GL_TEXTURE1), INST_ENUM("TEXTURE2", GL_TEXTURE2), INST_ENUM("TEXTURE3", GL_TEXTURE3), INST_ENUM("TEXTURE4", GL_TEXTURE4), INST_ENUM("TEXTURE5", GL_TEXTURE5), INST_ENUM("TEXTURE6", GL_TEXTURE6), INST_ENUM("TEXTURE7", GL_TEXTURE7), INST_ENUM("TEXTURE8", GL_TEXTURE8), INST_ENUM("TEXTURE9", GL_TEXTURE9), INST_ENUM("TEXTURE10", GL_TEXTURE10), INST_ENUM("TEXTURE11", GL_TEXTURE11), INST_ENUM("TEXTURE12", GL_TEXTURE12), INST_ENUM("TEXTURE13", GL_TEXTURE13), INST_ENUM("TEXTURE14", GL_TEXTURE14), INST_ENUM("TEXTURE15", GL_TEXTURE15), INST_ENUM("TEXTURE16", GL_TEXTURE16), INST_ENUM("TEXTURE17", GL_TEXTURE17), INST_ENUM("TEXTURE18", GL_TEXTURE18), INST_ENUM("TEXTURE19", GL_TEXTURE19), INST_ENUM("TEXTURE20", GL_TEXTURE20), INST_ENUM("TEXTURE21", GL_TEXTURE21), INST_ENUM("TEXTURE22", GL_TEXTURE22), INST_ENUM("TEXTURE23", GL_TEXTURE23), INST_ENUM("TEXTURE24", GL_TEXTURE24), INST_ENUM("TEXTURE25", GL_TEXTURE25), INST_ENUM("TEXTURE26", GL_TEXTURE26), INST_ENUM("TEXTURE27", GL_TEXTURE27), INST_ENUM("TEXTURE28", GL_TEXTURE28), INST_ENUM("TEXTURE29", GL_TEXTURE29), INST_ENUM("TEXTURE30", GL_TEXTURE30), INST_ENUM("TEXTURE31", GL_TEXTURE31), INST_ENUM("ACTIVE_TEXTURE", GL_ACTIVE_TEXTURE), INST_ENUM("REPEAT", GL_REPEAT), INST_ENUM("CLAMP_TO_EDGE", GL_CLAMP_TO_EDGE), INST_ENUM("MIRRORED_REPEAT", GL_MIRRORED_REPEAT), INST_ENUM("FLOAT_VEC2", GL_FLOAT_VEC2), INST_ENUM("FLOAT_VEC3", GL_FLOAT_VEC3), INST_ENUM("FLOAT_VEC4", GL_FLOAT_VEC4), INST_ENUM("INT_VEC2", GL_INT_VEC2), INST_ENUM("INT_VEC3", GL_INT_VEC3), INST_ENUM("INT_VEC4", GL_INT_VEC4), INST_ENUM("BOOL", GL_BOOL), INST_ENUM("BOOL_VEC2", GL_BOOL_VEC2), INST_ENUM("BOOL_VEC3", GL_BOOL_VEC3), INST_ENUM("BOOL_VEC4", GL_BOOL_VEC4), INST_ENUM("FLOAT_MAT2", GL_FLOAT_MAT2), INST_ENUM("FLOAT_MAT3", GL_FLOAT_MAT3), INST_ENUM("FLOAT_MAT4", GL_FLOAT_MAT4), INST_ENUM("SAMPLER_2D", GL_SAMPLER_2D), INST_ENUM("SAMPLER_CUBE", GL_SAMPLER_CUBE), INST_ENUM("VERTEX_ATTRIB_ARRAY_ENABLED", GL_VERTEX_ATTRIB_ARRAY_ENABLED), INST_ENUM("VERTEX_ATTRIB_ARRAY_SIZE", GL_VERTEX_ATTRIB_ARRAY_SIZE), INST_ENUM("VERTEX_ATTRIB_ARRAY_STRIDE", GL_VERTEX_ATTRIB_ARRAY_STRIDE), INST_ENUM("VERTEX_ATTRIB_ARRAY_TYPE", GL_VERTEX_ATTRIB_ARRAY_TYPE), INST_ENUM("VERTEX_ATTRIB_ARRAY_NORMALIZED", GL_VERTEX_ATTRIB_ARRAY_NORMALIZED), INST_ENUM("VERTEX_ATTRIB_ARRAY_POINTER", GL_VERTEX_ATTRIB_ARRAY_POINTER), INST_ENUM("VERTEX_ATTRIB_ARRAY_BUFFER_BINDING", GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING), INST_ENUM("IMPLEMENTATION_COLOR_READ_TYPE", GL_IMPLEMENTATION_COLOR_READ_TYPE), INST_ENUM("IMPLEMENTATION_COLOR_READ_FORMAT", GL_IMPLEMENTATION_COLOR_READ_FORMAT), INST_ENUM("COMPILE_STATUS", GL_COMPILE_STATUS), INST_ENUM("LOW_FLOAT", GL_LOW_FLOAT), INST_ENUM("MEDIUM_FLOAT", GL_MEDIUM_FLOAT), INST_ENUM("HIGH_FLOAT", GL_HIGH_FLOAT), INST_ENUM("LOW_INT", GL_LOW_INT), INST_ENUM("MEDIUM_INT", GL_MEDIUM_INT), INST_ENUM("HIGH_INT", GL_HIGH_INT), INST_ENUM("FRAMEBUFFER", GL_FRAMEBUFFER), INST_ENUM("RENDERBUFFER", GL_RENDERBUFFER), INST_ENUM("RGBA4", GL_RGBA4), INST_ENUM("RGB5_A1", GL_RGB5_A1), INST_ENUM("RGB565", GL_RGB565), INST_ENUM("DEPTH_COMPONENT16", GL_DEPTH_COMPONENT16), INST_ENUM("STENCIL_INDEX8", GL_STENCIL_INDEX8), INST_ENUM("DEPTH_STENCIL", GL_DEPTH_STENCIL), INST_ENUM("RENDERBUFFER_WIDTH", GL_RENDERBUFFER_WIDTH), INST_ENUM("RENDERBUFFER_HEIGHT", GL_RENDERBUFFER_HEIGHT), INST_ENUM("RENDERBUFFER_INTERNAL_FORMAT", GL_RENDERBUFFER_INTERNAL_FORMAT), INST_ENUM("RENDERBUFFER_RED_SIZE", GL_RENDERBUFFER_RED_SIZE), INST_ENUM("RENDERBUFFER_GREEN_SIZE", GL_RENDERBUFFER_GREEN_SIZE), INST_ENUM("RENDERBUFFER_BLUE_SIZE", GL_RENDERBUFFER_BLUE_SIZE), INST_ENUM("RENDERBUFFER_ALPHA_SIZE", GL_RENDERBUFFER_ALPHA_SIZE), INST_ENUM("RENDERBUFFER_DEPTH_SIZE", GL_RENDERBUFFER_DEPTH_SIZE), INST_ENUM("RENDERBUFFER_STENCIL_SIZE", GL_RENDERBUFFER_STENCIL_SIZE), INST_ENUM("FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE", GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE), INST_ENUM("FRAMEBUFFER_ATTACHMENT_OBJECT_NAME", GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME), INST_ENUM("FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL", GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL), INST_ENUM("FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE", GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE), INST_ENUM("COLOR_ATTACHMENT0", GL_COLOR_ATTACHMENT0), INST_ENUM("DEPTH_ATTACHMENT", GL_DEPTH_ATTACHMENT), INST_ENUM("STENCIL_ATTACHMENT", GL_STENCIL_ATTACHMENT), INST_ENUM("DEPTH_STENCIL_ATTACHMENT", GL_DEPTH_STENCIL_ATTACHMENT), INST_ENUM("NONE", GL_NONE), INST_ENUM("FRAMEBUFFER_COMPLETE", GL_FRAMEBUFFER_COMPLETE), INST_ENUM("FRAMEBUFFER_INCOMPLETE_ATTACHMENT", GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT), INST_ENUM("FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT", GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT), INST_ENUM("FRAMEBUFFER_INCOMPLETE_DIMENSIONS", GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT), INST_ENUM("FRAMEBUFFER_UNSUPPORTED", GL_FRAMEBUFFER_UNSUPPORTED), INST_ENUM("FRAMEBUFFER_BINDING", GL_FRAMEBUFFER_BINDING), INST_ENUM("RENDERBUFFER_BINDING", GL_RENDERBUFFER_BINDING), INST_ENUM("MAX_RENDERBUFFER_SIZE", GL_MAX_RENDERBUFFER_SIZE), INST_ENUM("INVALID_FRAMEBUFFER_OPERATION", GL_INVALID_FRAMEBUFFER_OPERATION), INST_ENUM("UNPACK_FLIP_Y_WEBGL", GL_UNPACK_FLIP_Y_WEBGL), INST_ENUM("UNPACK_PREMULTIPLY_ALPHA_WEBGL", GL_UNPACK_PREMULTIPLY_ALPHA_WEBGL), INST_ENUM("CONTEXT_LOST_WEBGL", GL_CONTEXT_LOST_WEBGL), INST_ENUM("UNPACK_COLORSPACE_CONVERSION_WEBGL", GL_UNPACK_COLORSPACE_CONVERSION_WEBGL), INST_ENUM("BROWSER_DEFAULT_WEBGL", GL_BROWSER_DEFAULT_WEBGL), INST_ENUM("UNMASKED_VENDOR_WEBGL", GL_UNMASKED_VENDOR_WEBGL), INST_ENUM("UNMASKED_RENDERER_WEBGL", GL_UNMASKED_RENDERER_WEBGL), #undef INST_ENUM }); }; // GL_EXPORT void glClear (GLbitfield mask); void WebGL2RenderingContext::Clear(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLbitfield mask = args[0]; clear_mask_ |= mask; GL_EXPORT::glClear(mask); } // GL_EXPORT void glClearColor (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha); void WebGL2RenderingContext::ClearColor(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glClearColor(args[0], args[1], args[2], args[3]); } // GL_EXPORT void glClearDepth (GLclampd depth); void WebGL2RenderingContext::ClearDepth(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glClearDepth(args[0]); } // GL_EXPORT void glColorMask (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); void WebGL2RenderingContext::ColorMask(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glColorMask(args[0], args[1], args[2], args[3]); } // GL_EXPORT void glCullFace (GLenum mode); void WebGL2RenderingContext::CullFace(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glCullFace(args[0]); } // GL_EXPORT void glDepthFunc (GLenum func); void WebGL2RenderingContext::DepthFunc(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glDepthFunc(args[0]); } // GL_EXPORT void glDepthMask (GLboolean flag); void WebGL2RenderingContext::DepthMask(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glDepthMask(args[0]); } // GL_EXPORT void glDepthRange (GLclampd zNear, GLclampd zFar); void WebGL2RenderingContext::DepthRange(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glDepthRange(args[0], args[1]); } // GL_EXPORT void glDisable (GLenum cap); void WebGL2RenderingContext::Disable(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glDisable(args[0]); } // GL_EXPORT void glDrawArrays (GLenum mode, GLint first, GLsizei count); void WebGL2RenderingContext::DrawArrays(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glDrawArrays(args[0], args[1], args[2]); } // GL_EXPORT void glDrawElements (GLenum mode, GLsizei count, GLenum type, const void *indices); void WebGL2RenderingContext::DrawElements(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glDrawElements(args[0], args[1], args[2], args[3]); } // GL_EXPORT void glEnable (GLenum cap); void WebGL2RenderingContext::Enable(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glEnable(args[0]); } // GL_EXPORT void glFinish (void); void WebGL2RenderingContext::Finish(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glFinish(); } // GL_EXPORT void glFlush (void); void WebGL2RenderingContext::Flush(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glFlush(); } // GL_EXPORT void glFrontFace (GLenum mode); void WebGL2RenderingContext::FrontFace(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glFrontFace(args[0]); } // GL_EXPORT GLenum glGetError (void); Napi::Value WebGL2RenderingContext::GetError(Napi::CallbackInfo const& info) { return CPPToNapi(info.Env())(GL_EXPORT::glGetError()); } // GL_EXPORT void glGetParameter (GLint pname); Napi::Value WebGL2RenderingContext::GetParameter(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLint pname = args[0]; switch (pname) { case GL_GPU_DISJOINT: case GL_MAX_CLIENT_WAIT_TIMEOUT_WEBGL: return CPPToNapi(info)(0); case GL_VENDOR: case GL_UNMASKED_VENDOR_WEBGL: { auto str = GL_EXPORT::glGetString(GL_VENDOR); if (str == NULL) { return info.Env().Null(); } return CPPToNapi(info)(std::string{reinterpret_cast<const GLchar*>(str)}); } case GL_RENDERER: case GL_UNMASKED_RENDERER_WEBGL: { auto str = GL_EXPORT::glGetString(GL_RENDERER); if (str == NULL) { return info.Env().Null(); } return CPPToNapi(info)(std::string{reinterpret_cast<const GLchar*>(str)}); } case GL_BLEND: case GL_CULL_FACE: case GL_DEPTH_TEST: case GL_DEPTH_WRITEMASK: case GL_DITHER: case GL_POLYGON_OFFSET_FILL: case GL_SAMPLE_COVERAGE_INVERT: case GL_SCISSOR_TEST: case GL_STENCIL_TEST: case GL_UNPACK_FLIP_Y_WEBGL: case GL_UNPACK_PREMULTIPLY_ALPHA_WEBGL: { GLubyte param{}; GL_EXPORT::glGetBooleanv(pname, &param); return CPPToNapi(info)(static_cast<bool>(param)); } case GL_COLOR_WRITEMASK: { std::vector<GLboolean> params(4); GL_EXPORT::glGetBooleanv(pname, params.data()); return CPPToNapi(info)(std::vector<bool>{params.begin(), params.end()}); } case GL_ARRAY_BUFFER_BINDING: case GL_CURRENT_PROGRAM: case GL_ELEMENT_ARRAY_BUFFER_BINDING: case GL_FRAMEBUFFER_BINDING: case GL_RENDERBUFFER_BINDING: case GL_TEXTURE_BINDING_2D: case GL_TEXTURE_BINDING_CUBE_MAP: { GLint params{}; GL_EXPORT::glGetIntegerv(pname, &params); return CPPToNapi(info)(params); } case GL_DEPTH_CLEAR_VALUE: case GL_LINE_WIDTH: case GL_POLYGON_OFFSET_FACTOR: case GL_POLYGON_OFFSET_UNITS: case GL_SAMPLE_COVERAGE_VALUE: { GLfloat param{}; GL_EXPORT::glGetFloatv(pname, &param); return CPPToNapi(info)(param); } case GL_SHADING_LANGUAGE_VERSION: case GL_VERSION: case GL_EXTENSIONS: { auto str = GL_EXPORT::glGetString(pname); if (str == NULL) { return info.Env().Null(); } return CPPToNapi(info)("WebGL " + std::string{reinterpret_cast<const GLchar*>(str)}); } case GL_MAX_VIEWPORT_DIMS: { auto buf = Napi::ArrayBuffer::New(info.Env(), 2 * sizeof(GLint)); GL_EXPORT::glGetIntegerv(pname, static_cast<GLint*>(buf.Data())); return Napi::Int32Array::New(info.Env(), 2, buf, 0); } case GL_VIEWPORT: case GL_SCISSOR_BOX: { auto buf = Napi::ArrayBuffer::New(info.Env(), 4 * sizeof(GLint)); GL_EXPORT::glGetIntegerv(pname, static_cast<GLint*>(buf.Data())); return Napi::Int32Array::New(info.Env(), 4, buf, 0); } case GL_DEPTH_RANGE: case GL_ALIASED_LINE_WIDTH_RANGE: case GL_ALIASED_POINT_SIZE_RANGE: { auto buf = Napi::ArrayBuffer::New(info.Env(), 2 * sizeof(GLfloat)); GL_EXPORT::glGetFloatv(pname, static_cast<GLfloat*>(buf.Data())); return Napi::Float32Array::New(info.Env(), 2, buf, 0); } case GL_BLEND_COLOR: case GL_COLOR_CLEAR_VALUE: { auto buf = Napi::ArrayBuffer::New(info.Env(), 4 * sizeof(GLfloat)); GL_EXPORT::glGetFloatv(pname, static_cast<GLfloat*>(buf.Data())); return Napi::Float32Array::New(info.Env(), 4, buf, 0); } default: { GLint params{}; GL_EXPORT::glGetIntegerv(pname, &params); return CPPToNapi(info)(params); } } } // GL_EXPORT const GLubyte * glGetString (GL_EXTENSIONS); Napi::Value WebGL2RenderingContext::GetSupportedExtensions(Napi::CallbackInfo const& info) { CallbackArgs args = info; auto str = reinterpret_cast<const GLchar*>(GL_EXPORT::glGetString(GL_EXTENSIONS)); if (str == NULL) { return info.Env().Null(); } auto iss = std::istringstream{str}; auto begin = std::istream_iterator<std::string>{iss}; auto end = std::istream_iterator<std::string>{}; std::vector<std::string> extensions{begin, end}; return CPPToNapi(info)(extensions); } // GL_EXPORT void glHint (GLenum target, GLenum mode); void WebGL2RenderingContext::Hint(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glHint(args[0], args[1]); } // GL_EXPORT GLboolean glIsEnabled (GLenum cap); Napi::Value WebGL2RenderingContext::IsEnabled(Napi::CallbackInfo const& info) { CallbackArgs args = info; auto enabled = GL_EXPORT::glIsEnabled(args[0]); return CPPToNapi(info.Env())(enabled); } // GL_EXPORT void glLineWidth (GLfloat width); void WebGL2RenderingContext::LineWidth(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glLineWidth(args[0]); } // GL_EXPORT void glPixelStorei (GLenum pname, GLint param); void WebGL2RenderingContext::PixelStorei(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLuint pname = args[0]; switch (pname) { case GL_PACK_ALIGNMENT: case GL_UNPACK_ALIGNMENT: GL_EXPORT::glPixelStorei(pname, args[1]); case GL_UNPACK_FLIP_Y_WEBGL: case GL_UNPACK_PREMULTIPLY_ALPHA_WEBGL: default: break; } } // GL_EXPORT void glPolygonOffset (GLfloat factor, GLfloat units); void WebGL2RenderingContext::PolygonOffset(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glPolygonOffset(args[0], args[1]); } // GL_EXPORT void glReadPixels (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, // GLenum type, void *pixels); void WebGL2RenderingContext::ReadPixels(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLint x = args[0]; GLint y = args[1]; GLsizei width = args[2]; GLsizei height = args[3]; GLenum format = args[4]; GLenum type = args[5]; if (!info[6].IsNumber()) { Span<char> ptr = args[6]; GL_EXPORT::glReadnPixels(x, y, width, height, format, type, ptr.size(), ptr.data()); } else { GLintptr ptr = args[6]; GL_EXPORT::glReadPixels(x, y, width, height, format, type, reinterpret_cast<void*>(ptr)); } } // GL_EXPORT void glScissor (GLint x, GLint y, GLsizei width, GLsizei height); void WebGL2RenderingContext::Scissor(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glScissor(args[0], args[1], args[2], args[3]); } // GL_EXPORT void glViewport (GLint x, GLint y, GLsizei width, GLsizei height); void WebGL2RenderingContext::Viewport(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glViewport(args[0], args[1], args[2], args[3]); } // GL_EXPORT void glDrawRangeElements (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum // type, const void *indices); void WebGL2RenderingContext::DrawRangeElements(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glDrawRangeElements(args[0], args[1], args[2], args[3], args[4], args[5]); } // GL_EXPORT void glSampleCoverage (GLclampf value, GLboolean invert); void WebGL2RenderingContext::SampleCoverage(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glSampleCoverage(args[0], args[1]); } // GL_EXPORT GLint glGetFragDataLocation (GLuint program, const GLchar* name); Napi::Value WebGL2RenderingContext::GetFragDataLocation(Napi::CallbackInfo const& info) { CallbackArgs args = info; std::string name = args[1]; return CPPToNapi(info)(GL_EXPORT::glGetFragDataLocation(args[0], name.data())); } Napi::Value WebGL2RenderingContext::GetContextAttributes(Napi::CallbackInfo const& info) { return this->context_attributes_.Value(); } Napi::Value WebGL2RenderingContext::GetClearMask_(Napi::CallbackInfo const& info) { return CPPToNapi(info.Env())(this->clear_mask_); } void WebGL2RenderingContext::SetClearMask_(Napi::CallbackInfo const& info, Napi::Value const& value) { this->clear_mask_ = NapiToCPP(value); } } // namespace nv
0
rapidsai_public_repos/node/modules/webgl
rapidsai_public_repos/node/modules/webgl/src/errors.hpp
// Copyright (c) 2020-2021, NVIDIA CORPORATION. // // 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. #pragma once #include "gl.hpp" #include <napi.h> namespace nv { inline Napi::Error glewError(Napi::Env const& env, const int code, const char* file, const uint32_t line) { auto error_name = reinterpret_cast<const char*>(GLEWAPIENTRY::glewGetString(code)); auto error_string = reinterpret_cast<const char*>(GLEWAPIENTRY::glewGetErrorString(code)); auto msg = std::to_string(code); msg += (error_name != NULL ? " " + std::string{error_name} : ""); msg += (error_string != NULL ? " " + std::string{error_string} : ""); msg += (file != NULL ? "\n at " + std::string{file} : "\n"); return Napi::Error::New(env, msg + ":" + std::to_string(line)); } } // namespace nv
0
rapidsai_public_repos/node/modules/webgl
rapidsai_public_repos/node/modules/webgl/src/transformfeedback.cpp
// Copyright (c) 2020-2021, NVIDIA CORPORATION. // // 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. #include "macros.hpp" #include "webgl.hpp" #include <nv_node/utilities/args.hpp> #include <nv_node/utilities/cpp_to_napi.hpp> namespace nv { // GL_EXPORT void glBeginTransformFeedback (GLenum primitiveMode); void WebGL2RenderingContext::BeginTransformFeedback(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glBeginTransformFeedback(args[0]); } // GL_EXPORT void glBindTransformFeedback (GLenum target, GLuint id); void WebGL2RenderingContext::BindTransformFeedback(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glBindTransformFeedback(args[0], args[1]); } // GL_EXPORT void glCreateTransformFeedbacks (GLsizei n, GLuint* ids); Napi::Value WebGL2RenderingContext::CreateTransformFeedback(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLuint transform_feedback{}; GL_EXPORT::glCreateTransformFeedbacks(1, &transform_feedback); return WebGLTransformFeedback::New(info.Env(), transform_feedback); } // GL_EXPORT void glCreateTransformFeedbacks (GLsizei n, GLuint* ids); Napi::Value WebGL2RenderingContext::CreateTransformFeedbacks(Napi::CallbackInfo const& info) { CallbackArgs args = info; std::vector<GLuint> transform_feedbacks(static_cast<size_t>(args[0])); GL_EXPORT::glCreateTransformFeedbacks(transform_feedbacks.size(), transform_feedbacks.data()); return CPPToNapi(info)(transform_feedbacks); } // GL_EXPORT void glDeleteTransformFeedbacks (GLsizei n, const GLuint* ids); void WebGL2RenderingContext::DeleteTransformFeedback(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLuint transform_feedback = args[0]; GL_EXPORT::glDeleteTransformFeedbacks(1, &transform_feedback); } // GL_EXPORT void glDeleteTransformFeedbacks (GLsizei n, const GLuint* ids); void WebGL2RenderingContext::DeleteTransformFeedbacks(Napi::CallbackInfo const& info) { CallbackArgs args = info; std::vector<GLuint> transform_feedbacks = args[0]; GL_EXPORT::glDeleteTransformFeedbacks(transform_feedbacks.size(), transform_feedbacks.data()); } // GL_EXPORT void glEndTransformFeedback (void); void WebGL2RenderingContext::EndTransformFeedback(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glEndTransformFeedback(); } // GL_EXPORT void glGetTransformFeedbackVarying (GLuint program, GLuint index, GLsizei bufSize, // GLsizei * length, GLsizei * size, GLenum * type, GLchar * name); Napi::Value WebGL2RenderingContext::GetTransformFeedbackVarying(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLuint program = args[0]; GLuint location = args[1]; GLint max_length{}; GL_EXPORT::glGetProgramiv(program, GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH, &max_length); if (max_length > 0) { GLuint type{}; GLint size{}, len{}; GLchar* name = reinterpret_cast<GLchar*>(std::malloc(max_length)); GL_EXPORT::glGetTransformFeedbackVarying( program, location, max_length, &len, &size, &type, name); return WebGLActiveInfo::New( info.Env(), size, type, std::string{name, static_cast<size_t>(len)}); } return info.Env().Null(); } // GL_EXPORT GLboolean glIsTransformFeedback (GLuint id); Napi::Value WebGL2RenderingContext::IsTransformFeedback(Napi::CallbackInfo const& info) { CallbackArgs args = info; auto is_transform_feedback = GL_EXPORT::glIsTransformFeedback(args[0]); return CPPToNapi(info)(is_transform_feedback); } // GL_EXPORT void glPauseTransformFeedback (void); void WebGL2RenderingContext::PauseTransformFeedback(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glPauseTransformFeedback(); } // GL_EXPORT void glResumeTransformFeedback (void); void WebGL2RenderingContext::ResumeTransformFeedback(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glResumeTransformFeedback(); } // GL_EXPORT void glTransformFeedbackVaryings (GLuint program, GLsizei count, const GLchar *const* // varyings, GLenum bufferMode); void WebGL2RenderingContext::TransformFeedbackVaryings(Napi::CallbackInfo const& info) { CallbackArgs args = info; std::vector<std::string> varyings = args[1]; std::vector<const GLchar*> varying_ptrs(varyings.size()); std::transform( varyings.begin(), varyings.end(), varying_ptrs.begin(), [&](const std::string& str) { return str.data(); }); GL_EXPORT::glTransformFeedbackVaryings(args[0], varyings.size(), varying_ptrs.data(), args[2]); } } // namespace nv
0
rapidsai_public_repos/node/modules/webgl
rapidsai_public_repos/node/modules/webgl/src/shader.cpp
// Copyright (c) 2020-2021, NVIDIA CORPORATION. // // 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. #include "macros.hpp" #include "webgl.hpp" #include <nv_node/utilities/args.hpp> #include <nv_node/utilities/cpp_to_napi.hpp> namespace nv { // GL_EXPORT void glAttachShader (GLuint program, GLuint shader); void WebGL2RenderingContext::AttachShader(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glAttachShader(args[0], args[1]); } // GL_EXPORT void glCompileShader (GLuint shader); void WebGL2RenderingContext::CompileShader(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glCompileShader(args[0]); } // GL_EXPORT GLuint glCreateShader (GLenum type); Napi::Value WebGL2RenderingContext::CreateShader(Napi::CallbackInfo const& info) { CallbackArgs args = info; auto shader = GL_EXPORT::glCreateShader(args[0]); return WebGLShader::New(info.Env(), shader); } // GL_EXPORT void glDeleteShader (GLuint shader); void WebGL2RenderingContext::DeleteShader(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glDeleteShader(args[0]); } // GL_EXPORT void glDetachShader (GLuint shader, GLuint shader); void WebGL2RenderingContext::DetachShader(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glDetachShader(args[0], args[1]); } // GL_EXPORT void glGetAttachedShaders (GLuint shader, GLsizei maxCount, GLsizei* count, GLuint* // shaders); Napi::Value WebGL2RenderingContext::GetAttachedShaders(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLuint program = args[0]; GLint max_count{0}; GL_EXPORT::glGetProgramiv(program, GL_ATTACHED_SHADERS, &max_count); if (max_count > 0) { GLint count{}; std::vector<GLuint> shaders(max_count); GL_EXPORT::glGetAttachedShaders(program, max_count, &count, shaders.data()); shaders.resize(count); shaders.shrink_to_fit(); std::vector<Napi::Object> objs(count); std::transform(shaders.begin(), shaders.end(), objs.begin(), [&](GLuint s) { return WebGLShader::New(info.Env(), s); }); return CPPToNapi(info)(objs); } return info.Env().Null(); } // GL_EXPORT void glGetShaderInfoLog (GLuint shader, GLsizei bufSize, GLsizei* length, GLchar* // infoLog); Napi::Value WebGL2RenderingContext::GetShaderInfoLog(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLuint shader = args[0]; GLint max_length{0}; GL_EXPORT::glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &max_length); if (max_length > 0) { GLint length{}; GLchar* info_log = reinterpret_cast<GLchar*>(std::malloc(max_length)); GL_EXPORT::glGetShaderInfoLog(shader, max_length, &length, info_log); return CPPToNapi(info)(std::string{info_log, static_cast<size_t>(length)}); } return info.Env().Null(); } // GL_EXPORT void glGetShaderiv (GLuint shader, GLenum pname, GLint* param); Napi::Value WebGL2RenderingContext::GetShaderParameter(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLuint shader = args[0]; GLint pname = args[1]; // GLint param{}; // GL_EXPORT::glGetShaderiv(shader, pname, &param); // return CPPToNapi(info)(param); switch (pname) { case GL_DELETE_STATUS: case GL_COMPILE_STATUS: { GLint param{}; GL_EXPORT::glGetShaderiv(shader, pname, &param); return CPPToNapi(info)(static_cast<bool>(param)); } case GL_SHADER_TYPE: { GLint param{}; GL_EXPORT::glGetShaderiv(shader, pname, &param); return CPPToNapi(info)(param); } default: GLEW_THROW(info.Env(), GL_INVALID_ENUM); } } // GL_EXPORT void glGetShaderPrecisionFormat (GLenum shadertype, GLenum precisiontype, GLint* range, // GLint *precision); Napi::Value WebGL2RenderingContext::GetShaderPrecisionFormat(Napi::CallbackInfo const& info) { CallbackArgs args = info; std::vector<GLint> range(2); GLint precision{}; GL_EXPORT::glGetShaderPrecisionFormat(args[0], args[1], range.data(), &precision); return WebGLShaderPrecisionFormat::New(info.Env(), range[0], range[1], precision); } // GL_EXPORT void glGetShaderSource (GLuint obj, GLsizei maxLength, GLsizei* length, GLchar* // source); Napi::Value WebGL2RenderingContext::GetShaderSource(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLuint shader = args[0]; GLint max_length{}; GL_EXPORT::glGetShaderiv(shader, GL_SHADER_SOURCE_LENGTH, &max_length); if (max_length > 0) { GLint length{}; GLchar* shader_source = reinterpret_cast<GLchar*>(std::malloc(max_length)); GL_EXPORT::glGetShaderSource(shader, max_length, &length, shader_source); return CPPToNapi(info)(std::string{shader_source, static_cast<size_t>(length)}); } return info.Env().Null(); } // GL_EXPORT void glGetTranslatedShaderSourceANGLE(GLuint shader, GLsizei bufsize, GLsizei* length, // GLchar* source); Napi::Value WebGL2RenderingContext::GetTranslatedShaderSource(Napi::CallbackInfo const& info) { CallbackArgs args = info; if (GLEW_ANGLE_translated_shader_source) { GLuint shader = args[0]; GLint max_length{}; GL_EXPORT::glGetShaderiv(shader, GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE, &max_length); if (max_length > 0) { GLint length{}; GLchar* shader_source = reinterpret_cast<GLchar*>(std::malloc(max_length)); GL_EXPORT::glGetTranslatedShaderSourceANGLE(shader, max_length, &length, shader_source); return CPPToNapi(info)(std::string{shader_source, static_cast<size_t>(length)}); } } return info.Env().Null(); } // GL_EXPORT GLboolean glIsShader (GLuint shader); Napi::Value WebGL2RenderingContext::IsShader(Napi::CallbackInfo const& info) { CallbackArgs args = info; auto is_shader = GL_EXPORT::glIsShader(args[0]); return CPPToNapi(info.Env())(is_shader); } // GL_EXPORT void glShaderSource (GLuint shader, GLsizei count, const GLchar *const* string, const // GLint* length); void WebGL2RenderingContext::ShaderSource(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLuint shader = args[0]; std::vector<std::string> sources = args[1]; std::vector<GLint> source_lengths(sources.size()); std::vector<const GLchar*> source_ptrs(sources.size()); auto idx = -1; std::for_each(sources.begin(), sources.end(), [&](std::string const& src) mutable { source_ptrs[++idx] = src.data(); source_lengths[idx] = src.size(); }); GL_EXPORT::glShaderSource(shader, sources.size(), source_ptrs.data(), source_lengths.data()); } } // namespace nv
0
rapidsai_public_repos/node/modules/webgl
rapidsai_public_repos/node/modules/webgl/src/vertexarray.cpp
// Copyright (c) 2020-2021, NVIDIA CORPORATION. // // 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. #include "macros.hpp" #include "webgl.hpp" #include <nv_node/utilities/args.hpp> #include <nv_node/utilities/cpp_to_napi.hpp> namespace nv { // GL_EXPORT void glCreateVertexArrays (GLsizei n, GLuint* arrays); Napi::Value WebGL2RenderingContext::CreateVertexArray(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLuint vertex_array{}; GL_EXPORT::glCreateVertexArrays(1, &vertex_array); return WebGLVertexArrayObject::New(info.Env(), vertex_array); } // GL_EXPORT void glCreateVertexArrays (GLsizei n, GLuint* arrays); Napi::Value WebGL2RenderingContext::CreateVertexArrays(Napi::CallbackInfo const& info) { CallbackArgs args = info; std::vector<GLuint> vertex_arrays(static_cast<size_t>(args[0])); GL_EXPORT::glCreateVertexArrays(vertex_arrays.size(), vertex_arrays.data()); return CPPToNapi(info.Env())(vertex_arrays); } // GL_EXPORT void glBindVertexArray (GLuint array); void WebGL2RenderingContext::BindVertexArray(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glBindVertexArray(args[0]); } // GL_EXPORT void glDeleteVertexArrays (GLsizei n, const GLuint* arrays); void WebGL2RenderingContext::DeleteVertexArray(Napi::CallbackInfo const& info) { CallbackArgs args = info; GLuint vertex_array = args[0]; GL_EXPORT::glDeleteVertexArrays(1, &vertex_array); } // GL_EXPORT void glDeleteVertexArrays (GLsizei n, const GLuint* arrays); void WebGL2RenderingContext::DeleteVertexArrays(Napi::CallbackInfo const& info) { CallbackArgs args = info; std::vector<GLuint> vertex_arrays = args[0]; GL_EXPORT::glDeleteVertexArrays(vertex_arrays.size(), vertex_arrays.data()); } // GL_EXPORT GLboolean glIsVertexArray (GLuint array); Napi::Value WebGL2RenderingContext::IsVertexArray(Napi::CallbackInfo const& info) { CallbackArgs args = info; auto is_vertex_array = GL_EXPORT::glIsVertexArray(args[0]); return CPPToNapi(info.Env())(is_vertex_array); } } // namespace nv
0
rapidsai_public_repos/node/modules/webgl
rapidsai_public_repos/node/modules/webgl/src/stencil.cpp
// Copyright (c) 2020-2021, NVIDIA CORPORATION. // // 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. #include "macros.hpp" #include "webgl.hpp" #include <nv_node/utilities/args.hpp> #include <nv_node/utilities/cpp_to_napi.hpp> namespace nv { // GL_EXPORT void glClearStencil (GLint s); void WebGL2RenderingContext::ClearStencil(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glClearStencil(args[0]); } // GL_EXPORT void glStencilFunc (GLenum func, GLint ref, GLuint mask); void WebGL2RenderingContext::StencilFunc(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glStencilFunc(args[0], args[1], args[2]); } // GL_EXPORT void glStencilFuncSeparate (GLenum frontfunc, GLenum backfunc, GLint ref, GLuint mask); void WebGL2RenderingContext::StencilFuncSeparate(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glStencilFuncSeparate(args[0], args[1], args[2], args[3]); } // GL_EXPORT void glStencilMask (GLuint mask); void WebGL2RenderingContext::StencilMask(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glStencilMask(args[0]); } // GL_EXPORT void glStencilMaskSeparate (GLenum face, GLuint mask); void WebGL2RenderingContext::StencilMaskSeparate(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glStencilMaskSeparate(args[0], args[1]); } // GL_EXPORT void glStencilOp (GLenum fail, GLenum zfail, GLenum zpass); void WebGL2RenderingContext::StencilOp(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glStencilOp(args[0], args[1], args[2]); } // GL_EXPORT void glStencilOpSeparate (GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass); void WebGL2RenderingContext::StencilOpSeparate(Napi::CallbackInfo const& info) { CallbackArgs args = info; GL_EXPORT::glStencilOpSeparate(args[0], args[1], args[2], args[3]); } } // namespace nv
0
rapidsai_public_repos/node/modules/webgl
rapidsai_public_repos/node/modules/webgl/src/addon.ts
// Copyright (c) 2020-2022, NVIDIA CORPORATION. // // 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. import {addon as CORE} from '@rapidsai/core'; export const gl: any = require('bindings')('rapidsai_webgl.node').init(CORE); export default gl;
0
rapidsai_public_repos/node/modules/webgl
rapidsai_public_repos/node/modules/webgl/src/macros.hpp
// Copyright (c) 2020-2021, NVIDIA CORPORATION. // // 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. #pragma once #include "errors.hpp" #define EXPORT_PROP(exports, name, val) exports.Set(name, val); #define EXPORT_ENUM(env, exports, name, val) \ EXPORT_PROP(exports, name, Napi::Number::New(env, static_cast<int64_t>(val))); #define EXPORT_FUNC(env, exports, name, func) \ exports.DefineProperty(Napi::PropertyDescriptor::Function( \ env, \ exports, \ Napi::String::New(env, name), \ func, \ static_cast<napi_property_attributes>(napi_writable | napi_enumerable | napi_configurable), \ nullptr)); #define GLEW_THROW(env, code) \ NAPI_THROW(nv::glewError(env, code, __FILE__, __LINE__), (e).Undefined()) #define GLEW_THROW_ASYNC(task, code) \ (task)->Reject(nv::glewError((task)->Env(), code, __FILE__, __LINE__).Value()); \ return (task)->Promise() #define GL_TRY(env, expr) \ do { \ (expr); \ GLenum const code = GL_EXPORT::glGetError(); \ if (code != GLEW_NO_ERROR) { GLEW_THROW(env, code); } \ } while (0) #define GL_TRY_VOID(env, expr) \ do { \ (expr); \ GLenum const code = GL_EXPORT::glGetError(); \ if (code != GLEW_NO_ERROR) { return; } \ } while (0) #define GL_TRY_ASYNC(env, expr) \ do { \ (expr); \ GLenum const code = GL_EXPORT::glGetError(); \ if (code != GLEW_NO_ERROR) { GLEW_THROW_ASYNC(env, code); } \ } while (0) #define GL_EXPECT_OK(env, expr) \ do { \ GLenum const code = (expr); \ if (code != GLEW_OK) { GLEW_THROW(env, code); } \ } while (0)
0
rapidsai_public_repos/node/modules/webgl
rapidsai_public_repos/node/modules/webgl/test/webgl-tests.ts
test('nothing', () => {});
0
rapidsai_public_repos/node/modules/webgl
rapidsai_public_repos/node/modules/webgl/test/tsconfig.json
{ "extends": "../tsconfig.json", "include": [ "../src/**/*.ts", "../test/**/*.ts" ], "compilerOptions": { "target": "esnext", "module": "commonjs", "allowJs": true, "importHelpers": false, "noEmitHelpers": false, "noEmitOnError": false, "sourceMap": false, "inlineSources": false, "inlineSourceMap": false, "downlevelIteration": false, "baseUrl": "../", "paths": { "@rapidsai/webgl": ["src/index"], "@rapidsai/webgl/*": ["src/*"] } } }
0
rapidsai_public_repos/node/modules
rapidsai_public_repos/node/modules/core/package.json
{ "name": "@rapidsai/core", "version": "22.12.2", "description": "Shared CMake modules, TypeScript configurations, and C++ headers for RAPIDS node native modules", "main": "index.js", "types": "build/js", "license": "Apache-2.0", "author": "NVIDIA, Inc. (https://nvidia.com/)", "maintainers": [ "Paul Taylor <[email protected]>" ], "homepage": "https://github.com/rapidsai/node/tree/main/modules/core#readme", "bugs": { "url": "https://github.com/rapidsai/node/issues" }, "repository": { "type": "git", "url": "git+https://github.com/rapidsai/node.git" }, "bin": { "rapidsai-install-native-module": "bin/rapidsai_install_native_module.js", "rapidsai-merge-compile-commands": "bin/rapidsai_merge_compile_commands.js" }, "scripts": { "clean": "rimraf build compile_commands.json", "build": "yarn tsc:build && yarn cpp:build", "build:debug": "yarn tsc:build && yarn cpp:build:debug", "compile": "yarn tsc:build && yarn cpp:compile", "compile:debug": "yarn tsc:build && yarn cpp:compile:debug", "rebuild": "yarn tsc:build && yarn cpp:rebuild", "rebuild:debug": "yarn tsc:build && yarn cpp:rebuild:debug", "cpp:clean": "npx cmake-js clean -O build/Release", "cpp:clean:debug": "npx cmake-js clean -O build/Debug", "cpp:build": "npx cmake-js build -g -O build/Release", "cpp:build:debug": "npx cmake-js build -g -D -O build/Debug", "cpp:compile": "npx cmake-js compile -g -O build/Release", "postcpp:compile": "npx rapidsai-merge-compile-commands", "cpp:compile:debug": "npx cmake-js compile -g -D -O build/Debug", "postcpp:compile:debug": "npx rapidsai-merge-compile-commands", "cpp:configure": "npx cmake-js configure -g -O build/Release", "postcpp:configure": "npx rapidsai-merge-compile-commands", "cpp:configure:debug": "npx cmake-js configure -g -D -O build/Debug", "postcpp:configure:debug": "npx rapidsai-merge-compile-commands", "cpp:rebuild": "npx cmake-js rebuild -g -O build/Release", "postcpp:rebuild": "npx rapidsai-merge-compile-commands", "cpp:rebuild:debug": "npx cmake-js rebuild -g -D -O build/Debug", "postcpp:rebuild:debug": "npx rapidsai-merge-compile-commands", "cpp:reconfigure": "npx cmake-js reconfigure -g -O build/Release", "postcpp:reconfigure": "npx rapidsai-merge-compile-commands", "cpp:reconfigure:debug": "npx cmake-js reconfigure -g -D -O build/Debug", "postcpp:reconfigure:debug": "npx rapidsai-merge-compile-commands", "tsc:clean": "rimraf build/js", "tsc:build": "yarn tsc:clean && tsc -p ./tsconfig.json", "tsc:watch": "yarn tsc:clean && tsc -p ./tsconfig.json -w" }, "dependencies": { "@types/node": "^15.0.0", "bindings": "^1.5.0", "cmake-js": "7.2.1", "cross-env": "7.0.3", "getos": "3.2.1", "tslib": "^2.3.0" }, "devDependencies": { "@types/jest": "26.0.23", "dotenv": "8.2.0", "jest": "26.5.3", "node-addon-api": "4.2.0", "rimraf": "3.0.0", "ts-jest": "26.5.3", "typedoc": "0.22.10", "typescript": "4.5.5" }, "files": [ "LICENSE", "bin", "cmake", "index.js", "package.json", "CMakeLists.txt", "include/nv_node", "build/js", "build/Release/*.node" ] }
0
rapidsai_public_repos/node/modules
rapidsai_public_repos/node/modules/core/index.js
// Copyright (c) 2020, NVIDIA CORPORATION. // // 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. module.exports = require('./build/js/index');
0
rapidsai_public_repos/node/modules
rapidsai_public_repos/node/modules/core/jest.config.js
// Copyright (c) 2020, NVIDIA CORPORATION. // // 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. try { require('dotenv').config(); } catch (e) {} module.exports = { 'verbose': true, 'testEnvironment': 'node', 'maxWorkers': process.env.PARALLEL_LEVEL || 1, 'globals': {'ts-jest': {'diagnostics': false, 'tsconfig': 'test/tsconfig.json'}}, 'rootDir': './', 'roots': ['<rootDir>/test/'], 'moduleFileExtensions': ['js', 'ts', 'tsx'], 'coverageReporters': ['lcov'], 'coveragePathIgnorePatterns': ['test\\/.*\\.(ts|tsx|js)$', '/node_modules/'], 'transform': {'^.+\\.jsx?$': 'ts-jest', '^.+\\.tsx?$': 'ts-jest'}, 'transformIgnorePatterns': ['/lib/*$', '/node_modules/(?!web-stream-tools).+\\.js$'], 'testRegex': '(.*(-|\\.)(test|spec)s?)\\.(ts|tsx|js)$', 'preset': 'ts-jest', 'testMatch': null, 'moduleNameMapper': { '^@rapidsai\/core(.*)': '<rootDir>/src/$1', } };
0
rapidsai_public_repos/node/modules
rapidsai_public_repos/node/modules/core/CMakeLists.txt
#============================================================================= # Copyright (c) 2020-2022, NVIDIA CORPORATION. # # 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. #============================================================================= cmake_minimum_required(VERSION 3.24.1 FATAL_ERROR) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) unset(CMAKE_LIBRARY_OUTPUT_DIRECTORY) unset(CMAKE_LIBRARY_OUTPUT_DIRECTORY CACHE) option(NODE_RAPIDS_USE_SCCACHE "Enable caching compilation results with sccache" ON) ################################################################################################### # - cmake modules --------------------------------------------------------------------------------- execute_process(COMMAND node -p "require('@rapidsai/core').cmake_modules_path" WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" OUTPUT_VARIABLE NODE_RAPIDS_CMAKE_MODULES_PATH OUTPUT_STRIP_TRAILING_WHITESPACE) include("${NODE_RAPIDS_CMAKE_MODULES_PATH}/cmake_policies.cmake") project(rapidsai_core VERSION $ENV{npm_package_version} LANGUAGES C CXX) include("${NODE_RAPIDS_CMAKE_MODULES_PATH}/ConfigureCXX.cmake") include("${NODE_RAPIDS_CMAKE_MODULES_PATH}/ConfigureCUDA.cmake") include("${NODE_RAPIDS_CMAKE_MODULES_PATH}/ConfigureNapi.cmake") include("${NODE_RAPIDS_CMAKE_MODULES_PATH}/install_utils.cmake") ################################################################################################### # - library paths --------------------------------------------------------------------------------- file(GLOB_RECURSE NODE_RAPIDS_CORE_SRC_FILES "${CMAKE_CURRENT_SOURCE_DIR}/src/addon.cpp") add_library(${PROJECT_NAME} SHARED ${NODE_RAPIDS_CORE_SRC_FILES} ${CMAKE_JS_SRC}) set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" SUFFIX ".node" BUILD_RPATH "\$ORIGIN" INSTALL_RPATH "\$ORIGIN" CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON CUDA_STANDARD 17 CUDA_STANDARD_REQUIRED ON POSITION_INDEPENDENT_CODE ON INTERFACE_POSITION_INDEPENDENT_CODE ON ) target_compile_options(${PROJECT_NAME} PRIVATE "$<BUILD_INTERFACE:$<$<COMPILE_LANGUAGE:C>:${NODE_RAPIDS_CMAKE_C_FLAGS}>>" "$<BUILD_INTERFACE:$<$<COMPILE_LANGUAGE:CXX>:${NODE_RAPIDS_CMAKE_CXX_FLAGS}>>" "$<BUILD_INTERFACE:$<$<COMPILE_LANGUAGE:CUDA>:${NODE_RAPIDS_CMAKE_CUDA_FLAGS}>>" ) target_include_directories(${PROJECT_NAME} PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>" "$<BUILD_INTERFACE:${NAPI_INCLUDE_DIRS}>" ) target_link_libraries(${PROJECT_NAME} PRIVATE CUDA::nvml) generate_install_rules(NAME ${PROJECT_NAME}) # Create a symlink to compile_commands.json for the llvm-vs-code-extensions.vscode-clangd plugin execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_CURRENT_BINARY_DIR}/compile_commands.json ${CMAKE_CURRENT_SOURCE_DIR}/compile_commands.json)
0
rapidsai_public_repos/node/modules
rapidsai_public_repos/node/modules/core/tsconfig.json
{ "include": ["src"], "exclude": ["node_modules"], "compilerOptions": { "baseUrl": "./", "paths": { "@rapidsai/core": ["src/index"], "@rapidsai/core/*": ["src/*"] }, "target": "ESNEXT", "module": "commonjs", "outDir": "./build/js", /* Decorators */ "experimentalDecorators": false, /* Basic stuff */ "moduleResolution": "node", "skipLibCheck": true, "skipDefaultLibCheck": true, "lib": ["dom", "esnext", "esnext.asynciterable"], /* Control what is emitted */ "declaration": true, "noEmitOnError": true, "removeComments": false, "downlevelIteration": true, /* Create inline sourcemaps with sources */ "sourceMap": false, "inlineSources": true, "inlineSourceMap": true, /* The most restrictive settings possible */ "strict": true, "importHelpers": true, "noEmitHelpers": true, "noImplicitAny": true, "noUnusedLocals": true, "noImplicitReturns": true, "allowUnusedLabels": false, "noUnusedParameters": true, "allowUnreachableCode": false, "noFallthroughCasesInSwitch": true, "forceConsistentCasingInFileNames": true } }
0
rapidsai_public_repos/node/modules
rapidsai_public_repos/node/modules/core/LICENSE
Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "{}" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright 2019 NVIDIA Corporation 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. -------------------------------------------------------------------------------- include/visit_struct/visit_struct.hpp (modified): BSL 1.0 Boost Software License - Version 1.0 - August 17th, 2003 Permission is hereby granted, free of charge, to any person or organization obtaining a copy of the software and accompanying documentation covered by this license (the "Software") to use, reproduce, display, distribute, execute, and transmit the Software, and to prepare derivative works of the Software, and to permit third-parties to whom the Software is furnished to do so, all subject to the following: The copyright notices in the Software and this entire statement, including the above license grant, this restriction and the following disclaimer, must be included in all copies of the Software, in whole or in part, and all derivative works of the Software, unless such copies or derivative works are solely in the form of machine-executable object code generated by a source language processor. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
0
rapidsai_public_repos/node/modules/core/include
rapidsai_public_repos/node/modules/core/include/nv_node/objectwrap.hpp
// Copyright (c) 2021, NVIDIA CORPORATION. // // 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. #pragma once #include <nv_node/addon.hpp> #include <napi.h> #include <type_traits> namespace nv { namespace detail { namespace tuple { // compile-time tuple iteration template <std::size_t I = 0, typename FuncT, typename... Tp> inline typename std::enable_if<I == sizeof...(Tp), void>::type for_each( std::tuple<Tp...> const&, FuncT) // Unused arguments are given no names. { // end recursion } template <std::size_t I = 0, typename FuncT, typename... Tp> inline typename std::enable_if < I<sizeof...(Tp), void>::type for_each(std::tuple<Tp...> const& t, FuncT func) { func(std::get<I>(t)); // recurse for_each<I + 1, FuncT, Tp...>(t, func); } } // namespace tuple } // namespace detail template <typename T> struct Wrapper : public Napi::Object { // Create a new _empty_ Wrapper<T> instance inline Wrapper() : Napi::Object() {} // Mirror the Napi::Object parent constructor inline Wrapper(napi_env env, napi_value value) : Napi::Object(env, value) { _parent = T::Unwrap(*this); } // Copy from an Napi::Object to Wrapper<T> inline Wrapper(Napi::Object const& value) : Napi::Object(value.Env(), value) { if (not T::IsInstance(value)) { NAPI_THROW(Napi::Error::New(Env(), "Attempted to create Wrapper for incompatible Object.")); } _parent = T::Unwrap(value); } // use default move constructor inline Wrapper(Wrapper<T>&&) = default; // use default copy constructor inline Wrapper(Wrapper<T> const&) = default; // use default move assignment operator inline Wrapper<T>& operator=(Wrapper<T>&&) = default; // use default copy assignment operator inline Wrapper<T>& operator=(Wrapper<T> const&) = default; // Allow converting Wrapper<T> to T& inline operator T&() const noexcept { return *_parent; } // Access T members via pointer-access operator inline T* operator->() const noexcept { return _parent; } // Allow converting to T& via dereference operator inline T& operator*() const noexcept { return *_parent; } private: T* _parent{nullptr}; }; template <typename T> struct EnvLocalObjectWrap : public Napi::ObjectWrap<T>, // public Napi::Reference<Wrapper<T>> { using wrapper_t = Wrapper<T>; using Napi::ObjectWrap<T>::Env; using Napi::ObjectWrap<T>::Ref; using Napi::ObjectWrap<T>::Unref; using Napi::ObjectWrap<T>::Reset; using Napi::ObjectWrap<T>::Value; using Napi::ObjectWrap<T>::SuppressDestruct; inline EnvLocalObjectWrap(Napi::CallbackInfo const& info) : Napi::ObjectWrap<T>(info){}; /** * @brief Retrieve the JavaScript constructor function for C++ type `T`. * * @param env The currently active JavaScript environment. * @return Napi::Function The JavaScript constructor function for C++ type T. */ inline static Napi::Function Constructor(Napi::Env env) { return env.GetInstanceData<EnvLocalAddon>()->GetConstructor<T>(); } /** * @brief Check whether an Napi value is an instance of C++ type `T`. * * @param value The Napi::Value to test * @return true if the value is an instance of type T * @return false if the value is not an instance of type T */ inline static bool IsInstance(Napi::Value const& value) { return value.IsObject() and value.As<Napi::Object>().InstanceOf(Constructor(value.Env())); } /** * @brief Construct a new instance of `T` from C++. * * @param env The currently active JavaScript environment. * @param napi_values The Napi::Value arguments to pass to the constructor for * type `T`. * @return Wrapper<T> The JavaScript Object representing the new C++ instance. * The lifetime of the C++ instance is tied to the lifetime of the returned * wrapper. */ inline static wrapper_t New(Napi::Env env, std::initializer_list<napi_value> const& napi_values) { return Constructor(env).New(napi_values); } /** * @brief Construct a new instance of `T` from C++. * * @param env The currently active JavaScript environment. * @param napi_values The Napi::Value arguments to pass to the constructor for * type `T`. * @return Wrapper<T> The JavaScript Object representing the new C++ instance. * The lifetime of the C++ instance is tied to the lifetime of the returned * wrapper. */ inline static wrapper_t New(Napi::Env env, std::vector<napi_value> const& napi_values) { return Constructor(env).New(napi_values); } /** * @brief Construct a new instance of `T` from C++ values. * * @param env The currently active JavaScript environment. * @param args VarArgs converted to Napi::Value and passed to the constructor * for type `T`. * @return Wrapper<T> The JavaScript Object representing the new C++ instance. * The lifetime of the C++ instance is tied to the lifetime of the returned * wrapper. */ template <typename... Args> inline static wrapper_t New(Napi::Env env, Args&&... args) { std::vector<napi_value> napi_values; napi_values.reserve(sizeof...(Args)); detail::tuple::for_each( std::make_tuple<Args...>(std::forward<Args>(args)...), [&](auto const& x) mutable { napi_values.push_back(Napi::Value::From(env, x)); }); return Constructor(env).New(napi_values); } inline operator wrapper_t() const { return Value(); } // inline wrapper_t Value() const { return Napi::ObjectWrap<T>::Value(); } }; } // namespace nv namespace Napi { namespace details { // Tell `Napi::Value::From` that `Wrapper<T>` instances cannot be converted to Strings template <typename T> struct can_make_string<nv::Wrapper<T>> : std::false_type {}; // Tell `Napi::Value::From` that `EnvLocalObjectWrap<T>` instances cannot be converted to Strings template <typename T> struct can_make_string<nv::EnvLocalObjectWrap<T>> : std::false_type {}; template <typename T> struct vf_fallback<nv::Wrapper<T>> { inline static Value From(napi_env env, nv::Wrapper<T> const& wrapper) { return wrapper; } }; } // namespace details } // namespace Napi
0
rapidsai_public_repos/node/modules/core/include
rapidsai_public_repos/node/modules/core/include/nv_node/addon.hpp
// Copyright (c) 2021, NVIDIA CORPORATION. // // 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. #pragma once #include <napi.h> #include <string> #include <typeinfo> namespace nv { struct EnvLocalAddon { inline EnvLocalAddon(Napi::Env const& env, Napi::Object exports) { _cpp_exports = Napi::Persistent(Napi::Object::New(env)); }; inline Napi::Value GetCppExports(Napi::CallbackInfo const& info) { return _cpp_exports.Value(); } template <typename Class> inline Napi::Function GetConstructor() { return _cpp_exports.Get(std::to_string(typeid(Class).hash_code())).As<Napi::Function>(); } protected: Napi::ObjectReference _cpp_exports; Napi::FunctionReference _after_init; template <typename Class> inline Napi::Function InitClass(Napi::Env const& env, Napi::Object exports) { auto const constructor = Class::Init(env, exports); _cpp_exports.Set(std::to_string(typeid(Class).hash_code()), constructor); return constructor; } inline Napi::Value InitAddon(Napi::CallbackInfo const& info) { std::vector<napi_value> args; args.reserve(info.Length()); for (std::size_t i = 0; i < info.Length(); ++i) { args.push_back(info[i]); } RegisterAddon(info.Env(), args); if (!_after_init.IsEmpty()) { // _after_init.Call(info.This(), args); } return info.This(); } inline void RegisterAddon(Napi::Env env, std::vector<napi_value> const& info) { auto rhs = env.GetInstanceData<EnvLocalAddon>()->_cpp_exports.Value(); auto GlobalObject = env.Global().Get("Object").As<Napi::Function>(); auto ObjectAssign = GlobalObject.Get("assign").As<Napi::Function>(); for (auto const& _ : info) { Napi::HandleScope scope(env); Napi::Value const module(env, _); if (module.IsObject()) { auto const addon = module.As<Napi::Object>(); if (addon.Has("_cpp_exports")) { auto const exports = addon.Get("_cpp_exports"); if (exports.Type() == napi_object) { // ObjectAssign({rhs, exports.As<Napi::Object>()}); } } } } } }; } // namespace nv
0
rapidsai_public_repos/node/modules/core/include
rapidsai_public_repos/node/modules/core/include/nv_node/macros.hpp
// Copyright (c) 2020, NVIDIA CORPORATION. // // 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. #pragma once #ifndef EXPORT_PROP #define EXPORT_PROP(exports, name, val) exports.Set(name, val); #endif #ifndef EXPORT_ENUM #define EXPORT_ENUM(env, exports, name, val) \ EXPORT_PROP(exports, name, Napi::Number::New(env, static_cast<int64_t>(val))); #endif #ifndef EXPORT_FUNC #define EXPORT_FUNC(env, exports, name, func) \ exports.DefineProperty(Napi::PropertyDescriptor::Function( \ env, \ exports, \ Napi::String::New(env, name), \ func, \ static_cast<napi_property_attributes>(napi_writable | napi_enumerable | napi_configurable), \ nullptr)); #endif
0
rapidsai_public_repos/node/modules/core/include/nv_node
rapidsai_public_repos/node/modules/core/include/nv_node/async/task.hpp
// Copyright (c) 2020-2021, NVIDIA CORPORATION. // // 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. #pragma once #include <napi.h> namespace nv { class Task : public Napi::AsyncWorker { public: static inline Napi::Promise Rejected(const Napi::Value& value) { return (new Task(value.Env()))->Reject(value).Promise(); } static inline Napi::Promise Resolved(const Napi::Value& value) { return (new Task(value.Env()))->Resolve(value).Promise(); } // Safe to call from any thread static inline void Notify(void* task) { Task::Notify(static_cast<Task*>(task)); } static inline void Notify(Task* task) { if (!task->notified_ && (task->notified_ = true)) { task->Queue(); } } Task(Napi::Env const& env) : Task(env, env.Undefined()){}; Task(Napi::Env const& env, Napi::Value value) : Napi::AsyncWorker(env), deferred_(Napi::Promise::Deferred::New(env)) { this->Inject(value); } Napi::Promise Promise() const { return deferred_.Promise(); } Task& Inject(const Napi::Value& value) { if (!(value.IsObject() || value.IsFunction())) { val_ = value; } else { ref_.Reset(value); } return *this; } Task& Reject() { if (notified_ == false && (rejected_ = true)) { Task::Notify(this); } return *this; } Task& Reject(const Napi::Value& value) { return (notified_ ? *this : this->Inject(value)).Reject(); } Task& Resolve() { if (notified_ == false && !(rejected_ = false)) { Task::Notify(this); } return *this; } Task& Resolve(const Napi::Value& value) { return (notified_ ? *this : this->Inject(value)).Resolve(); } inline bool DelayResolve(const bool shouldDelayResolve) { if (!shouldDelayResolve) this->Resolve(); return shouldDelayResolve; } protected: void Execute() override {} void OnOK() override { if (!settled_ && (settled_ = true)) { Napi::HandleScope scope(Env()); auto val = !ref_.IsEmpty() ? ref_.Value() : !val_.IsEmpty() ? val_ : Env().Undefined(); rejected_ == true ? deferred_.Reject(val) : deferred_.Resolve(val); } } bool settled_ = false; bool rejected_ = false; bool notified_ = false; Napi::Value val_; Napi::Reference<Napi::Value> ref_; Napi::Promise::Deferred deferred_; }; } // namespace nv
0
rapidsai_public_repos/node/modules/core/include/nv_node
rapidsai_public_repos/node/modules/core/include/nv_node/utilities/napi_to_cpp.hpp
// Copyright (c) 2020-2021, NVIDIA CORPORATION. // // 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. #pragma once #include "../objectwrap.hpp" #include "span.hpp" #include <napi.h> #include <cstring> #include <iostream> #include <map> #include <string> #include <type_traits> #include <vector> namespace nv { struct NapiToCPP { Napi::Value val; inline NapiToCPP(const Napi::Value& val) : val(val) {} struct Object { Napi::Object val; inline Object(Napi::Object const& o) : val(o) {} inline Object(Napi::Value const& o) : val(o.As<Napi::Object>()) {} inline operator Napi::Object() const { return val; } inline Napi::Env Env() const { return val.Env(); } inline bool Has(napi_value key) const { return val.Has(key); } inline bool Has(Napi::Value key) const { return val.Has(key); } inline bool Has(const char* key) const { return val.Has(key); } inline bool Has(const std::string& key) const { return val.Has(key); } inline NapiToCPP Get(napi_value key) const { return GetOrDefault(key, Env().Undefined()); } inline NapiToCPP Get(Napi::Value key) const { return GetOrDefault(key, Env().Undefined()); } inline NapiToCPP Get(const char* key) const { return GetOrDefault(key, Env().Undefined()); } inline NapiToCPP Get(std::string const& key) const { return GetOrDefault(key, Env().Undefined()); } inline NapiToCPP GetOrDefault(napi_value key, Napi::Value const& default_val) const { return Has(key) ? val.Get(key) : default_val; } inline NapiToCPP GetOrDefault(Napi::Value key, Napi::Value const& default_val) const { return Has(key) ? val.Get(key) : default_val; } inline NapiToCPP GetOrDefault(const char* key, Napi::Value const& default_val) const { return Has(key) ? val.Get(key) : default_val; } inline NapiToCPP GetOrDefault(std::string const& key, Napi::Value const& default_val) const { return Has(key) ? val.Get(key) : default_val; } }; inline std::ostream& operator<<(std::ostream& os) const { return os << val.ToString().operator std::string(); } inline Napi::Env Env() const { return val.Env(); } inline bool IsEmpty() const { return val.IsEmpty(); } inline bool IsUndefined() const { return val.IsUndefined(); } inline bool IsNull() const { return val.IsNull(); } inline bool IsBoolean() const { return val.IsBoolean(); } inline bool IsNumber() const { return val.IsNumber(); } inline bool IsBigInt() const { return val.IsBigInt(); } inline bool IsDate() const { return val.IsDate(); } inline bool IsString() const { return val.IsString(); } inline bool IsSymbol() const { return val.IsSymbol(); } inline bool IsArray() const { return val.IsArray(); } inline bool IsArrayBuffer() const { return val.IsArrayBuffer(); } inline bool IsTypedArray() const { return val.IsTypedArray(); } inline bool IsObject() const { return val.IsObject(); } inline bool IsFunction() const { return val.IsFunction(); } inline bool IsPromise() const { return val.IsPromise(); } inline bool IsDataView() const { return val.IsDataView(); } inline bool IsBuffer() const { return val.IsBuffer(); } inline bool IsExternal() const { return val.IsExternal(); } inline bool IsMemoryViewLike() const { if (IsTypedArray() || IsDataView() || IsBuffer()) { return true; } if (val.IsObject() and not val.IsNull() and val.As<Napi::Object>().Has("buffer")) { return NapiToCPP(val.As<Napi::Object>().Get("buffer")).IsMemoryLike(); } return false; } inline bool IsMemoryLike() const { if (IsArrayBuffer() || IsTypedArray() || IsDataView() || IsBuffer()) { return true; } if (val.IsObject() and not val.IsNull()) { auto obj = val.As<Napi::Object>(); if (obj.Has("buffer")) { // return NapiToCPP(obj.Get("buffer")).IsMemoryLike(); } return obj.Has("ptr") and obj.Get("ptr").IsNumber(); } return false; } inline bool IsDeviceMemoryLike() const { if (IsObject() and not IsNull()) { NapiToCPP::Object const& obj = val; if (obj.Has("buffer")) { // return obj.Get("buffer").IsDeviceMemoryLike(); } return obj.Has("ptr") and obj.Get("ptr").IsNumber(); } return false; } inline Napi::Boolean ToBoolean() const { return val.ToBoolean(); } inline Napi::Number ToNumber() const { return val.ToNumber(); } inline Napi::String ToString() const { return val.ToString(); } inline Napi::Object ToObject() const { return val.ToObject(); } template <typename T> T As() const { return val.As<T>(); } template <typename T> operator Wrapper<T>() const { return Wrapper<T>(As<Napi::Object>()); } template <typename T> operator T() const; // // Napi identities // inline operator Napi::Value() const { return val; } inline operator Napi::Boolean() const { return val.As<Napi::Boolean>(); } inline operator Napi::Number() const { return val.As<Napi::Number>(); } inline operator Napi::String() const { return val.As<Napi::String>(); } inline operator Napi::Object() const { return val.As<Napi::Object>(); } inline operator Napi::Array() const { return val.As<Napi::Array>(); } inline operator Napi::Function() const { return val.As<Napi::Function>(); } inline operator Napi::Error() const { return val.As<Napi::Error>(); } inline operator Napi::ArrayBuffer() const { if (val.IsArrayBuffer()) { return val.As<Napi::ArrayBuffer>(); } if (val.IsDataView()) { return val.As<Napi::DataView>().ArrayBuffer(); } if (val.IsTypedArray()) { return val.As<Napi::TypedArray>().ArrayBuffer(); } auto msg = "Value must be ArrayBuffer or ArrayBufferView"; NAPI_THROW(Napi::Error::New(val.Env(), msg), val.Env().Undefined()); } inline operator Napi::DataView() const { return val.As<Napi::DataView>(); } inline operator Napi::TypedArray() const { return val.As<Napi::TypedArray>(); } template <typename T> inline operator Napi::TypedArrayOf<T>() const { bool is_valid{false}; std::size_t length{}; std::size_t offset{}; Napi::ArrayBuffer buffer; if (IsArrayBuffer()) { is_valid = true; buffer = val.As<Napi::ArrayBuffer>(); length = buffer.ByteLength() / sizeof(T); } else if (IsDataView()) { is_valid = true; auto const ary = val.As<Napi::DataView>(); buffer = ary.ArrayBuffer(); offset = ary.ByteOffset(); length = ary.ByteLength() / sizeof(T); } else if (IsTypedArray()) { is_valid = true; auto const ary = val.As<Napi::TypedArray>(); buffer = ary.ArrayBuffer(); offset = ary.ByteOffset(); length = ary.ByteLength() / sizeof(T); } if (is_valid) { return Napi::TypedArrayOf<T>::New(Env(), length, buffer, offset); } throw Napi::Error::New(Env(), "Expected ArrayBuffer or ArrayBufferView"); } template <typename T> inline operator Napi::Buffer<T>() const { return val.As<Napi::Buffer<T>>(); } inline operator Object() const { return Object(val); } // // Primitives // inline operator bool() const { return val.ToBoolean(); } inline operator float() const { return to_numeric<float>(); } inline operator double() const { return to_numeric<double>(); } inline operator int8_t() const { return to_numeric<int64_t>(); } inline operator int16_t() const { return to_numeric<int64_t>(); } inline operator int32_t() const { return to_numeric<int32_t>(); } inline operator int64_t() const { return to_numeric<int64_t>(); } inline operator uint8_t() const { return to_numeric<int64_t>(); } inline operator uint16_t() const { return to_numeric<int64_t>(); } inline operator uint32_t() const { return to_numeric<uint32_t>(); } inline operator uint64_t() const { return to_numeric<int64_t>(); } inline operator std::string() const { return val.ToString(); } inline operator std::u16string() const { return val.ToString(); } inline operator napi_value() const { return val.operator napi_value(); } // // Arrays // template <typename T> inline operator std::vector<T>() const { if (val.IsArray()) { auto env = Env(); NapiToCPP v{env.Null()}; auto arr = val.As<Napi::Array>(); std::vector<T> vec; vec.reserve(arr.Length()); for (uint32_t i = 0; i < arr.Length(); ++i) { Napi::HandleScope scope{env}; v.val = arr.Get(i); vec.push_back(v); } return vec; } if (!(val.IsNull() || val.IsEmpty())) { // return std::vector<T>{this->operator T()}; } return std::vector<T>{}; } // // Objects // template <typename Key, typename Val> inline operator std::map<Key, Val>() const { if (val.IsObject()) { auto env = Env(); NapiToCPP k{env.Null()}; NapiToCPP v{env.Null()}; std::map<Key, Val> map{}; auto obj = val.As<Napi::Object>(); auto keys = obj.GetPropertyNames(); for (uint32_t i = 0; i < keys.Length(); ++i) { Napi::HandleScope scope{env}; k.val = keys.Get(i); v.val = obj.Get(k.val); map[k] = v; } return map; } return std::map<Key, Val>{}; } // // Pointers // inline operator void*() const { // return static_cast<void*>(as_span<char>().data()); } inline operator void const*() const { // return static_cast<void const*>(as_span<char>().data()); } template <typename T> inline operator T*() const { return as_span<T>(); } template <typename T> inline operator Span<T>() const { return as_span<T>(); } #ifdef GLEW_VERSION inline operator GLsync() const { return reinterpret_cast<GLsync>(this->operator char*()); } #endif #ifdef GLFW_APIENTRY_DEFINED inline operator GLFWcursor*() const { return reinterpret_cast<GLFWcursor*>(this->operator char*()); } inline operator GLFWwindow*() const { return reinterpret_cast<GLFWwindow*>(this->operator char*()); } inline operator GLFWmonitor*() const { return reinterpret_cast<GLFWmonitor*>(this->operator char*()); } inline operator GLFWglproc*() const { return reinterpret_cast<GLFWglproc*>(this->operator char*()); } #endif protected: template <typename T> inline Span<T> as_span() const { // Easy cases -- ArrayBuffers and ArrayBufferViews if (val.IsDataView()) { return Span<T>(val.As<Napi::DataView>()); } if (val.IsTypedArray()) { return Span<T>(val.As<Napi::TypedArray>()); } if (val.IsArrayBuffer()) { return Span<T>(val.As<Napi::ArrayBuffer>()); } // Value could be an Napi::External wrapper around a raw pointer if (val.IsExternal()) { return Span<T>(val.As<Napi::External<T>>()); } // Allow treating JS numbers as memory addresses. Useful, but dangerous. if (val.IsNumber()) { // return Span<T>(reinterpret_cast<char*>(val.ToNumber().Int64Value()), 0); } // Objects wrapping raw memory with some conventions: // * Objects with a numeric "ptr" field and optional numeric "byteLength" field // * Objects with a "buffer" field, which itself has numeric "byteLength" and "ptr" fields // If the wrapping object has a numeric "byteOffset" field, it is propagated to the span. if (val.IsObject() and not val.IsNull()) { size_t length{0}; size_t offset{0}; auto obj = val.As<Napi::Object>(); if (obj.Has("byteOffset") and obj.Get("byteOffset").IsNumber()) { offset = NapiToCPP(obj.Get("byteOffset")); } if (obj.Has("byteLength") and obj.Get("byteLength").IsNumber()) { length = NapiToCPP(obj.Get("byteLength")); } if (obj.Has("buffer") and obj.Get("buffer").IsObject()) { obj = obj.Get("buffer").As<Napi::Object>(); } if (obj.Has("ptr")) { if (obj.Get("ptr").IsNumber()) { return Span<T>(static_cast<char*>(NapiToCPP(obj.Get("ptr"))) + offset, length); } NAPI_THROW("Expected `ptr` to be numeric"); } auto span = NapiToCPP(obj).as_span<T>() + offset; if (span.data() != nullptr) { // return Span<T>(span.data(), std::min(span.size(), length)); } } return Span<T>(static_cast<char*>(nullptr), 0); } template <typename T> inline T to_numeric() const { if (val.IsNull() || val.IsEmpty()) { return 0; } if (val.IsNumber() || val.IsString()) { return val.ToNumber(); } if (val.IsBigInt()) { bool lossless = true; return std::is_signed<T>() ? static_cast<T>(val.As<Napi::BigInt>().Int64Value(&lossless)) : static_cast<T>(val.As<Napi::BigInt>().Uint64Value(&lossless)); } if (val.IsBoolean()) { return val.ToBoolean().operator bool(); } // Accept single-element numeric Arrays (e.g. OpenGL) if (val.IsArray()) { auto ary = val.As<Napi::Array>(); if (ary.Length() == 1) { auto elt = ary.Get(uint32_t{0}); if (elt.IsNumber() || elt.IsBigInt()) { return static_cast<T>(NapiToCPP(ary.Get(uint32_t{0}))); } NAPI_THROW("Expected `0` to be numeric"); } return 0; } // Accept Objects with a numeric "ptr" field (e.g. OpenGL) if (val.IsObject()) { auto obj = val.As<Napi::Object>(); if (obj.Has("ptr")) { auto ptr = obj.Get("ptr"); if (ptr.IsNumber()) { // return static_cast<T>(NapiToCPP(ptr)); } NAPI_THROW("Expected `ptr` to be numeric"); } } return 0; } }; } // namespace nv
0
rapidsai_public_repos/node/modules/core/include/nv_node
rapidsai_public_repos/node/modules/core/include/nv_node/utilities/span.hpp
// Copyright (c) 2020, NVIDIA CORPORATION. // // 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. #pragma once #include <napi.h> namespace nv { template <typename T> struct Span { Span(std::size_t size) : data_{nullptr}, size_{size} {} Span(T* data, std::size_t size) : data_{data}, size_{size} {} Span(void* data, std::size_t size) : Span(reinterpret_cast<T*>(data), size) {} template <typename R> Span(R* data, std::size_t size) : data_{reinterpret_cast<T*>(data)}, // size_{static_cast<size_t>(static_cast<double>(sizeof(R)) / sizeof(T) * size)} {} Span(Napi::External<T> const& external) : Span<T>(external.Data(), 0) {} Span(Napi::ArrayBuffer& buffer) : Span<T>(buffer.Data(), buffer.ByteLength() / sizeof(T)) {} Span(Napi::ArrayBuffer const& buffer) : Span<T>(*const_cast<Napi::ArrayBuffer*>(&buffer)) {} Span(Napi::DataView const& view) { this->data_ = reinterpret_cast<T*>(view.ArrayBuffer().Data()) + (view.ByteOffset() / sizeof(T)); this->size_ = view.ByteLength() / sizeof(T); } Span(Napi::TypedArray const& ary) { this->data_ = reinterpret_cast<T*>(ary.ArrayBuffer().Data()) + (ary.ByteOffset() / sizeof(T)); this->size_ = ary.ByteLength() / sizeof(T); } template <typename R> inline operator Span<R>() const { return Span<R>(data_, size_); } inline operator void*() const noexcept { return static_cast<void*>(data_); } inline T* data() const noexcept { return data_; } inline operator T*() const noexcept { return data_; } inline std::size_t size() const noexcept { return size_; } inline operator std::size_t() const noexcept { return size_; } inline std::size_t addr() const noexcept { return reinterpret_cast<std::size_t>(data_); } Span<T>& operator+=(std::size_t const offset) noexcept { if (data_ != nullptr && size_ > 0) { this->data_ += offset; this->size_ -= offset; } return *this; } Span<T> inline operator+(std::size_t offset) const noexcept { auto copy = *this; copy += offset; return copy; } private: T* data_{}; std::size_t size_{}; }; } // namespace nv
0
rapidsai_public_repos/node/modules/core/include/nv_node
rapidsai_public_repos/node/modules/core/include/nv_node/utilities/cpp_to_napi.hpp
// Copyright (c) 2020-2021, NVIDIA CORPORATION. // // 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. #pragma once #include "span.hpp" #include <napi.h> #include <initializer_list> #include <map> #include <stdexcept> #include <string> #include <type_traits> #include <vector> namespace nv { namespace casting { template <std::size_t I = 0, typename FuncT, typename... Tp> inline typename std::enable_if<I == sizeof...(Tp), void>::type for_each( std::tuple<Tp...> const&, FuncT) // Unused arguments are given no names. {} template <std::size_t I = 0, typename FuncT, typename... Tp> inline typename std::enable_if < I<sizeof...(Tp), void>::type for_each(std::tuple<Tp...> const& t, FuncT f) { f(std::get<I>(t)); for_each<I + 1, FuncT, Tp...>(t, f); } } // namespace casting struct CPPToNapi { inline CPPToNapi(Napi::Env const& env) : _env(env) {} inline CPPToNapi(Napi::CallbackInfo const& info) : CPPToNapi(info.Env()) {} inline Napi::Env Env() const { return _env; } template <typename Arg> Napi::Value operator()(Arg const&) const; // // Napi identities // inline napi_value operator()(napi_value const& val) const { return val; } inline Napi::Value operator()(Napi::Value const& val) const { return val; } inline Napi::Boolean operator()(Napi::Boolean const& val) const { return val; } inline Napi::Number operator()(Napi::Number const& val) const { return val; } inline Napi::String operator()(Napi::String const& val) const { return val; } inline Napi::Object operator()(Napi::Object const& val) const { return val; } inline Napi::Array operator()(Napi::Array const& val) const { return val; } inline Napi::Function operator()(Napi::Function const& val) const { return val; } inline Napi::Error operator()(Napi::Error const& val) const { return val; } inline Napi::ArrayBuffer operator()(Napi::ArrayBuffer const& val) const { return val; } inline Napi::DataView operator()(Napi::DataView const& val) const { return val; } inline Napi::TypedArray operator()(Napi::TypedArray const& val) const { return val; } template <typename T> inline Napi::TypedArrayOf<T> operator()(Napi::TypedArrayOf<T> const& val) const { return val; } template <typename T> inline Napi::Buffer<T> operator()(Napi::Buffer<T> const& val) const { return val; } // Primitives inline Napi::Boolean operator()(bool const& val) const { return Napi::Boolean::New(Env(), val); } inline Napi::Number operator()(float const& val) const { return Napi::Number::New(Env(), val); } inline Napi::Number operator()(double const& val) const { return Napi::Number::New(Env(), val); } inline Napi::Number operator()(int8_t const& val) const { return Napi::Number::New(Env(), val); } inline Napi::Number operator()(int16_t const& val) const { return Napi::Number::New(Env(), val); } inline Napi::Number operator()(int32_t const& val) const { return Napi::Number::New(Env(), val); } inline Napi::Number operator()(int64_t const& val) const { return Napi::Number::New(Env(), val); } inline Napi::Number operator()(uint8_t const& val) const { return Napi::Number::New(Env(), val); } inline Napi::Number operator()(uint16_t const& val) const { return Napi::Number::New(Env(), val); } inline Napi::Number operator()(uint32_t const& val) const { return Napi::Number::New(Env(), val); } inline Napi::Number operator()(uint64_t const& val) const { return Napi::Number::New(Env(), val); } inline Napi::String operator()(std::string const& val) const { return Napi::String::New(Env(), val); } inline Napi::String operator()(std::u16string const& val) const { return Napi::String::New(Env(), val); } // // Pair // template <typename T> Napi::Object inline operator()(std::pair<T, T> const& pair) const { auto cast_t = *this; auto obj = Napi::Array::New(Env(), 2); obj.Set(uint32_t(0), cast_t(pair.first)); obj.Set(uint32_t(1), cast_t(pair.second)); return obj; } // // Arrays // // template <typename T, int N> // inline Napi::Array operator()(const T (&arr)[N]) const { // return (*this)(std::vector<T>{arr, arr + N}); // } template <typename T> inline Napi::Array operator()(std::vector<T> const& vec) const { uint32_t idx = 0; auto arr = Napi::Array::New(Env(), vec.size()); std::for_each( vec.begin(), vec.end(), [&](T const& val) mutable { arr.Set((*this)(idx++), (*this)(val)); }); return arr; } template <typename T> inline Napi::Array operator()(std::initializer_list<T> const& vec) const { uint32_t idx = 0; auto arr = Napi::Array::New(Env(), vec.size()); std::for_each( vec.begin(), vec.end(), [&](T const& val) mutable { arr.Set((*this)(idx++), (*this)(val)); }); return arr; } // // Objects // template <typename Key, typename Val> Napi::Object inline operator()(const std::map<Key, Val> map) const { auto cast_t = *this; auto obj = Napi::Object::New(Env()); for (auto pair : map) { obj.Set(cast_t(pair.first), cast_t(pair.second)); } return obj; } template <typename T> inline Napi::Object operator()(std::vector<T> const& vals, std::vector<std::string> const& keys) const { auto self = *this; auto val = vals.begin(); auto key = keys.begin(); auto obj = Napi::Object::New(Env()); while ((val != vals.end()) && (key != keys.end())) { obj.Set(self(*key), self(*val)); std::advance(key, 1); std::advance(val, 1); } return obj; } template <typename... Vals> Napi::Object inline operator()(std::initializer_list<std::string> const& keys, std::tuple<Vals...> const& vals) const { auto cast_t = *this; auto key = keys.begin(); auto obj = Napi::Object::New(Env()); nv::casting::for_each(vals, [&](auto val) { obj.Set(cast_t(*key), cast_t(val)); std::advance(key, 1); }); return obj; } // // Pointers // template <typename T> inline Napi::Value operator()(T* data) const { return Napi::Number::New(Env(), reinterpret_cast<uintptr_t>(data)); } template <typename T> inline Napi::Value operator()(T const* data) const { return Napi::Number::New(Env(), reinterpret_cast<uintptr_t>(data)); } template <typename T> inline Napi::Value operator()(std::tuple<T const*, size_t> pair) const { auto size = sizeof(T) * std::get<1>(pair); auto buf = Napi::ArrayBuffer::New(Env(), size); std::memcpy(buf.Data(), std::get<0>(pair), size); return buffer_to_typed_array<T>(buf); } template <typename T> inline Napi::Value operator()(Span<T> const& span) const { auto obj = Napi::Object::New(Env()); obj["ptr"] = span.addr(); obj["byteLength"] = span.size(); return obj; } #ifdef GLEW_VERSION inline Napi::External<void> operator()(GLsync const& sync) const { return Napi::External<void>::New(Env(), sync); } #endif #ifdef GLFW_APIENTRY_DEFINED inline Napi::Number operator()(GLFWcursor* ptr) const { return Napi::Number::New(Env(), reinterpret_cast<size_t>(ptr)); } inline Napi::Number operator()(GLFWwindow* ptr) const { return Napi::Number::New(Env(), reinterpret_cast<size_t>(ptr)); } inline Napi::Number operator()(GLFWmonitor* ptr) const { return Napi::Number::New(Env(), reinterpret_cast<size_t>(ptr)); } inline Napi::Number operator()(GLFWglproc* ptr) const { return Napi::Number::New(Env(), reinterpret_cast<size_t>(ptr)); } #endif protected: template <typename T> Napi::Value buffer_to_typed_array(Napi::ArrayBuffer const& buf) const { auto len = const_cast<Napi::ArrayBuffer&>(buf).ByteLength() / sizeof(T); if (std::is_same<T, int8_t>() || std::is_same<T, char>()) { return Napi::Int8Array::New(Env(), len, buf, 0); } if (std::is_same<T, uint8_t>() || std::is_same<T, unsigned char>()) { return Napi::Uint8Array::New(Env(), len, buf, 0); } if (std::is_same<T, int16_t>() || std::is_same<T, short>()) { return Napi::Int16Array::New(Env(), len, buf, 0); } if (std::is_same<T, uint16_t>() || std::is_same<T, unsigned short>()) { return Napi::Uint16Array::New(Env(), len, buf, 0); } if (std::is_same<T, int32_t>()) { // return Napi::Int32Array::New(Env(), len, buf, 0); } if (std::is_same<T, uint32_t>()) { // return Napi::Uint32Array::New(Env(), len, buf, 0); } if (std::is_same<T, float>()) { // return Napi::Float32Array::New(Env(), len, buf, 0); } if (std::is_same<T, double>()) { // return Napi::Float64Array::New(Env(), len, buf, 0); } NAPI_THROW(std::runtime_error{"Unknown TypedArray type"}, env.Undefined()); } private: Napi::Env const _env; }; } // namespace nv namespace Napi { namespace details { template <typename T> struct can_make_string<nv::Span<T>> : std::false_type {}; template <typename T> struct vf_fallback<nv::Span<T>> { inline static Value From(napi_env env, nv::Span<T> const& span) { auto obj = Napi::Object::New(env); obj["ptr"] = span.addr(); obj["byteLength"] = span.size(); return obj; } }; template <typename T> struct vf_fallback<std::pair<T, T>> { inline static Value From(napi_env env, std::pair<T, T> const& pair) { auto obj = Array::New(env, 2); obj.Set(0u, Value::From(env, pair.first)); obj.Set(1u, Value::From(env, pair.second)); return obj; } }; } // namespace details } // namespace Napi
0
rapidsai_public_repos/node/modules/core/include/nv_node
rapidsai_public_repos/node/modules/core/include/nv_node/utilities/args.hpp
// Copyright (c) 2020-2021, NVIDIA CORPORATION. // // 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. #pragma once #include "cpp_to_napi.hpp" #include "napi_to_cpp.hpp" #include <napi.h> namespace nv { struct CallbackArgs { // Constructor that accepts the same arguments as the Napi::CallbackInfo constructor CallbackArgs(napi_env env, napi_callback_info info) : CallbackArgs(new Napi::CallbackInfo(env, info), true) {} // Construct a CallbackArgs by proxying to an Napi::CallbackInfo instance CallbackArgs(Napi::CallbackInfo const* info, bool owns_info = false) : owns_info_(owns_info), info_(info){}; // Construct a CallbackArgs by proxying to an Napi::CallbackInfo instance CallbackArgs(Napi::CallbackInfo const& info) : info_(&info){}; ~CallbackArgs() { if (owns_info_) { delete info_; } info_ = nullptr; } // Proxy all the public methods Napi::Env Env() const { return info_->Env(); } Napi::Value NewTarget() const { return info_->NewTarget(); } bool IsConstructCall() const { return info_->IsConstructCall(); } size_t Length() const { return info_->Length(); } Napi::Value This() const { return info_->This(); } void* Data() const { return info_->Data(); } void SetData(void* data) { const_cast<Napi::CallbackInfo*>(info_)->SetData(data); } // the [] operator returns instances with implicit conversion operators from JS to C++ types NapiToCPP const operator[](size_t i) const { return info_->operator[](i); } inline Napi::CallbackInfo const& info() const { return *info_; } inline operator Napi::CallbackInfo const&() const { return *info_; } private: bool owns_info_{false}; Napi::CallbackInfo const* info_{nullptr}; }; } // namespace nv
0
rapidsai_public_repos/node/modules/core
rapidsai_public_repos/node/modules/core/bin/rapidsai_merge_compile_commands.js
#!/usr/bin/env node process.exitCode = require('./exec')('merge-compile-commands', process.argv.slice(2)).status;
0
rapidsai_public_repos/node/modules/core
rapidsai_public_repos/node/modules/core/bin/exec_install_deps.js
#!/usr/bin/env node process.exitCode = require('./exec')('install-deps', process.argv.slice(2)).status;
0
rapidsai_public_repos/node/modules/core
rapidsai_public_repos/node/modules/core/bin/rapidsai_install_native_module.js
#!/usr/bin/env node // Copyright (c) 2022-2023, NVIDIA CORPORATION. // // 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. const { npm_package_name: pkg_name, npm_package_version: npm_pkg_ver, RAPIDSAI_DOWNLOAD_VERSION: pkg_ver = npm_pkg_ver, } = process.env; if (process.env.RAPIDSAI_SKIP_DOWNLOAD === '1') { console.info(`${pkg_name}: Not downloading native module because RAPIDSAI_SKIP_DOWNLOAD=1`); return; } try { require('@rapidsai/core'); } catch (e) { return; } const { getCudaDriverVersion, getArchFromComputeCapabilities, } = require('@rapidsai/core'); require('assert')(require('os').platform() === 'linux', // `${pkg_name} is only supported on Linux`); const { createWriteStream, constants: {F_OK}, } = require('fs'); const Url = require('url'); const Path = require('path'); const https = require('https'); const fs = require('fs/promises'); const stream = require('stream/promises'); const getOS = require('util').promisify(require('getos')); const extraFiles = process.argv.slice(2); const binary_dir = Path.join((() => { try { return Path.dirname(require.resolve(pkg_name)); } catch (e) { const cwd = Path.dirname(Path.join(process.cwd(), 'package.json')); if (cwd.endsWith(Path.join(...pkg_name.split('/')))) { return cwd; } throw e; } })(), 'build', 'Release'); (async () => { const distro = typeof process.env.RAPIDSAI_LINUX_DISTRO !== 'undefined' ? process.env.RAPIDSAI_LINUX_DISTRO : await (async () => { const {dist = '', release = ''} = await getOS(); switch (dist.toLowerCase()) { case 'debian': if ((+release) >= 11) { return 'ubuntu20.04'; } break; case 'ubuntu': if (release.split('.')[0] >= 20) { return 'ubuntu20.04'; } break; default: break; } throw new Error( `${pkg_name}:` + `Detected unsupported Linux distro "${dist} ${release}".\n` + `Currently only Debian 11+ and Ubuntu 20.04+ are supported.\n` + `If you believe you've encountered this message in error, set\n` + `the \`RAPIDSAI_LINUX_DISTRO\` environment variable to one of\n` + `the distributions listed in https://github.com/rapidsai/node/releases\n` + `and reinstall ${pkg_name}`); })(); const cpu_arch = typeof process.env.RAPIDSAI_CPU_ARCHITECTURE !== 'undefined' ? process.env.RAPIDSAI_CPU_ARCHITECTURE : (() => { switch (require('os').arch()) { case 'x64': return 'amd64'; case 'arm': return 'aarch64'; case 'arm64': return 'aarch64'; default: return 'amd64'; } })(); const gpu_arch = typeof process.env.RAPIDSAI_GPU_ARCHITECTURE !== 'undefined' ? process.env.RAPIDSAI_GPU_ARCHITECTURE : getArchFromComputeCapabilities(); const cuda_ver = `cuda${(() => { let cuda_major_ver = 11, rest = []; try { if (typeof process.env.RAPIDSAI_CUDA_VERSION !== 'undefined') { cuda_major_ver = +process.env.RAPIDSAI_CUDA_VERSION; } else if (typeof process.env.CUDA_VERSION_MAJOR !== 'undefined') { cuda_major_ver = +process.env.CUDA_VERSION_MAJOR; } else if (typeof process.env.CUDA_VERSION !== 'undefined') { [cuda_major_ver, ...rest] = process.env.CUDA_VERSION.split('.').map((x) => +x); } else { [cuda_major_ver, ...rest] = getCudaDriverVersion().map((x) => +x); } } catch { /**/ } if (cuda_major_ver < 11) { throw new Error(`${pkg_name}:` + `The detected CUDA driver only supports CUDA toolkit "v${ [cuda_major_ver, ...rest].join('.')}".\n` + `Please update to a CUDA driver that supports at least CUDA 11.6.2.\n` + `An archive of all CUDA driver and toolkit releases can be found at:\n` + ` https://developer.nvidia.com/cuda-toolkit-archive\n\n` + `The driver version that aligns with a CUDA toolkit can be found in\n` + `the CUDA toolkit release notes.\n\n` + `If you believe you've encountered this message in error, set\n` + `the \`RAPIDSAI_CUDA_VERSION\` environment variable to one of\n` + `the CUDA versions listed in the release artifacts here:\n` + ` https://github.com/rapidsai/node/releases/v${pkg_ver}\n` + `and reinstall ${pkg_name}`); } return Math.min(11, cuda_major_ver || 11); })()}`; const PKG_NAME = pkg_name.replace('@', '').replace('/', '_'); const MOD_NAME = [PKG_NAME, pkg_ver, cuda_ver, distro, cpu_arch, gpu_arch ? `sm${gpu_arch}` : ``] .filter(Boolean) .join('-'); await Promise.all([ [ `${PKG_NAME}.node`, `${MOD_NAME}.node`, ], ...extraFiles.map((slug) => [slug, slug]) ].map(([localSlug, remoteSlug]) => maybeDownload(localSlug, remoteSlug))); })() .catch((e) => { if (e) console.error(e); return 1; }) .then((code = 0) => process.exit(code)); function maybeDownload(localSlug, remoteSlug) { return new Promise((resolve, reject) => { const dst = Path.join(binary_dir, localSlug); fs.access(dst, F_OK) .catch(() => { return fs.access(binary_dir, F_OK) .catch(() => fs.mkdir(binary_dir, {recursive: true, mode: `0755`})) .then(() => fetch({ hostname: `github.com`, path: `/rapidsai/node/releases/download/v${pkg_ver}/${remoteSlug}`, headers: { [`Accept`]: `application/octet-stream`, [`Accept-Encoding`]: `br;q=1.0, gzip;q=0.8, deflate;q=0.6, identity;q=0.4, *;q=0.1` } }).then((res) => stream.pipeline(res, createWriteStream(dst)))); }) .then(resolve, reject); }); } function fetch(options = {}, numRedirects = 0) { return new Promise((resolve, reject) => { https .get(options, (res) => { if (res.statusCode > 300 && res.statusCode < 400 && res.headers.location) { const {hostname = options.hostname, path, ...rest} = Url.parse(res.headers.location); if (numRedirects < 10) { fetch({...rest, headers: options.headers, hostname, path}, numRedirects + 1) .then(resolve, reject); } else { reject('Too many redirects'); } } else if (res.statusCode > 199 && res.statusCode < 300) { const encoding = res.headers['content-encoding'] || ''; if (encoding.includes('gzip')) { res = res.pipe(require('zlib').createGunzip()); } else if (encoding.includes('deflate')) { res = res.pipe(require('zlib').createInflate()); } else if (encoding.includes('br')) { res = res.pipe(require('zlib').createBrotliDecompress()); } resolve(res); } else { res.on('error', (e) => {}).destroy(); reject({ statusCode: res.statusCode, statusMessage: res.statusMessage, url: new URL(options.path, `https://${options.hostname}`), }); } }) .on('error', (e) => {}) .end(); }); }
0
rapidsai_public_repos/node/modules/core
rapidsai_public_repos/node/modules/core/bin/exec.js
#!/usr/bin/env node module.exports = function (cmd, args, env = {}) { try { require('dotenv').config(); } catch (e) { }; var Path = require('path'); var env_ = Object.assign({}, process.env, env); var binp = Path.join(__dirname, '../', 'node_modules', '.bin'); var opts = { // shell: true, stdio: 'inherit', cwd: process.cwd(), env: Object.assign({}, env_, { PATH: `${env_.PATH}:${binp}` }) }; var name = (() => { switch (require('os').platform()) { case 'win32': return 'windows.sh' default: return 'linux.sh' } })(); return require('child_process').spawnSync( Path.join(__dirname, cmd, name), args, opts); } if (require.main === module) { process.exitCode = module.exports(process.argv[2], process.argv.slice(3)).status; }
0
rapidsai_public_repos/node/modules/core/bin
rapidsai_public_repos/node/modules/core/bin/merge-compile-commands/linux.sh
#!/usr/bin/env bash set -Eeo pipefail if ! type jq >/dev/null 2>&1; then exit 0; fi cwd="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"; RAPIDS_MODULES_PATH="$(realpath "$cwd/../../../")"; if [[ "$(basename "$RAPIDS_MODULES_PATH")" != modules ]]; then exit 0; fi # Get the latest `compile_commands.json` from each module compile_command_files="$( \ find "$RAPIDS_MODULES_PATH" -mindepth 1 -maxdepth 1 -type d | xargs -n1 -I__ \ bash -c 'find __ -type f \ -path "*build/*/compile_commands.json" \ -exec stat -c "%y %n" {} + \ | sort -r \ | head -n1' \ | grep -Eo "$RAPIDS_MODULES_PATH/.*$" || echo "" \ )"; # Now merge them all together jq -s '.|flatten' $(echo "$compile_command_files") \ > "$RAPIDS_MODULES_PATH/../compile_commands.json" \ || true;
0
rapidsai_public_repos/node/modules/core/bin
rapidsai_public_repos/node/modules/core/bin/install-deps/debian.sh
#!/usr/bin/env bash set -Eeo pipefail APT_DEPS="" CMAKE_OPTS="" INSTALL_CMAKE="" INSTALLED_CLANGD="" OS_RELEASE=$(lsb_release -cs) IS_UBUNTU=$(. /etc/os-release;[ "$ID" = "ubuntu" ] && echo 1 || echo 0) ask_before_install() { while true; do read -p "$1 " CHOICE </dev/tty case $CHOICE in [Nn]* ) break;; [Yy]* ) eval $2; break;; * ) echo "Please answer 'y' or 'n'";; esac done } check_apt() { [ -n "$(apt policy $1 2> /dev/null | grep -i 'Installed: (none)')" ] && echo "0" || echo "1"; } install_apt_deps() { for DEP in $@; do if [ "$(check_apt $DEP)" -eq "0" ]; then ask_before_install \ "Missing $DEP. Install $DEP now? (y/n)" \ "APT_DEPS=\${APT_DEPS:+\$APT_DEPS }$DEP"; fi; done } install_cmake() { INSTALL_CMAKE=1 install_apt_deps zlib1g-dev } install_vscode() { APT_DEPS="${APT_DEPS:+$APT_DEPS }code" if [ ! -d "/etc/apt/sources.list.d/vscode.list" ]; then curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > packages.microsoft.gpg sudo install -o root -g root -m 644 packages.microsoft.gpg /usr/share/keyrings/ && rm packages.microsoft.gpg sudo sh -c 'echo "deb [arch=amd64 signed-by=/usr/share/keyrings/packages.microsoft.gpg] https://packages.microsoft.com/repos/vscode stable main" > /etc/apt/sources.list.d/vscode.list' fi } install_clangd() { INSTALLED_CLANGD=1 APT_DEPS="${APT_DEPS:+$APT_DEPS }clangd-17 clang-format-17" if [ ! -d "/etc/apt/sources.list.d/llvm.list" ]; then curl -fsSL https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - echo "deb http://apt.llvm.org/$OS_RELEASE/ llvm-toolchain-$OS_RELEASE-17 main deb-src http://apt.llvm.org/$OS_RELEASE/ llvm-toolchain-$OS_RELEASE-17 main " | sudo tee /etc/apt/sources.list.d/llvm.list fi } install_vscode_extensions() { CODE="$1" for EXT in ${@:2}; do if [ -z "$($CODE --list-extensions | grep $EXT)" ]; then ask_before_install \ "Missing $CODE extension $EXT. Install $EXT now? (y/n)" \ "$CODE --install-extension $EXT" fi done } [ -z "$(which cmake)" ] && ask_before_install "Missing cmake. Install cmake (y/n)?" "install_cmake" [ -z "$(which code)" ] && ask_before_install "Missing vscode. Install vscode (y/n)?" "install_vscode" [ -z "$(which clangd)" ] && ask_before_install "Missing clangd. Install clangd (y/n)?" "install_clangd" # 1. cuSpatial dependencies # 2. X11 dependencies # 3. node-canvas dependencies # 4. GLEW dependencies install_apt_deps jq software-properties-common \ libgdal-dev \ libx11-dev libxrandr-dev libxinerama-dev libxcursor-dev \ libcairo2-dev libpango1.0-dev libjpeg-dev libgif-dev librsvg2-dev \ build-essential libxmu-dev libxi-dev libgl1-mesa-dev libegl1-mesa-dev libglu1-mesa-dev if [ -n "$INSTALL_CMAKE" ]; then # Ensure Qt-5 is installed for CMake GUI, otherwise no cmake GUI if [ "$(check_apt qt5-default)" -eq "0" ]; then ask_before_install "Missing qt5-default needed by CMake GUI. Install it now (y/n)?" \ 'APT_DEPS=${APT_DEPS:+$APT_DEPS }qt5-default; CMAKE_OPTS=${CMAKE_OPTS:+$CMAKE_OPTS }--qt-gui;'; fi if [ "$(check_apt libcurl4-openssl-dev)" -eq "0" ] || [ "$(check_apt libssl-dev)" -eq "0" ]; then ask_before_install "Missing libcurl4-openssl-dev and/or libssl-dev needed by CMake. Install them now (y/n)?" \ 'APT_DEPS=${APT_DEPS:+$APT_DEPS }libcurl4-openssl-dev libssl-dev; CMAKE_OPTS=${CMAKE_OPTS:+$CMAKE_OPTS }--system-curl;'; fi fi if [ -n "$APT_DEPS" ]; then sudo apt update sudo apt install -y $APT_DEPS; if [ -n "$INSTALLED_CLANGD" ]; then sudo update-alternatives --install /usr/bin/clangd clangd /usr/bin/clangd-17 100 sudo update-alternatives --set clangd /usr/bin/clangd fi fi if [ -n "$INSTALL_CMAKE" ]; then NJOBS=$(nproc --ignore=2) CMAKE_OPTS="${CMAKE_OPTS:+$CMAKE_OPTS } --parallel=$NJOBS" CMAKE_VERSION=$(curl -s https://api.github.com/repos/Kitware/CMake/releases/latest | jq -r ".tag_name" | tr -d 'v') wget -O- https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/cmake-${CMAKE_VERSION}.tar.gz | tar -xz \ && cd cmake-${CMAKE_VERSION} \ && ./bootstrap $CMAKE_OPTS \ && sudo make install -j${NJOBS} \ && cd - && rm -rf cmake-${CMAKE_VERSION} fi for CODE in "code" "code-insiders"; do # 1. Install Microsoft C++ Tools if it isn't installed # 2. Install vscode-clangd if it isn't installed if [ -n "$(which $CODE)" ]; then install_vscode_extensions "$CODE" "ms-vscode.cpptools" "llvm-vs-code-extensions.vscode-clangd"; fi done
0
rapidsai_public_repos/node/modules/core/bin
rapidsai_public_repos/node/modules/core/bin/install-deps/linux.sh
#!/usr/bin/env bash set -Eeo pipefail SCRIPT_DIR=$(dirname "$(realpath "$0")") IS_DEBIAN=$(. /etc/os-release;[ "$ID_LIKE" = "debian" ] && echo 1 || echo 0) if [ $IS_DEBIAN ]; then source "$SCRIPT_DIR/debian.sh" fi # TODO: other distros
0
rapidsai_public_repos/node/modules/core
rapidsai_public_repos/node/modules/core/cmake/versions.json
{ "packages": { "nvcomp": { "version": "2.4.1", "git_url": "https://github.com/NVIDIA/nvcomp.git", "git_tag": "v2.2.0", "proprietary_binary": { "x86_64-linux": "http://developer.download.nvidia.com/compute/nvcomp/${version}/local_installers/nvcomp_${version}_Linux_CUDA_11.x.tgz" } }, "Thrust": { "version": "1.17.2.0", "git_url": "https://github.com/NVIDIA/thrust.git", "git_tag": "1.17.2", "always_download": "NO", "patches": [ { "file": "Thrust/install_rules.diff", "issue": "Thrust 1.X installs incorrect files [https://github.com/NVIDIA/thrust/issues/1790]", "fixed_in": "2.0.0" }, { "file": "${current_json_dir}/patches/thrust_transform_iter_with_reduce_by_key.diff", "issue": "Support transform_output_iterator as output of reduce by key [https://github.com/NVIDIA/thrust/pull/1805]", "fixed_in": "2.1" }, { "file": "${current_json_dir}/patches/thrust_faster_sort_compile_times.diff", "issue": "Improve Thrust sort compile times by not unrolling loops for inlined comparators [https://github.com/rapidsai/cudf/pull/10577]", "fixed_in": "" }, { "file": "${current_json_dir}/patches/thrust_faster_scan_compile_times.diff", "issue": "Improve Thrust scan compile times by reducing the number of kernels generated [https://github.com/rapidsai/cudf/pull/8183]", "fixed_in": "" } ] } } }
0
rapidsai_public_repos/node/modules/core/cmake
rapidsai_public_repos/node/modules/core/cmake/patches/cuml.patch
diff --git a/cpp/cmake/thirdparty/get_nccl.cmake b/cpp/cmake/thirdparty/get_nccl.cmake index a80eefab..a69ae4ca 100644 --- a/cpp/cmake/thirdparty/get_nccl.cmake +++ b/cpp/cmake/thirdparty/get_nccl.cmake @@ -16,23 +16,20 @@ function(find_and_configure_nccl) - if(TARGET nccl::nccl) + if(TARGET NCCL::NCCL) return() endif() rapids_find_generate_module(NCCL HEADER_NAMES nccl.h LIBRARY_NAMES nccl + BUILD_EXPORT_SET cuml-exports ) # Currently NCCL has no CMake build-system so we require # it built and installed on the machine already - rapids_find_package(NCCL REQUIRED) + rapids_find_package(NCCL REQUIRED BUILD_EXPORT_SET cuml-exports) endfunction() find_and_configure_nccl() - - - -
0