mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 23:21:59 +00:00
Add a test
This commit is contained in:
parent
73eba44238
commit
968a559917
45
tests/queries/0_stateless/03269_bf16.reference
Normal file
45
tests/queries/0_stateless/03269_bf16.reference
Normal file
@ -0,0 +1,45 @@
|
||||
1 -1 1.09375 -1.09375 1 -1 1.09375 -1.09375 18446744000000000000 -0 inf -inf nan
|
||||
1.09375 1.09375 1.09375 1
|
||||
1 1 0 1 1
|
||||
0 2.1875 1.1962891 1 Float32 Float32 Float32 Float64
|
||||
-0.006250000000000089 2.19375 1.203125 1.0057142857142858 Float64 Float64 Float64 Float64
|
||||
0 0 1 0
|
||||
1000 1000 1 0
|
||||
2000 2000 1 0
|
||||
3000 2992 0 8
|
||||
4000 4000 1 0
|
||||
5000 4992 0 8
|
||||
6000 5984 0 16
|
||||
7000 6976 0 24
|
||||
8000 8000 1 0
|
||||
9000 8960 0 40
|
||||
49995000 49855104 4999.5 4985.5104 0 0 9999 9984 10000 925 10000 925
|
||||
0 0 1 0
|
||||
1000 1000 1 0
|
||||
2000 2000 1 0
|
||||
3000 2992 0 8
|
||||
4000 4000 1 0
|
||||
5000 4992 0 8
|
||||
6000 5984 0 16
|
||||
7000 6976 0 24
|
||||
8000 8000 1 0
|
||||
9000 8960 0 40
|
||||
49995000 49855104 4999.5 4985.5104 0 0 9999 9984 10000 925 10000 925
|
||||
Row 1:
|
||||
──────
|
||||
a32: [0,0.5,1,1.5,2,2.5,3,3.5,4,4.5,5,5.5,6,6.5,7,7.5,8,8.5,9,9.5,10,10.5,11,11.5,12,12.5,13,13.5,14,14.5,15,15.5,16,16.5,17,17.5,18,18.5,19,19.5,20,20.5,21,21.5,22,22.5,23,23.5,24,24.5,25,25.5,26,26.5,27,27.5,28,28.5,29,29.5,30,30.5,31,31.5,32,32.5,33,33.5,34,34.5,35,35.5,36,36.5,37,37.5,38,38.5,39,39.5,40,40.5,41,41.5,42,42.5,43,43.5,44,44.5,45,45.5,46,46.5,47,47.5,48,48.5,49,49.5,50,50.5,51,51.5,52,52.5,53,53.5,54,54.5,55,55.5,56,56.5,57,57.5,58,58.5,59,59.5,60,60.5,61,61.5,62,62.5,63,63.5,64,64.5,65,65.5,66,66.5,67,67.5,68,68.5,69,69.5,70,70.5,71,71.5,72,72.5,73,73.5,74,74.5,75,75.5,76,76.5,77,77.5,78,78.5,79,79.5,80,80.5,81,81.5,82,82.5,83,83.5,84,84.5,85,85.5,86,86.5,87,87.5,88,88.5,89,89.5,90,90.5,91,91.5,92,92.5,93,93.5,94,94.5,95,95.5,96,96.5,97,97.5,98,98.5,99,99.5,100,100.5,101,101.5,102,102.5,103,103.5,104,104.5,105,105.5,106,106.5,107,107.5,108,108.5,109,109.5,110,110.5,111,111.5,112,112.5,113,113.5,114,114.5,115,115.5,116,116.5,117,117.5,118,118.5,119,119.5,120,120.5,121,121.5,122,122.5,123,123.5,124,124.5,125,125.5,126,126.5,127,127.5,128,128.5,129,129.5,130,130.5,131,131.5,132,132.5,133,133.5,134,134.5,135,135.5,136,136.5,137,137.5,138,138.5,139,139.5,140,140.5,141,141.5,142,142.5,143,143.5,144,144.5,145,145.5,146,146.5,147,147.5,148,148.5,149,149.5,150,150.5,151,151.5,152,152.5,153,153.5,154,154.5,155,155.5,156,156.5,157,157.5,158,158.5,159,159.5,160,160.5,161,161.5,162,162.5,163,163.5,164,164.5,165,165.5,166,166.5,167,167.5,168,168.5,169,169.5,170,170.5,171,171.5,172,172.5,173,173.5,174,174.5,175,175.5,176,176.5,177,177.5,178,178.5,179,179.5,180,180.5,181,181.5,182,182.5,183,183.5,184,184.5,185,185.5,186,186.5,187,187.5,188,188.5,189,189.5,190,190.5,191,191.5]
|
||||
a16: [0,0.5,1,1.5,2,2.5,3,3.5,4,4.5,5,5.5,6,6.5,7,7.5,8,8.5,9,9.5,10,10.5,11,11.5,12,12.5,13,13.5,14,14.5,15,15.5,16,16.5,17,17.5,18,18.5,19,19.5,20,20.5,21,21.5,22,22.5,23,23.5,24,24.5,25,25.5,26,26.5,27,27.5,28,28.5,29,29.5,30,30.5,31,31.5,32,32.5,33,33.5,34,34.5,35,35.5,36,36.5,37,37.5,38,38.5,39,39.5,40,40.5,41,41.5,42,42.5,43,43.5,44,44.5,45,45.5,46,46.5,47,47.5,48,48.5,49,49.5,50,50.5,51,51.5,52,52.5,53,53.5,54,54.5,55,55.5,56,56.5,57,57.5,58,58.5,59,59.5,60,60.5,61,61.5,62,62.5,63,63.5,64,64.5,65,65.5,66,66.5,67,67.5,68,68.5,69,69.5,70,70.5,71,71.5,72,72.5,73,73.5,74,74.5,75,75.5,76,76.5,77,77.5,78,78.5,79,79.5,80,80.5,81,81.5,82,82.5,83,83.5,84,84.5,85,85.5,86,86.5,87,87.5,88,88.5,89,89.5,90,90.5,91,91.5,92,92.5,93,93.5,94,94.5,95,95.5,96,96.5,97,97.5,98,98.5,99,99.5,100,100.5,101,101.5,102,102.5,103,103.5,104,104.5,105,105.5,106,106.5,107,107.5,108,108.5,109,109.5,110,110.5,111,111.5,112,112.5,113,113.5,114,114.5,115,115.5,116,116.5,117,117.5,118,118.5,119,119.5,120,120.5,121,121.5,122,122.5,123,123.5,124,124.5,125,125.5,126,126.5,127,127.5,128,128,129,129,130,130,131,131,132,132,133,133,134,134,135,135,136,136,137,137,138,138,139,139,140,140,141,141,142,142,143,143,144,144,145,145,146,146,147,147,148,148,149,149,150,150,151,151,152,152,153,153,154,154,155,155,156,156,157,157,158,158,159,159,160,160,161,161,162,162,163,163,164,164,165,165,166,166,167,167,168,168,169,169,170,170,171,171,172,172,173,173,174,174,175,175,176,176,177,177,178,178,179,179,180,180,181,181,182,182,183,183,184,184,185,185,186,186,187,187,188,188,189,189,190,190,191,191]
|
||||
a32_1: [1,1.5,2,2.5,3,3.5,4,4.5,5,5.5,6,6.5,7,7.5,8,8.5,9,9.5,10,10.5,11,11.5,12,12.5,13,13.5,14,14.5,15,15.5,16,16.5,17,17.5,18,18.5,19,19.5,20,20.5,21,21.5,22,22.5,23,23.5,24,24.5,25,25.5,26,26.5,27,27.5,28,28.5,29,29.5,30,30.5,31,31.5,32,32.5,33,33.5,34,34.5,35,35.5,36,36.5,37,37.5,38,38.5,39,39.5,40,40.5,41,41.5,42,42.5,43,43.5,44,44.5,45,45.5,46,46.5,47,47.5,48,48.5,49,49.5,50,50.5,51,51.5,52,52.5,53,53.5,54,54.5,55,55.5,56,56.5,57,57.5,58,58.5,59,59.5,60,60.5,61,61.5,62,62.5,63,63.5,64,64.5,65,65.5,66,66.5,67,67.5,68,68.5,69,69.5,70,70.5,71,71.5,72,72.5,73,73.5,74,74.5,75,75.5,76,76.5,77,77.5,78,78.5,79,79.5,80,80.5,81,81.5,82,82.5,83,83.5,84,84.5,85,85.5,86,86.5,87,87.5,88,88.5,89,89.5,90,90.5,91,91.5,92,92.5,93,93.5,94,94.5,95,95.5,96,96.5,97,97.5,98,98.5,99,99.5,100,100.5,101,101.5,102,102.5,103,103.5,104,104.5,105,105.5,106,106.5,107,107.5,108,108.5,109,109.5,110,110.5,111,111.5,112,112.5,113,113.5,114,114.5,115,115.5,116,116.5,117,117.5,118,118.5,119,119.5,120,120.5,121,121.5,122,122.5,123,123.5,124,124.5,125,125.5,126,126.5,127,127.5,128,128.5,129,129.5,130,130.5,131,131.5,132,132.5,133,133.5,134,134.5,135,135.5,136,136.5,137,137.5,138,138.5,139,139.5,140,140.5,141,141.5,142,142.5,143,143.5,144,144.5,145,145.5,146,146.5,147,147.5,148,148.5,149,149.5,150,150.5,151,151.5,152,152.5,153,153.5,154,154.5,155,155.5,156,156.5,157,157.5,158,158.5,159,159.5,160,160.5,161,161.5,162,162.5,163,163.5,164,164.5,165,165.5,166,166.5,167,167.5,168,168.5,169,169.5,170,170.5,171,171.5,172,172.5,173,173.5,174,174.5,175,175.5,176,176.5,177,177.5,178,178.5,179,179.5,180,180.5,181,181.5,182,182.5,183,183.5,184,184.5,185,185.5,186,186.5,187,187.5,188,188.5,189,189.5,190,190.5,191,191.5,192,192.5]
|
||||
a16_1: [1,1.5,2,2.5,3,3.5,4,4.5,5,5.5,6,6.5,7,7.5,8,8.5,9,9.5,10,10.5,11,11.5,12,12.5,13,13.5,14,14.5,15,15.5,16,16.5,17,17.5,18,18.5,19,19.5,20,20.5,21,21.5,22,22.5,23,23.5,24,24.5,25,25.5,26,26.5,27,27.5,28,28.5,29,29.5,30,30.5,31,31.5,32,32.5,33,33.5,34,34.5,35,35.5,36,36.5,37,37.5,38,38.5,39,39.5,40,40.5,41,41.5,42,42.5,43,43.5,44,44.5,45,45.5,46,46.5,47,47.5,48,48.5,49,49.5,50,50.5,51,51.5,52,52.5,53,53.5,54,54.5,55,55.5,56,56.5,57,57.5,58,58.5,59,59.5,60,60.5,61,61.5,62,62.5,63,63.5,64,64.5,65,65.5,66,66.5,67,67.5,68,68.5,69,69.5,70,70.5,71,71.5,72,72.5,73,73.5,74,74.5,75,75.5,76,76.5,77,77.5,78,78.5,79,79.5,80,80.5,81,81.5,82,82.5,83,83.5,84,84.5,85,85.5,86,86.5,87,87.5,88,88.5,89,89.5,90,90.5,91,91.5,92,92.5,93,93.5,94,94.5,95,95.5,96,96.5,97,97.5,98,98.5,99,99.5,100,100.5,101,101.5,102,102.5,103,103.5,104,104.5,105,105.5,106,106.5,107,107.5,108,108.5,109,109.5,110,110.5,111,111.5,112,112.5,113,113.5,114,114.5,115,115.5,116,116.5,117,117.5,118,118.5,119,119.5,120,120.5,121,121.5,122,122.5,123,123.5,124,124.5,125,125.5,126,126.5,127,127.5,128,128.5,129,129,130,130,131,131,132,132,133,133,134,134,135,135,136,136,137,137,138,138,139,139,140,140,141,141,142,142,143,143,144,144,145,145,146,146,147,147,148,148,149,149,150,150,151,151,152,152,153,153,154,154,155,155,156,156,157,157,158,158,159,159,160,160,161,161,162,162,163,163,164,164,165,165,166,166,167,167,168,168,169,169,170,170,171,171,172,172,173,173,174,174,175,175,176,176,177,177,178,178,179,179,180,180,181,181,182,182,183,183,184,184,185,185,186,186,187,187,188,188,189,189,190,190,191,191,192,192]
|
||||
dotProduct(a32, a32_1): 4736944 -- 4.74 million
|
||||
dotProduct(a16, a16_1): 4726688 -- 4.73 million
|
||||
cosineDistance(a32, a32_1): 0.000010093636084174129
|
||||
cosineDistance(a16, a16_1): 0.00001010226319664298
|
||||
L2Distance(a32, a32_1): 19.595917942265423
|
||||
L2Distance(a16, a16_1): 19.595917942265423
|
||||
L1Distance(a32, a32_1): 384
|
||||
L1Distance(a16, a16_1): 384
|
||||
LinfDistance(a32, a32_1): 1
|
||||
LinfDistance(a16, a16_1): 1
|
||||
LpDistance(a32, a32_1, 5): 3.2875036590344515
|
||||
LpDistance(a16, a16_1, 5): 3.2875036590344515
|
88
tests/queries/0_stateless/03269_bf16.sql
Normal file
88
tests/queries/0_stateless/03269_bf16.sql
Normal file
@ -0,0 +1,88 @@
|
||||
SET allow_experimental_bfloat16_type = 1;
|
||||
|
||||
-- This is a smoke test, non exhaustive.
|
||||
|
||||
-- Conversions
|
||||
|
||||
SELECT
|
||||
1::BFloat16,
|
||||
-1::BFloat16,
|
||||
1.1::BFloat16,
|
||||
-1.1::BFloat16,
|
||||
CAST(1 AS BFloat16),
|
||||
CAST(-1 AS BFloat16),
|
||||
CAST(1.1 AS BFloat16),
|
||||
CAST(-1.1 AS BFloat16),
|
||||
CAST(0xFFFFFFFFFFFFFFFF AS BFloat16),
|
||||
CAST(-0.0 AS BFloat16),
|
||||
CAST(inf AS BFloat16),
|
||||
CAST(-inf AS BFloat16),
|
||||
CAST(nan AS BFloat16);
|
||||
|
||||
-- Conversions back
|
||||
|
||||
SELECT
|
||||
CAST(1.1::BFloat16 AS BFloat16),
|
||||
CAST(1.1::BFloat16 AS Float32),
|
||||
CAST(1.1::BFloat16 AS Float64),
|
||||
CAST(1.1::BFloat16 AS Int8);
|
||||
|
||||
-- Comparisons
|
||||
|
||||
SELECT
|
||||
1.1::BFloat16 = 1.1::BFloat16,
|
||||
1.1::BFloat16 < 1.1,
|
||||
1.1::BFloat16 > 1.1,
|
||||
1.1::BFloat16 > 1,
|
||||
1.1::BFloat16 = 1.09375;
|
||||
|
||||
-- Arithmetic
|
||||
|
||||
SELECT
|
||||
1.1::BFloat16 - 1.1::BFloat16 AS a,
|
||||
1.1::BFloat16 + 1.1::BFloat16 AS b,
|
||||
1.1::BFloat16 * 1.1::BFloat16 AS c,
|
||||
1.1::BFloat16 / 1.1::BFloat16 AS d,
|
||||
toTypeName(a), toTypeName(b), toTypeName(c), toTypeName(d);
|
||||
|
||||
SELECT
|
||||
1.1::BFloat16 - 1.1 AS a,
|
||||
1.1 + 1.1::BFloat16 AS b,
|
||||
1.1::BFloat16 * 1.1 AS c,
|
||||
1.1 / 1.1::BFloat16 AS d,
|
||||
toTypeName(a), toTypeName(b), toTypeName(c), toTypeName(d);
|
||||
|
||||
-- Tables
|
||||
|
||||
DROP TABLE IF EXISTS t;
|
||||
CREATE TEMPORARY TABLE t (n UInt64, x BFloat16);
|
||||
INSERT INTO t SELECT number, number FROM numbers(10000);
|
||||
SELECT *, n = x, n - x FROM t WHERE n % 1000 = 0 ORDER BY n;
|
||||
|
||||
-- Aggregate functions
|
||||
|
||||
SELECT sum(n), sum(x), avg(n), avg(x), min(n), min(x), max(n), max(x), uniq(n), uniq(x), uniqExact(n), uniqExact(x) FROM t;
|
||||
|
||||
-- MergeTree
|
||||
|
||||
DROP TABLE t;
|
||||
CREATE TABLE t (n UInt64, x BFloat16) ENGINE = MergeTree ORDER BY n;
|
||||
INSERT INTO t SELECT number, number FROM numbers(10000);
|
||||
SELECT *, n = x, n - x FROM t WHERE n % 1000 = 0 ORDER BY n;
|
||||
SELECT sum(n), sum(x), avg(n), avg(x), min(n), min(x), max(n), max(x), uniq(n), uniq(x), uniqExact(n), uniqExact(x) FROM t;
|
||||
|
||||
-- Distances
|
||||
|
||||
WITH
|
||||
arrayMap(x -> toFloat32(x) / 2, range(384)) AS a32,
|
||||
arrayMap(x -> toBFloat16(x) / 2, range(384)) AS a16,
|
||||
arrayMap(x -> x + 1, a32) AS a32_1,
|
||||
arrayMap(x -> x + 1, a16) AS a16_1
|
||||
SELECT a32, a16, a32_1, a16_1,
|
||||
dotProduct(a32, a32_1), dotProduct(a16, a16_1),
|
||||
cosineDistance(a32, a32_1), cosineDistance(a16, a16_1),
|
||||
L2Distance(a32, a32_1), L2Distance(a16, a16_1),
|
||||
L1Distance(a32, a32_1), L1Distance(a16, a16_1),
|
||||
LinfDistance(a32, a32_1), LinfDistance(a16, a16_1),
|
||||
LpDistance(a32, a32_1, 5), LpDistance(a16, a16_1, 5)
|
||||
FORMAT Vertical;
|
Loading…
Reference in New Issue
Block a user