Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ltuZA-0001VV-HJ for pgsql-general@arkaria.postgresql.org; Thu, 17 Jun 2021 16:08:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ltuZ9-0005gH-Cj for pgsql-general@arkaria.postgresql.org; Thu, 17 Jun 2021 16:08:27 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ltuZ8-0005g9-VG for pgsql-general@lists.postgresql.org; Thu, 17 Jun 2021 16:08:27 +0000 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ltuZ3-0004Zf-Ti for pgsql-general@lists.postgresql.org; Thu, 17 Jun 2021 16:08:26 +0000 Received: by mail-pj1-x102c.google.com with SMTP id bb10-20020a17090b008ab029016eef083425so5991756pjb.5 for ; Thu, 17 Jun 2021 09:08:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=illuminatedcomputing-com.20150623.gappssmtp.com; s=20150623; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=s/qCxFW+NZhFebjv8XVDSpZ6beHN7fhoPYrqHxIuvrg=; b=AkCZ3jjwR0t3mFgpk84YhqAPOeNBI9H273br1XlPZRbHwKzMln9vrDf9j1LhFrbsTU MKB3Iw6EgXQ5hAe4TYOuTc5SnvXMc883cZl8BzOdG/fSSMIN0BY448sOt+//qISqffip 32rKyE9vuolAAJrqEbH2Gap6W3Ag4LwFvmqPqNUG/4ILgBPK2MUOrl+INwvn7g+icpM5 jKorOQOvCZVHuyYo1rd82elKMRDQf+vLSEQVoD5luiCj9YRbfobKDeTnyWsOr2WdmIXE /17f3VuYbkPVWtm3MQAFg9GfkywKpu7bDbJkHOf88opdpsgmsbLfOk2z6M4UjoNMX38G D3Ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=s/qCxFW+NZhFebjv8XVDSpZ6beHN7fhoPYrqHxIuvrg=; b=TiMp9pQ+iouAjih4z7bnnvXEAqLZgKnoksm6itx1xZMtU1plnpHmoplNJfBmjetu3E ara1iPaCdgOyRW9kdp0w19cCEsj45ieHCk4P9ZdtMseFhCgKBwtFAcG/z+CiI9K1MwEJ Pl0k7hs8e63M0Fb7xjbvhtF8BHVw9C+1vF59mI8WK1NR3dhfRZnljV2tgjuo0ETSL03I AdWZjZVv8sj4vhjDXxGYEG9DZpIIdMzwzL11CNAA6H5wl/3pStNepxl0m1U3TqF/KOGu u64oH+RO2WWCHnuLIBFOZNtbGaknnSKDyCeo5oDRwbfry5z3OeTd/m7lE53RpSiTSK6H mzuQ== X-Gm-Message-State: AOAM532u+DRE7/Fy1esEiGTMt7OJcjg+ELCiVFwfpKUZRKoKfKmaYYip gyOmu1EF5DwmaxwTXhcBDAwgodwi3oNUag== X-Google-Smtp-Source: ABdhPJzw4yS+rCdJb9UgFrDdrFYKyxQdDkSlWpb0xLs0oYyq0noBEA2xvwnDOYAFSWXtmZI51B5M3A== X-Received: by 2002:a17:902:dac5:b029:11f:16ff:f93e with SMTP id q5-20020a170902dac5b029011f16fff93emr654283plx.60.1623946099500; Thu, 17 Jun 2021 09:08:19 -0700 (PDT) Received: from [192.168.2.144] ([50.53.109.254]) by smtp.googlemail.com with ESMTPSA id mg22sm5395358pjb.26.2021.06.17.09.08.18 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 17 Jun 2021 09:08:18 -0700 (PDT) Subject: Re: Treating float arrays as vectors? To: pgsql-general@lists.postgresql.org References: From: Paul Jungwirth Message-ID: Date: Thu, 17 Jun 2021 09:08:18 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 6/17/21 7:13 AM, Celia McInnis wrote: > I would love it if there was a vector data type in postgresql along with > such vector operations as addition, subtraction, scalar multiplication, > cross product, dot product, normalization, length and various sorts of > vector distances. I wrote an extension to define vector-based functions that take & return numeric arrays: https://github.com/pjungwir/floatvec It only has basic arithmetic, but matrix math functions could be added. If you want aggregate functions instead I wrote another extension for that: https://github.com/pjungwir/aggs_for_vecs I haven't touched either in a while, but if you find they have problems on modern versions of Postgres, let me know and I should be able to get them updated quickly. I experimented a bit with an AVX implementation, and it showed a worthwhile performance improvement, but I never got around to adding it to all functions, so it was just a proof-of-concept. I could dust that off if you're interested. But since the extension is C things are already pretty fast. Yours, -- Paul ~{:-) pj@illuminatedcomputing.com